bpf: Simplify logging-related error conditions handling

Move log->level == 0 check into bpf_vlog_truncated() instead of doing it
explicitly. Also remove unnecessary goto in kernel/bpf/verifier.c.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Lorenz Bauer <lmb@isovalent.com>
Link: https://lore.kernel.org/bpf/20230406234205.323208-11-andrii@kernel.org
This commit is contained in:
Andrii Nakryiko 2023-04-06 16:41:56 -07:00 committed by Daniel Borkmann
parent cbedb42a0d
commit 8a6ca6bc55
3 changed files with 6 additions and 6 deletions

View File

@ -5594,7 +5594,7 @@ static struct btf *btf_parse(bpfptr_t btf_data, u32 btf_data_size,
}
bpf_vlog_finalize(log);
if (log->level && bpf_vlog_truncated(log)) {
if (bpf_vlog_truncated(log)) {
err = -ENOSPC;
goto errout_meta;
}

View File

@ -169,7 +169,9 @@ static int bpf_vlog_reverse_ubuf(struct bpf_verifier_log *log, int start, int en
bool bpf_vlog_truncated(const struct bpf_verifier_log *log)
{
if (log->level & BPF_LOG_FIXED)
if (!log->level)
return false;
else if (log->level & BPF_LOG_FIXED)
return bpf_log_used(log) >= log->len_total - 1;
else
return log->start_pos > 0;

View File

@ -18861,12 +18861,10 @@ skip_full_check:
env->prog->aux->verified_insns = env->insn_processed;
bpf_vlog_finalize(log);
if (log->level && bpf_vlog_truncated(log))
if (bpf_vlog_truncated(log))
ret = -ENOSPC;
if (log->level && log->level != BPF_LOG_KERNEL && !log->ubuf) {
if (log->level && log->level != BPF_LOG_KERNEL && !log->ubuf)
ret = -EFAULT;
goto err_release_maps;
}
if (ret)
goto err_release_maps;