]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf: Add a map/btf from a fd array more consistently
authorAnton Protopopov <a.s.protopopov@gmail.com>
Fri, 13 Feb 2026 21:29:49 +0000 (21:29 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 13 Feb 2026 22:37:02 +0000 (14:37 -0800)
commitb0b1a8583d8e797114e613139e3e3318a1704690
tree3530dd28f15b494ae5994daf440b340311bc8a2b
parentde516a9167e4634cadee1e7ff13fd08e2a122bf0
bpf: Add a map/btf from a fd array more consistently

The add_fd_from_fd_array() function takes a file descriptor as a
parameter and tries to add either map or btf to the corresponding
list of used objects. As was reported by Dan Carpenter, since the
commit c81e4322acf0 ("bpf: Fix a potential use-after-free of BTF
object"), the fdget() is called twice on the file descriptor, and
thus userspace, potentially, can replace the file pointed to by the
file descriptor in between the two calls. On practice, this shouldn't
break anything on the kernel side, but for consistency fix the code
such that only one fdget() is executed.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/aY689z7gHNv8rgVO@stanley.mountain/
Fixes: ccd2d799ed44 ("bpf: Fix a potential use-after-free of BTF object")
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
Link: https://lore.kernel.org/r/20260213212949.759321-1-a.s.protopopov@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c