From patchwork Mon Jul 15 18:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142410 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 B432C45626; Mon, 15 Jul 2024 20:05:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A2FA34065F; Mon, 15 Jul 2024 20:05:40 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mails.dpdk.org (Postfix) with ESMTP id EF917402AF; Mon, 15 Jul 2024 20:05:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721066739; x=1752602739; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=50MQX9KzkRTfowu2a3I4WK0eYsfHL6sVpCaUk6wYt1A=; b=BYeESBzQSslrdplWUIYFcx2RWdNBpI++7yYlpt8/bblksayhdWaHYKOT /DKs19cvPoywJC5mI29Gf9rKz/HFbA2UWU7Y6dmAZoosi64hSXbSxkXEJ RDgLDS4ij8kd98+S2VfxLVZ131E1wUIp/fIqnlP6+ljOlTyakPh3m+SIC nbKsTUc0n27bounxHg46sPGDT8ADvSdOc6QfGzVVjQuR1ZPW2ew/DuZNs lOpEQLB9DDp6FxyJapkOPoeEoTLx9XM/tUPeobfFnhor6WBTcAkTg2gcb jEvhMxHYGmrBte3L1Ew3Hxh/QCZ0GZyj8ArI02xCuCMgxoi6NPQFJdXri g==; X-CSE-ConnectionGUID: DISAbwxjTXeN3sKZ6sxEsg== X-CSE-MsgGUID: F1uwoI/5RgKReAI980Gmag== X-IronPort-AV: E=McAfee;i="6700,10204,11134"; a="36005005" X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="36005005" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2024 11:05:37 -0700 X-CSE-ConnectionGUID: +H4OyH5JTQmQf9khR0rAfQ== X-CSE-MsgGUID: RORe6Z2sQXiVrPhEMwZvCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="80376365" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa002.jf.intel.com with ESMTP; 15 Jul 2024 11:05:36 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org, Michael Theodore Stolarchuk Subject: [PATCH v2 1/3] net/ice: fix possible memory leak Date: Mon, 15 Jul 2024 18:04:39 +0000 Message-Id: <20240715180441.3682734-1-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240711165907.3169191-1-vladimir.medvedkin@intel.com> References: <20240711165907.3169191-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 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c index f923641533..913f54fca4 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,17 +710,20 @@ 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; } From patchwork Mon Jul 15 18:04:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142411 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 1025545626; Mon, 15 Jul 2024 20:05:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 70A7540E3E; Mon, 15 Jul 2024 20:05:48 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mails.dpdk.org (Postfix) with ESMTP id 235BC40EDC for ; Mon, 15 Jul 2024 20:05:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721066746; x=1752602746; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a1zb7ugc+HjaZhBGO4Vjihn0FzzQR/YQpifXLGjrifg=; b=WVs3UG4bD2CcdTPSCXFoHnU9WH9gPi2CfjVXbClF7rW2WSvx5MInyxYJ NFyH1x94NHDMBre0s9JXYgM7YYvPtVxFPOmkqx/VOd92RX/acdQ2QIUgK 6xDA7zNDAsX3YDs9e2Vp8hCh9y+s0SWU4RlmVsOcEumKfPzygidIX0So+ MBShh4dOvjDoc8+zQoKzqJWH+h9iBBRgVHpV6UzO44u3LT7m7oepRZCcn 2rkK2uf3xBH7HVA5rrUnAXdNlRDzm9PbfP0bAFiOnFZGIABO0vNN6GBo0 vgwN0mKKUORF5quxEHB2ocCfFcXP5TRAxWx8ApJs1uGdYDVSCcmg2Wxp4 w==; X-CSE-ConnectionGUID: AFwKighBTwupCDorvgqkMQ== X-CSE-MsgGUID: UEec4D/ISu+7o4q/kdGRog== X-IronPort-AV: E=McAfee;i="6700,10204,11134"; a="36005017" X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="36005017" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2024 11:05:45 -0700 X-CSE-ConnectionGUID: 6tzpge0wR66YVGHqammEHQ== X-CSE-MsgGUID: 1y7HzZm9SYGQRVHkSPmAsg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="80376425" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa002.jf.intel.com with ESMTP; 15 Jul 2024 11:05:45 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com Subject: [PATCH v2 2/3] net/ice: refactor raw pattern parsing function Date: Mon, 15 Jul 2024 18:04:40 +0000 Message-Id: <20240715180441.3682734-2-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240715180441.3682734-1-vladimir.medvedkin@intel.com> References: <20240711165907.3169191-1-vladimir.medvedkin@intel.com> <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 Replace strlen with more secure strnlen in ice_hash_parse_raw_pattern. Signed-off-by: Vladimir Medvedkin Acked-by: Bruce Richardson --- 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 913f54fca4..00503d0d28 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 15 18:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142412 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 4F74E45626; Mon, 15 Jul 2024 20:05:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C54514111B; Mon, 15 Jul 2024 20:05:50 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mails.dpdk.org (Postfix) with ESMTP id CDCB0410D3; Mon, 15 Jul 2024 20:05:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721066749; x=1752602749; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cBhuLsjjPtBdDAo0vkaGM6058YjSgGbFJYhQt03aJdI=; b=WHUqCPlsIbMwCABASSDkAKkPUQxjRFmCB+31t1SjXd22IVj0p2WmG5QC Vz/8rEwuZdpDP6NB8hzJirJIZ7Z1NtKIfFFgbky/T1R4vtmm+R7rW5z9Z 3ZevmLaOh4i7Pv8+ZdkeSt5svrYvDpmnA+4LzYJXB+nEEQVIgMjqqvo3I U9yskG5RalaDwB6KgkCbI676b9nKEydHbaqsgsIKSDwSRK2sdKbGhKhbF LAfnMt5Kz3ve5hWbc2pYFCDTVLkfVbre/fdWRNkJ7allSANhPUjWM2d6p LnPrLK8NkPQ4ZHW5OTwk4D/+wZVfSHYBdC9zbqQnIADPnT/k2TcWDHfVX g==; X-CSE-ConnectionGUID: zrpTvBrxRy2tzQJXHL/WkQ== X-CSE-MsgGUID: 8enTtU76RGyswSS0ZFA1GQ== X-IronPort-AV: E=McAfee;i="6700,10204,11134"; a="36005024" X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="36005024" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2024 11:05:48 -0700 X-CSE-ConnectionGUID: qeveVcWGQg+tKHw6LHhHvQ== X-CSE-MsgGUID: 4iW4o9L0QYCy03JkSmF53Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="80376471" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa002.jf.intel.com with ESMTP; 15 Jul 2024 11:05:48 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org Subject: [PATCH v2 3/3] net/ice: fix return value for raw pattern parsing function Date: Mon, 15 Jul 2024 18:04:41 +0000 Message-Id: <20240715180441.3682734-3-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240715180441.3682734-1-vladimir.medvedkin@intel.com> References: <20240711165907.3169191-1-vladimir.medvedkin@intel.com> <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 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 Acked-by: Bruce Richardson --- 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 00503d0d28..13a68b8f02 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;