Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp499826pxb; Wed, 15 Sep 2021 06:58:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQWxpF68l76gkGmu37WeQAGBjPFJezgUU42QYriYyE1WKcWbCH/A/CWqNWfeb5GlwpunB1 X-Received: by 2002:a17:906:b183:: with SMTP id w3mr149648ejy.394.1631714298265; Wed, 15 Sep 2021 06:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631714298; cv=none; d=google.com; s=arc-20160816; b=qA2Sic9Xbxjw387o9eWlbI2EREFajgg8QBTPeV+OlKUm0o8LUJfX5zAUKH862vAJrQ YvfvGSsidtw/JpXBOy5ugdwzGgxRbhSYSWszUCP330gIHBOL9FNcKeooewsXZ7EgeZ5B kbKgbfzSC78QM2zwRKL7d3ZSxdyu2tCriD/q4iZFTyNwe5ioGtAetiCFPwTMMYRIEKd4 tCb1bh4XLPSucD64zXYh7ZirOglovvqxhM793sGnsDfS9un9zXBHKD/o8P2QBhF/i2Hd wX8cDRqPow5NNivVbta02I+917QZWAoRsTm39FxT/rR/+DYfniOkOuCeME7AYDzw0e4t tDQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ucU3O/hf/sq4lb/tagsrxVIPAB3S0I1t/jcSjQOulJU=; b=Ycb4ZAII/9xgAcx0YrhDAebWGCktvisJD049fQsg117Q4vsdabIVXIDYhv7/tzqdP4 q92EFBGlwnUSTrdgXgaCtYHrNG3TZSduNUhEz9KrtFd2T3wL+SRsRO6kw+ByzZZZiOsn 0S7OGhbZBDEeciol2hViPsDcTe6e0cywth14+WYLE4ZE8JRUQaFivWq5fJAsI6RdBTrH 7ZkVgyHD8cKOwytWSSnq0WLiAeV8b0fRgEKsnL4IPOFwax87AvajyJqKTN4TNWlUcN4J E1AtuLjtrpuD9Kn1NpsQv+jNuYO3PlsGkcaGyzRiZbWE2/p+/UIZ3X6rKe6s1TJvrtPv ueug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d7si33263edr.491.2021.09.15.06.57.53; Wed, 15 Sep 2021 06:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237602AbhION5r (ORCPT + 99 others); Wed, 15 Sep 2021 09:57:47 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:9876 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234639AbhION5i (ORCPT ); Wed, 15 Sep 2021 09:57:38 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H8hTd2GM7z8yLV; Wed, 15 Sep 2021 21:51:49 +0800 (CST) Received: from kwepemm600016.china.huawei.com (7.193.23.20) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 15 Sep 2021 21:56:15 +0800 Received: from localhost.localdomain (10.67.165.24) by kwepemm600016.china.huawei.com (7.193.23.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 15 Sep 2021 21:56:15 +0800 From: Guangbin Huang To: , CC: , , , Subject: [PATCH net 4/6] net: hns3: check queue id range before using Date: Wed, 15 Sep 2021 21:52:09 +0800 Message-ID: <20210915135211.9129-5-huangguangbin2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210915135211.9129-1-huangguangbin2@huawei.com> References: <20210915135211.9129-1-huangguangbin2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600016.china.huawei.com (7.193.23.20) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yufeng Mo The input parameters may not be reliable. Before using the queue id, we should check this parameter. Otherwise, memory overwriting may occur. Fixes: d34100184685 ("net: hns3: refactor the mailbox message between PF and VF") Signed-off-by: Yufeng Mo Signed-off-by: Guangbin Huang --- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c index 07aa6ada4fdb..65d78ee4d65a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c @@ -590,9 +590,17 @@ static void hclge_get_queue_id_in_pf(struct hclge_vport *vport, struct hclge_mbx_vf_to_pf_cmd *mbx_req, struct hclge_respond_to_vf_msg *resp_msg) { + struct hnae3_handle *handle = &vport->nic; + struct hclge_dev *hdev = vport->back; u16 queue_id, qid_in_pf; memcpy(&queue_id, mbx_req->msg.data, sizeof(queue_id)); + if (queue_id >= handle->kinfo.num_tqps) { + dev_err(&hdev->pdev->dev, "Invalid queue id(%u) from VF %u\n", + queue_id, mbx_req->mbx_src_vfid); + return; + } + qid_in_pf = hclge_covert_handle_qid_global(&vport->nic, queue_id); memcpy(resp_msg->data, &qid_in_pf, sizeof(qid_in_pf)); resp_msg->len = sizeof(qid_in_pf); -- 2.33.0