]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpf: Fix off-by-one boundary validation in arena direct-value access
authorJunyoung Jang <graypanda.inzag@gmail.com>
Sun, 26 Apr 2026 17:25:05 +0000 (02:25 +0900)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 9 May 2026 23:18:39 +0000 (16:18 -0700)
BPF_MAP_TYPE_ARENA accepts BPF_PSEUDO_MAP_VALUE offsets at exactly
the end of the arena mapping (off == arena_size). The boundary check
in arena_map_direct_value_addr() uses `>` instead of `>=`, which
incorrectly allows a one-past-end pointer to be accepted.

Change the condition to `>=` to correctly reject offsets that fall
outside the valid arena user_vm range.

Fixes: 317460317a02 ("bpf: Introduce bpf_arena.")
Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Link: https://lore.kernel.org/r/20260426172505.1947915-1-graypanda.inzag@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/arena.c

index 802656c6fd3c0306fbe05c422a0461c839e7b480..49a8f7b1beef59855cd100f7928c1adc37de82bc 100644 (file)
@@ -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)
                return -ERANGE;
        *imm = (unsigned long)arena->user_vm_start;
        return 0;