|
|
a8751b1 |
From 8358b02bf67d3a5d8a825070e1aa73f25fb2e4c7 Mon Sep 17 00:00:00 2001
|
|
|
a8751b1 |
From: Jann Horn <jannh@google.com>
|
|
|
a8751b1 |
Date: Tue, 26 Apr 2016 22:26:26 +0200
|
|
|
a8751b1 |
Subject: [PATCH] bpf: fix double-fdput in replace_map_fd_with_map_ptr()
|
|
|
a8751b1 |
|
|
|
a8751b1 |
When bpf(BPF_PROG_LOAD, ...) was invoked with a BPF program whose bytecode
|
|
|
a8751b1 |
references a non-map file descriptor as a map file descriptor, the error
|
|
|
a8751b1 |
handling code called fdput() twice instead of once (in __bpf_map_get() and
|
|
|
a8751b1 |
in replace_map_fd_with_map_ptr()). If the file descriptor table of the
|
|
|
a8751b1 |
current task is shared, this causes f_count to be decremented too much,
|
|
|
a8751b1 |
allowing the struct file to be freed while it is still in use
|
|
|
a8751b1 |
(use-after-free). This can be exploited to gain root privileges by an
|
|
|
a8751b1 |
unprivileged user.
|
|
|
a8751b1 |
|
|
|
a8751b1 |
This bug was introduced in
|
|
|
a8751b1 |
commit 0246e64d9a5f ("bpf: handle pseudo BPF_LD_IMM64 insn"), but is only
|
|
|
a8751b1 |
exploitable since
|
|
|
a8751b1 |
commit 1be7f75d1668 ("bpf: enable non-root eBPF programs") because
|
|
|
a8751b1 |
previously, CAP_SYS_ADMIN was required to reach the vulnerable code.
|
|
|
a8751b1 |
|
|
|
a8751b1 |
(posted publicly according to request by maintainer)
|
|
|
a8751b1 |
|
|
|
a8751b1 |
Signed-off-by: Jann Horn <jannh@google.com>
|
|
|
a8751b1 |
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
|
|
|
a8751b1 |
Acked-by: Alexei Starovoitov <ast@kernel.org>
|
|
|
a8751b1 |
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
|
|
|
a8751b1 |
Signed-off-by: David S. Miller <davem@davemloft.net>
|
|
|
a8751b1 |
---
|
|
|
a8751b1 |
kernel/bpf/verifier.c | 1 -
|
|
|
a8751b1 |
1 file changed, 1 deletion(-)
|
|
|
a8751b1 |
|
|
|
a8751b1 |
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
|
|
|
a8751b1 |
index 618ef77c302a..db2574e7b8b0 100644
|
|
|
a8751b1 |
--- a/kernel/bpf/verifier.c
|
|
|
a8751b1 |
+++ b/kernel/bpf/verifier.c
|
|
|
a8751b1 |
@@ -2030,7 +2030,6 @@ static int replace_map_fd_with_map_ptr(struct verifier_env *env)
|
|
|
a8751b1 |
if (IS_ERR(map)) {
|
|
|
a8751b1 |
verbose("fd %d is not pointing to valid bpf_map\n",
|
|
|
a8751b1 |
insn->imm);
|
|
|
a8751b1 |
- fdput(f);
|
|
|
a8751b1 |
return PTR_ERR(map);
|
|
|
a8751b1 |
}
|
|
|
a8751b1 |
|
|
|
a8751b1 |
--
|
|
|
a8751b1 |
2.5.5
|
|
|
a8751b1 |
|