All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2] bpf: Fix UAF due to concurrent consumption of waiting_for_gp_ttrace
Date: Thu, 27 Aug 2026 08:47:56 +0000	[thread overview]
Message-ID: <20260827084756.EC4271F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827084013.1062816-1-pulehui@huaweicloud.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch fixes concurrent consumption for `waiting_for_gp_ttrace` but incorrectly claims `free_by_rcu_ttrace` is safe. A race condition during cache destruction leads to a Use-After-Free on `free_by_rcu_ttrace`.
--

commit ed5f43858e59ce799a585eeedfe466c5543df6aa
Author: Pu Lehui <pulehui@huawei.com>
Subject: bpf: Fix UAF due to concurrent consumption of waiting_for_gp_ttrace

This commit fixes a use-after-free caused by concurrent consumption of
waiting_for_gp_ttrace nodes by alloc_bulk() and __free_rcu(). It introduces
a raw spinlock to synchronize operations on this list.

The commit message notes:
> Note that free_by_rcu_ttrace does not suffer from this issue as it only
> has a single active consumer during normal operation.

> diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c
> index e9662db7198fe..58296e92a4fed 100644
> --- a/kernel/bpf/memalloc.c
> +++ b/kernel/bpf/memalloc.c
[ ... ]
> @@ -297,6 +307,7 @@ static void enque_to_free(struct bpf_mem_cache *c, void *obj)
>  static void do_call_rcu_ttrace(struct bpf_mem_cache *c)
>  {
>  	struct llist_node *llnode, *t;
> +	unsigned long flags;
>  
>  	if (atomic_xchg(&c->call_rcu_ttrace_in_progress, 1)) {
>  		if (unlikely(READ_ONCE(c->draining))) {
>  			llnode = llist_del_all(&c->free_by_rcu_ttrace);
>  			free_all(c, llnode, !!c->percpu_size);
>  		}

[Severity: High]
This is a pre-existing issue, but does free_by_rcu_ttrace actually suffer
from a similar race condition during cache destruction?

If userspace triggers destruction of a BPF memory allocator via
bpf_mem_alloc_destroy(), CPU 0 sets c->draining = true and synchronizes
the irq_work:

CPU 0: bpf_mem_alloc_destroy()
    WRITE_ONCE(c->draining, true);
    irq_work_sync(&c->refill_work);

Meanwhile, CPU 1 could be executing alloc_bulk() inside the refill work,
consuming from free_by_rcu_ttrace:

CPU 1: alloc_bulk()
    obj = llist_del_first(&c->free_by_rcu_ttrace);

If CPU 1 reads the head pointer in llist_del_first() but is delayed before
READ_ONCE(entry->next), and concurrently an RCU callback on CPU 2 calls
do_call_rcu_ttrace(), CPU 2 will observe draining == true here and
immediately free the nodes.

When CPU 1 resumes and executes READ_ONCE(entry->next), won't this result
in a use-after-free on the node that was just freed to the slab allocator?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260827084013.1062816-1-pulehui@huaweicloud.com?part=1

  reply	other threads:[~2026-08-27  8:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27  8:40 [PATCH bpf v2] bpf: Fix UAF due to concurrent consumption of waiting_for_gp_ttrace Pu Lehui
2026-08-27  8:47 ` sashiko-bot [this message]
2026-08-27 11:45   ` Pu Lehui
2026-08-27 14:43     ` Hou Tao
2026-08-27  8:51 ` Leon Hwang
2026-08-27 11:45   ` Pu Lehui
2026-08-27  9:24 ` bot+bpf-ci
2026-08-27 14:40   ` Hou Tao
2026-08-29  9:50     ` Pu Lehui

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=20260827084756.EC4271F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=pulehui@huaweicloud.com \
    --cc=sashiko-reviews@lists.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.