Skip to contentSkip to conversation

bpf: Tidy verifier bug message

PATCH Applied Paul Chaignon 4 participants 4 messages Aug 11, 2025 – Aug 12, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Tidy verifier bug message

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")
---
 include/linux/bpf_verifier.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
include/linux/bpf_verifier.h +6 -3
index c823f8efe3ed..d38b5ac6a191 100644
@@ -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)
 {
Signature · 1 line
2.43.0
maintainer Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Paul Chaignon

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)
Quoted 8 lines

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")

---

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

[...]

reviewer Acked-by on v1 1/1
#2 lore raw
In reply to Paul Chaignon
Quoted 7 lines · Paul Chaignon

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)
Quoted 7 lines

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")
#3 lore raw
In reply to Paul Chaignon
Quoted 24 lines · Paul Chaignon

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")
---
 include/linux/bpf_verifier.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
include/linux/bpf_verifier.h +0 -0
index c823f8efe3ed..d38b5ac6a191 100644

include/linux/bpf_verifier.h __printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env, · line 880

Quoted 7 lines
include/linux/bpf_verifier.h +1 -2
@@ -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 {}

include/linux/bpf_verifier.h __printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env, · line 887

Quoted 8 lines
include/linux/bpf_verifier.h +5 -1
                (__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.

Quoted 6 lines
include/linux/bpf_verifier.h +0 -1
 static inline struct bpf_func_state *cur_func(struct bpf_verifier_env *env)
 {
--

2.43.0