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 16F1845A9D
	for <public@inbox.dpdk.org>; Wed,  2 Oct 2024 17:44:56 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id A42D740684;
	Wed,  2 Oct 2024 17:44:51 +0200 (CEST)
Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com
 [209.85.210.172])
 by mails.dpdk.org (Postfix) with ESMTP id BF54D4064A
 for <stable@dpdk.org>; Wed,  2 Oct 2024 17:44:45 +0200 (CEST)
Received: by mail-pf1-f172.google.com with SMTP id
 d2e1a72fcca58-719b17b2da1so7126b3a.0
 for <stable@dpdk.org>; Wed, 02 Oct 2024 08:44:45 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727883885;
 x=1728488685; 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=DNl4kXyaxETFUnH8wG9XFoQOjpiMjv1IW72UvfT6R4H0AOVSwleGZb69zP4bPqWr34
 XK2u2NXuvH3ni9Zqj2AWZWbT5hgSiuzJ7qYzSiXEHiYNg7UisR52LI202naWLDkt/WP3
 HjqnjwuXTYMcDkrD75IxYOd1mSnyVFSVLD3Z8D94Ksz4qaEWxnMHL8gGt5wRL4oMVf2S
 EVwzO95+WuWq7j85tA93HAoRuGD0eci1Eaf6sgMa1Wf54RB2fMbomgzJL/xIv9AKzfKs
 ta/gOcjcCa+xKGOWmqagfYxafCTRxrhyJkIbSPrk1pAMphCLj6+4i2ugvS2osWt6Y5E2
 Ud5Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1727883885; x=1728488685;
 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=mTIg6Ahn3iGlJrVBm2uxb6St8E4FuuT/M/eyXUwUlJKVCMANCc38TTPtUuM9OPutfF
 saqdJAkmK8OGI8KqDu4ckwG3lP+GVXoyUuhPlEsha02JG7J4RGBEXd1uB8SBpD5vtNS9
 pFF98eAgNwi+rywkFhgesxVrOFpvvjqm1qbyzjH+6xXa/vaRjeTuGJ919YpOIY9MuRfO
 37ZJ7rtXPutFvqNZ1yfsxnfvNSE5XfCCJ7HOy4IXOkOsirvh1ntWAnmBOUpRnEZezZNr
 GZsXdtUzbk1lcxUYaXMs5K+J8DIk2ugYMZ8K25gkjK1ZkhAafOEI0fCNZZcRgo0BgYtM
 sORQ==
X-Forwarded-Encrypted: i=1;
 AJvYcCWXcoPP5scwwGYQxo8rqNoJmZ+Dg7ZQG+/WtAv0PKaAC8Qey8xnDA64PqRhU2fbE+LsUur7Ke8=@dpdk.org
X-Gm-Message-State: AOJu0Yx3VB34FuLgfCyPdArhLTCMakakH2MIdACfg9jUWHx/NphhVVnH
 rafhX1mM9Ta5q3Rzde0nw64v+tLJUdJVYjpFS6Z26L0bxipkHTN2ocHsjACgMvE=
X-Google-Smtp-Source: AGHT+IG7GAq1nH2NigDDVB3D4JgJhxd1Lggt4CeR2a5VEtBEcCD+FFdbYW5v+cSmYlp7Z0WWI+97tg==
X-Received: by 2002:a05:6a00:8d1:b0:718:f026:6c78 with SMTP id
 d2e1a72fcca58-71dc5ca80efmr4870702b3a.13.1727883884997; 
 Wed, 02 Oct 2024 08:44:44 -0700 (PDT)
Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226])
 by smtp.gmail.com with ESMTPSA id
 41be03b00d2f7-7e6db2927c7sm10247363a12.1.2024.10.02.08.44.44
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 02 Oct 2024 08:44:44 -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 v6 07/17] bpf: fix free mismatch if convert fails
Date: Wed,  2 Oct 2024 08:42:51 -0700
Message-ID: <20241002154429.64357-8-stephen@networkplumber.org>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20241002154429.64357-1-stephen@networkplumber.org>
References: <20240927204742.546164-1-stephen@networkplumber.org>
 <20241002154429.64357-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