All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sanghyun Park" <sanghyun.park.cnu@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v6] bpf: Fix use-after-free on mm_struct in bpf_find_vma()
Date: Tue, 30 Jun 2026 03:37:44 +0000	[thread overview]
Message-ID: <20260630033745.B80201F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260630032543.3165720-1-sanghyun.park.cnu@gmail.com>

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

Pre-existing issues:
- [High] Pre-existing race condition between concurrent NMIs and HW IRQs leading to a leaked mmap_read_trylock() in bpf_find_vma().
--

commit 4672ecd9d6bd9a98e0de397e206fa5c87190b657
Author: Sanghyun Park <sanghyun.park.cnu@gmail.com>

bpf: Fix use-after-free on mm_struct in bpf_find_vma()
    
This commit fixes a use-after-free on mm_struct in bpf_find_vma() by pinning
the mm_struct via task->alloc_lock for foreign tasks. It introduces a trylock
and mmput_async() path to safely handle the mm lifecycle when interacting
with tasks other than current.

> diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
> index e791ae065c39b..22db3fcedd2fb 100644
> --- a/kernel/bpf/task_iter.c
> +++ b/kernel/bpf/task_iter.c

[ ... ]

> @@ -765,14 +766,38 @@ BPF_CALL_5(bpf_find_vma, struct task_struct *, task, u64, start,

[ ... ]

>  	if (!mm)
>  		return -ENOENT;
>  
>  	irq_work_busy = bpf_mmap_unlock_get_irq_work(&work);
>  
> -	if (irq_work_busy || !mmap_read_trylock(mm))
> -		return -EBUSY;
> +	if (irq_work_busy || !mmap_read_trylock(mm)) {
> +		ret = -EBUSY;
> +		goto out;
> +	}
>  
>  	vma = find_vma(mm, start);
>  
> @@ -782,6 +807,11 @@ BPF_CALL_5(bpf_find_vma, struct task_struct *, task, u64, start,
>  		ret = 0;
>  	}
>  	bpf_mmap_unlock_mm(work, mm);

[Severity: High]
This isn't a bug introduced by this patch, but could a race condition between
concurrent NMIs and hardware IRQs leak the mmap read lock here?

If a hardware IRQ calls bpf_find_vma(), it fetches the per-CPU
mmap_unlock_irq_work structure via bpf_mmap_unlock_get_irq_work(). If an NMI
interrupts execution before bpf_mmap_unlock_mm() is called and queues the
work, an NMI tracing program could also call bpf_find_vma().

Because irqs_disabled() is true in the NMI, it fetches the exact same per-CPU
work structure. The NMI would successfully acquire mmap_read_trylock(), set
work->mm to its mm, queue the work, and return.

When the hardware IRQ resumes, it takes its own mmap_read_trylock(), calls
bpf_mmap_unlock_mm(), overwrites work->mm with the hardware IRQ's mm, and
attempts to queue the already-pending work. When the irq_work later executes,
it only drops the lock for the hardware IRQ's mm, permanently leaking the
read lock for the NMI's mm.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260630032543.3165720-1-sanghyun.park.cnu@gmail.com?part=1

  reply	other threads:[~2026-06-30  3:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30  3:25 [PATCH bpf-next v6] bpf: Fix use-after-free on mm_struct in bpf_find_vma() Sanghyun Park
2026-06-30  3:37 ` sashiko-bot [this message]
2026-07-01 19:48 ` Andrii Nakryiko
2026-07-06 11:28   ` Puranjay Mohan

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=20260630033745.B80201F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sanghyun.park.cnu@gmail.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.