From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alan Maguire <alan.maguire@oracle.com>, chenyuan <chenyuan_fl@163.com>
Cc: eddyz87@gmail.com, yonghong.song@linux.dev, andrii@kernel.org,
ast@kernel.org, bot+bpf-ci@kernel.org, bpf@vger.kernel.org,
chenyuan@kylinos.cn, clm@meta.com, daniel@iogearbox.net,
jolsa@kernel.org, linux-kernel@vger.kernel.org,
martin.lau@kernel.org, martin.lau@linux.dev, memxor@gmail.com,
song@kernel.org
Subject: Re: [PATCH bpf v3 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref
Date: Mon, 8 Jun 2026 17:46:33 -0700 [thread overview]
Message-ID: <9a3bfb46-9c25-4f58-afb6-8f6fcd0d0bda@linux.dev> (raw)
In-Reply-To: <7a9e6b7b-f566-47e6-80bd-6fff7ed55241@oracle.com>
On 6/4/26 3:21 AM, Alan Maguire wrote:
> On 04/06/2026 10:14, chenyuan wrote:
>> Hi Ihor:
>>> Could you please elaborate on the "incorrect type information" generated
>> by pahole 1.30?
>> I extracted the .BTF and .BTF.base sections from the same
>> bpf_testmod.ko built with pahole 1.30 vs 1.31 to compare:
>>
>> # pahole 1.30 — bpf_prog_aux in split BTF, NOT in base
>> $ bpftool btf dump file btf_1_30_base.bin | grep bpf_prog_aux
>> (empty)
>> $ bpftool btf dump -B btf_1_30_base.bin file btf_1_30.bin | grep aux
>> [3172] STRUCT 'bpf_prog_aux' size=2016 vlen=87
>>
>> # pahole 1.31 — bpf_prog_aux in base BTF, NOT in split
>> $ bpftool btf dump file btf_1_31_base.bin | grep bpf_prog_aux
>> [10] STRUCT 'bpf_prog_aux' size=2016 vlen=0
>> $ bpftool btf dump -B btf_1_31_base.bin file btf_1_31.bin | grep aux
>> (empty)
>>
>> pahole 1.30 places struct bpf_prog_aux in the module's split BTF
>> (instead of the distilled base). pahole 1.31 correctly moves it to
>> the base BTF.
>
> Would be worth digging a bit more here I think. To confirm is this
> the v1.31 release where it is fixed or the post-1.31 pahole (i.e.
> do you know the top commit for the fixed pahole version)?
>
> pahole uses the libbpf machinery to do BTF distillation in .BTF.base
> so if we know which libbpf sync has the fix that will be helpful.
>
> The most recent pahole HEAD is synced with libbpf v1.8, but I
> suspect the previous sync that occured just after v1.30 (so v1.31
> had the fix but v1.30 didn't):
>
> 042d73962d35 ("pahole: Sync with libbpf mainline")
>
> is the one. From the commit log:
>
> "To pull in dedup fix in
>
> commit 8e64c387c942 ("libbpf: Add identical pointer detection to btf_dedup_is_equiv()")
>
> sync with latest libbpf."
>
> My suspicion is that since v1.30 didn't have that fix, dedup failed for
> struct bpf_prog_aux on pahole v1.30 so it wound up in split BTF and base.
> v1.31 had the fix so the module bpf_prog_aux was correctly flagged as a
> dup of the kernel one, therefore we did the distillation into .BTF.base
> correctly.
>
> Does this fit with your observations?
Hi everyone.
I've been scratching my head trying to understand exactly what may
cause the divergence that Yuan reported. It took me and the bots a
while, but I think I figured it out.
TL;DR is that compilers may produce multiple DW_TAG_pointer_type DIEs
in DWARF for the same field/arg if they differ for example in address
space. The libbpf commit 8e64c387c942 ("libbpf: Add identical pointer
detection to btf_dedup_is_equiv()"), that Alan referenced looks like
the right fix for this for the BTF generation.
Since the fix is already there, the recommendation for people running
into this is to update their libbpf to at least 1.6:
# in https://github.com/libbpf/libbpf
$ git tag --contains 5ee9fbf7d769fb4e84881e0a073d6259b8555880
v1.6.0
v1.6.1
v1.6.2
v1.6.3
v1.7.0
Now some details. Consider a code example below.
base.c:
struct aux {
int __seg_gs *pcpu_a;
int __seg_gs *pcpu_b;
};
int base_use(struct aux *aux)
{
return aux != 0;
}
module.c:
struct aux {
int __seg_gs *pcpu_a;
int __seg_fs *pcpu_b; // <-- NOTE: a different attribute
};
int kfunc_pick_a(struct aux *aux)
{
// TYPEOF_UNQUAL macro is referenced in Alan's fix (8e64c387c942)
// as a trigger for the dedup bug
__typeof_unqual__(*aux->pcpu_a) *plain_from_typeof_unqual;
plain_from_typeof_unqual = (int *)(unsigned long)aux->pcpu_a;
return plain_from_typeof_unqual != 0;
}
If you compile module.c, you can see in the DWARF there are two
pointer DIEs for int * that only differ in DW_AT_address_class:
0x00000040: DW_TAG_member
DW_AT_name ("pcpu_a")
DW_AT_type (0x00000057 "int *")
0x0000004b: DW_TAG_member
DW_AT_name ("pcpu_b")
DW_AT_type (0x00000064 "int *")
0x00000057: DW_TAG_pointer_type
DW_AT_address_class (0x02)
0x00000064: DW_TAG_pointer_type
DW_AT_address_class (0x01)
DW_AT_name ("plain_from_typeof_unqual")
DW_AT_type (0x000000b4 "int *")
Then when you use pahole (without the libbpf fix) to create base BTF
from base.c, and a split BTF for module.c, you can see struct aux
still exists in the split BTF, and the kfunc_pick_a() prototype
referencing it:
[7] STRUCT 'aux' size=16 vlen=2
'pcpu_a' type_id=2 bits_offset=0
'pcpu_b' type_id=2 bits_offset=64
[8] PTR '(anon)' type_id=7
[9] FUNC_PROTO '(anon)' ret_type_id=3 vlen=1
'aux' type_id=8
[10] FUNC 'kfunc_pick_a' type_id=9 linkage=static
The reason for this is that pahole generates a ref type for each
DW_TAG_pointer_type [1], so there are two BTF IDs for int * in this
example. This then makes the struct aux BTF referenced from the module
and from the base "different", exposing the dedup bug.
The DW_AT_address_class is never even loaded and is not taken into
account anywhere in pahole. But that seems fine, I suspect there are
other examples of valid DWARF where the difference is not relevant to
BTF dedup.
[1] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/tree/btf_encoder.c?h=v1.31#n1647
>
> Thanks!
>
> Alan
next prev parent reply other threads:[~2026-06-09 0:46 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 8:09 [PATCH] bpf: fix btf_types_are_same for cross-BTF type comparison chenyuan_fl
2026-04-07 8:58 ` Leon Hwang
2026-04-07 9:01 ` bot+bpf-ci
2026-04-07 11:19 ` Alan Maguire
2026-05-15 18:27 ` Ihor Solodrai
2026-06-01 6:46 ` [PATCH bpf v2 0/2] bpf: Fix kfunc implicit arg injection and add selftest chenyuan_fl
2026-06-01 6:46 ` [PATCH bpf v2 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref chenyuan_fl
2026-06-01 7:42 ` bot+bpf-ci
2026-06-01 19:32 ` Eduard Zingerman
2026-06-02 8:58 ` [PATCH bpf v3 0/2] bpf: Fix kfunc implicit arg injection and add selftest chenyuan_fl
2026-06-02 8:58 ` [PATCH bpf v3 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref chenyuan_fl
2026-06-02 9:23 ` sashiko-bot
2026-06-02 9:44 ` bot+bpf-ci
2026-06-02 18:52 ` Ihor Solodrai
2026-06-04 9:14 ` chenyuan
2026-06-04 10:21 ` Alan Maguire
2026-06-09 0:46 ` Ihor Solodrai [this message]
2026-06-02 8:58 ` [PATCH bpf v3 2/2] selftests/bpf: Add regression test for kfunc implicit arg injection chenyuan_fl
2026-06-02 9:31 ` sashiko-bot
2026-06-02 9:44 ` bot+bpf-ci
2026-06-02 9:38 ` [PATCH bpf v4 0/2] bpf: Fix kfunc implicit arg injection and add selftest chenyuan_fl
2026-06-02 9:38 ` [PATCH bpf v4 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref chenyuan_fl
2026-06-02 9:58 ` sashiko-bot
2026-06-02 10:42 ` bot+bpf-ci
2026-06-05 0:42 ` Eduard Zingerman
2026-06-02 9:38 ` [PATCH bpf v4 2/2] selftests/bpf: Add regression test for kfunc implicit arg injection chenyuan_fl
2026-06-02 10:06 ` sashiko-bot
2026-06-02 10:27 ` bot+bpf-ci
2026-06-02 17:36 ` kernel test robot
2026-06-02 18:37 ` kernel test robot
2026-06-05 1:29 ` Eduard Zingerman
2026-06-08 14:26 ` [PATCH bpf v5 0/2] bpf: Fix kfunc implicit arg injection and add selftest chenyuan_fl
2026-06-08 14:26 ` [PATCH bpf v5 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref chenyuan_fl
2026-06-08 14:47 ` sashiko-bot
2026-06-08 14:52 ` bot+bpf-ci
2026-06-08 17:28 ` Eduard Zingerman
2026-06-09 0:54 ` Ihor Solodrai
2026-06-09 1:00 ` Eduard Zingerman
2026-06-09 1:18 ` Ihor Solodrai
2026-06-09 6:20 ` Eduard Zingerman
2026-06-08 14:26 ` [PATCH bpf v5 2/2] selftests/bpf: strengthen bpf_kfunc_implicit_arg to verify aux injection chenyuan_fl
2026-06-08 14:53 ` sashiko-bot
2026-06-08 17:34 ` Eduard Zingerman
2026-06-09 0:59 ` Ihor Solodrai
2026-06-08 19:58 ` [PATCH bpf v5 0/2] bpf: Fix kfunc implicit arg injection and add selftest Alexei Starovoitov
2026-06-09 12:52 ` [PATCH bpf v6 " chenyuan_fl
2026-06-09 12:52 ` [PATCH bpf v6 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref chenyuan_fl
2026-06-09 13:08 ` sashiko-bot
2026-06-09 13:32 ` bot+bpf-ci
2026-06-09 12:52 ` [PATCH bpf v6 2/2] selftests/bpf: strengthen bpf_kfunc_implicit_arg to verify aux injection chenyuan_fl
2026-06-09 12:59 ` sashiko-bot
2026-06-01 17:12 ` [PATCH bpf v2 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref Yonghong Song
2026-06-01 21:36 ` Eduard Zingerman
2026-06-01 6:46 ` [PATCH bpf v2 2/2] selftests/bpf: Add regression test for kfunc implicit arg injection with stale register chenyuan_fl
2026-06-01 7:08 ` sashiko-bot
2026-06-01 17:17 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9a3bfb46-9c25-4f58-afb6-8f6fcd0d0bda@linux.dev \
--to=ihor.solodrai@linux.dev \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyuan@kylinos.cn \
--cc=chenyuan_fl@163.com \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.