From patchwork Fri Sep 16 18:31:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Knut Omang X-Patchwork-Id: 9336403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 257F7601C2 for ; Fri, 16 Sep 2016 18:34:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B7E22A06D for ; Fri, 16 Sep 2016 18:34:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 100A32A073; Fri, 16 Sep 2016 18:34:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93DFA2A06C for ; Fri, 16 Sep 2016 18:33:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933940AbcIPSdX (ORCPT ); Fri, 16 Sep 2016 14:33:23 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:48152 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934319AbcIPSdS (ORCPT ); Fri, 16 Sep 2016 14:33:18 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8GIWgnf012612 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Sep 2016 18:32:43 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u8GIWgE2007076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Sep 2016 18:32:42 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u8GIWg7i018859; Fri, 16 Sep 2016 18:32:42 GMT Received: from abi.no.oracle.com (/10.172.144.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 16 Sep 2016 11:32:41 -0700 From: Knut Omang To: Doug Ledford Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Knut Omang , Sean Hefty , Hal Rosenstock , Matan Barak , Sagi Grimberg , Yishai Hadas , Leon Romanovsky , Majd Dibbiny , Eran Ben Elisha , Or Gerlitz Subject: [PATCH v2 5/8] ib_uverbs: Add padding to end align ib_uverbs_reg_mr_resp Date: Fri, 16 Sep 2016 20:31:16 +0200 Message-Id: X-Mailer: git-send-email 2.5.5 In-Reply-To: References: In-Reply-To: References: X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ib_uverbs_reg_mr_resp structure was not 64 bit end aligned as required by the protocol. This causes alignment issues if a device specific driver needs to transfer extra response arguments. Avoid breaking backward compatibility by improving the handling of the length checking in ib_uverbs_reg_mr to consider the case where the kernel has been updated, but user space still has the old length without padding. Signed-off-by: Knut Omang --- drivers/infiniband/core/uverbs_cmd.c | 10 ++++++---- include/uapi/rdma/ib_user_verbs.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index dbc5885..fa8a717 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -967,16 +967,18 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, struct ib_pd *pd; struct ib_mr *mr; int ret; + size_t resp_size = sizeof resp; - if (out_len < sizeof resp) - return -ENOSPC; + if (out_len < resp_size) { + resp_size = out_len; + } if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; INIT_UDATA(&udata, buf + sizeof cmd, (unsigned long) cmd.response + sizeof resp, - in_len - sizeof cmd, out_len - sizeof resp); + in_len - sizeof cmd, out_len - resp_size); if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)) return -EINVAL; @@ -1030,7 +1032,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, resp.mr_handle = uobj->id; if (copy_to_user((void __user *) (unsigned long) cmd.response, - &resp, sizeof resp)) { + &resp, resp_size)) { ret = -EFAULT; goto err_copy; } diff --git a/include/uapi/rdma/ib_user_verbs.h b/include/uapi/rdma/ib_user_verbs.h index 7f035f4..6b8c9c0 100644 --- a/include/uapi/rdma/ib_user_verbs.h +++ b/include/uapi/rdma/ib_user_verbs.h @@ -307,6 +307,7 @@ struct ib_uverbs_reg_mr_resp { __u32 mr_handle; __u32 lkey; __u32 rkey; + __u32 reserved; }; struct ib_uverbs_rereg_mr {