From: "Emil Tsalapatis" <emil@etsalapatis.com>
To: "Yiyang Chen" <chenyy23@mails.tsinghua.edu.cn>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: "Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>, "Shuah Khan" <shuah@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Puranjay Mohan" <puranjay@kernel.org>, <bpf@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next 1/2] bpf: Reject arena frees below the arena base
Date: Wed, 01 Jul 2026 17:12:24 -0400 [thread overview]
Message-ID: <DJNJLQZIR0N9.2V69YW14LMS49@etsalapatis.com> (raw)
In-Reply-To: <2a3747e64898cc7dda6578279cb5688f7029f658.1782813442.git.chenyy23@mails.tsinghua.edu.cn>
On Tue Jun 30, 2026 at 6:12 AM EDT, Yiyang Chen wrote:
> bpf_arena_free_pages() accepts scalar arena addresses. The runtime
> masks the address to the low 32 bits and reconstructs a full user
> address from the arena base before returning the range to the arena
> free tree.
>
> When the scalar value is below the low 32 bits of the arena base,
> full_uaddr falls below user_vm_start. The existing upper-end clipping
> then turns this into an out-of-range free-tree offset. A later
> allocation can reuse that offset and return an address below the arena
> mapping.
>
This seems reasonable, my understanding is that this happens because
neither arena start nor end actually has to be aligned at a 4GiB
boundary, while the underlying kernel mapping does span the full
32 bits. AFAICT this bug returns an address that is not actually
mapped into userspace and is inaccessible from it, correct?
If the above is correct, feel free to add:
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
> Reject such frees before computing the clipped range.
>
> Fixes: 317460317a02a ("bpf: Introduce bpf_arena.")
> Signed-off-by: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>
> ---
> kernel/bpf/arena.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
> index 49a8f7b1beef5..e28e83bed8c51 100644
> --- a/kernel/bpf/arena.c
> +++ b/kernel/bpf/arena.c
> @@ -693,6 +693,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;
> uaddr_end = min(arena->user_vm_end, full_uaddr + (page_cnt << PAGE_SHIFT));
> if (full_uaddr >= uaddr_end)
> return;
next prev parent reply other threads:[~2026-07-01 21:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 10:12 [PATCH bpf-next 0/2] bpf: Reject arena frees below the arena base Yiyang Chen
2026-06-30 10:12 ` [PATCH bpf-next 1/2] " Yiyang Chen
2026-07-01 21:12 ` Emil Tsalapatis [this message]
2026-07-02 5:11 ` Yiyang Chen
2026-06-30 10:12 ` [PATCH bpf-next 2/2] selftests/bpf: Cover scalar arena frees below the base Yiyang Chen
2026-07-01 21:13 ` Emil Tsalapatis
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=DJNJLQZIR0N9.2V69YW14LMS49@etsalapatis.com \
--to=emil@etsalapatis.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyy23@mails.tsinghua.edu.cn \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=puranjay@kernel.org \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox