From patchwork Fri Apr 12 17:55:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10898975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B98917E6 for ; Fri, 12 Apr 2019 17:57:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF01628CF6 for ; Fri, 12 Apr 2019 17:57:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0D3528ED0; Fri, 12 Apr 2019 17:57:15 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 6237C28CF6 for ; Fri, 12 Apr 2019 17:57:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726812AbfDLR5O (ORCPT ); Fri, 12 Apr 2019 13:57:14 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:58360 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726808AbfDLR5O (ORCPT ); Fri, 12 Apr 2019 13:57:14 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3CHsMnG192408; Fri, 12 Apr 2019 17:57:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=r3g4vAXNSgdySLuOI8pDwA5w+fOvOc026ShsV6/RK18=; b=Giy7V4DN3237GBMxhdv8rj8y5S3Le/85f6xisFp0XyVgUbnuDIC45OpButuYU4VOfORy TW6bH8m4orwKeTEDQ/bQv1NQwshi+m9+MIoG6qi0t7D/kvHKFuFRt07OLwk8XTtrJYuV i9pBsJ8hzoQvQ0zIq6Bdz43R0BSos7ZN+iD3JMUIYXHjQKqLKeBcHLKjNcsDIi9x0D0n rI67k9OK3S7dpEPgRr25advWYq93hEPGm9RJhBrVMLeBWmVzU/P5KL+qGN4BKz9QL3/k XvE1H16C8XLHQANyRmMPby/yukUofQ/MbYJRKC9L6kkh0NlU4xlMzYDTCSxfcer7XppV qw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 2rphmf006q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Apr 2019 17:57:07 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3CHsage049943; Fri, 12 Apr 2019 17:55:06 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2rtqnp77gd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Apr 2019 17:55:06 +0000 Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3CHt3DC019485; Fri, 12 Apr 2019 17:55:03 GMT Received: from kadam (/197.157.0.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 12 Apr 2019 10:55:03 -0700 Date: Fri, 12 Apr 2019 20:55:04 +0300 From: Dan Carpenter To: Leon Romanovsky , Eli Cohen Cc: Doug Ledford , Jason Gunthorpe , linux-rdma@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] IB/mlx5: add checking for "vf" from do_setvfinfo() Message-ID: <20190412175504.GA20857@kadam> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9224 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904120121 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9224 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904120121 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 My static checker complains that these "vf" variables come from the user in do_setvfinfo() and haven't been checked to make sure they're valid. Fixes: eff901d30e6c ("IB/mlx5: Implement callbacks for manipulating VFs") Signed-off-by: Dan Carpenter --- Untested static checker stuff. Please review carefully. drivers/infiniband/hw/mlx5/ib_virt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/infiniband/hw/mlx5/ib_virt.c b/drivers/infiniband/hw/mlx5/ib_virt.c index 649a3364f838..9a8eebe3d462 100644 --- a/drivers/infiniband/hw/mlx5/ib_virt.c +++ b/drivers/infiniband/hw/mlx5/ib_virt.c @@ -56,6 +56,9 @@ int mlx5_ib_get_vf_config(struct ib_device *device, int vf, u8 port, struct mlx5_hca_vport_context *rep; int err; + if (vf < 0 || vf >= pci_sriov_get_totalvfs(mdev->pdev)) + return -EINVAL; + rep = kzalloc(sizeof(*rep), GFP_KERNEL); if (!rep) return -ENOMEM; @@ -99,6 +102,9 @@ int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf, struct mlx5_vf_context *vfs_ctx = mdev->priv.sriov.vfs_ctx; int err; + if (vf < 0 || vf >= pci_sriov_get_totalvfs(mdev->pdev)) + return -EINVAL; + in = kzalloc(sizeof(*in), GFP_KERNEL); if (!in) return -ENOMEM;