From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA75A478E36; Sat, 12 Sep 2026 16:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789229019; cv=none; b=t0DH1Lamb0ViuX7zPDDhuKtL6XtENhyLYhMf5nrJL4Mfxl1pYz2jvz50Un6bNz5IiSHhuPycjpQ44Xoy7Q/LOUn239wdaG9rbDdnVk9NYbCcm6fteAx91Nai9ds8qEk5Hl3NPLcXOiZrqns1Ou/nJrFLXZF3i7eH/AaF9KoLI3c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789229019; c=relaxed/simple; bh=uOhKmlSHoK6xEvkZ4BxAYCTJWQeRhaLMi6ZkZMfXE6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LbxbcedWm7qHiKsSMbug4/1CNb2OT/gTRcEfolnz8z8VlM0cbook3ZITgb6zsXoev7cN43He7AwdFpdpv1ol9h3Kb9PL4+uhDv42Uee1tSITG2OdSRFCCjQ4WkQmQcgbc8H0gMAox+rPi/UcvA06e2cjw5SftnPGgulX2sPz234= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1fNHY/84; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1fNHY/84" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 342981F000FF; Sat, 12 Sep 2026 16:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789229017; bh=k0sQBk7BaoqxKNx95anJ2XXzUGvofGhwVR9sQk4NsX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1fNHY/84LCntqdLUKlss9csFciGYQ6v0kRAi/VYvU726pZ4SAPGojpfrdzo4wbq52 Ukm4f6X4fuOZAOA1QgGauZfM8WHnhOIzH8t7uMfwClrp50a3dPrVMsf9Kd2wdfE5fm Wt9R0t791nS5eO3U205MNgTZg3XLM8gH22IVEiJ4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yichong Chen , Andrii Nakryiko , Emil Tsalapatis , Sasha Levin Subject: [PATCH 6.1 0502/1191] tools/bpf/bpftool: Reset vmlinux BTF after map commands Date: Sat, 12 Sep 2026 08:53:50 +0200 Message-ID: <20260912065559.513422236@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yichong Chen [ Upstream commit 66d7e39e49b0dd57610c9b63afc65b4d5690983b ] get_map_kv_btf() caches the vmlinux BTF object when a map uses btf_vmlinux_value_type_id. map dump released that object when the command completed, but left the global pointer stale. The same cached object can also be returned to print_key_value(), which freed it directly. That leaves btf_vmlinux dangling before the command cleanup path runs. Use free_map_kv_btf() for per-entry cleanup, and reset the cached btf_vmlinux pointer when the map command releases the object. This keeps batch mode from reusing a freed BTF object. Fixes: 4e1ea33292ff ("bpftool: Support dumping a map with btf_vmlinux_value_type_id") Signed-off-by: Yichong Chen Signed-off-by: Andrii Nakryiko Reviewed-by: Emil Tsalapatis Link: https://lore.kernel.org/bpf/9072F43B3F74DF91+20260624025055.1574875-2-chenyichong@uniontech.com Signed-off-by: Sasha Levin --- tools/bpf/bpftool/map.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 3087ced658adc..1cbed8d7b2ba3 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -781,6 +781,12 @@ static int maps_have_btf(int *fds, int nb_fds) static struct btf *btf_vmlinux; +static void free_btf_vmlinux(void) +{ + btf__free(btf_vmlinux); + btf_vmlinux = NULL; +} + static int get_map_kv_btf(const struct bpf_map_info *info, struct btf **btf) { int err = 0; @@ -1046,7 +1052,7 @@ static void print_key_value(struct bpf_map_info *info, void *key, btf_wtr = get_btf_writer(); if (!btf_wtr) { p_info("failed to create json writer for btf. falling back to plain output"); - btf__free(btf); + free_map_kv_btf(btf); btf = NULL; print_entry_plain(info, key, value); } else { @@ -1062,7 +1068,7 @@ static void print_key_value(struct bpf_map_info *info, void *key, } else { print_entry_plain(info, key, value); } - btf__free(btf); + free_map_kv_btf(btf); } static int do_lookup(int argc, char **argv) -- 2.53.0