Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp481371imu; Wed, 19 Dec 2018 23:38:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/XBqUazhSiuFpWLgz1MAAUD4oyZfAIi4piDXzY3Gi38M9M85VkmwwpEWxTIldP1cVE1EqKP X-Received: by 2002:a17:902:7b88:: with SMTP id w8mr23004628pll.320.1545291521631; Wed, 19 Dec 2018 23:38:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545291521; cv=none; d=google.com; s=arc-20160816; b=fiZQ00pa52ngrryJgX9dma9Ruk7G9B3es5mZUikEolGwMsO/n5BiKS2i9YhZtd1s/P TM5sGd2AxBVUJkro5Y315GfAXm2eWX5I6UVLbP21eAKN4ITl5df/7aZYsDr2YD+k5/z5 naRBw7PirYx3ktT7h8RJkxXkCEwKrQQ1JWTDkQ02owLALr+NcnPL/vn+aQv27LCoGFpw ny3H5Hhh67vDw8xTvkEsUUpwEqHQpoDwMuIf2v/MFFdNqj6hsdpw3IrQ+V7laXm9IBJf 2/jHggpLAjJbcgUINInnId9qjoBxiFr2Kv5NmFAxqUzm7I/wqIS9qBjwPKQdExo6ejMX aX7g== 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; bh=jEFNxAow/tqfr7qcvhcgbV3W+NNCKyUjI4Fdp9dlZnc=; b=g4MC8CwD4fzCfKlT8XiByzRERpRk0qi6ySJKIT+hfSWagf2ytyH66Ehfb0iBlhh8QO 9RDNb+7A+xqJK5YawYG0Mgx+jiuLoLBaHzjbl5ZgHc8qRj1c5a0KS2jM7Hbs/3U306n8 hMDbWlXR3lw1uVsF9bDvxqzcWv058IjW3aNbJbYxaWL/iLCQv6qlxC6bORwgIuCzPlin lgYIe62dsLqLCQFft1oGrAzM6WvyNrg3nOG7/jC1xqoJny453hYqTUlgYt9KZscgwSbh MHhi93FS+dyz+2WS20BdjbI3g0lIoqs5qSZmmpxzbbDRnp/lgsycaxm9/GdqIhMrVPcd Q4EQ== 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 p26si6645388pfj.244.2018.12.19.23.38.24; Wed, 19 Dec 2018 23:38:41 -0800 (PST) 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 S1729367AbeLTDQY (ORCPT + 99 others); Wed, 19 Dec 2018 22:16:24 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:59691 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729183AbeLTDQX (ORCPT ); Wed, 19 Dec 2018 22:16:23 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DD122845A3967; Thu, 20 Dec 2018 11:16:19 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.408.0; Thu, 20 Dec 2018 11:16:15 +0800 From: Peng Li To: CC: , , , , , Subject: [PATCH net-next 6/9] net: hns3: fix vf id check issue when add flow director rule Date: Thu, 20 Dec 2018 11:52:03 +0800 Message-ID: <1545277926-66432-7-git-send-email-lipeng321@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1545277926-66432-1-git-send-email-lipeng321@huawei.com> References: <1545277926-66432-1-git-send-email-lipeng321@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jian Shen When add flow director fule for vf, the vf id is used as array subscript before valid checking, which may cause memory overflow. Fixes: dd74f815dd41 ("net: hns3: Add support for rule add/delete for flow director") Signed-off-by: Jian Shen Signed-off-by: Peng Li --- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index 98ae282..9f89858 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -4677,6 +4677,13 @@ static int hclge_add_fd_entry(struct hnae3_handle *handle, u8 vf = ethtool_get_flow_spec_ring_vf(fs->ring_cookie); u16 tqps; + if (vf > hdev->num_req_vfs) { + dev_err(&hdev->pdev->dev, + "Error: vf id (%d) > max vf num (%d)\n", + vf, hdev->num_req_vfs); + return -EINVAL; + } + dst_vport_id = vf ? hdev->vport[vf].vport_id : vport->vport_id; tqps = vf ? hdev->vport[vf].alloc_tqps : vport->alloc_tqps; @@ -4687,13 +4694,6 @@ static int hclge_add_fd_entry(struct hnae3_handle *handle, return -EINVAL; } - if (vf > hdev->num_req_vfs) { - dev_err(&hdev->pdev->dev, - "Error: vf id (%d) > max vf num (%d)\n", - vf, hdev->num_req_vfs); - return -EINVAL; - } - action = HCLGE_FD_ACTION_ACCEPT_PACKET; q_index = ring; } -- 1.9.1