mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pu Lehui <pulehui@huaweicloud.com>
To: bot+bpf-ci@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org, ast@kernel.org,
	houtao@huaweicloud.com, leon.hwang@linux.dev
Cc: daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
	memxor@gmail.com, martin.lau@linux.dev, yonghong.song@linux.dev,
	song@kernel.org, jolsa@kernel.org, emil@etsalapatis.com,
	ihor.solodrai@linux.dev, pulehui@huawei.com,
	martin.lau@kernel.org, mason@kernel.org
Subject: Re: [PATCH bpf v4] bpf: Fix UAF due to concurrent consumption of ttrace lists in alloc_bulk
Date: Sat, 5 Sep 2026 11:57:06 +0800	[thread overview]
Message-ID: <4a837795-6b89-41e6-a346-78082cf35d64@huaweicloud.com> (raw)
In-Reply-To: <6fb6eba20f7975410960a3603614f1873fe7212e4d4f77408dcc33726dc31fde@mail.kernel.org>


On 2026/9/5 11:00, bot+bpf-ci@kernel.org wrote:
>> Syzkaller repeatedly triggered UAF splats related to nodes in
>> waiting_for_gp_ttrace within the bpf memalloc:
>> BUG: KASAN: slab-use-after-free in llist_del_first+0x85/0x110 lib/llist.c:61
>> Read of size 8 at addr ffff8881572cd080 by task syz.4.470/5112
>>   ...
>>   llist_del_first+0x85/0x110 lib/llist.c:61
>>   alloc_bulk+0x193/0x460 kernel/bpf/memalloc.c:229
>>   bpf_mem_refill+0x386/0x560 kernel/bpf/memalloc.c:436
>> Freed by task 14:
>>   ...
>>   __free_rcu kernel/bpf/memalloc.c:281 [inline]
>>   __free_rcu_tasks_trace+0x48/0xd0 kernel/bpf/memalloc.c:291
>>   rcu_tasks_invoke_cbs+0x1ec/0x3e0 kernel/rcu/tasks.h:571
>>   rcu_tasks_one_gp+0x13d/0x220 kernel/rcu/tasks.h:621
>>   rcu_tasks_kthread+0xf3/0x120 kernel/rcu/tasks.h:651
> 
> The file and line numbers in this stack trace refer to v6.6 (the v1
> posting included 'Not tainted 6.6.0+', which was dropped in later
> versions). Against the current tree, these line numbers point to different
> locations: alloc_bulk() line 229 is in a blank/'if (i >= cnt)' section
> (the waiting_for_gp_ttrace access is now at line 231), bpf_mem_refill()
> line 436 is the closing brace, and __free_rcu_tasks_trace() no longer
> exists at all (removed by commit 57b23c0f612d).
> 
> Should the stack trace include the kernel version to prevent future
> readers from trying to map these line numbers onto the current tree?

This is reproducible on mainline too, and the log makes the race pretty 
obvious at a glance. I don't think there's any real need to change it.

> 
>> In addition, there is also a theoretical race condition on the
>> free_by_rcu_ttrace list. This race requires two preconditions: an
>> in-flight Tasks Trace GP keeping c->call_rcu_ttrace_in_progress == 1,
>> and concurrent cross-CPU frees repopulating c->free_by_rcu_ttrace with
>> new nodes. Under these conditions, the following scenario triggers UAF:
>> // CPU0
>> // irq work is still busy (on PREEMPT_RT)
>> alloc_bulk()
>>    llist_del_first(&c->free_by_rcu_ttrace)
>>      entry = smp_load_acquire(&head->first);
>>      do {
>>        if (entry == NULL)
>>          return NULL;
>>          // CPU1
>>          bpf_mem_alloc_destroy()
>>            WRITE_ONCE(c->draining, true)
>>            // wait for CPU0
>>            irq_work_sync()
>>                  // CPU2
>>                  do_call_rcu_ttrace(tgt(CPU0))
>>                    if (c->draining) {
>>                      llist_del_all(&c->free_by_rcu_ttrace)
>>                      free_all()
>>                    }
>> // CPU0 continue
>>        next = READ_ONCE(entry->next); <-- trigger UAF
> 
> The annotation suggests this race window exists only on PREEMPT_RT
> kernels. However, on non-PREEMPT_RT configurations, alloc_bulk() runs in
> hard IRQ context and irq_work_sync() from another CPU still has to wait
> for it, so the same race window exists there too. The earlier comment that
> commit d114dde245f9 removed also mentioned non-RT cases: 'arch_irq_work_
> has_interrupt() being false and irq work is invoked in timer interrupt.'
> 
> Would '(e.g., on PREEMPT_RT)' be more accurate than '(on PREEMPT_RT)' to
> indicate this is an example rather than a precondition?

PREEMPT_RT was just a handy example here.

> 
> 
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
> 
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33938697434


  reply	other threads:[~2026-09-05  3:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-05  2:11 Pu Lehui
2026-09-05  3:00 ` bot+bpf-ci
2026-09-05  3:57   ` Pu Lehui [this message]
2026-09-07  2:40 ` Hou Tao
2026-09-11  1:17 ` Pu Lehui
2026-09-11 15:29   ` Alexei Starovoitov
2026-09-14  2:48 ` Alexei Starovoitov
2026-09-14  2:50 ` patchwork-bot+netdevbpf

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=4a837795-6b89-41e6-a346-78082cf35d64@huaweicloud.com \
    --to=pulehui@huaweicloud.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=houtao@huaweicloud.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=leon.hwang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=pulehui@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®