From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 77517A0547; Wed, 21 Apr 2021 04:08:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D56714189C; Wed, 21 Apr 2021 04:08:10 +0200 (CEST) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mails.dpdk.org (Postfix) with ESMTP id 9F2CC41385 for ; Wed, 21 Apr 2021 04:08:07 +0200 (CEST) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FQ3m04S3WzpZl5 for ; Wed, 21 Apr 2021 10:05:04 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Wed, 21 Apr 2021 10:08:03 +0800 From: "Min Hu (Connor)" To: CC: , , Date: Wed, 21 Apr 2021 10:08:15 +0800 Message-ID: <1618970896-37852-2-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1618970896-37852-1-git-send-email-humin29@huawei.com> References: <1618970896-37852-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Chengwen Feng This patch adds checking spad user index validity when set or get attr. Fixes: 277310027965 ("raw/ntb: introduce NTB raw device driver") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Signed-off-by: Min Hu (Connor) --- drivers/raw/ntb/ntb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/raw/ntb/ntb.c b/drivers/raw/ntb/ntb.c index 6dd213e..0f0e3f2 100644 --- a/drivers/raw/ntb/ntb.c +++ b/drivers/raw/ntb/ntb.c @@ -1080,6 +1080,10 @@ ntb_attr_set(struct rte_rawdev *dev, const char *attr_name, if (hw->ntb_ops->spad_write == NULL) return -ENOTSUP; index = atoi(&attr_name[NTB_SPAD_USER_LEN]); + if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) { + NTB_LOG(ERR, "Invalid attribute (%s)", attr_name); + return -EINVAL; + } (*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index], 1, attr_value); NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")", @@ -1174,6 +1178,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name, if (hw->ntb_ops->spad_read == NULL) return -ENOTSUP; index = atoi(&attr_name[NTB_SPAD_USER_LEN]); + if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) { + NTB_LOG(ERR, "Attribute (%s) out of range", attr_name); + return -EINVAL; + } *attr_value = (*hw->ntb_ops->spad_read)(dev, hw->spad_user_list[index], 0); NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")", -- 2.7.4