bpf: Rename RET_PTR_TO_ALLOC_MEM
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Mon, 14 Nov 2022 19:15:26 +0000 (00:45 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 15 Nov 2022 05:52:45 +0000 (21:52 -0800)
Currently, the verifier has two return types, RET_PTR_TO_ALLOC_MEM, and
RET_PTR_TO_ALLOC_MEM_OR_NULL, however the former is confusingly named to
imply that it carries MEM_ALLOC, while only the latter does. This causes
confusion during code review leading to conclusions like that the return
value of RET_PTR_TO_DYNPTR_MEM_OR_NULL (which is RET_PTR_TO_ALLOC_MEM |
PTR_MAYBE_NULL) may be consumable by bpf_ringbuf_{submit,commit}.

Rename it to make it clear MEM_ALLOC needs to be tacked on top of
RET_PTR_TO_MEM.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20221114191547.1694267-6-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/verifier.c

index 05f98e9e5c482eb0a2321ac5dac9fe1e31679992..2fe3ec620d549ea9d79a4998bd699b0dda8224f4 100644 (file)
@@ -607,7 +607,7 @@ enum bpf_return_type {
        RET_PTR_TO_SOCKET,              /* returns a pointer to a socket */
        RET_PTR_TO_TCP_SOCK,            /* returns a pointer to a tcp_sock */
        RET_PTR_TO_SOCK_COMMON,         /* returns a pointer to a sock_common */
-       RET_PTR_TO_ALLOC_MEM,           /* returns a pointer to dynamically allocated memory */
+       RET_PTR_TO_MEM,                 /* returns a pointer to memory */
        RET_PTR_TO_MEM_OR_BTF_ID,       /* returns a pointer to a valid memory or a btf_id */
        RET_PTR_TO_BTF_ID,              /* returns a pointer to a btf_id */
        __BPF_RET_TYPE_MAX,
@@ -617,8 +617,8 @@ enum bpf_return_type {
        RET_PTR_TO_SOCKET_OR_NULL       = PTR_MAYBE_NULL | RET_PTR_TO_SOCKET,
        RET_PTR_TO_TCP_SOCK_OR_NULL     = PTR_MAYBE_NULL | RET_PTR_TO_TCP_SOCK,
        RET_PTR_TO_SOCK_COMMON_OR_NULL  = PTR_MAYBE_NULL | RET_PTR_TO_SOCK_COMMON,
-       RET_PTR_TO_ALLOC_MEM_OR_NULL    = PTR_MAYBE_NULL | MEM_ALLOC | RET_PTR_TO_ALLOC_MEM,
-       RET_PTR_TO_DYNPTR_MEM_OR_NULL   = PTR_MAYBE_NULL | RET_PTR_TO_ALLOC_MEM,
+       RET_PTR_TO_ALLOC_MEM_OR_NULL    = PTR_MAYBE_NULL | MEM_ALLOC | RET_PTR_TO_MEM,
+       RET_PTR_TO_DYNPTR_MEM_OR_NULL   = PTR_MAYBE_NULL | RET_PTR_TO_MEM,
        RET_PTR_TO_BTF_ID_OR_NULL       = PTR_MAYBE_NULL | RET_PTR_TO_BTF_ID,
 
        /* This must be the last entry. Its purpose is to ensure the enum is
index a50018e2d4a0db548c02a94f2293bbbfc994c5f1..c88da7e3ca74e1a00fc20ba6b70f42565cab2e92 100644 (file)
@@ -7630,7 +7630,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
                mark_reg_known_zero(env, regs, BPF_REG_0);
                regs[BPF_REG_0].type = PTR_TO_TCP_SOCK | ret_flag;
                break;
-       case RET_PTR_TO_ALLOC_MEM:
+       case RET_PTR_TO_MEM:
                mark_reg_known_zero(env, regs, BPF_REG_0);
                regs[BPF_REG_0].type = PTR_TO_MEM | ret_flag;
                regs[BPF_REG_0].mem_size = meta.mem_size;