From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-4.mta1.migadu.com [95.215.58.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 054D547ACFA for ; Tue, 1 Sep 2026 10:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788259853; cv=none; b=az0uG6i8irWQlGDTKi6uslUdZJZhEdf/IkMnCESY4dYEXL7Hh7BbqtRSqKcFFRCpZdRNLGQRF8fc46tUIoNub4dvx4xixFXDS79e4zb75EwfRQJAhxKCD1UqFGkc8nabEXoBkBaUQEL6wPCDbwiGxMky7/Xh1CI7d/LRN3TMsCw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788259853; c=relaxed/simple; bh=gPKpCL1/0/HGOmJCv2o0g9Ep/ccfdyIwBD6hFRIQHy4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=naXaNlZsUMsCiVM+XDbLO9M2jOSoUcL3D/JwDP0+pRWZexBVe4FJsSq2mPSOnc3RK69L9tlb+NE5WmohBPUht2a8e0A3WUW9Ovu1HL+mCMmJl09jdQH9u78HopJqDwuCdYvevBpQWas5S7MiRdVf/T4vBmNZeu9SFtwITIOFJ7M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=uEJYFSbr; arc=none smtp.client-ip=95.215.58.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="uEJYFSbr" X-Envelope-To: linux-kselftest@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=gPKpCL1/0/HGOmJCv2o0g9Ep/ccfdyIwBD6hFRIQHy4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1788259849; v=1; x=1788864649; b=uEJYFSbro7W7xdPBNUVefEqxyrraOEozoGq7QcvFvtumYFUE7sBxrCKk9eRIxIgGlRho0lWS et8UuFbh0N+9DzU3fdq9lAV8EJf0LNlwf0lzMbkkQ96qVdPEq2ZpFceZT2bbETHxxCvWyDeBOr9 KIpx3HIz3GDm6AAUdXBFKa68= X-Envelope-To: linux-kselftest@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 41aadf1de9cb078d; Tue, 01 Sep 2026 10:50:49 +0000 X-Mizu-Trace-ID: 41aadf1de9cb078d X-Migadu-Flow: FLOW_OUT From: Jiayuan Chen To: bpf@vger.kernel.org Cc: Jiayuan Chen , Ihor Solodrai , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Shuah Khan , Mykyta Yatsenko , Alan Maguire , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf v4 2/5] bpf: Fix NULL-ptr-deref when showing a void BTF type Date: Tue, 1 Sep 2026 18:47:36 +0800 Message-ID: <20260901104924.346187-3-jiayuan.chen@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260901104924.346187-1-jiayuan.chen@linux.dev> References: <20260901104924.346187-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit btf_modifier_show() resolves the modifier and then calls btf_type_ops(t)->show() unconditionally. For the void type (type_id 0, BTF_KIND_UNKN) kind_ops[] has no entry, so ->show is NULL. A "const void" (a modifier resolving to void) cannot be a map key or value - map_check_btf() rejects it because void has no size - so the map dump path does not reach it. But bpf_snprintf_btf() takes a type_id straight from the BPF program, and passing such a "const void" from the vmlinux BTF NULL-derefs: KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f] RIP: 0010:btf_modifier_show (kernel/bpf/btf.c:2914) Call Trace: btf_type_show (kernel/bpf/btf.c:8251) btf_type_snprintf_show (kernel/bpf/btf.c:8321) bpf_snprintf_btf (kernel/trace/bpf_trace.c:1047) bpf_prog_test_run_raw_tp (net/bpf/test_run.c:829) __sys_bpf (kernel/bpf/syscall.c:4804) do_syscall_64 (arch/x86/entry/syscall_64.c:94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Fall back to btf_df_show() when the resolved type has no show op; it emits the "" placeholder already used for kinds like FWD and FUNC. bpf_snprintf_btf() then returns the length as usual. Fixes: c4d0bfb45068 ("bpf: Add bpf_snprintf_btf helper") Signed-off-by: Jiayuan Chen Acked-by: Ihor Solodrai --- re bot+bpf-ci: a "const void" is a modifier with a nonzero type_id, so map_check_btf() rejects it as key or value on the size check. The bare void key (id 0) is a different path, handled by patch 1. re sashiko-bot: btf_var_show() has the same bug, fixed in patch 3. --- kernel/bpf/btf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 91b8ce77f699..7835fe201384 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -2911,7 +2911,14 @@ static void btf_modifier_show(const struct btf *btf, else t = btf_type_skip_modifiers(btf, type_id, NULL); - btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show); + /* + * A modifier can resolve to void, which has no show op; print a + * placeholder rather than dereferencing NULL. + */ + if (!btf_type_ops(t)) + btf_df_show(btf, t, type_id, data, bits_offset, show); + else + btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show); } static void btf_var_show(const struct btf *btf, const struct btf_type *t, -- 2.43.0