All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Khawar Ahemad" <ahemadkhawar123@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v6 2/4] bpf: arena: allocate the fault-in page outside the lock
Date: Tue, 25 Aug 2026 09:32:40 +0000	[thread overview]
Message-ID: <20260825093240.968801F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825091952.81971-3-ahemadkhawar123@gmail.com>

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

Pre-existing issues:
- [Critical] Uninitialized kernel memory can be mapped to user space via the non-blocking BPF arena page allocator.
--

--- Patch [2]: [PATCH v6 2/4] bpf: arena: allocate the fault-in page outside the lock ---
commit ff315e328e06f5f1bb6983dd7c2505e416510536
Author: Jiayuan Chen <jiayuan.chen@linux.dev>

bpf: arena: allocate the fault-in page outside the lock

This commit reworks arena_vm_fault() to preallocate the fault-in page outside
the lock, allowing it to sleep and use memory reclaim. It handles failures by
returning VM_FAULT_SIGBUS instead of SIGSEGV, and uses a lockless probe to
skip preallocation when possible.

> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
> index 7b6847200b431..fa462a0ff1ad6 100644
> --- a/kernel/bpf/arena.c
> +++ b/kernel/bpf/arena.c
[ ... ]
> @@ -489,59 +490,106 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)
>  	kbase = bpf_arena_get_kern_vm_start(arena);
>  	kaddr = kbase + (u32)(vmf->address);
[ ... ]
> +	if (!new_page) {
> +		/*
> +		 * Very rare race: the bpf program had allocated a page here, so
> +		 * the lockless probe saw it and we skipped preallocation, but it
> +		 * freed the page before we took the lock. Now we do need one;
> +		 * sleeping is not allowed here, so fall back to the non-blocking
> +		 * allocator and give up if it fails.
> +		 */
> +		ret = bpf_map_alloc_pages(map, map->numa_node, 1, &new_page);

[Severity: Critical]
This is a pre-existing issue, but does this fallback path expose uninitialized
kernel memory to user space?

When this rare race happens and we call bpf_map_alloc_pages() under the
arena->spinlock, preemption is disabled. The bpf_map_alloc_pages() function
calls __bpf_alloc_page(), which checks can_alloc_pages() (returning false
because preemption/IRQs are disabled).

It then falls back to alloc_pages_nolock():

kernel/bpf/syscall.c:__bpf_alloc_page() {
    ...
    if (!can_alloc_pages())
        return alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);
    ...
}

The __GFP_ACCOUNT flag completely omits __GFP_ZERO. This causes the raw page
allocator to return an unzeroed page. This page is then mapped into the user
VMA via apply_to_page_range(), which allows user space to read the residual
kernel data.

Since this new fallback path relies on the same non-blocking allocator, it
appears vulnerable to the same issue. Can __GFP_ZERO be added to the
alloc_pages_nolock() call to prevent this?

> +		if (ret) {
> +			fault_ret = VM_FAULT_SIGBUS;
> +			goto out_err_locked_memcg;
> +		}
> +	}
>  
>  	ret = range_tree_clear(&arena->rt, vmf->pgoff, 1);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260825091952.81971-1-ahemadkhawar123@gmail.com?part=2

  reply	other threads:[~2026-08-25  9:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  9:19 [PATCH bpf-next v6 0/4] bpf: arena: handle memory.max on fault-in with reclaim/OOM Khawar Ahemad
2026-08-25  9:19 ` [PATCH v6 1/4] bpf: Add a sleepable page allocator for map memory Khawar Ahemad
2026-08-25  9:32   ` sashiko-bot
2026-08-25  9:19 ` [PATCH v6 2/4] bpf: arena: allocate the fault-in page outside the lock Khawar Ahemad
2026-08-25  9:32   ` sashiko-bot [this message]
2026-08-25  9:19 ` [PATCH v6 3/4] selftests/bpf: Add read_cgroup_file() to cgroup_helpers Khawar Ahemad
2026-08-25  9:19 ` [PATCH v6 4/4] selftests/bpf: Add a test for arena fault-in under memory.max Khawar Ahemad
  -- strict thread matches above, loose matches on Subject: below --
2026-08-25  9:16 [PATCH bpf-next v6 0/4] bpf: arena: handle memory.max on fault-in with reclaim/OOM Khawar Ahemad
2026-08-25  9:16 ` [PATCH v6 2/4] bpf: arena: allocate the fault-in page outside the lock Khawar Ahemad

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=20260825093240.968801F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ahemadkhawar123@gmail.com \
    --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.