From patchwork Mon Jul 22 08:28:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142574 X-Patchwork-Delegate: bruce.richardson@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D49D04567F; Mon, 22 Jul 2024 11:01:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 687BE427D6; Mon, 22 Jul 2024 11:01:51 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mails.dpdk.org (Postfix) with ESMTP id D123D40E0B; Mon, 22 Jul 2024 10:28:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721636932; x=1753172932; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ACmZLSp9+iicTUZBm7thc+0r1r/+CPLmOwjIHZg0iXI=; b=HoWrsHe43kcVMeR643WlqNiglI4F7g/qTMtMx1E1kFszILh+Y3CmIOwu QVZImmi3yJyE6c6fLAuNXkKHgd7aqX+TFfQVU/SJwqt3RKsvBlS8Hotv9 4uhfGoJ+eNJXXdhc9tUDg1PGpFmDmglUn8852+YzWWczJ6WnDrhIi0Cl1 ifGVFg79OtEug2ZNtAxeGmRFQRvRL7sozUIIHPxqVALe6XV9svv255isI XwKS6nJYXc64SDlmW7Y6Fbyrw0cuqlGlYliH6sqJBuD7lmYl8Idt2GEEB azhrJo/aJcSDnwp3Legy8K8P+FvrB3TeqMCDeAlvicEhvo/gb4ED1MjNC w==; X-CSE-ConnectionGUID: bhqwrCMCQ/mhtuf1rdyqUA== X-CSE-MsgGUID: 0an/cqWYRTG2Gah7S47YuQ== X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="23055581" X-IronPort-AV: E=Sophos;i="6.09,227,1716274800"; d="scan'208";a="23055581" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 01:28:49 -0700 X-CSE-ConnectionGUID: m7r7NSOnSR2JcxsiMjbbAw== X-CSE-MsgGUID: CK3KahhKRESb7KxuKjaMAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,227,1716274800"; d="scan'208";a="51698114" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa010.jf.intel.com with ESMTP; 22 Jul 2024 01:28:48 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org, Michael Theodore Stolarchuk Subject: [PATCH v3 1/3] net/ice: fix possible memory leak Date: Mon, 22 Jul 2024 08:28:34 +0000 Message-Id: <20240722082836.176515-1-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240715180441.3682734-1-vladimir.medvedkin@intel.com> References: <20240715180441.3682734-1-vladimir.medvedkin@intel.com> MIME-Version: 1.0 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 This patch fixes possible memory leak inside the ice_hash_parse_raw_pattern() due to the lack of a call to rte_free() for previously allocated pkt_buf and msk_buf. Fixes: 1b9c68120a1c ("net/ice: enable protocol agnostic flow offloading in RSS") Cc: stable@dpdk.org Reported-by: Michael Theodore Stolarchuk Signed-off-by: Vladimir Medvedkin --- drivers/net/ice/ice_hash.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c index f923641533..cdce1d0ea2 100644 --- a/drivers/net/ice/ice_hash.c +++ b/drivers/net/ice/ice_hash.c @@ -650,7 +650,7 @@ ice_hash_parse_raw_pattern(struct ice_adapter *ad, uint8_t *pkt_buf, *msk_buf; uint8_t tmp_val = 0; uint8_t tmp_c = 0; - int i, j; + int i, j, ret = 0; if (ad->psr == NULL) return -rte_errno; @@ -670,8 +670,10 @@ ice_hash_parse_raw_pattern(struct ice_adapter *ad, return -ENOMEM; msk_buf = rte_zmalloc(NULL, pkt_len, 0); - if (!msk_buf) + if (!msk_buf) { + rte_free(pkt_buf); return -ENOMEM; + } /* convert string to int array */ for (i = 0, j = 0; i < spec_len; i += 2, j++) { @@ -708,18 +710,21 @@ ice_hash_parse_raw_pattern(struct ice_adapter *ad, msk_buf[j] = tmp_val * 16 + tmp_c - '0'; } - if (ice_parser_run(ad->psr, pkt_buf, pkt_len, &rslt)) - return -rte_errno; + ret = ice_parser_run(ad->psr, pkt_buf, pkt_len, &rslt); + if (ret) + goto free_mem; - if (ice_parser_profile_init(&rslt, pkt_buf, msk_buf, - pkt_len, ICE_BLK_RSS, true, &prof)) - return -rte_errno; + ret = ice_parser_profile_init(&rslt, pkt_buf, msk_buf, + pkt_len, ICE_BLK_RSS, true, &prof); + goto free_mem; rte_memcpy(&meta->raw.prof, &prof, sizeof(prof)); +free_mem: rte_free(pkt_buf); rte_free(msk_buf); - return 0; + + return ret; } static void From patchwork Mon Jul 22 08:28:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142575 X-Patchwork-Delegate: bruce.richardson@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 75DF94567F; Mon, 22 Jul 2024 11:01:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A4E2142EF4; Mon, 22 Jul 2024 11:01:52 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mails.dpdk.org (Postfix) with ESMTP id 8D7A740E0B for ; Mon, 22 Jul 2024 10:28:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721636933; x=1753172933; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JmBhCnZ8TPqse4hpyub5Viq5ugvBLRTDUfkRAjQWrZM=; b=Dvdy8S55w0BIyDxzc5so97Vvn/oWcj4OpIf2T+U0xsDiDs3No7wGWD+b +0R8hVcmdqbI/At0kmlv7qafQ+5Y5oZPGggBpEXD+u8q5PVlG5VERfK90 67q7W2TtptguvYGMOYH4pQ5bbbfp7zrHzcYz0DpyRoU0TyfIabd6KP1iT lqpLXIFVSpQIounGiTmKFvrzvr2TZ2oBZjES0Trvt7mzPd7Se4gydmKnh 60xeXopBt4Aag7uvelHhGT+qQGmJbkYdnZHRO0xjqcm43yQXBhWKNPm1r rYCR+2V0tVejJc1+wtWYvaD81yKlv7yqYupLrIbh13dB7hCK7pnRxkZFv g==; X-CSE-ConnectionGUID: OkHKOOsCRa2OggVMYcCZDw== X-CSE-MsgGUID: GTNizYKlRUS2m4wwUkBdWg== X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="23055585" X-IronPort-AV: E=Sophos;i="6.09,227,1716274800"; d="scan'208";a="23055585" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 01:28:50 -0700 X-CSE-ConnectionGUID: N8FoxHfuSCWKHo6EQ4LjYQ== X-CSE-MsgGUID: BWyinDpgRRWGJyXiSrUmUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,227,1716274800"; d="scan'208";a="51698131" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa010.jf.intel.com with ESMTP; 22 Jul 2024 01:28:49 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com Subject: [PATCH v3 2/3] net/ice: refactor raw pattern parsing function Date: Mon, 22 Jul 2024 08:28:35 +0000 Message-Id: <20240722082836.176515-2-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722082836.176515-1-vladimir.medvedkin@intel.com> References: <20240715180441.3682734-1-vladimir.medvedkin@intel.com> <20240722082836.176515-1-vladimir.medvedkin@intel.com> MIME-Version: 1.0 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 Replace strlen with more secure strnlen in ice_hash_parse_raw_pattern. Signed-off-by: Vladimir Medvedkin --- drivers/net/ice/ice_hash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c index cdce1d0ea2..d63e673b25 100644 --- a/drivers/net/ice/ice_hash.c +++ b/drivers/net/ice/ice_hash.c @@ -658,9 +658,9 @@ ice_hash_parse_raw_pattern(struct ice_adapter *ad, raw_spec = item->spec; raw_mask = item->mask; - spec_len = strlen((char *)(uintptr_t)raw_spec->pattern); - if (strlen((char *)(uintptr_t)raw_mask->pattern) != - spec_len) + spec_len = strnlen((char *)(uintptr_t)raw_spec->pattern, raw_spec->length); + if (strnlen((char *)(uintptr_t)raw_mask->pattern, raw_spec->length) != + spec_len) return -rte_errno; pkt_len = spec_len / 2; From patchwork Mon Jul 22 08:28:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142576 X-Patchwork-Delegate: bruce.richardson@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9669A4567F; Mon, 22 Jul 2024 11:02:07 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C737342F00; Mon, 22 Jul 2024 11:01:53 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mails.dpdk.org (Postfix) with ESMTP id 045F240E1B; Mon, 22 Jul 2024 10:28:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721636933; x=1753172933; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m03pKXhM4oiuIpf03V0q8HpsvUXV7RIiiBUfbfg5+k8=; b=bgDINInj8k7vcTP+XIkt+VzhyTS2x1xa6ZjUsRUHUglD5O2AbDPaN3Vs d1X6y6nYpMwhPsKyJHYnuogl7bPHUe610oAt6hY7fRZyt3d8BwqNtwKbI V3vVKP7t3iWJD5xl5mlD687sae9PqF8eRU6Dtw/jZYWWQ7AdNgEHJ+i7E quX+gV6HzvMN/0kcYgfXR3u0arBZWhzIOkJp3hVbtQHU/0PXvbdPsT+6R FhfqwjsnjzCgiXBs8ug6bmuSPGEc8tlxVkFU49zNDRC3NyQyTJc0hwfiM BDoZaQdbA8E07Gtm0sMR0Pfvyh4ocO445AfzKZh+OStBDgwO2ZkPKx245 g==; X-CSE-ConnectionGUID: n3d5+UaKSX2saWbxltkJvA== X-CSE-MsgGUID: WSTevSv4TLO5IkJX0Pwiog== X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="23055589" X-IronPort-AV: E=Sophos;i="6.09,227,1716274800"; d="scan'208";a="23055589" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 01:28:52 -0700 X-CSE-ConnectionGUID: Hq1VDMhxRpGJ9llBelZYdA== X-CSE-MsgGUID: 5XcdA64FQ6ONySCemjSTEg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,227,1716274800"; d="scan'208";a="51698151" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa010.jf.intel.com with ESMTP; 22 Jul 2024 01:28:50 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org Subject: [PATCH v3 3/3] net/ice: fix return value for raw pattern parsing function Date: Mon, 22 Jul 2024 08:28:36 +0000 Message-Id: <20240722082836.176515-3-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722082836.176515-1-vladimir.medvedkin@intel.com> References: <20240715180441.3682734-1-vladimir.medvedkin@intel.com> <20240722082836.176515-1-vladimir.medvedkin@intel.com> MIME-Version: 1.0 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 If the parser was not initialized when calling ice_hash_parse_raw_pattern() -rte_errno was returned. Replace returning rte_errno with ENOTSUP since rte_errno is meaningless in the context of ice_hash_parse_raw_pattern(). Fixes: 1b9c68120a1c ("net/ice: enable protocol agnostic flow offloading in RSS") Cc: stable@dpdk.org Signed-off-by: Vladimir Medvedkin --- drivers/net/ice/ice_hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c index d63e673b25..b040a198bb 100644 --- a/drivers/net/ice/ice_hash.c +++ b/drivers/net/ice/ice_hash.c @@ -653,7 +653,7 @@ ice_hash_parse_raw_pattern(struct ice_adapter *ad, int i, j, ret = 0; if (ad->psr == NULL) - return -rte_errno; + return -ENOTSUP; raw_spec = item->spec; raw_mask = item->mask;