Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Add missing checks to avoid verbose verifier log

There are a few places where log level is not checked before calling
"verbose()". This forces programs working only at
BPF_LOG_LEVEL_STATS (e.g. veristat) to allocate unnecessarily large
log buffers. Add missing checks.

Reported-by: Emil Tsalapatis <emil@etsalapatis.com>
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20251114200542.912386-1-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Eduard Zingerman and committed by
Alexei Starovoitov
e5d2e34e c1da3df7

+6 -4
+6 -4
kernel/bpf/verifier.c
··· 10720 10720 return err; 10721 10721 } 10722 10722 10723 - verbose(env, "Func#%d ('%s') is global and assumed valid.\n", 10724 - subprog, sub_name); 10723 + if (env->log.level & BPF_LOG_LEVEL) 10724 + verbose(env, "Func#%d ('%s') is global and assumed valid.\n", 10725 + subprog, sub_name); 10725 10726 if (env->subprog_info[subprog].changes_pkt_data) 10726 10727 clear_all_pkt_pointers(env); 10727 10728 /* mark global subprog for verifying after main prog */ ··· 19471 19470 bt_set_frame_slot(&env->bt, fr, i); 19472 19471 first = false; 19473 19472 } 19474 - if (!first) 19473 + if (!first && (env->log.level & BPF_LOG_LEVEL2)) 19475 19474 verbose(env, "\n"); 19476 19475 } 19477 19476 ··· 23699 23698 struct bpf_subprog_arg_info *arg; 23700 23699 struct bpf_reg_state *reg; 23701 23700 23702 - verbose(env, "Validating %s() func#%d...\n", sub_name, subprog); 23701 + if (env->log.level & BPF_LOG_LEVEL) 23702 + verbose(env, "Validating %s() func#%d...\n", sub_name, subprog); 23703 23703 ret = btf_prepare_func_args(env, subprog); 23704 23704 if (ret) 23705 23705 goto out;