lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQLk1y8k7xBdJbF+W+V5JQdV50kFxvLpkZp_LPs2KMt7Mw@mail.gmail.com>
Date: Sat, 31 Jan 2026 19:06:46 -0800
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Feng Yang <yangfeng59949@....com>
Cc: Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>, 
	Andrii Nakryiko <andrii@...nel.org>, Martin KaFai Lau <martin.lau@...ux.dev>, Eduard <eddyz87@...il.com>, 
	Song Liu <song@...nel.org>, Yonghong Song <yonghong.song@...ux.dev>, 
	John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>, 
	Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>, 
	Mykyta Yatsenko <mykyta.yatsenko5@...il.com>, bpf <bpf@...r.kernel.org>, 
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 bpf-next] bpf: Add the missing types in the logs

On Fri, Jan 30, 2026 at 12:16 AM Feng Yang <yangfeng59949@....com> wrote:
>
> From: Feng Yang <yangfeng@...inos.cn>
>
> Add the missing types to avoid such uninformative errors as shown below:
> R1 type=ptr_ expected=ptr_
>
> Signed-off-by: Feng Yang <yangfeng@...inos.cn>
> ---
> Changes in v4:
> - Added a part that was accidentally omitted before, please ignore the v3 version.
> Changes in v3:
> - Fix the self-test failures caused by this patch.
> - Link to v2: https://lore.kernel.org/all/20260129073614.113380-1-yangfeng59949@163.com/
> Changes in v2:
> - Group together those for which only 0 or 1 can be selected. thanks, Mykyta Yatsenko.
> - Link to v1: https://lore.kernel.org/all/20260128085842.145057-1-yangfeng59949@163.com/
> ---
>  kernel/bpf/log.c                              | 53 +++++++++++++++++--
>  .../selftests/bpf/prog_tests/linked_list.c    |  6 +--
>  .../selftests/bpf/prog_tests/spin_lock.c      |  6 +--
>  .../testing/selftests/bpf/progs/dynptr_fail.c |  4 +-
>  .../selftests/bpf/progs/linked_list_peek.c    |  2 +-
>  .../bpf/progs/local_kptr_stash_fail.c         |  2 +-
>  .../selftests/bpf/progs/percpu_alloc_fail.c   |  4 +-
>  .../selftests/bpf/progs/rbtree_search.c       |  4 +-
>  .../struct_ops_kptr_return_fail__local_kptr.c |  2 +-
>  9 files changed, 63 insertions(+), 20 deletions(-)
>
> diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c
> index a0c3b35de2ce..c7d08b1ba96f 100644
> --- a/kernel/bpf/log.c
> +++ b/kernel/bpf/log.c
> @@ -432,6 +432,44 @@ static const char *btf_type_name(const struct btf *btf, u32 id)
>         return btf_name_by_offset(btf, btf_type_by_id(btf, id)->name_off);
>  }
>
> +static const char *dynptr_reg_type(enum bpf_reg_type type)
> +{
> +       if (type & DYNPTR_TYPE_LOCAL)
> +               return "dynptr_local_";
> +       if (type & DYNPTR_TYPE_RINGBUF)
> +               return "dynptr_ringbuf_";
> +       if (type & DYNPTR_TYPE_SKB)
> +               return "dynptr_skb_";
> +       if (type & DYNPTR_TYPE_XDP)
> +               return "dynptr_xdp_";
> +       if (type & DYNPTR_TYPE_SKB_META)
> +               return "dynptr_skb_meta_";
> +       if (type & DYNPTR_TYPE_FILE)
> +               return "dynptr_file_";
> +
> +       return "";
> +}
> +
> +static const char *trusted_reg_type(enum bpf_reg_type type)
> +{
> +       if (type & PTR_TRUSTED)
> +               return "trusted_";
> +       if (type & PTR_UNTRUSTED)
> +               return "untrusted_";
> +
> +       return "";
> +}
> +
> +static const char *rw_reg_type(enum bpf_reg_type type)
> +{
> +       if (type & MEM_RDONLY)
> +               return "rdonly_";
> +       if (type & MEM_WRITE)
> +               return "write_";
> +
> +       return "";
> +}
> +
>  /* string representation of 'enum bpf_reg_type'
>   *
>   * Note that reg_type_str() can not appear more than once in a single verbose()
> @@ -439,7 +477,7 @@ static const char *btf_type_name(const struct btf *btf, u32 id)
>   */
>  const char *reg_type_str(struct bpf_verifier_env *env, enum bpf_reg_type type)
>  {
> -       char postfix[16] = {0}, prefix[64] = {0};
> +       char postfix[16] = {0}, prefix[128] = {0};
>         static const char * const str[] = {
>                 [NOT_INIT]              = "?",
>                 [SCALAR_VALUE]          = "scalar",
> @@ -473,14 +511,19 @@ const char *reg_type_str(struct bpf_verifier_env *env, enum bpf_reg_type type)
>                         strscpy(postfix, "_or_null");
>         }
>
> -       snprintf(prefix, sizeof(prefix), "%s%s%s%s%s%s%s",
> -                type & MEM_RDONLY ? "rdonly_" : "",
> +       snprintf(prefix, sizeof(prefix), "%s%s%s%s%s%s%s%s%s%s%s%s",
> +                rw_reg_type(type),
> +                trusted_reg_type(type),
> +                dynptr_reg_type(type),
>                  type & MEM_RINGBUF ? "ringbuf_" : "",
>                  type & MEM_USER ? "user_" : "",
>                  type & MEM_PERCPU ? "percpu_" : "",
>                  type & MEM_RCU ? "rcu_" : "",
> -                type & PTR_UNTRUSTED ? "untrusted_" : "",
> -                type & PTR_TRUSTED ? "trusted_" : ""
> +                type & MEM_UNINIT ? "uninit_" : "",
> +                type & MEM_FIXED_SIZE ? "fixed_size_" : "",
> +                type & MEM_ALLOC ? "alloc_" : "",
> +                type & NON_OWN_REF ? "non_own_ref_" : "",
> +                type & MEM_ALIGNED ? "aligned_" : ""
>         );
>
>         snprintf(env->tmp_str_buf, TMP_STR_BUF_LEN, "%s%s%s",
> diff --git a/tools/testing/selftests/bpf/prog_tests/linked_list.c b/tools/testing/selftests/bpf/prog_tests/linked_list.c
> index 14c5a7ef0e87..141c611de1cf 100644
> --- a/tools/testing/selftests/bpf/prog_tests/linked_list.c
> +++ b/tools/testing/selftests/bpf/prog_tests/linked_list.c
> @@ -69,7 +69,7 @@ static struct {
>         { "obj_new_no_composite", "bpf_obj_new/bpf_percpu_obj_new type ID argument must be of a struct" },
>         { "obj_new_no_struct", "bpf_obj_new/bpf_percpu_obj_new type ID argument must be of a struct" },
>         { "obj_drop_non_zero_off", "R1 must have zero offset when passed to release func" },
> -       { "new_null_ret", "R0 invalid mem access 'ptr_or_null_'" },
> +       { "new_null_ret", "R0 invalid mem access 'alloc_ptr_or_null_'" },
>         { "obj_new_acq", "Unreleased reference id=" },
>         { "use_after_drop", "invalid mem access 'scalar'" },
>         { "ptr_walk_scalar", "type=rdonly_untrusted_mem expected=percpu_ptr_" },
> @@ -87,12 +87,12 @@ static struct {
>         { "incorrect_value_type",
>           "operation on bpf_list_head expects arg#1 bpf_list_node at offset=48 in struct foo, "
>           "but arg is at offset=0 in struct bar" },
> -       { "incorrect_node_var_off", "variable ptr_ access var_off=(0x0; 0xffffffff) disallowed" },
> +       { "incorrect_node_var_off", "variable alloc_ptr_ access var_off=(0x0; 0xffffffff) disallowed" },
>         { "incorrect_node_off1", "bpf_list_node not found at offset=49" },
>         { "incorrect_node_off2", "arg#1 offset=0, but expected bpf_list_node at offset=48 in struct foo" },
>         { "no_head_type", "bpf_list_head not found at offset=0" },
>         { "incorrect_head_var_off1", "R1 doesn't have constant offset" },
> -       { "incorrect_head_var_off2", "variable ptr_ access var_off=(0x0; 0xffffffff) disallowed" },
> +       { "incorrect_head_var_off2", "variable alloc_ptr_ access var_off=(0x0; 0xffffffff) disallowed" },
>         { "incorrect_head_off1", "bpf_list_head not found at offset=25" },
>         { "incorrect_head_off2", "bpf_list_head not found at offset=1" },
>         { "pop_front_off", "off 48 doesn't point to 'struct bpf_spin_lock' that is at 40" },
> diff --git a/tools/testing/selftests/bpf/prog_tests/spin_lock.c b/tools/testing/selftests/bpf/prog_tests/spin_lock.c
> index 254fbfeab06a..b365010e47c6 100644
> --- a/tools/testing/selftests/bpf/prog_tests/spin_lock.c
> +++ b/tools/testing/selftests/bpf/prog_tests/spin_lock.c
> @@ -13,9 +13,9 @@ static struct {
>         const char *err_msg;
>  } spin_lock_fail_tests[] = {
>         { "lock_id_kptr_preserve",
> -         "5: (bf) r1 = r0                       ; R0=ptr_foo(id=2,ref_obj_id=2) "
> -         "R1=ptr_foo(id=2,ref_obj_id=2) refs=2\n6: (85) call bpf_this_cpu_ptr#154\n"
> -         "R1 type=ptr_ expected=percpu_ptr_" },
> +         "5: (bf) r1 = r0                       ; R0=alloc_ptr_foo(id=2,ref_obj_id=2) "
> +         "R1=alloc_ptr_foo(id=2,ref_obj_id=2) refs=2\n6: (85) call bpf_this_cpu_ptr#154\n"
> +         "R1 type=alloc_ptr_ expected=percpu_ptr_, percpu_rcu_ptr_, trusted_percpu_ptr_" },
>         { "lock_id_global_zero",
>           "; R1=map_value(map=.data.A,ks=4,vs=4)\n2: (85) call bpf_this_cpu_ptr#154\n"
>           "R1 type=map_value expected=percpu_ptr_" },
> diff --git a/tools/testing/selftests/bpf/progs/dynptr_fail.c b/tools/testing/selftests/bpf/progs/dynptr_fail.c
> index 8f2ae9640886..b497e61a3224 100644
> --- a/tools/testing/selftests/bpf/progs/dynptr_fail.c
> +++ b/tools/testing/selftests/bpf/progs/dynptr_fail.c
> @@ -1090,7 +1090,7 @@ int dynptr_read_into_slot(void *ctx)
>
>  /* bpf_dynptr_slice()s are read-only and cannot be written to */
>  SEC("?tc")
> -__failure __msg("R{{[0-9]+}} cannot write into rdonly_mem")
> +__failure __msg("R{{[0-9]+}} cannot write into rdonly_dynptr_skb_mem")
>  int skb_invalid_slice_write(struct __sk_buff *skb)
>  {
>         struct bpf_dynptr ptr;
> @@ -1111,7 +1111,7 @@ int skb_invalid_slice_write(struct __sk_buff *skb)
>
>  /* bpf_dynptr_slice()s are read-only and cannot be written to */
>  SEC("?tc")
> -__failure __msg("R{{[0-9]+}} cannot write into rdonly_mem")
> +__failure __msg("R{{[0-9]+}} cannot write into rdonly_dynptr_skb_meta_mem")
>  int skb_meta_invalid_slice_write(struct __sk_buff *skb)
>  {
>         struct bpf_dynptr meta;
> diff --git a/tools/testing/selftests/bpf/progs/linked_list_peek.c b/tools/testing/selftests/bpf/progs/linked_list_peek.c
> index 264e81bfb287..60f3f9e4d3a8 100644
> --- a/tools/testing/selftests/bpf/progs/linked_list_peek.c
> +++ b/tools/testing/selftests/bpf/progs/linked_list_peek.c
> @@ -100,7 +100,7 @@ long test_##op##_spinlock_##dolock(void *ctx)                       \
>         return !!jiffies;                                       \
>  }
>
> -#define MSG "call bpf_list_{{(front|back).+}}; R0{{(_w)?}}=ptr_or_null_node_data(id={{[0-9]+}},non_own_ref"
> +#define MSG "call bpf_list_{{(front|back).+}}; R0{{(_w)?}}=alloc_non_own_ref_ptr_or_null_node_data(id={{[0-9]+}},non_own_ref"
>  TEST_FB(front, true)
>  TEST_FB(back, true)
>  #undef MSG
> diff --git a/tools/testing/selftests/bpf/progs/local_kptr_stash_fail.c b/tools/testing/selftests/bpf/progs/local_kptr_stash_fail.c
> index fcf7a7567da2..ae6cf9efab5f 100644
> --- a/tools/testing/selftests/bpf/progs/local_kptr_stash_fail.c
> +++ b/tools/testing/selftests/bpf/progs/local_kptr_stash_fail.c
> @@ -40,7 +40,7 @@ struct {
>  } some_nodes SEC(".maps");
>
>  SEC("tc")
> -__failure __msg("invalid kptr access, R2 type=ptr_node_data2 expected=ptr_node_data")
> +__failure __msg("invalid kptr access, R2 type=alloc_ptr_node_data2 expected=ptr_node_data")
>  long stash_rb_nodes(void *ctx)
>  {
>         struct map_value *mapval;
> diff --git a/tools/testing/selftests/bpf/progs/percpu_alloc_fail.c b/tools/testing/selftests/bpf/progs/percpu_alloc_fail.c
> index f2b8eb2ff76f..87154ca70bb4 100644
> --- a/tools/testing/selftests/bpf/progs/percpu_alloc_fail.c
> +++ b/tools/testing/selftests/bpf/progs/percpu_alloc_fail.c
> @@ -60,7 +60,7 @@ int BPF_PROG(test_array_map_1)
>  }
>
>  SEC("?fentry/bpf_fentry_test1")
> -__failure __msg("invalid kptr access, R2 type=percpu_ptr_val2_t expected=ptr_val_t")
> +__failure __msg("invalid kptr access, R2 type=percpu_alloc_ptr_val2_t expected=ptr_val_t")
>  int BPF_PROG(test_array_map_2)
>  {
>         struct val2_t __percpu_kptr *p2;
> @@ -84,7 +84,7 @@ int BPF_PROG(test_array_map_2)
>  }
>
>  SEC("?fentry.s/bpf_fentry_test1")
> -__failure __msg("R1 type=scalar expected=percpu_ptr_, percpu_rcu_ptr_, percpu_trusted_ptr_")
> +__failure __msg("R1 type=scalar expected=percpu_ptr_, percpu_rcu_ptr_, trusted_percpu_ptr_")
>  int BPF_PROG(test_array_map_3)
>  {
>         struct val_t __percpu_kptr *p, *p1;
> diff --git a/tools/testing/selftests/bpf/progs/rbtree_search.c b/tools/testing/selftests/bpf/progs/rbtree_search.c
> index b05565d1db0d..f060d7ae22fa 100644
> --- a/tools/testing/selftests/bpf/progs/rbtree_search.c
> +++ b/tools/testing/selftests/bpf/progs/rbtree_search.c
> @@ -189,10 +189,10 @@ long test_##op##_spinlock_##dolock(void *ctx)             \
>   * Otherwise, the test_loader will incorrectly match the prog lineinfo
>   * instead of the log generated by the verifier.
>   */
> -#define MSG "call bpf_rbtree_root{{.+}}; R0{{(_w)?}}=rcu_ptr_or_null_node_data(id={{[0-9]+}},non_own_ref"
> +#define MSG "call bpf_rbtree_root{{.+}}; R0{{(_w)?}}=rcu_alloc_non_own_ref_ptr_or_null_node_data(id={{[0-9]+}},non_own_ref"
>  TEST_ROOT(true)
>  #undef MSG
> -#define MSG "call bpf_rbtree_{{(left|right).+}}; R0{{(_w)?}}=rcu_ptr_or_null_node_data(id={{[0-9]+}},non_own_ref"
> +#define MSG "call bpf_rbtree_{{(left|right).+}}; R0{{(_w)?}}=rcu_alloc_non_own_ref_ptr_or_null_node_data(id={{[0-9]+}},non_own_ref"

I don't think it's an improvement.
Now it's completely unreadable.

The "R1 type=ptr_ expected=ptr_" message sucks, but not because of
type modifiers. It's missing struct name and that's where the mismatch
often happens.
trusted/rdonly/alloc/non_own is all noise.

pw-bot: cr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