All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aditya Sharma" <adi.sharma@zohomail.in>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpf: Only check nmi_uaccess_okay() when signalling current
Date: Wed, 02 Sep 2026 15:14:42 +0000	[thread overview]
Message-ID: <20260902151443.14BE91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902150439.692725-1-adi.sharma@zohomail.in>

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

New issues:
- [Low] Multi-line comment does not follow BPF subsystem standards.

Pre-existing issues:
- [High] A TOCTOU data race on the per-CPU `send_signal_work` structure allows NMI reentrancy to corrupt irq_work data and leak a task_struct reference.
--

commit b0fb28992ab88d35a628c6d9650cd4ab7e67c397
Author: Aditya Sharma <adi.sharma@zohomail.in>

bpf: Only check nmi_uaccess_okay() when signalling current

nmi_uaccess_okay() takes no task argument and is a statement about current.
This commit restricts the check to only apply when signalling the current
task, fixing a bug where bpf_send_signal_task() returned -EPERM for kernel
threads.

Link: https://lore.kernel.org/bpf/20260819124324.43162-1-adi.sharma@zohomail.in/T/#u

> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 29260951aa871..f7a41f2225999 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -871,7 +871,10 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type, struct task_struc
>  	 */
>  	if (unlikely(task->flags & (PF_KTHREAD | PF_EXITING)))
>  		return -EPERM;
> -	if (unlikely(!nmi_uaccess_okay()))
> +	/* Since nmi_uaccess_okay() is only for the current
> +	 * task, check if task is current.
> +	 */

[Severity: Low]
This isn't a bug, but does this newly added comment violate the BPF subsystem
multi-line comment style?

The BPF subsystem strictly requires multi-line comments to have the opening
/* on its own line, with the text starting on the next line.

> +	if (task == current && unlikely(!nmi_uaccess_okay()))
>  		return -EPERM;
>  	/* Task should not be pid=1 to avoid kernel panic. */
>  	if (unlikely(is_global_init(task)))

[Severity: High]
This is a pre-existing issue, but is there a TOCTOU data race on the per-CPU
send_signal_work structure later in bpf_send_signal_common()?

If a BPF program executing in a context with IRQs disabled calls
bpf_send_signal(), it evaluates irq_work_is_busy() as false. Before it
queues the work, an NMI could fire on the same CPU and also call
bpf_send_signal():

kernel/trace/bpf_trace.c:bpf_send_signal_common() {
        ...
	if (preempt_count() != 0 || irqs_disabled()) {
                ...
		work = this_cpu_ptr(&send_signal_work);
		if (irq_work_is_busy(&work->irq_work))
			return -EBUSY;

                /* NMI fires here, calls bpf_send_signal_common(), evaluating
                 * irq_work_is_busy() as false since it's not queued yet.
                 * NMI writes its data and queues the work.
                 */

		work->task = get_task_struct(task);
		work->has_siginfo = siginfo == &info;
		if (work->has_siginfo)
			copy_siginfo(&work->info, &info);
		work->sig = sig;
		work->type = type;
		irq_work_queue(&work->irq_work);
		return 0;
	}
        ...
}

Upon return from the NMI, the interrupted context resumes, overwrites
work->task with a new get_task_struct(), and fails to queue the work since
the NMI already queued it.

Could this allow NMI reentrancy to corrupt irq_work data and permanently leak
a task_struct reference?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902150439.692725-1-adi.sharma@zohomail.in?part=1

  parent reply	other threads:[~2026-09-02 15:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 15:04 [PATCH bpf-next 1/2] bpf: Only check nmi_uaccess_okay() when signalling current Aditya Sharma
2026-09-02 15:04 ` [PATCH bpf-next 2/2] selftests/bpf: Test bpf_send_signal_task() from kernel thread context Aditya Sharma
2026-09-02 15:18   ` sashiko-bot
2026-09-02 15:14 ` sashiko-bot [this message]
2026-09-08 23:21 ` [PATCH bpf-next 1/2] bpf: Only check nmi_uaccess_okay() when signalling current Andrii Nakryiko

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=20260902151443.14BE91F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=adi.sharma@zohomail.in \
    --cc=bpf@vger.kernel.org \
    --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.