From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 6D06345A5D
	for <public@inbox.dpdk.org>; Sun, 29 Sep 2024 17:41:37 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 376F940651;
	Sun, 29 Sep 2024 17:41:32 +0200 (CEST)
Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com
 [209.85.210.176])
 by mails.dpdk.org (Postfix) with ESMTP id 6E1FA4060F
 for <stable@dpdk.org>; Sun, 29 Sep 2024 17:41:25 +0200 (CEST)
Received: by mail-pf1-f176.google.com with SMTP id
 d2e1a72fcca58-718e6299191so1863956b3a.2
 for <stable@dpdk.org>; Sun, 29 Sep 2024 08:41:25 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727624484;
 x=1728229284; darn=dpdk.org; 
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=PmRTbddZLG2JxQ2OFMT3a37iU/8U3GJd/GKLMFfTKa0=;
 b=CpVj8quLcDGkPPw2F+9B5Cq8l+/Y9bMYIZdT9wXpTE3L2TcEYiFrf1NIrjybyskUYy
 pMo4QySkQEt1JvEV8vbrZhRIyNBg1FqchxlzY5/klaW53an9vuojFIhDY4CB4Xf/bTcc
 L65oASxHpy26ue8bS5Js2rYOk5okzFLcA+ddVw312bQz1/xF9XIYOuqosD745ZMb455i
 3caXS8H/EgAWP8UEQgeBnWHwOl3gdo+XnVkaR/+QmZyj8HDmTzhXUcHX9SY51N+kOfn/
 sIlomryITgtYoIg2lHord8+OmMGam7Exv+HoN53unGwEB/wCe0kz0+UlxkSXb531umK8
 jzzA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1727624484; x=1728229284;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=PmRTbddZLG2JxQ2OFMT3a37iU/8U3GJd/GKLMFfTKa0=;
 b=MpAc/r4Rf6Y8vnI+BzvQb3v8TrxFfLqFZEp/hEEf0vYjcDuFJbXXR0yuwCUUdFSUUh
 AaQnNbQ9Y0SFoigALGXy5jmozNUMrwBd1/iAjjLcrvKzNsv0Nc68EgGWfN3XCnNz/th5
 +gGjmz3vVDmfb7C3odTdDjqcoWbUj4x4PCKYbMnK4EwKBZ5ePXQUGiSwtyRRWkkmcegh
 isnOr92w6DukrPl3QeyFd8Em9sy6P6PLQl/es0l2HA6nrmMnYRiLmUcAPj0nNTCUSU77
 UvD4naYvgSBsx2C35K3C+fE0X2DWy2/BG3e9rCpBxACItPLUhv0gxYixe3dEbI8/kREG
 Rv1A==
X-Forwarded-Encrypted: i=1;
 AJvYcCWeDVt7T3W6aifvIXh0YIFqS1sKqotUso+xyb5kXcDP3EZDsqaYsRs+/g0h6G21p7P8uZ7li/o=@dpdk.org
X-Gm-Message-State: AOJu0Yw+co2EWyXGjZUxvpX1LM4JfSqW8dAw5bKNG0LeNPge35dsq1r/
 FCA4o+5F6i+SdX52anPlDPEJgSc3kMl+GCBjk7XctWG6KJhmkxbYin/Xc/+sbNQ=
X-Google-Smtp-Source: AGHT+IHw7ZTeHWgZ8Zl0hM7ECF0rAXwDPTH2sycZG/Ug/r+JiPzd9+VA5Edk62jGcXldgwXwQ68dbg==
X-Received: by 2002:a05:6a00:2195:b0:719:8f48:ff01 with SMTP id
 d2e1a72fcca58-71b25f28598mr14083803b3a.6.1727624484583; 
 Sun, 29 Sep 2024 08:41:24 -0700 (PDT)
Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226])
 by smtp.gmail.com with ESMTPSA id
 d2e1a72fcca58-71b2649c775sm4707416b3a.29.2024.09.29.08.41.24
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 29 Sep 2024 08:41:24 -0700 (PDT)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>, stable@dpdk.org,
 Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>,
 Ray Kinsella <mdr@ashroe.eu>
Subject: [PATCH v3 07/18] bpf: fix free mismatch if convert fails
Date: Sun, 29 Sep 2024 08:34:32 -0700
Message-ID: <20240929154107.62539-8-stephen@networkplumber.org>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240929154107.62539-1-stephen@networkplumber.org>
References: <20240927204742.546164-1-stephen@networkplumber.org>
 <20240929154107.62539-1-stephen@networkplumber.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org

If conversion of cBF to eBPF fails then an object allocated with
rte_malloc() would be passed to free().

[908/3201] Compiling C object lib/librte_bpf.a.p/bpf_bpf_convert.c.o
../lib/bpf/bpf_convert.c: In function ‘rte_bpf_convert’:
../lib/bpf/bpf_convert.c:559:17: warning: ‘free’ called on pointer returned from a mismatched allocation function [-Wmismatched-dealloc]
  559 |                 free(prm);
      |                 ^~~~~~~~~
../lib/bpf/bpf_convert.c:545:15: note: returned from ‘rte_zmalloc’
  545 |         prm = rte_zmalloc("bpf_filter",
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~
  546 |                           sizeof(*prm) + ebpf_len * sizeof(*ebpf), 0);
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/bpf/bpf_convert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/bpf/bpf_convert.c b/lib/bpf/bpf_convert.c
index d7ff2b4325..e7e298c9cb 100644
--- a/lib/bpf/bpf_convert.c
+++ b/lib/bpf/bpf_convert.c
@@ -556,7 +556,7 @@ rte_bpf_convert(const struct bpf_program *prog)
 	ret = bpf_convert_filter(prog->bf_insns, prog->bf_len, ebpf, &ebpf_len);
 	if (ret < 0) {
 		RTE_BPF_LOG_LINE(ERR, "%s: cannot convert cBPF to eBPF", __func__);
-		free(prm);
+		rte_free(prm);
 		rte_errno = -ret;
 		return NULL;
 	}
-- 
2.45.2