From patchwork Mon Jul 22 13:50:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142613 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 5837945681; Mon, 22 Jul 2024 15:50:53 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3836A40676; Mon, 22 Jul 2024 15:50:52 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by mails.dpdk.org (Postfix) with ESMTP id C0C5C402A8; Mon, 22 Jul 2024 15:50: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=1721656251; x=1753192251; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D3JjspUW9cMQ299XCFV4uvmhvAaNCZE8MOZTvfVd8UI=; b=IWFcLgq2zt9OmxOjCgy7KH1kMBEjcck6tCWqcgfZPTTuiBuuhII47h3Q IVh+ZvkWroEnXmJhwpiKlaj5CsEnH+JF7mmQODBEGVMsY7lVT+srqCCnZ oX8QlmbRduxNXaUTDRVE09THVWBjPo+Z20OzZj6dRYoD4EcaG0EwjvCTr 8p+1dkxoqnU5i/f+ifGvSQJ/FadQ934o7lJCF+3pRHzN12n9rNc2V8lgH lwRYMmFeakForG22qxf91ewtqW7fgyTuouxRBZc+YEpmEwW+FHwuNBC+Q WNZ9+gGAKzyiGuvmMeH5SwCydccNDpYAOZUzgjW+/4ff/OfDvNEbv9nfp w==; X-CSE-ConnectionGUID: 0cW/7n5aSk+pA97NeLXrUw== X-CSE-MsgGUID: U7cLAz9ISx6dRoHbq0MqEA== X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="19354995" X-IronPort-AV: E=Sophos;i="6.09,228,1716274800"; d="scan'208";a="19354995" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 06:50:50 -0700 X-CSE-ConnectionGUID: pEFn47W8R8uZxUGCAxaUDQ== X-CSE-MsgGUID: 7KZG3qhMTlOSY11jK8hU1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,228,1716274800"; d="scan'208";a="52494935" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa007.jf.intel.com with ESMTP; 22 Jul 2024 06:50:49 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org, Michael Theodore Stolarchuk Subject: [PATCH v5 1/3] net/ice: fix possible memory leak Date: Mon, 22 Jul 2024 13:50:44 +0000 Message-Id: <20240722135046.285868-1-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722105950.199804-1-vladimir.medvedkin@intel.com> References: <20240722105950.199804-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 Acked-by: Bruce Richardson --- drivers/net/ice/ice_hash.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c index f923641533..6b3095e2c5 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,22 @@ 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); + if (ret) + 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 13:50:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142614 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 96BED45681; Mon, 22 Jul 2024 15:50:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 543384067B; Mon, 22 Jul 2024 15:50:53 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by mails.dpdk.org (Postfix) with ESMTP id 873C1402A8 for ; Mon, 22 Jul 2024 15:50:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721656252; x=1753192252; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pLf0IzYksPP8odQQQ+vdHoc0pPLdyIWdvCkSwpjiZF4=; b=LvfQjZf8Im/r2GuhCiw7EgEKoSO4WCmlY3WZnw8QMzwlq+W7dAXmEaUk jTRCPbqEGDHIwIdi7lvHeXDVF10jTHorgqYPGZk8MayYasgyLv5ER3I++ SLtZheTB/j5PSSmVfy/rBpJr0R7o0R2r8lN4Ptctm6qLINqHvUUWAV59R dGwtyDs4e4X0UMEx0D0AjwCCbLIOeNOfrHPokstBkNXcUvqfnlCoE9Ktp r0SbZrxC03YhR9VjupJTBZY9AMiXPO5ZFvy6+wrEUL64SzPwFWX8cQFns 3SbvZdUlobwth8BouCN7v1YR99QP3tKvCZb2ttb8R7U76JAnlxwKsmK6k A==; X-CSE-ConnectionGUID: I8VlK7KoT4miQgFpaSf6/g== X-CSE-MsgGUID: lqwxSU3kRSCZOk+X2ZZG7g== X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="19354997" X-IronPort-AV: E=Sophos;i="6.09,228,1716274800"; d="scan'208";a="19354997" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 06:50:51 -0700 X-CSE-ConnectionGUID: yHtE7FmzTJiC+PqJgmmzrQ== X-CSE-MsgGUID: tlUDwwU2QAel8fn62rVPhg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,228,1716274800"; d="scan'208";a="52494940" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa007.jf.intel.com with ESMTP; 22 Jul 2024 06:50:50 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com Subject: [PATCH v5 2/3] net/ice: refactor raw pattern parsing function Date: Mon, 22 Jul 2024 13:50:45 +0000 Message-Id: <20240722135046.285868-2-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722135046.285868-1-vladimir.medvedkin@intel.com> References: <20240722105950.199804-1-vladimir.medvedkin@intel.com> <20240722135046.285868-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 tmp Acked-by: Bruce Richardson --- drivers/net/ice/ice_hash.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c index 6b3095e2c5..aa76718313 100644 --- a/drivers/net/ice/ice_hash.c +++ b/drivers/net/ice/ice_hash.c @@ -658,10 +658,13 @@ 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) - return -rte_errno; + spec_len = strnlen((char *)(uintptr_t)raw_spec->pattern, + raw_spec->length + 1); + if (spec_len != raw_spec->length) + return -EINVAL; + if (strnlen((char *)(uintptr_t)raw_mask->pattern, raw_spec->length + 1) != + spec_len) + return -EINVAL; pkt_len = spec_len / 2; From patchwork Mon Jul 22 13:50:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 142615 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 4C86145681; Mon, 22 Jul 2024 15:51:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B9A0940678; Mon, 22 Jul 2024 15:50:56 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by mails.dpdk.org (Postfix) with ESMTP id 5464840678; Mon, 22 Jul 2024 15:50: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=1721656253; x=1753192253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1V5lWQebHb3+XLNxvej5/iGIHZHHI5lmNmD+JBtIYt4=; b=c6fJQb7nvWJ4IdBDcX/GqprJdm0tKSciRy90Jjo140v5j3ql04K0V/tW mVEMDVnUsyrl3uqb0aRAMl1O15rsPlY+1QTOqiJHFMOyxaeKTUnjPGdTh MInFmZgg1uqxbbCf0/JzL6Ig5XVrk3mv35o6iJQ8TLytokgHOGcGmoNSq 0rHE7DKDnA1pFWRgRXZ3rQyfbfapTV44T6bUp4QDKrDknkvVGVEWi0Hyi sv4H9mX7UTA8/FeBQFvcP04+iqgSPRNzke4lRq6OOuQr+j3tf74jwBN3Y pY/Gro2usqWtq9Yn/CVFNDB8j19rLQGJTd4tBN4EsjdDNTR9OKOoKxF4X A==; X-CSE-ConnectionGUID: +fAXOT0OR7a1QNofipayAA== X-CSE-MsgGUID: CZon0G+bSdejawwGxfe4bw== X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="19354998" X-IronPort-AV: E=Sophos;i="6.09,228,1716274800"; d="scan'208";a="19354998" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 06:50:52 -0700 X-CSE-ConnectionGUID: p3dmF8BTRTGUI6BfcmhAXQ== X-CSE-MsgGUID: RfEJ9MeLRfyzG7pSXXQH4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,228,1716274800"; d="scan'208";a="52494944" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa007.jf.intel.com with ESMTP; 22 Jul 2024 06:50:51 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org Subject: [PATCH v5 3/3] net/ice: fix return value for raw pattern parsing function Date: Mon, 22 Jul 2024 13:50:46 +0000 Message-Id: <20240722135046.285868-3-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722135046.285868-1-vladimir.medvedkin@intel.com> References: <20240722105950.199804-1-vladimir.medvedkin@intel.com> <20240722135046.285868-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 aa76718313..b720e0f755 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;