BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Edward Adam Davis" <eadavis@qq.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH] bpf: Fix smp_processor_id() call trace for preemptible kernels
Date: Tue, 30 Jun 2026 08:49:10 +0000	[thread overview]
Message-ID: <20260630084910.D5C3A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <tencent_C4C3064909A16EDCAEDB0C8767D886D01206@qq.com>

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

Pre-existing issues:
- [High] Silencing a preemption warning with `raw_smp_processor_id()` leaves a severe cross-CPU task migration hazard intact, leading to lockless list corruption in the BPF memory allocator.
--

commit b3d3adf96792401d9a691908ba210c6315bac1bb
Author: Edward Adam Davis <eadavis@qq.com>

bpf: Fix smp_processor_id() call trace for preemptible kernels

This patch attempts to resolve a preemption warning in
bpf_mem_cache_free_rcu() by replacing this_cpu_ptr() with per_cpu_ptr()
and raw_smp_processor_id().

Closes: https://syzkaller.appspot.com/bug?extid=fd7e415d891073b83e1f

> diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c
> index e9662db7198fe..f2b7828e6ac7c 100644
> --- a/kernel/bpf/memalloc.c
> +++ b/kernel/bpf/memalloc.c
> @@ -951,7 +951,7 @@ void notrace bpf_mem_cache_free_rcu(struct bpf_mem_alloc *ma, void *ptr)
>  	if (!ptr)
>  		return;
>  
> -	unit_free_rcu(this_cpu_ptr(ma->cache), ptr);
> +	unit_free_rcu(per_cpu_ptr(ma->cache, raw_smp_processor_id()), ptr);

[Severity: High]
This is a pre-existing issue with bpf_mem_cache_free_rcu() being called in a
preemptible context, but does silencing the warning with
raw_smp_processor_id() leave the underlying cross-CPU task migration hazard
intact?

If a task evaluates raw_smp_processor_id(), gets preempted, and then migrates
to another CPU, unit_free_rcu() will execute on the new CPU while still
operating on the original CPU's cache.

Since unit_free_rcu() only disables local interrupts for the current CPU,
the original CPU can concurrently modify its own cache. This could lead to
data races on the local_t active counter and concurrent execution of the
non-atomic __llist_add() operation, as seen here:

kernel/bpf/memalloc.c:unit_free_rcu() {
    ...
    local_irq_save(flags);
    if (local_inc_return(&c->active) == 1) {
        if (__llist_add(llnode, &c->free_by_rcu))
    ...
}

Could this concurrent access corrupt the lockless lists?

>  }
>  
>  /* Directly does a kfree() without putting 'ptr' back to the free_llist

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_C4C3064909A16EDCAEDB0C8767D886D01206@qq.com?part=1

  reply	other threads:[~2026-06-30  8:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30  6:20 [syzbot] [bpf?] BUG: using smp_processor_id() in preemptible code in bpf_mem_cache_free_rcu syzbot
2026-06-30  8:41 ` [PATCH] bpf: Fix smp_processor_id() call trace for preemptible kernels Edward Adam Davis
2026-06-30  8:49   ` sashiko-bot [this message]
2026-06-30  9:11     ` [PATCH v2] " Edward Adam Davis
2026-06-30  9:48       ` sashiko-bot
2026-06-30 11:14         ` Edward Adam Davis
2026-06-30 12:25           ` Jiayuan Chen
2026-06-30 12:46             ` Edward Adam Davis
2026-06-30 13:09               ` [PATCH v3] " Edward Adam Davis
2026-06-30 13:22                 ` sashiko-bot
2026-06-30 14:11                   ` [PATCH v4] " Edward Adam Davis
2026-06-30 14:29                     ` sashiko-bot
2026-06-30 14:46                     ` bot+bpf-ci
2026-07-01  0:27                   ` [PATCH v5] " Edward Adam Davis
2026-07-01 19:57                     ` Andrii Nakryiko
2026-07-02  4:34                       ` Edward Adam Davis
2026-07-02  5:40                         ` Alexei Starovoitov

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=20260630084910.D5C3A1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=eadavis@qq.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox