bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Tidy verifier bug message
@ 2025-08-11 18:58 Paul Chaignon
  2025-08-11 20:01 ` Eduard Zingerman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Paul Chaignon @ 2025-08-11 18:58 UTC (permalink / raw)
  To: bpf; +Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Yonghong Song

Yonghong noticed that error messages for potential verifier bugs often
have a '(1)' at the end. This is happening because verifier_bug_if(cond,
env, fmt, args...) prints "(" #cond ")\n" as part of the message and
verifier_bug() is defined as:

  #define verifier_bug(env, fmt, args...) verifier_bug_if(1, env, fmt, ##args)

Hence, verifier_bug() always ends up displaying '(1)'. This small patch
fixes it by having verifier_bug_if conditionally call verifier_bug
instead of the other way around.

Fixes: 1cb0f56d9618 ("bpf: WARN_ONCE on verifier bugs")
Reported-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
---
 include/linux/bpf_verifier.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index c823f8efe3ed..d38b5ac6a191 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -876,12 +876,15 @@ __printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env,
 	({											\
 		bool __cond = (cond);								\
 		if (unlikely(__cond)) {								\
-			BPF_WARN_ONCE(1, "verifier bug: " fmt "(" #cond ")\n", ##args);		\
-			bpf_log(&env->log, "verifier bug: " fmt "(" #cond ")\n", ##args);	\
+			verifier_bug(env, fmt " (" #cond ")", ##args);				\
 		}										\
 		(__cond);									\
 	})
-#define verifier_bug(env, fmt, args...) verifier_bug_if(1, env, fmt, ##args)
+#define verifier_bug(env, fmt, args...)					\
+	({								\
+		BPF_WARN_ONCE(1, "verifier bug: " fmt "\n", ##args);	\
+		bpf_log(&env->log, "verifier bug: " fmt "\n", ##args);	\
+	})
 
 static inline struct bpf_func_state *cur_func(struct bpf_verifier_env *env)
 {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] bpf: Tidy verifier bug message
  2025-08-11 18:58 [PATCH bpf-next] bpf: Tidy verifier bug message Paul Chaignon
@ 2025-08-11 20:01 ` Eduard Zingerman
  2025-08-12  2:20 ` Yonghong Song
  2025-08-12 22:51 ` Andrii Nakryiko
  2 siblings, 0 replies; 4+ messages in thread
From: Eduard Zingerman @ 2025-08-11 20:01 UTC (permalink / raw)
  To: Paul Chaignon, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Yonghong Song

On Mon, 2025-08-11 at 20:58 +0200, Paul Chaignon wrote:
> Yonghong noticed that error messages for potential verifier bugs often
> have a '(1)' at the end. This is happening because verifier_bug_if(cond,
> env, fmt, args...) prints "(" #cond ")\n" as part of the message and
> verifier_bug() is defined as:
> 
>   #define verifier_bug(env, fmt, args...) verifier_bug_if(1, env, fmt, ##args)
> 
> Hence, verifier_bug() always ends up displaying '(1)'. This small patch
> fixes it by having verifier_bug_if conditionally call verifier_bug
> instead of the other way around.
> 
> Fixes: 1cb0f56d9618 ("bpf: WARN_ONCE on verifier bugs")
> Reported-by: Yonghong Song <yonghong.song@linux.dev>
> Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
> ---

I wondered why that '(1)' was printed lately...
Tried this patch for both verifier_bug and verifier_bug_if,
works as expected.

Tested-by: Eduard Zingerman <eddyz87@gmail.com>

