]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf: cpumap: propagate underlying error in cpu_map_update_elem()
authorKohei Enju <enjuk@amazon.com>
Mon, 8 Dec 2025 13:14:31 +0000 (22:14 +0900)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 10 Dec 2025 07:53:27 +0000 (23:53 -0800)
commit48e11bad9a1fd803a22d25c9a7d3aced1ba87817
tree7c2449734c47bc383f6e5727f57b7a47bda885bd
parent5d9fb42f05e5bea386e6648d5699c2beaabe1c6a
bpf: cpumap: propagate underlying error in cpu_map_update_elem()

After commit 9216477449f3 ("bpf: cpumap: Add the possibility to attach
an eBPF program to cpumap"), __cpu_map_entry_alloc() may fail with
errors other than -ENOMEM, such as -EBADF or -EINVAL.

However, __cpu_map_entry_alloc() returns NULL on all failures, and
cpu_map_update_elem() unconditionally converts this NULL into -ENOMEM.
As a result, user space always receives -ENOMEM regardless of the actual
underlying error.

Examples of unexpected behavior:
  - Nonexistent fd  : -ENOMEM (should be -EBADF)
  - Non-BPF fd      : -ENOMEM (should be -EINVAL)
  - Bad attach type : -ENOMEM (should be -EINVAL)

Change __cpu_map_entry_alloc() to return ERR_PTR(err) instead of NULL
and have cpu_map_update_elem() propagate this error.

Signed-off-by: Kohei Enju <enjuk@amazon.com>
Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/r/20251208131449.73036-2-enjuk@amazon.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/cpumap.c