> diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
> index 1eeb31c5b..241f11d4d 100644
> --- a/kernel/bpf/arraymap.c
> +++ b/kernel/bpf/arraymap.c

[ ... ]

> @@ -398,18 +405,18 @@ int bpf_percpu_array_update(struct bpf_map *map, void 
> *key, void *value,
>       struct bpf_array *array = container_of(map, struct bpf_array, map);
>       u32 index = *(u32 *)key;
>       void __percpu *pptr;
> -     int cpu, off = 0;
> +     void *ptr, *val;
>       u32 size;
> +     int cpu;
>
> -     if (unlikely(map_flags > BPF_EXIST))
> -             /* unknown flags */
> +     if (unlikely(map_flags & BPF_F_LOCK))
>               return -EINVAL;
>
>       if (unlikely(index >= array->map.max_entries))
>               /* all elements were pre-allocated, cannot insert a new one */
>               return -E2BIG;
>
> -     if (unlikely(map_flags == BPF_NOEXIST))
> +     if (unlikely(map_flags & BPF_NOEXIST))
>               /* all elements already exist */
>               return -EEXIST;

This isn't a bug, but the change from equality check to bit test might
allow confusing flag combinations. The old code rejected map_flags > 2,
which prevented BPF_NOEXIST | BPF_EXIST (flags=3) entirely. With the new
bit test, userspace can pass both flags and BPF_NOEXIST takes precedence.

Should bpf_map_check_op_flags() validate mutual exclusivity of BPF_NOEXIST
and BPF_EXIST, similar to how it validates BPF_F_CPU and BPF_F_ALL_CPUS at
include/linux/bpf.h:3858?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/19674301388

Reply via email to