Skip to content

Commit c93c59b

Browse files
pchaignoanakryiko
authored andcommitted
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: 1cb0f56 ("bpf: WARN_ONCE on verifier bugs") Reported-by: Yonghong Song <[email protected]> Signed-off-by: Paul Chaignon <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Tested-by: Eduard Zingerman <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 3e2b799 commit c93c59b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

include/linux/bpf_verifier.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,13 +875,15 @@ __printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env,
875875
#define verifier_bug_if(cond, env, fmt, args...) \
876876
({ \
877877
bool __cond = (cond); \
878-
if (unlikely(__cond)) { \
879-
BPF_WARN_ONCE(1, "verifier bug: " fmt "(" #cond ")\n", ##args); \
880-
bpf_log(&env->log, "verifier bug: " fmt "(" #cond ")\n", ##args); \
881-
} \
878+
if (unlikely(__cond)) \
879+
verifier_bug(env, fmt " (" #cond ")", ##args); \
882880
(__cond); \
883881
})
884-
#define verifier_bug(env, fmt, args...) verifier_bug_if(1, env, fmt, ##args)
882+
#define verifier_bug(env, fmt, args...) \
883+
({ \
884+
BPF_WARN_ONCE(1, "verifier bug: " fmt "\n", ##args); \
885+
bpf_log(&env->log, "verifier bug: " fmt "\n", ##args); \
886+
})
885887

886888
static inline struct bpf_func_state *cur_func(struct bpf_verifier_env *env)
887889
{

0 commit comments

Comments
 (0)