Skip to content

Commit 8358b02

Browse files
thejhdavem330
authored andcommitted
bpf: fix double-fdput in replace_map_fd_with_map_ptr()
When bpf(BPF_PROG_LOAD, ...) was invoked with a BPF program whose bytecode references a non-map file descriptor as a map file descriptor, the error handling code called fdput() twice instead of once (in __bpf_map_get() and in replace_map_fd_with_map_ptr()). If the file descriptor table of the current task is shared, this causes f_count to be decremented too much, allowing the struct file to be freed while it is still in use (use-after-free). This can be exploited to gain root privileges by an unprivileged user. This bug was introduced in commit 0246e64 ("bpf: handle pseudo BPF_LD_IMM64 insn"), but is only exploitable since commit 1be7f75 ("bpf: enable non-root eBPF programs") because previously, CAP_SYS_ADMIN was required to reach the vulnerable code. (posted publicly according to request by maintainer) Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 38bd10c commit 8358b02

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

Diff for: kernel/bpf/verifier.c

-1
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,6 @@ static int replace_map_fd_with_map_ptr(struct verifier_env *env)
20302030
if (IS_ERR(map)) {
20312031
verbose("fd %d is not pointing to valid bpf_map\n",
20322032
insn->imm);
2033-
fdput(f);
20342033
return PTR_ERR(map);
20352034
}
20362035

0 commit comments

Comments
 (0)