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 3FA41A034E; Tue, 22 Feb 2022 11:08:41 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E16A240DF6; Tue, 22 Feb 2022 11:08:40 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 2C71940DF4 for ; Tue, 22 Feb 2022 11:08:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645524519; 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=4/tZV8aGRTi/+NEyal1ryQoRLFZZiBen+StMIq3fLM8=; b=STqDobymMz64j1H53U6aUzCI0NeuduUmh8LdF/AvEMFqyY+8zffIvFYOWQsOhmY6CJyR0p cJvwtAVjys1NT8oaTxdruCcfrsNlEMgHRCoRlYSo2SWx492X68CAAP3H2vc2UFdfDIJMgj u3dmo7mHI3A8KquHM9oaJ+552q0mObE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-299-mcE7JdgjPy2ACqyCsmX9lg-1; Tue, 22 Feb 2022 05:08:38 -0500 X-MC-Unique: mcE7JdgjPy2ACqyCsmX9lg-1 Received: by mail-wm1-f69.google.com with SMTP id b17-20020a05600c4e1100b0037cc0d56524so651773wmq.2 for ; Tue, 22 Feb 2022 02:08:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:references:content-language:in-reply-to :content-transfer-encoding; bh=4/tZV8aGRTi/+NEyal1ryQoRLFZZiBen+StMIq3fLM8=; b=Zu2pFhy/8q2huwNYRip/E7my4gB1UXs/5yBiokQflruT2Q1h5xgDLR/yUS2L215d17 nhAi3slrwjwT6vy0j85VRE2m/XdOmltg8FQt1SStton5EEt4Bu+3mrB28AeligpOQ6Kq JSGcblh0Zjp8HWJaJzDH73TtaxvawFglOszhFaZwDvt7MZUtrMoxQ4Cn6HMzUBd/BHjz 0gKx29eObjF4JVXlp3ebB3ccbhhWs1uYPJ4RO0lrklRZvn2AND1DgXjUtm8eSdOBEzRg dqDSPtorR65DhWovwRKvsyGpqDAAKet2Ab8nO3b+wDK7HuWS6NXGJ/Wq2GHNvQROgPf9 aBgg== X-Gm-Message-State: AOAM532HuTxiVoLzveORE1kJoYKImHYamSr7wN0+YaLZZ/sKezIKUtoR 8eYEn+gra2PuknSRlKsy+GiSGNIReYpgc88c/DP79g3Y3y48h3uIO0W+MipyVilkYRxO/wAl+rE hUEg= X-Received: by 2002:a05:6000:1817:b0:1e4:bb97:d844 with SMTP id m23-20020a056000181700b001e4bb97d844mr18040017wrh.628.1645524517244; Tue, 22 Feb 2022 02:08:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyx9fjDktxvI4rP7WTbndMjqKZ4wxvNVGCnsgXCF8CQVp3Drb2LQS84eEMZ/0R+4dnEUCxIGg== X-Received: by 2002:a05:6000:1817:b0:1e4:bb97:d844 with SMTP id m23-20020a056000181700b001e4bb97d844mr18040007wrh.628.1645524517052; Tue, 22 Feb 2022 02:08:37 -0800 (PST) Received: from [192.168.0.36] ([78.16.131.8]) by smtp.gmail.com with ESMTPSA id x11sm1886065wmi.37.2022.02.22.02.08.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Feb 2022 02:08:36 -0800 (PST) Message-ID: <3deb0be5-0c61-c899-d15f-acab9e2b6eaf@redhat.com> Date: Tue, 22 Feb 2022 10:08:35 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 From: Kevin Traynor Subject: Re: [PATCH v6] eventdev/eth_rx: fix memory leak when token parsing finished To: Jerin Jacob , "Jayatheerthan, Jay" Cc: Weiguo Li , "Kundapura, Ganapati" , "Naga Harish K, S V" , "stephen@networkplumber.org" , "dev@dpdk.org" References: In-Reply-To: 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-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 On 18/02/2022 09:39, Jerin Jacob wrote: > On Fri, Feb 4, 2022 at 3:17 PM Jayatheerthan, Jay > wrote: >> >> Looks good. Thanks Weiguo for posting this patch and addressing all the comments! >> >> Acked-by: Jay Jayatheerthan < jay.jayatheerthan@intel.com> > > Applied to dpdk-next-net-eventdev/for-main. Thanks > > >> >> -Jay >> >> >> >>> -----Original Message----- >>> From: Weiguo Li >>> Sent: Friday, February 4, 2022 1:51 PM >>> To: Jayatheerthan, Jay >>> Cc: Kundapura, Ganapati ; Naga Harish K, S V ; >>> stephen@networkplumber.org; dev@dpdk.org >>> Subject: [PATCH v6] eventdev/eth_rx: fix memory leak when token parsing finished >>> >>> 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") >>> No stable tag - is it wanted for relevant stable branches? >>> Signed-off-by: Weiguo Li >>> Acked-by: Ganapati Kundapura >>> >>> --- >>> v6: >>> * fix double free problem in v5 as Jay noted >>> v5: >>> * fix according to Jay's comment. >>> * fix anothor bypassing the freeing of memory problem >>> v4: >>> * fix compilation issue >>> v3: >>> * validate "eth_dev_id" by rte_eth_dev_is_valid_port() >>> as Ganapati's comment. >>> * validate "token" by macros to reduce code redundancy. >>> * use new macros to avoid bypassing the freeing of memory problem. >>> v2: >>> * add memory check after strdup >>> --- >>> 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 ae1e260c08..4da6f1ff90 100644 >>> --- a/lib/eventdev/rte_event_eth_rx_adapter.c >>> +++ b/lib/eventdev/rte_event_eth_rx_adapter.c >>> @@ -293,6 +293,30 @@ 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) >>> { >>> @@ -3323,7 +3347,7 @@ 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; >>> >>> @@ -3332,33 +3356,37 @@ 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 */ >>> rx_queue_id = strtoul(token, NULL, 10); >>> 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; >>> } >>> >>> token = strtok(NULL, "\0"); >>> if (token != NULL) >>> 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, >>> rx_queue_id, &queue_conf)) { >>> @@ -3378,6 +3406,10 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, >>> RXA_ADD_DICT(queue_conf.ev, flow_id); >>> >>> return 0; >>> + >>> +error: >>> + free(l_params); >>> + return ret; >>> } >>> >>> static int >>> @@ -3387,7 +3419,7 @@ 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; >>> >>> @@ -3396,33 +3428,37 @@ 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 */ >>> rx_queue_id = strtoul(token, NULL, 10); >>> 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; >>> } >>> >>> token = strtok(NULL, "\0"); >>> if (token != NULL) >>> 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, >>> rx_queue_id, &q_stats)) { >>> @@ -3441,6 +3477,10 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, >>> RXA_ADD_DICT(q_stats, rx_dropped); >>> >>> return 0; >>> + >>> +error: >>> + free(l_params); >>> + return ret; >>> } >>> >>> static int >>> @@ -3450,7 +3490,7 @@ 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; >>> >>> if (params == NULL || strlen(params) == 0 || !isdigit(*params)) >>> @@ -3458,33 +3498,37 @@ 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 */ >>> rx_queue_id = strtoul(token, NULL, 10); >>> 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; >>> } >>> >>> token = strtok(NULL, "\0"); >>> if (token != NULL) >>> 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, >>> eth_dev_id, >>> @@ -3494,6 +3538,10 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, >>> } >>> >>> return 0; >>> + >>> +error: >>> + free(l_params); >>> + return ret; >>> } >>> >>> RTE_INIT(rxa_init_telemetry) >>> -- >>> 2.25.1 >> >