From: "Emil Tsalapatis" <emil@etsalapatis.com>
To: <sashiko@lists.linux.dev>, "Junyoung Jang" <graypanda.inzag@gmail.com>
Cc: <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf v2] bpf: Fix off-by-one boundary validation in arena direct-value access
Date: Sun, 26 Apr 2026 15:16:47 -0400 [thread overview]
Message-ID: <DI3BT9LJCI1D.2TRRBC1BVKIP2@etsalapatis.com> (raw)
In-Reply-To: <20260426181736.794BCC2BCAF@smtp.kernel.org>
On Sun Apr 26, 2026 at 2:17 PM EDT, sashiko-bot wrote:
> Sashiko AI review found 1 potential issue(s):
> - [Medium] Data race and bounds check bypass in arena_map_direct_value_addr() due to lockless reads
> --
>
> commit a9b5d3016475abf10be02a320dc627c95b306d92
> Author: Junyoung Jang <graypanda.inzag@gmail.com>
>
> bpf: Fix off-by-one boundary validation in arena direct-value access
>
> This commit fixes an off-by-one error in the arena map boundary check
> where offsets exactly at the end of the mapping were incorrectly accepted.
>
>> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
>> index 802656c6fd3c..49a8f7b1beef 100644
>> --- a/kernel/bpf/arena.c
>> +++ b/kernel/bpf/arena.c
>> @@ -511,7 +511,7 @@ static int arena_map_direct_value_addr(const struct bpf_map *map, u64 *imm, u32
>> {
>> struct bpf_arena *arena = container_of(map, struct bpf_arena, map);
>>
>> - if ((u64)off > arena->user_vm_end - arena->user_vm_start)
>> + if ((u64)off >= arena->user_vm_end - arena->user_vm_start)
>
> Could this evaluation be vulnerable to a data race?
>
> This function reads arena->user_vm_end and arena->user_vm_start without
> holding arena->lock or using READ_ONCE().
>
> Concurrently, a user-space process calling mmap() on the arena map FD
> can invoke arena_map_mmap(), which updates these fields under arena->lock.
> Because user_vm_start is updated first, a concurrent reader here might
> observe the new user_vm_start (a high address) and the old user_vm_end
> (which might be 0).
>
> In that scenario, arena->user_vm_end - arena->user_vm_start would
> underflow to a large 64-bit value, which would allow arbitrary offsets
> to bypass this bounds check.
This seems like a valid concern, though it is unrelated to the fix here
which seems correct. Can you sent a followup patch using an arena lock
guard in map_direct_value_addr? I don't see any issues with taking the
lock since the method is only used at verification time.
>
> Does this logic require synchronization or READ_ONCE() annotations to
> ensure the verifier's boundary validation remains effective?
>
>> return -ERANGE;
>> *imm = (unsigned long)arena->user_vm_start;
>> return 0;
>> }
next prev parent reply other threads:[~2026-04-26 19:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2026042614-scowling-hankie-f84b@gregkh>
2026-04-26 15:27 ` [PATCH bpf] bpf: Fix off-by-one boundary validation in arena direct-value access Junyoung Jang
2026-04-26 16:11 ` bot+bpf-ci
2026-04-26 17:25 ` [PATCH bpf v2] " Junyoung Jang
2026-04-26 18:17 ` sashiko-bot
2026-04-26 19:16 ` Emil Tsalapatis [this message]
2026-04-26 19:58 ` Alexei Starovoitov
2026-04-26 19:17 ` Emil Tsalapatis
2026-05-09 23:20 ` patchwork-bot+netdevbpf
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=DI3BT9LJCI1D.2TRRBC1BVKIP2@etsalapatis.com \
--to=emil@etsalapatis.com \
--cc=bpf@vger.kernel.org \
--cc=graypanda.inzag@gmail.com \
--cc=sashiko@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.