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 1FE93A0548; Tue, 27 Apr 2021 13:39:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F26AA40150; Tue, 27 Apr 2021 13:39:35 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 620854014E for ; Tue, 27 Apr 2021 13:39:34 +0200 (CEST) Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4FV08T2z09z5tZj for ; Tue, 27 Apr 2021 19:36:25 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 27 Apr 2021 19:39:31 +0800 From: "Min Hu (Connor)" To: CC: , Date: Tue, 27 Apr 2021 19:39:41 +0800 Message-ID: <1619523581-60870-1-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1619075569-33619-1-git-send-email-humin29@huawei.com> References: <1619075569-33619-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v4] net/bonding: fix socket id check 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: Chengchang Tang The socket ID entered by user is cast to an unsigned integer. However, the value may be an illegal negative value, which may cause some problems. In this case, an error should be returned. In addition, the socket ID may be an invalid positive number, which is also processed in this patch. Fixes: 2efb58cbab6e ("bond: new link bonding library") Cc: stable@dpdk.org Signed-off-by: Chengchang Tang Signed-off-by: Min Hu (Connor) --- v4: * changed type of socket id getting from 'strtol'. * delete unused comments. v3: * changed type of socket id. v2: * fixed socket id type. --- drivers/net/bonding/rte_eth_bond_args.c | 8 ++++---- drivers/net/bonding/rte_eth_bond_pmd.c | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/bonding/rte_eth_bond_args.c b/drivers/net/bonding/rte_eth_bond_args.c index 8c5f90d..dc68e52 100644 --- a/drivers/net/bonding/rte_eth_bond_args.c +++ b/drivers/net/bonding/rte_eth_bond_args.c @@ -200,20 +200,20 @@ int bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused, const char *value, void *extra_args) { - int socket_id; + long socket_id; char *endptr; if (value == NULL || extra_args == NULL) return -1; errno = 0; - socket_id = (uint8_t)strtol(value, &endptr, 10); + socket_id = strtol(value, &endptr, 10); if (*endptr != 0 || errno != 0) return -1; /* validate socket id value */ - if (socket_id >= 0) { - *(uint8_t *)extra_args = (uint8_t)socket_id; + if (socket_id >= 0 && socket_id < RTE_MAX_NUMA_NODES) { + *(int *)extra_args = (int)socket_id; return 0; } return -1; diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c index 2e9cea5..2f7d6ad 100644 --- a/drivers/net/bonding/rte_eth_bond_pmd.c +++ b/drivers/net/bonding/rte_eth_bond_pmd.c @@ -3333,8 +3333,9 @@ bond_probe(struct rte_vdev_device *dev) const char *name; struct bond_dev_private *internals; struct rte_kvargs *kvlist; - uint8_t bonding_mode, socket_id/*, agg_mode*/; - int arg_count, port_id; + uint8_t bonding_mode; + int arg_count, port_id; + int socket_id; uint8_t agg_mode; struct rte_eth_dev *eth_dev; -- 2.7.4