[...]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] bpf: Tidy verifier bug message
  2025-08-11 18:58 [PATCH bpf-next] bpf: Tidy verifier bug message Paul Chaignon
  2025-08-11 20:01 ` Eduard Zingerman
@ 2025-08-12  2:20 ` Yonghong Song
  2025-08-12 22:51 ` Andrii Nakryiko
  2 siblings, 0 replies; 4+ messages in thread
From: Yonghong Song @ 2025-08-12  2:20 UTC (permalink / raw)
  To: Paul Chaignon, bpf; +Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko



On 8/11/25 11:58 AM, Paul Chaignon wrote:
> Yonghong noticed that error messages for potential verifier bugs often
> have a '(1)' at the end. This is happening because verifier_bug_if(cond,
> env, fmt, args...) prints "(" #cond ")\n" as part of the message and
> verifier_bug() is defined as:
>
>    #define verifier_bug(env, fmt, args...) verifier_bug_if(1, env, fmt, ##args)
>
> Hence, verifier_bug() always ends up displaying '(1)'. This small patch
> fixes it by having verifier_bug_if conditionally call verifier_bug
> instead of the other way around.
>
> Fixes: 1cb0f56d9618 ("bpf: WARN_ONCE on verifier bugs")
> Reported-by: Yonghong Song <yonghong.song@linux.dev>
> Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>

Acked-by: Yonghong Song <yonghong.song@linux.dev>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] bpf: Tidy verifier bug message
  2025-08-11 18:58 [PATCH bpf-next] bpf: Tidy verifier bug message Paul Chaignon
  2025-08-11 20:01 ` Eduard Zingerman
  2025-08-12  2:20 ` Yonghong Song
@ 2025-08-12 22:51 ` Andrii Nakryiko
  2 siblings, 0 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2025-08-12 22:51 UTC (permalink / raw)
  To: Paul Chaignon
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Yonghong Song

On Mon, Aug 11, 2025 at 11:58 AM Paul Chaignon <paul.chaignon@gmail.com> wrote:
>
> Yonghong noticed that error messages for potential verifier bugs often
> have a '(1)' at the end. This is happening because verifier_bug_if(cond,
> env, fmt, args...) prints "(" #cond ")\n" as part of the message and
> verifier_bug() is defined as:
>
>   #define verifier_bug(env, fmt, args...) verifier_bug_if(1, env, fmt, ##args)
>
> Hence, verifier_bug() always ends up displaying '(1)'. This small patch
> fixes it by having verifier_bug_if conditionally call verifier_bug
> instead of the other way around.
>
> Fixes: 1cb0f56d9618 ("bpf: WARN_ONCE on verifier bugs")
> Reported-by: Yonghong Song <yonghong.song@linux.dev>
> Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
> ---
>  include/linux/bpf_verifier.h | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
> index c823f8efe3ed..d38b5ac6a191 100644
> --- a/include/linux/bpf_verifier.h
> +++ b/include/linux/bpf_verifier.h
> @@ -876,12 +876,15 @@ __printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env,
>         ({                                                                                      \
>                 bool __cond = (cond);                                                           \
>                 if (unlikely(__cond)) {                                                         \
> -                       BPF_WARN_ONCE(1, "verifier bug: " fmt "(" #cond ")\n", ##args);         \
> -                       bpf_log(&env->log, "verifier bug: " fmt "(" #cond ")\n", ##args);       \
> +                       verifier_bug(env, fmt " (" #cond ")", ##args);                          \
>                 }                                                                               \

dropped now unnecessary {}

>                 (__cond);                                                                       \
>         })
> -#define verifier_bug(env, fmt, args...) verifier_bug_if(1, env, fmt, ##args)
> +#define verifier_bug(env, fmt, args...)                                        \
> +       ({                                                              \
> +               BPF_WARN_ONCE(1, "verifier bug: " fmt "\n", ##args);    \
> +               bpf_log(&env->log, "verifier bug: " fmt "\n", ##args);  \
> +       })

shifted those ending \ to align with verifier_buf_if's ones.

Applied to bpf-next, thanks.


>
>  static inline struct bpf_func_state *cur_func(struct bpf_verifier_env *env)
>  {
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-12 22:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 18:58 [PATCH bpf-next] bpf: Tidy verifier bug message Paul Chaignon
2025-08-11 20:01 ` Eduard Zingerman
2025-08-12  2:20 ` Yonghong Song
2025-08-12 22:51 ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).