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 A522E3603C3; Sat, 12 Sep 2026 18:37:52 +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=1789238273; cv=none; b=V9Jwe0l4k0VBngFa4gX0XG4ULO6DAN+uBXx+NApsnAGN8tcy8vHTzT0LtbLLlJF5jf0uiABShqUNsP39wKgoPQ8sgAJxUy6JjymmW3msy+/qarPI39OIng3YXR+WqB5JAv4+XbSCOo8faQC0DuC5sxIGX97h86TgKtwx3hKKHow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789238273; c=relaxed/simple; bh=AJg6rQNs7A4cXTU50q2DWUn3Pma8R/B9FLaMzPjDDbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hOzCmn5BYD6OY91ztRc4R2nqpV94MOE7m9Jaag4sCrzAwHnHTZ3mqPbLUeLkIZ8Use+AS7VQTe/OfJTVKmVHRjNoAB3RArk1V1ufvNNs9+IEYg/OSi2ruB9jMhTMpKFGi3qOoD9ffLXMvkY/0SRA7mg4qtsGWOuoPQE02/AGUiE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NKz0OMNS; 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="NKz0OMNS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A94CE1F000FF; Sat, 12 Sep 2026 18:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789238272; bh=HSUMiNN6TiBMjLLXs5VeZjamoiSLaQccmXH4pwakVaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NKz0OMNS4mizpZs30k/vS80n6UefqeCnvW4WMn5df3BEENO4WE3c8VXaILSldGXbg XayX2BovTpgtrQILWCfBFBAQclIUbH4pmAuIwr3g2IQ0XFHnFuyjtaVxMHaOOfBE63 mjrVb872DaYAUg4oG11adcQ0wT+Swv0x+9O91iGE= 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 5.15 427/935] tools/bpf/bpftool: Reset vmlinux BTF after map commands Date: Sat, 12 Sep 2026 08:57:37 +0200 Message-ID: <20260912065536.621534799@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065526.833703348@linuxfoundation.org> References: <20260912065526.833703348@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 5.15-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 fe3ac01db919e..9575cb555e2cf 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -792,6 +792,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; @@ -1053,7 +1059,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 { @@ -1069,7 +1075,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