[02/13] bpf/verifier: disallow pointer subtraction

Message ID 1549862710-24224-3-git-send-email-tyhicks@canonical.com
State New
Headers show
Series
  • Multiple BPF security issues
Related show

Commit Message

Tyler Hicks Feb. 11, 2019, 5:24 a.m.
From: Alexei Starovoitov <ast@kernel.org>

BugLink: https://bugs.launchpad.net/bugs/1815259

Subtraction of pointers was accidentally allowed for unpriv programs
by commit 82abbf8d2fc4. Revert that part of commit.

Fixes: 82abbf8d2fc4 ("bpf: do not allow root to mangle valid pointers")
Reported-by: Jann Horn <jannh@google.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
(cherry picked from commit dd066823db2ac4e22f721ec85190817b58059a54)
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
---
 kernel/bpf/verifier.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 200b25335984..70497384cf91 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2427,7 +2427,7 @@  static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
 				 * an arbitrary scalar. Disallow all math except
 				 * pointer subtraction
 				 */
-				if (opcode == BPF_SUB){
+				if (opcode == BPF_SUB && env->allow_ptr_leaks) {
 					mark_reg_unknown(env, regs, insn->dst_reg);
 					return 0;
 				}