Skip to content

Commit

Permalink
selftests/bpf: Fix segfault in bpf_tcp_ca
Browse files Browse the repository at this point in the history
Since commit ad9a7f9 ("libbpf: Improve logging around BPF program
loading"), libbpf_debug_print() gets an additional prog_name parameter
but doesn't pass it to printf(). Since the format string now expects two
arguments, printf() may read uninitialized data and segfault. Pass
prog_name through.

Fixes: ad9a7f9 ("libbpf: Improve logging around BPF program loading")
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211213183058.346066-1-jean-philippe@linaro.org
  • Loading branch information
Jean-Philippe Brucker authored and Andrii Nakryiko committed Dec 13, 2021
1 parent c8064e5 commit acd143e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,22 @@ static bool found;
static int libbpf_debug_print(enum libbpf_print_level level,
const char *format, va_list args)
{
const char *log_buf;
const char *prog_name, *log_buf;

if (level != LIBBPF_WARN ||
!strstr(format, "-- BEGIN PROG LOAD LOG --")) {
vprintf(format, args);
return 0;
}

/* skip prog_name */
va_arg(args, char *);
prog_name = va_arg(args, char *);
log_buf = va_arg(args, char *);
if (!log_buf)
goto out;
if (err_str && strstr(log_buf, err_str) != NULL)
found = true;
out:
printf(format, log_buf);
printf(format, prog_name, log_buf);
return 0;
}

Expand Down

0 comments on commit acd143e

Please sign in to comment.