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 4CD8F455FE; Thu, 11 Jul 2024 18:59:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 36FC742E5A; Thu, 11 Jul 2024 18:59:15 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by mails.dpdk.org (Postfix) with ESMTP id 606A24065B for ; Thu, 11 Jul 2024 18:59:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720717153; x=1752253153; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=r+F08kVrQv0BNnxUaR9QSpgvutbfqCUw7guCeUK2i/k=; b=JEO3Oihq37YZ0KUqQz+rfB4NALs+JAN7o4JFtxKhS/3oYPP66bxiLRQE 2X4PDgVZmShFZ0fGHU2FcU/7nihCaMJEcP/VoiWzLFi1kQjQk9MsJK9wY 3zpMHf6gER79GGHyqyXwbNWLSEibbke3OmHXA4SBvgDU+mGkL/k4q6fwF W9ZtiXywWdPw3JaMsclCEBM/m6X28TKHx+ccv8ymTWSh8dpE+iWwaNuzy Dafi1JqArN2eBOnU0UJ7VoblDWMzmwJ5xAXoIn13QKdcm6XiNxWg7l8C3 26cx1jMXTY4oMHvDMVHc6UAsZvfgvHlmsQnuJ0tFHSrdjpbpCVunUHgJe w==; X-CSE-ConnectionGUID: WkAMzQzCT5Wo4jbL27niGw== X-CSE-MsgGUID: m7MRwjVKTl6+72YyicLt6w== X-IronPort-AV: E=McAfee;i="6700,10204,11130"; a="28788894" X-IronPort-AV: E=Sophos;i="6.09,200,1716274800"; d="scan'208";a="28788894" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2024 09:59:12 -0700 X-CSE-ConnectionGUID: jyoYvSr5SqGYDFb6JTJHOg== X-CSE-MsgGUID: jsGvA178TSO1VTvPce5G5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,200,1716274800"; d="scan'208";a="53446176" Received: from unknown (HELO silpixa00401176.ir.intel.com) ([10.243.22.170]) by orviesa003.jf.intel.com with ESMTP; 11 Jul 2024 09:59:10 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: bruce.richardson@intel.com, ting.xu@intel.com, Michael Theodore Stolarchuk Subject: [PATCH] net/ice: fix possible memory leak Date: Thu, 11 Jul 2024 16:59:07 +0000 Message-Id: <20240711165907.3169191-1-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 memleak inside the ice_hash_parse_raw_pattern(). Additionally replaces using strlen() with more secure strnlen(). Also replaces the returned inconsistent rte_errno with explicit error statuses. Fixes: 1b9c68120a1c ("net/ice: enable protocol agnostic flow offloading in RSS") Cc: ting.xu@intel.com Cc:stable@dpdk.org Reported-by: Michael Theodore Stolarchuk Signed-off-by: Vladimir Medvedkin --- drivers/net/ice/ice_hash.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c index f923641533..a7dbb54d91 100644 --- a/drivers/net/ice/ice_hash.c +++ b/drivers/net/ice/ice_hash.c @@ -650,18 +650,18 @@ 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; + return -ENOTSUP; 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); + if (strnlen((char *)(uintptr_t)raw_mask->pattern, raw_mask->length) != + spec_len) + return -EINVAL; pkt_len = spec_len / 2; @@ -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 -- 2.34.1