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 4AC77427E0; Mon, 20 Mar 2023 10:29:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CC82342D47; Mon, 20 Mar 2023 10:28:19 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id E966642BC9 for ; Mon, 20 Mar 2023 10:28:05 +0100 (CET) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Pg8XY5xczz9vCB; Mon, 20 Mar 2023 17:27:41 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 17:28:01 +0800 From: Chengwen Feng To: , , Jakub Grajciar , Ferruh Yigit CC: Subject: [PATCH v2 03/44] net/memif: fix segment fault when parse devargs Date: Mon, 20 Mar 2023 09:20:29 +0000 Message-ID: <20230320092110.37295-4-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230320092110.37295-1-fengchengwen@huawei.com> References: <20230314124813.39521-1-fengchengwen@huawei.com> <20230320092110.37295-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected 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 The rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'. This patch fixes segment fault when parse input args with 'only keys'. Fixes: 09c7e63a71f9 ("net/memif: introduce memory interface PMD") Fixes: 2f865ed07bb6 ("net/memif: use abstract socket address") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- drivers/net/memif/rte_eth_memif.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/net/memif/rte_eth_memif.c b/drivers/net/memif/rte_eth_memif.c index 6a8ff5b4eb..6fafb6de1f 100644 --- a/drivers/net/memif/rte_eth_memif.c +++ b/drivers/net/memif/rte_eth_memif.c @@ -1720,6 +1720,9 @@ memif_set_role(const char *key __rte_unused, const char *value, { enum memif_role_t *role = (enum memif_role_t *)extra_args; + if (value == NULL) + return -EINVAL; + if (strstr(value, "server") != NULL) { *role = MEMIF_ROLE_SERVER; } else if (strstr(value, "client") != NULL) { @@ -1742,6 +1745,9 @@ memif_set_zc(const char *key __rte_unused, const char *value, void *extra_args) { uint32_t *flags = (uint32_t *)extra_args; + if (value == NULL) + return -EINVAL; + if (strstr(value, "yes") != NULL) { if (!rte_mcfg_get_single_file_segments()) { MIF_LOG(ERR, "Zero-copy doesn't support multi-file segments."); @@ -1762,6 +1768,9 @@ memif_set_id(const char *key __rte_unused, const char *value, void *extra_args) { memif_interface_id_t *id = (memif_interface_id_t *)extra_args; + if (value == NULL) + return -EINVAL; + /* even if parsing fails, 0 is a valid id */ *id = strtoul(value, NULL, 10); return 0; @@ -1773,6 +1782,9 @@ memif_set_bs(const char *key __rte_unused, const char *value, void *extra_args) unsigned long tmp; uint16_t *pkt_buffer_size = (uint16_t *)extra_args; + if (value == NULL) + return -EINVAL; + tmp = strtoul(value, NULL, 10); if (tmp == 0 || tmp > 0xFFFF) { MIF_LOG(ERR, "Invalid buffer size: %s.", value); @@ -1789,6 +1801,9 @@ memif_set_rs(const char *key __rte_unused, const char *value, void *extra_args) memif_log2_ring_size_t *log2_ring_size = (memif_log2_ring_size_t *)extra_args; + if (value == NULL) + return -EINVAL; + tmp = strtoul(value, NULL, 10); if (tmp == 0 || tmp > ETH_MEMIF_MAX_LOG2_RING_SIZE) { MIF_LOG(ERR, "Invalid ring size: %s (max %u).", @@ -1840,6 +1855,9 @@ memif_set_socket_filename(const char *key __rte_unused, const char *value, { const char **socket_filename = (const char **)extra_args; + if (value == NULL) + return -EINVAL; + *socket_filename = value; return 0; } @@ -1849,6 +1867,9 @@ memif_set_is_socket_abstract(const char *key __rte_unused, const char *value, vo { uint32_t *flags = (uint32_t *)extra_args; + if (value == NULL) + return -EINVAL; + if (strstr(value, "yes") != NULL) { *flags |= ETH_MEMIF_FLAG_SOCKET_ABSTRACT; } else if (strstr(value, "no") != NULL) { @@ -1870,6 +1891,9 @@ memif_set_owner(const char *key, const char *value, void *extra_args) char *end = NULL; uint32_t *id = (uint32_t *)extra_args; + if (value == NULL) + return -EINVAL; + val = strtoul(value, &end, 10); if (*value == '\0' || *end != '\0') { MIF_LOG(ERR, "Failed to parse %s: %s.", key, value); @@ -1889,6 +1913,9 @@ memif_set_mac(const char *key __rte_unused, const char *value, void *extra_args) { struct rte_ether_addr *ether_addr = (struct rte_ether_addr *)extra_args; + if (value == NULL) + return -EINVAL; + if (rte_ether_unformat_addr(value, ether_addr) < 0) MIF_LOG(WARNING, "Failed to parse mac '%s'.", value); return 0; @@ -1899,6 +1926,9 @@ memif_set_secret(const char *key __rte_unused, const char *value, void *extra_ar { const char **secret = (const char **)extra_args; + if (value == NULL) + return -EINVAL; + *secret = value; return 0; } -- 2.17.1