aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
authorJoe Stringer <joe@wand.net.nz>2018-10-02 16:35:30 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-10-02 20:53:47 -0400
commitaad2eeaf46973a0968a75640cd1f8f1c650322a0 (patch)
treecf24312daa4784ab76c0a176da7ae9f56aac7319 /kernel/bpf
parentf3709f69b7c5cba6323cc03c29b64293b93be817 (diff)
bpf: Simplify ptr_min_max_vals adjustment
An upcoming commit will add another two pointer types that need very similar behaviour, so generalise this function now. Signed-off-by: Joe Stringer <joe@wand.net.nz> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/verifier.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 9c82d8f58085..abf567200574 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2669,20 +2669,18 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
2669 return -EACCES; 2669 return -EACCES;
2670 } 2670 }
2671 2671
2672 if (ptr_reg->type == PTR_TO_MAP_VALUE_OR_NULL) { 2672 switch (ptr_reg->type) {
2673 verbose(env, "R%d pointer arithmetic on PTR_TO_MAP_VALUE_OR_NULL prohibited, null-check it first\n", 2673 case PTR_TO_MAP_VALUE_OR_NULL:
2674 dst); 2674 verbose(env, "R%d pointer arithmetic on %s prohibited, null-check it first\n",
2675 return -EACCES; 2675 dst, reg_type_str[ptr_reg->type]);
2676 }
2677 if (ptr_reg->type == CONST_PTR_TO_MAP) {
2678 verbose(env, "R%d pointer arithmetic on CONST_PTR_TO_MAP prohibited\n",
2679 dst);
2680 return -EACCES; 2676 return -EACCES;
2681 } 2677 case CONST_PTR_TO_MAP:
2682 if (ptr_reg->type == PTR_TO_PACKET_END) { 2678 case PTR_TO_PACKET_END:
2683 verbose(env, "R%d pointer arithmetic on PTR_TO_PACKET_END prohibited\n", 2679 verbose(env, "R%d pointer arithmetic on %s prohibited\n",
2684 dst); 2680 dst, reg_type_str[ptr_reg->type]);
2685 return -EACCES; 2681 return -EACCES;
2682 default:
2683 break;
2686 } 2684 }
2687 2685
2688 /* In case of 'scalar += pointer', dst_reg inherits pointer type and id. 2686 /* In case of 'scalar += pointer', dst_reg inherits pointer type and id.