From patchwork Tue May 1 18:55:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salil Mehta X-Patchwork-Id: 134798 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp5282410lji; Tue, 1 May 2018 12:00:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqjC+tf8GG+juBwNHj1P0JvZXxpkn8W9Uf1Any9pyUf+/JS46bUSHCgwDHmkdSYCWTE51rp X-Received: by 2002:a17:902:a612:: with SMTP id u18-v6mr16728764plq.192.1525201256154; Tue, 01 May 2018 12:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525201256; cv=none; d=google.com; s=arc-20160816; b=e2kUSt6aEUdQtZcsZXzoTc68zhcVkt+uZM9Hs08JHebu/UnJ9cDjI8QhWqv8e3Fs/e 2+zt9kkx3l4Kj0+3cN/EWs/zKyH4i72jr4ZgA0Ste3p+j+92lpvSUFrW0AWeTKOJ37Jh 6qjU0+DY091Zz7jHWlcY1jyt++k+L4QRL78XMfLG6VfLGydxdtWHTe/2JXu5FWSK83K+ 2zEx3QhODN9ZJOGXwdKabG8o5w6lHHWvc/gKOvHRTvmutyMteaiXd1Vew5J9NDMaUWf8 jjOVXFXFcw2yk3jS9MCj2x+PBlOyESP5cAJVgHNE98s8NZr1FH8nCfol8/etiEAgrOgk aAqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=mNRr40qhrJkA/zO5Ycc4HhzTUzhy9OiiMGFXc2b9jM8=; b=BfzcsSvisRO2dQXtW8Yyo1AeslcVT6r75Dip00rLDqhUmohQPHBEtlpW1GiM5xijHv m3y6ufvHkqrAZo9HX2TkEqQ+0x6xhkvP7B5g9jyiLJYmXJJIywCecZ0MAVIesWENYXZH d4W7Ng5rZDFHAwQWfZbiu7A4fyVDQpkOzYc5B3qnXXaVJnHN+kYCG96Nwc/kYIhOBvVZ Zp0hLlzWrVlXBkC22NYYoqw/K9jT3v7j12aKhq80X4WdWbM6RCj0f0ZnlSUfMJrdWMxF 2OWWtSdDoWhxSThP+QQfxPZIeGErQYBTKcfHVsWKFuA03Gww5opK4bCNlTZoZaXobFtH 59+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6-v6si2130814pla.509.2018.05.01.12.00.55; Tue, 01 May 2018 12:00:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756521AbeEAS6D (ORCPT + 29 others); Tue, 1 May 2018 14:58:03 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:7640 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754790AbeEAS6A (ORCPT ); Tue, 1 May 2018 14:58:00 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 46FD65074A8F3; Wed, 2 May 2018 02:57:47 +0800 (CST) Received: from S00293818-DELL1.china.huawei.com (10.202.226.46) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 02:57:41 +0800 From: Salil Mehta To: CC: , , , , , , , Huazhong Tan Subject: [PATCH net-next 3/9] net: hns3: Fixes the out of bounds access in hclge_map_tqp Date: Tue, 1 May 2018 19:55:59 +0100 Message-ID: <20180501185605.9584-4-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20180501185605.9584-1-salil.mehta@huawei.com> References: <20180501185605.9584-1-salil.mehta@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.226.46] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huazhong Tan This patch fixes the handling of the check when number of vports are detected to be more than available TPQs. Current handling causes an out of bounds access in hclge_map_tqp(). Fixes: 7df7dad633e2 ("net: hns3: Refactor the mapping of tqp to vport") Signed-off-by: Huazhong Tan Signed-off-by: Peng Li Signed-off-by: Salil Mehta --- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index 2066dd7..c9e80ca 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -1459,8 +1459,11 @@ static int hclge_alloc_vport(struct hclge_dev *hdev) /* We need to alloc a vport for main NIC of PF */ num_vport = hdev->num_vmdq_vport + hdev->num_req_vfs + 1; - if (hdev->num_tqps < num_vport) - num_vport = hdev->num_tqps; + if (hdev->num_tqps < num_vport) { + dev_err(&hdev->pdev->dev, "tqps(%d) is less than vports(%d)", + hdev->num_tqps, num_vport); + return -EINVAL; + } /* Alloc the same number of TQPs for every vport */ tqp_per_vport = hdev->num_tqps / num_vport;