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 31766A034F for ; Tue, 1 Mar 2022 11:43:52 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2A14C426DA; Tue, 1 Mar 2022 11:43:52 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id C9951407FF for ; Tue, 1 Mar 2022 11:43:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646131430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hX/y6I2WFyc2tLAYVy4o2hXS8wYM1NAer+R6NvQ6yQ=; b=c3JWuDGZDeOhJJoe1upLHZ1ttewNcs7siPJUMeU/piKXS4wC22n0GnPV9xCb1OzdhRqhHZ dIZ5niD68X7F836T8no+yxZCaBH56wVcj2HrlERF1xRDX4eA0bp1Rbolqkz7/7KS2/CFpx LdseNFy8+MQmu4YYKFTlopWoeRQ+O90= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658-k_41C5jFNGSswKImAgFGlQ-1; Tue, 01 Mar 2022 05:43:45 -0500 X-MC-Unique: k_41C5jFNGSswKImAgFGlQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 26A3F186833A; Tue, 1 Mar 2022 10:43:44 +0000 (UTC) Received: from rh.Home (unknown [10.39.194.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id F29E1752D1; Tue, 1 Mar 2022 10:43:42 +0000 (UTC) From: Kevin Traynor To: Weiguo Li Cc: Ganapati Kundapura , Jay Jayatheerthan , dpdk stable Subject: patch 'eventdev/eth_rx: fix parameters parsing memory leak' has been queued to stable release 21.11.1 Date: Tue, 1 Mar 2022 10:41:35 +0000 Message-Id: <20220301104300.334382-19-ktraynor@redhat.com> In-Reply-To: <20220301104300.334382-1-ktraynor@redhat.com> References: <20220301104300.334382-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ktraynor@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 21.11.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 03/06/22. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable/commit/529f3a735e4eb837049e340c1334ea6a6355397b Thanks. Kevin --- >From 529f3a735e4eb837049e340c1334ea6a6355397b Mon Sep 17 00:00:00 2001 From: Weiguo Li Date: Fri, 4 Feb 2022 16:21:28 +0800 Subject: [PATCH] eventdev/eth_rx: fix parameters parsing memory leak [ upstream commit 74b034ff817239b1a5dcf4dfd7d33ccd5684996a ] The memory get from strdup should be freed when parameter parsing finished, and also should be freed when error occurs. Fixes: 814d01709328 ("eventdev/eth_rx: support telemetry") Fixes: 9e583185318f ("eventdev/eth_rx: support telemetry") Signed-off-by: Weiguo Li Acked-by: Ganapati Kundapura Acked-by: Jay Jayatheerthan --- lib/eventdev/rte_event_eth_rx_adapter.c | 96 ++++++++++++++++++------- 1 file changed, 72 insertions(+), 24 deletions(-) diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index f946137b25..ce94999738 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -294,4 +294,28 @@ rxa_event_buf_get(struct event_eth_rx_adapter *rx_adapter, uint16_t eth_dev_id, } while (0) +#define RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(id, retval) do { \ + if (!rxa_validate_id(id)) { \ + RTE_EDEV_LOG_ERR("Invalid eth Rx adapter id = %d\n", id); \ + ret = retval; \ + goto error; \ + } \ +} while (0) + +#define RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, retval) do { \ + if ((token) == NULL || strlen(token) == 0 || !isdigit(*token)) { \ + RTE_EDEV_LOG_ERR("Invalid eth Rx adapter token\n"); \ + ret = retval; \ + goto error; \ + } \ +} while (0) + +#define RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(port_id, retval) do { \ + if (!rte_eth_dev_is_valid_port(port_id)) { \ + RTE_ETHDEV_LOG(ERR, "Invalid port_id=%u\n", port_id); \ + ret = retval; \ + goto error; \ + } \ +} while (0) + static inline int rxa_sw_adapter_queue_count(struct event_eth_rx_adapter *rx_adapter) @@ -3304,5 +3328,5 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; - int eth_dev_id; + int eth_dev_id, ret = -1; char *token, *l_params; struct rte_event_eth_rx_adapter_queue_conf queue_conf; @@ -3313,19 +3337,20 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, /* Get Rx adapter ID from parameter string */ l_params = strdup(params); + if (l_params == NULL) + return -ENOMEM; token = strtok(l_params, ","); + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); - RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(rx_adapter_id, -EINVAL); + RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) - return -1; + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); - RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(eth_dev_id, -EINVAL); + RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) - return -1; + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3333,5 +3358,6 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, if (rx_queue_id >= rte_eth_devices[eth_dev_id].data->nb_rx_queues) { RTE_EDEV_LOG_ERR("Invalid rx queue_id %u", rx_queue_id); - return -EINVAL; + ret = -EINVAL; + goto error; } @@ -3340,4 +3366,6 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); + /* Parsing parameter finished */ + free(l_params); if (rte_event_eth_rx_adapter_queue_conf_get(rx_adapter_id, eth_dev_id, @@ -3359,4 +3387,8 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, return 0; + +error: + free(l_params); + return ret; } @@ -3368,5 +3400,5 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; - int eth_dev_id; + int eth_dev_id, ret = -1; char *token, *l_params; struct rte_event_eth_rx_adapter_queue_stats q_stats; @@ -3377,19 +3409,20 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, /* Get Rx adapter ID from parameter string */ l_params = strdup(params); + if (l_params == NULL) + return -ENOMEM; token = strtok(l_params, ","); + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); - RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(rx_adapter_id, -EINVAL); + RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) - return -1; + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); - RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(eth_dev_id, -EINVAL); + RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) - return -1; + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3397,5 +3430,6 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, if (rx_queue_id >= rte_eth_devices[eth_dev_id].data->nb_rx_queues) { RTE_EDEV_LOG_ERR("Invalid rx queue_id %u", rx_queue_id); - return -EINVAL; + ret = -EINVAL; + goto error; } @@ -3404,4 +3438,6 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); + /* Parsing parameter finished */ + free(l_params); if (rte_event_eth_rx_adapter_queue_stats_get(rx_adapter_id, eth_dev_id, @@ -3422,4 +3458,8 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, return 0; + +error: + free(l_params); + return ret; } @@ -3431,5 +3471,5 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; - int eth_dev_id; + int eth_dev_id, ret = -1; char *token, *l_params; @@ -3439,19 +3479,20 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, /* Get Rx adapter ID from parameter string */ l_params = strdup(params); + if (l_params == NULL) + return -ENOMEM; token = strtok(l_params, ","); + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); - RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(rx_adapter_id, -EINVAL); + RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) - return -1; + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); - RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(eth_dev_id, -EINVAL); + RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) - return -1; + RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3459,5 +3500,6 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, if (rx_queue_id >= rte_eth_devices[eth_dev_id].data->nb_rx_queues) { RTE_EDEV_LOG_ERR("Invalid rx queue_id %u", rx_queue_id); - return -EINVAL; + ret = -EINVAL; + goto error; } @@ -3466,4 +3508,6 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); + /* Parsing parameter finished */ + free(l_params); if (rte_event_eth_rx_adapter_queue_stats_reset(rx_adapter_id, @@ -3475,4 +3519,8 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, return 0; + +error: + free(l_params); + return ret; } -- 2.34.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2022-03-01 10:41:01.906616705 +0000 +++ 0019-eventdev-eth_rx-fix-parameters-parsing-memory-leak.patch 2022-03-01 10:41:01.256244088 +0000 @@ -1 +1 @@ -From 74b034ff817239b1a5dcf4dfd7d33ccd5684996a Mon Sep 17 00:00:00 2001 +From 529f3a735e4eb837049e340c1334ea6a6355397b Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 74b034ff817239b1a5dcf4dfd7d33ccd5684996a ] + @@ -11 +12,0 @@ -Cc: stable@dpdk.org @@ -21 +22 @@ -index ae1e260c08..4da6f1ff90 100644 +index f946137b25..ce94999738 100644 @@ -53 +54 @@ -@@ -3324,5 +3348,5 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, +@@ -3304,5 +3328,5 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, @@ -60 +61 @@ -@@ -3333,19 +3357,20 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, +@@ -3313,19 +3337,20 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, @@ -87 +88 @@ -@@ -3353,5 +3378,6 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, +@@ -3333,5 +3358,6 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, @@ -95 +96 @@ -@@ -3360,4 +3386,6 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, +@@ -3340,4 +3366,6 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, @@ -102 +103 @@ -@@ -3379,4 +3407,8 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, +@@ -3359,4 +3387,8 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, @@ -111 +112 @@ -@@ -3388,5 +3420,5 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, +@@ -3368,5 +3400,5 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, @@ -118 +119 @@ -@@ -3397,19 +3429,20 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, +@@ -3377,19 +3409,20 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, @@ -145 +146 @@ -@@ -3417,5 +3450,6 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, +@@ -3397,5 +3430,6 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, @@ -153 +154 @@ -@@ -3424,4 +3458,6 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, +@@ -3404,4 +3438,6 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, @@ -160 +161 @@ -@@ -3442,4 +3478,8 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, +@@ -3422,4 +3458,8 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, @@ -169 +170 @@ -@@ -3451,5 +3491,5 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, +@@ -3431,5 +3471,5 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, @@ -176 +177 @@ -@@ -3459,19 +3499,20 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, +@@ -3439,19 +3479,20 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, @@ -203 +204 @@ -@@ -3479,5 +3520,6 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, +@@ -3459,5 +3500,6 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, @@ -211 +212 @@ -@@ -3486,4 +3528,6 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, +@@ -3466,4 +3508,6 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, @@ -218 +219 @@ -@@ -3495,4 +3539,8 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, +@@ -3475,4 +3519,8 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,