OSDN Git Service

bpf: Use a table to drive helper arg type checks
authorLorenz Bauer <lmb@cloudflare.com>
Mon, 21 Sep 2020 12:12:27 +0000 (13:12 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 21 Sep 2020 22:00:41 +0000 (15:00 -0700)
commitf79e7ea571732a6e16f15c6e2f000c347e2d7431
tree7ea295685ddd54b775cdc688bcfe0b5f577e48f6
parentfd1b0d604c56e0d9f143b39a92132a2ea9625e6d
bpf: Use a table to drive helper arg type checks

The mapping between bpf_arg_type and bpf_reg_type is encoded in a big
hairy if statement that is hard to follow. The debug output also leaves
to be desired: if a reg_type doesn't match we only print one of the
options, instead printing all the valid ones.

Convert the if statement into a table which is then used to drive type
checking. If none of the reg_types match we print all options, e.g.:

    R2 type=rdonly_buf expected=fp, pkt, pkt_meta, map_value

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-12-lmb@cloudflare.com
include/linux/bpf.h
kernel/bpf/verifier.c