summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorLorenz Bauer <lmb@cloudflare.com>2020-09-21 13:12:23 +0100
committerAlexei Starovoitov <ast@kernel.org>2020-09-21 15:00:41 -0700
commitfeec70401672bd9b0268ae59ec5efd15d86ae138 (patch)
treed3e545d04b0c1ff4aabc04fe6fa8923583c2c1dc /kernel
parent02f7c9585d1e2d5d76cac497bd5ced8ecf9d6f56 (diff)
bpf: Make context access check generic
Always check context access if the register we're operating on is PTR_TO_CTX, rather than relying on ARG_PTR_TO_CTX. This allows simplifying the arg_type checking section of the function. Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/20200921121227.255763-8-lmb@cloudflare.com
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/verifier.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index a4549b2656ad..fc795bac42ed 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -4021,9 +4021,6 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
arg_type == ARG_PTR_TO_CTX_OR_NULL)) {
if (type != expected_type)
goto err_type;
- err = check_ctx_reg(env, reg, regno);
- if (err < 0)
- return err;
}
} else if (arg_type == ARG_PTR_TO_SOCK_COMMON) {
expected_type = PTR_TO_SOCK_COMMON;
@@ -4107,6 +4104,10 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
regno);
return -EACCES;
}
+ } else if (type == PTR_TO_CTX) {
+ err = check_ctx_reg(env, reg, regno);
+ if (err < 0)
+ return err;
}
if (reg->ref_obj_id) {