]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.20.6/bpf-restrict-unknown-scalars-of-mixed-signed-bounds-.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.20.6 / bpf-restrict-unknown-scalars-of-mixed-signed-bounds-.patch
1 From 46ba709213a5bfb10a77c4efea24e4dcf99d434f Mon Sep 17 00:00:00 2001
2 From: Daniel Borkmann <daniel@iogearbox.net>
3 Date: Mon, 28 Jan 2019 21:23:26 +0100
4 Subject: bpf: restrict unknown scalars of mixed signed bounds for unprivileged
5
6 [ commit 9d7eceede769f90b66cfa06ad5b357140d5141ed upstream ]
7
8 For unknown scalars of mixed signed bounds, meaning their smin_value is
9 negative and their smax_value is positive, we need to reject arithmetic
10 with pointer to map value. For unprivileged the goal is to mask every
11 map pointer arithmetic and this cannot reliably be done when it is
12 unknown at verification time whether the scalar value is negative or
13 positive. Given this is a corner case, the likelihood of breaking should
14 be very small.
15
16 Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
17 Acked-by: Alexei Starovoitov <ast@kernel.org>
18 Signed-off-by: Alexei Starovoitov <ast@kernel.org>
19 Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
20 Signed-off-by: Sasha Levin <sashal@kernel.org>
21 ---
22 kernel/bpf/verifier.c | 9 ++++++++-
23 1 file changed, 8 insertions(+), 1 deletion(-)
24
25 diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
26 index dc9c57f1a153..8e90e795ca68 100644
27 --- a/kernel/bpf/verifier.c
28 +++ b/kernel/bpf/verifier.c
29 @@ -2997,8 +2997,8 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
30 smin_ptr = ptr_reg->smin_value, smax_ptr = ptr_reg->smax_value;
31 u64 umin_val = off_reg->umin_value, umax_val = off_reg->umax_value,
32 umin_ptr = ptr_reg->umin_value, umax_ptr = ptr_reg->umax_value;
33 + u32 dst = insn->dst_reg, src = insn->src_reg;
34 u8 opcode = BPF_OP(insn->code);
35 - u32 dst = insn->dst_reg;
36
37 dst_reg = &regs[dst];
38
39 @@ -3031,6 +3031,13 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
40 verbose(env, "R%d pointer arithmetic on %s prohibited\n",
41 dst, reg_type_str[ptr_reg->type]);
42 return -EACCES;
43 + case PTR_TO_MAP_VALUE:
44 + if (!env->allow_ptr_leaks && !known && (smin_val < 0) != (smax_val < 0)) {
45 + verbose(env, "R%d has unknown scalar with mixed signed bounds, pointer arithmetic with it prohibited for !root\n",
46 + off_reg == dst_reg ? dst : src);
47 + return -EACCES;
48 + }
49 + /* fall-through */
50 default:
51 break;
52 }
53 --
54 2.19.1
55