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 E50C0427E0; Mon, 20 Mar 2023 10:31:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 437AC42F84; Mon, 20 Mar 2023 10:28:51 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 6787A42D3A for ; Mon, 20 Mar 2023 10:28:14 +0100 (CET) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pg8VY6dDKzKsJB; Mon, 20 Mar 2023 17:25:57 +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:13 +0800 From: Chengwen Feng To: , , Kai Ji , Pablo de Lara , Fan Zhang , Kirill Rybalchenko , Declan Doherty CC: Subject: [PATCH v2 35/44] crypto/scheduler: fix segment fault when parse devargs Date: Mon, 20 Mar 2023 09:21:01 +0000 Message-ID: <20230320092110.37295-36-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: 503e9c5afb38 ("crypto/scheduler: register as vdev driver") Fixes: 4c07e0552f0a ("crypto/scheduler: add multicore scheduling mode") Fixes: a0e805ee086a ("crypto/scheduler: add more options") Fixes: ee9586dd15fb ("crypto/scheduler: add mode-specific parameter") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- drivers/crypto/scheduler/scheduler_pmd.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/crypto/scheduler/scheduler_pmd.c b/drivers/crypto/scheduler/scheduler_pmd.c index 9d1ce46622..7fa8bef4f2 100644 --- a/drivers/crypto/scheduler/scheduler_pmd.c +++ b/drivers/crypto/scheduler/scheduler_pmd.c @@ -272,6 +272,9 @@ parse_integer_arg(const char *key __rte_unused, { int *i = (int *) extra_args; + if (value == NULL) + return -EINVAL; + *i = atoi(value); if (*i < 0) { CR_SCHED_LOG(ERR, "Argument has to be positive."); @@ -338,6 +341,9 @@ parse_corelist_arg(const char *key __rte_unused, { struct scheduler_init_params *params = extra_args; + if (value == NULL) + return -EINVAL; + params->nb_wc = 0; const char *token = value; @@ -367,6 +373,9 @@ parse_name_arg(const char *key __rte_unused, { struct rte_cryptodev_pmd_init_params *params = extra_args; + if (value == NULL) + return -EINVAL; + if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) { CR_SCHED_LOG(ERR, "Invalid name %s, should be less than " "%u bytes.", value, @@ -386,6 +395,9 @@ parse_worker_arg(const char *key __rte_unused, { struct scheduler_init_params *param = extra_args; + if (value == NULL) + return -EINVAL; + if (param->nb_workers >= RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKERS) { CR_SCHED_LOG(ERR, "Too many workers."); return -ENOMEM; @@ -404,6 +416,9 @@ parse_mode_arg(const char *key __rte_unused, struct scheduler_init_params *param = extra_args; uint32_t i; + if (value == NULL) + return -EINVAL; + for (i = 0; i < RTE_DIM(scheduler_mode_map); i++) { if (strcmp(value, scheduler_mode_map[i].name) == 0) { param->mode = (enum rte_cryptodev_scheduler_mode) @@ -427,6 +442,9 @@ parse_mode_param_arg(const char *key __rte_unused, { struct scheduler_init_params *param = extra_args; + if (value == NULL) + return -EINVAL; + strlcpy(param->mode_param_str, value, RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN); @@ -440,6 +458,9 @@ parse_ordering_arg(const char *key __rte_unused, struct scheduler_init_params *param = extra_args; uint32_t i; + if (value == NULL) + return -EINVAL; + for (i = 0; i < RTE_DIM(scheduler_ordering_map); i++) { if (strcmp(value, scheduler_ordering_map[i].name) == 0) { param->enable_ordering = -- 2.17.1