@@ -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.
@@ -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 },
};
@@ -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,
@@ -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 },
};
@@ -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 },
};
Remove ARG_PTR_TO_MEM_OR_NULL and use flag to mark that the argument may be null. Signed-off-by: Hao Luo <haoluo@google.com> --- 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(-)