All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nuoqi Gui" <gnq25@mails.tsinghua.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpf: Reject out-of-range arena free addresses
Date: Mon, 06 Jul 2026 16:09:07 +0000	[thread overview]
Message-ID: <20260706160907.DC97B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706-f01-31-arena-free-bpf-next-v1-1-3ad6e7384285@mails.tsinghua.edu.cn>

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

Pre-existing issues:
- [High] Missing 32-bit boundary check in `arena_map_mmap` allows kernel PTE overwrite and sandbox escape.
--

commit d41218f03bbc51a996de1d468ac821cb61f84615
Author: Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>

bpf: Reject out-of-range arena free addresses

This commit adds a check in arena_free_pages() to reject frees where the
computed full address is below arena->user_vm_start. This prevents
out-of-domain page offsets from being inserted into the free range tree.

> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
> index 80b7b8a694464..97a5d8d212955 100644
> --- a/kernel/bpf/arena.c
> +++ b/kernel/bpf/arena.c
> @@ -853,6 +853,8 @@ static void arena_free_pages(struct bpf_arena *arena, long uaddr, long page_cnt,
>  	uaddr &= PAGE_MASK;
>  	kaddr = bpf_arena_get_kern_vm_start(arena) + uaddr;
>  	full_uaddr = clear_lo32(arena->user_vm_start) + uaddr;
> +	if (full_uaddr < arena->user_vm_start)
> +		return;

[Severity: High]
This is a pre-existing issue, but looking at arena_map_mmap(), is it possible
for a user to dynamically choose a VMA that crosses a 32-bit boundary?

kernel/bpf/arena.c:arena_map_mmap() {
[ ... ]
	arena->user_vm_start = vma->vm_start;
	arena->user_vm_end = vma->vm_end;
[ ... ]
}

If a user maps the arena at an address crossing a 32-bit boundary (e.g.,
0x7FFF_FFFF0000 with a size of 4MB) by not specifying map_extra and using
mmap with MAP_FIXED, does this bypass the boundary check?

If so, could this lead to an overflow in arena_alloc_pages() when calculating
uaddr32?

kernel/bpf/arena.c:arena_alloc_pages() {
[ ... ]
	uaddr32 = (u32)(arena->user_vm_start + pgoff * PAGE_SIZE);

	while (remaining) {
[ ... ]
		ret = apply_to_page_range(&init_mm,
					  kern_vm_start + uaddr32 + (mapped << PAGE_SHIFT),
					  this_batch << PAGE_SHIFT, apply_range_set_cb, &data);
[ ... ]
}

When uaddr32 overflows, does the calculation kern_vm_start + uaddr32 exceed
the KERN_VM_SZ bounds? Can this overwrite PTEs of adjacent vmalloc areas?

>  	uaddr_end = min(arena->user_vm_end, full_uaddr + (page_cnt << PAGE_SHIFT));
>  	if (full_uaddr >= uaddr_end)
>  		return;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260706-f01-31-arena-free-bpf-next-v1-0-3ad6e7384285@mails.tsinghua.edu.cn?part=1

  reply	other threads:[~2026-07-06 16:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 15:52 [PATCH bpf-next 0/2] bpf: Reject out-of-range arena free addresses Nuoqi Gui
2026-07-06 15:52 ` [PATCH bpf-next 1/2] " Nuoqi Gui
2026-07-06 16:09   ` sashiko-bot [this message]
2026-07-06 16:57   ` Emil Tsalapatis
2026-07-06 15:52 ` [PATCH bpf-next 2/2] selftests/bpf: Cover " Nuoqi Gui

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=20260706160907.DC97B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=gnq25@mails.tsinghua.edu.cn \
    --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.