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 bpf-next v6 1/4] bpf: Add a sleepable page allocator for map memory
Date: Tue, 25 Aug 2026 10:11:50 +0000	[thread overview]
Message-ID: <20260825101151.21A4C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825094955.83240-2-ahemadkhawar123@gmail.com>

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

Pre-existing issues:
- [Critical] Pages allocated via `__bpf_alloc_page()` in non-sleepable contexts are not zeroed, leading to a critical information leak. When `can_alloc_pages()` is false (e.g., in BPF programs running inside a BPF spinlock where IRQs are disabled, or under the spinlock in `arena_vm_fault`), the allocator falls back to `alloc_pages_nolock(__GFP_ACCOUNT, nid, 0)`. Because `__GFP_ZERO` is omitted and the page is never manually cleared, uninitialized physical memory is returned and subsequently mapped into the BPF arena. User space can then read this uninitialized kernel memory. (Note: The originally provided concern regarding missing dcache flushes on cache-aliasing architectures is a false positive because BPF arenas are only supported on hardware-coherent PIPT architectures like x86_64, arm64, riscv64, etc., via `bpf_jit_supports_arena()`).
--

--- Patch [1]: [PATCH bpf-next v6 1/4] bpf: Add a sleepable page allocator for map memory ---
commit 49db9a147d01ab11180f1f75062c2ee24918b7a4
Author: Jiayuan Chen <jiayuan.chen@linux.dev>

bpf: Add a sleepable page allocator for map memory
    
This commit adds bpf_map_alloc_page_sleepable() for callers that are known to
be in a sleepable context. It allows them to use the normal blocking allocator
which can reclaim memory and engage the OOM machinery.

> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -602,15 +602,14 @@ static bool can_alloc_pages(void)
>  		!IS_ENABLED(CONFIG_PREEMPT_RT);
>  }
>  
> +#define BPF_PAGE_GFP (GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT | __GFP_NOWARN)
> +
>  static struct page *__bpf_alloc_page(int nid)
>  {
>  	if (!can_alloc_pages())
>  		return alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);

[Severity: Critical]
This is a pre-existing issue, but does missing __GFP_ZERO here cause an
information leak?

When can_alloc_pages() evaluates to false (e.g., in BPF programs running
inside a BPF spinlock where IRQs are disabled, or under the spinlock in
arena_vm_fault), the allocator falls back to alloc_pages_nolock() without
zeroing the page. 

Because this uninitialized kernel memory can subsequently be mapped into the
BPF arena, user space could read it.

> -	return alloc_pages_node(nid,
> -				GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT
> -				| __GFP_NOWARN,
> -				0);
> +	return alloc_pages_node(nid, BPF_PAGE_GFP, 0);
>  }

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

  reply	other threads:[~2026-08-25 10:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  9:49 [PATCH bpf-next v6 0/4] bpf: arena: handle memory.max on fault-in with reclaim/OOM Khawar Ahemad
2026-08-25  9:49 ` [PATCH bpf-next v6 1/4] bpf: Add a sleepable page allocator for map memory Khawar Ahemad
2026-08-25 10:11   ` sashiko-bot [this message]
2026-08-25 10:22   ` Khawar Ahemad
2026-08-25 10:32   ` bot+bpf-ci
2026-08-25  9:49 ` [PATCH bpf-next v6 2/4] bpf: arena: allocate the fault-in page outside the lock Khawar Ahemad
2026-08-25 10:32   ` bot+bpf-ci
2026-08-25  9:49 ` [PATCH bpf-next v6 3/4] selftests/bpf: Add read_cgroup_file() to cgroup_helpers Khawar Ahemad
2026-08-25  9:49 ` [PATCH bpf-next v6 4/4] selftests/bpf: Add a test for arena fault-in under memory.max Khawar Ahemad
2026-08-25 10:32   ` bot+bpf-ci
2026-08-25 10:43   ` Khawar Ahemad
2026-08-25 11:19     ` Jiayuan Chen
2026-08-25 12:23       ` Kumar Kartikeya Dwivedi
2026-08-25 11:28   ` Khawar Ahemad
2026-08-25  9:55 ` [PATCH bpf-next v6 0/4] bpf: arena: handle memory.max on fault-in with reclaim/OOM Jiayuan Chen

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=20260825101151.21A4C1F000E9@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.