summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMasoud Aghasi <maghasi@disroot.org>2026-10-08 13:07:32 +0100
committerAlexei Starovoitov <ast@kernel.org>2026-10-18 22:52:05 +0000
commita898ff0f3e9968b5f7c248d2af3cf1ddaf239e51 (patch)
treee4069be4c517644914d92c8a0fff58297f659be2 /include
parenta2e3191f5bab76fba550e558296c03ba003c04f0 (diff)
downloadlinux-a898ff0f3e9968b5f7c248d2af3cf1ddaf239e51.tar.gz
linux-a898ff0f3e9968b5f7c248d2af3cf1ddaf239e51.zip
bpf: Fix incorrect handling of user flags in bpf_percpu_array_update
For BPF_MAP_TYPE_PERCPU_ARRAY map, bpf_percpu_array_update() is not considering the possibility of a combination of (BPF_NOEXIST, BPF_EXIST) flags with (BPF_F_CPU, BPF_F_ALL_CPUS) flags. This causes the (BPF_NOEXIST, BPF_EXIST) flags to lose their effect in some cases. For example, using the (BPF_F_ALL_CPUS | BPF_EXIST) flag combination with bpf_map_update_elem() results in an incorrect EINVAL error response, even though the flag combination is valid. This patch fixes the bug by adding proper flag validations and checks. Before this patch, bpf_percpu_array_update() rejected BPF_F_ALL_CPUS | BPF_EXIST and BPF_F_ALL_CPUS | BPF_NOEXIST with -EINVAL. Also the BPF_F_CPU | BPF_NOEXIST were accepted. After the patch BPF_F_ALL_CPUS | BPF_EXIST is accepted and BPF_F_ALL_CPUS | BPF_NOEXIST and BPF_F_CPU | BPF_NOEXIST result in -EEXIST. This patch also starts returning -EINVAL for (BPF_EXIST | BPF_NOEXIST), with or without BPF_F_CPU, which was previously accepted. Fixes: 8eb76cb03f0f ("bpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu_array maps") Signed-off-by: Masoud Aghasi <maghasi@disroot.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Leon Hwang <leon.hwang@linux.dev> Link: https://patch.msgid.link/20261008120734.1565972-2-maghasi@disroot.org
Diffstat (limited to 'include')
-rw-r--r--include/linux/bpf.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index feb7de6483e3..aeb8b9b97052 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -4396,6 +4396,9 @@ static inline bool bpf_map_is_percpu_map(enum bpf_map_type map_type)
}
}
+#define BPF_EXIST_FLAGS (BPF_EXIST | BPF_NOEXIST)
+#define BPF_CPU_FLAGS (BPF_F_CPU | BPF_F_ALL_CPUS)
+
static inline int bpf_map_check_op_flags(struct bpf_map *map, u64 flags, u64 allowed_flags)
{
u32 cpu;