Remove ARG_PTR_TO_MEM_OR_NULL and use flag to mark that the argument may be null. Signed-off-by: Hao Luo <haoluo@xxxxxxxxxx> --- include/linux/bpf.h | 1 - kernel/bpf/helpers.c | 10 ++++++++-- kernel/bpf/verifier.c | 3 --- kernel/trace/bpf_trace.c | 15 ++++++++++++--- net/core/filter.c | 15 ++++++++++++--- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index d8de8f00e40d..dd92418814b5 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -317,7 +317,6 @@ struct bpf_arg_type { * functions that access data on eBPF program stack */ ARG_PTR_TO_MEM, /* pointer to valid memory (stack, packet, map value) */ - ARG_PTR_TO_MEM_OR_NULL, /* pointer to valid memory or NULL */ ARG_PTR_TO_UNINIT_MEM, /* pointer to memory does not need to be initialized, * helper function must fill all bytes or clear * them in error case. diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index d68c70f4b4b6..cd792777afb2 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -1008,10 +1008,16 @@ const struct bpf_func_proto bpf_snprintf_proto = { .func = bpf_snprintf, .gpl_only = true, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, .arg3 = { .type = ARG_PTR_TO_CONST_STR }, - .arg4 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg4 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, }; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index f55967f92d22..eb69b8bddee5 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -481,7 +481,6 @@ static bool arg_type_may_be_refcounted(struct bpf_arg_type arg) static bool arg_type_may_be_null(struct bpf_arg_type arg) { return arg.flag & ARG_FLAG_MAYBE_NULL || - arg.type == ARG_PTR_TO_MEM_OR_NULL || arg.type == ARG_PTR_TO_CTX_OR_NULL || arg.type == ARG_PTR_TO_SOCKET_OR_NULL || arg.type == ARG_PTR_TO_ALLOC_MEM_OR_NULL || @@ -4951,7 +4950,6 @@ static int process_timer_func(struct bpf_verifier_env *env, int regno, static bool arg_type_is_mem_ptr(struct bpf_arg_type arg) { return arg.type == ARG_PTR_TO_MEM || - arg.type == ARG_PTR_TO_MEM_OR_NULL || arg.type == ARG_PTR_TO_UNINIT_MEM; } @@ -5104,7 +5102,6 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_PTR_TO_BTF_ID] = &btf_ptr_types, [ARG_PTR_TO_SPIN_LOCK] = &spin_lock_types, [ARG_PTR_TO_MEM] = &mem_types, - [ARG_PTR_TO_MEM_OR_NULL] = &mem_types, [ARG_PTR_TO_UNINIT_MEM] = &mem_types, [ARG_PTR_TO_ALLOC_MEM] = &alloc_mem_types, [ARG_PTR_TO_ALLOC_MEM_OR_NULL] = &alloc_mem_types, diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 6e0b17637787..086889a29ca7 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -452,7 +452,10 @@ static const struct bpf_func_proto bpf_trace_vprintk_proto = { .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_MEM }, .arg2 = { .type = ARG_CONST_SIZE }, - .arg3 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_CONST_SIZE_OR_ZERO }, }; @@ -494,7 +497,10 @@ static const struct bpf_func_proto bpf_seq_printf_proto = { .arg1_btf_id = &btf_seq_file_ids[0], .arg2 = { .type = ARG_PTR_TO_MEM }, .arg3 = { .type = ARG_CONST_SIZE }, - .arg4 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg4 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, }; @@ -1435,7 +1441,10 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_CTX }, - .arg2 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg2 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, .arg4 = { .type = ARG_ANYTHING }, }; diff --git a/net/core/filter.c b/net/core/filter.c index 90fa7f67f3c2..81c6638ffc2a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2018,9 +2018,15 @@ static const struct bpf_func_proto bpf_csum_diff_proto = { .gpl_only = false, .pkt_access = true, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, - .arg3 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_CONST_SIZE_OR_ZERO }, .arg5 = { .type = ARG_ANYTHING }, }; @@ -2541,7 +2547,10 @@ static const struct bpf_func_proto bpf_redirect_neigh_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_ANYTHING }, - .arg2 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg2 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, .arg4 = { .type = ARG_ANYTHING }, }; -- 2.34.0.rc0.344.g81b53c2807-goog