From patchwork Wed Jul 26 16:14:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ismail, Mustafa" X-Patchwork-Id: 9865379 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 7C18B6038C for ; Wed, 26 Jul 2017 16:15:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6208F28790 for ; Wed, 26 Jul 2017 16:15:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 560A5287A8; Wed, 26 Jul 2017 16:15:27 +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 autolearn=ham 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 7A6B028790 for ; Wed, 26 Jul 2017 16:15:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751620AbdGZQPQ (ORCPT ); Wed, 26 Jul 2017 12:15:16 -0400 Received: from mga05.intel.com ([192.55.52.43]:6959 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750898AbdGZQPQ (ORCPT ); Wed, 26 Jul 2017 12:15:16 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP; 26 Jul 2017 09:15:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,416,1496127600"; d="scan'208";a="291738524" Received: from mustafai-mobl.amr.corp.intel.com ([10.122.34.7]) by fmsmga004.fm.intel.com with ESMTP; 26 Jul 2017 09:15:14 -0700 From: Mustafa Ismail To: linux-rdma@vger.kernel.org Cc: mustafa.ismail@intel.com, e1000-rdma@lists.sourceforge.net, chien.tin.tung@intel.com, shiraz.saleem@intel.com, "# v4 . 2-v4 . 9" , security@kernel.org, Doug Ledford , Steve Wise , Mike Marciniszyn Subject: [PATCH] RDMA/uverbs: Fix the check for port number Date: Wed, 26 Jul 2017 11:14:46 -0500 Message-Id: <1501085686-12916-1-git-send-email-mustafa.ismail@intel.com> X-Mailer: git-send-email 2.7.4 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 port number is only valid if IB_QP_PORT is set in the mask. So only check port number if it is valid to prevent modify_qp from failing due to an invalid port number. Fixes: 5ecce4c9b17b("Check port number supplied by user verbs cmds") Cc: # v4.2-v4.9 Cc: Cc: Doug Ledford Cc: Steve Wise Cc: Mike Marciniszyn Signed-off-by: Mustafa Ismail Upstream commit 5a7a88f1b488("Fix the check for port number") Modified from upstream commit: helper function rdma_is_port_valid does not exist in these kernel versions. --- drivers/infiniband/core/uverbs_cmd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index 01e3a37..d118ffe 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -2342,8 +2342,9 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; - if (cmd.port_num < rdma_start_port(ib_dev) || - cmd.port_num > rdma_end_port(ib_dev)) + if ((cmd.attr_mask & IB_QP_PORT) && + (cmd.port_num < rdma_start_port(ib_dev) || + cmd.port_num > rdma_end_port(ib_dev))) return -EINVAL; INIT_UDATA(&udata, buf + sizeof cmd, NULL, in_len - sizeof cmd,