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

Use thread-safe function pointer in libbpf_print

This patch fixes a thread safety bug where libbpf_print uses the
global variable storing the print function pointer rather than the local
variable that had the print function set via __atomic_load_n.

Fixes: f1cb927cdb62 ("libbpf: Ensure print callback usage is thread-safe")
Signed-off-by: Jonathan Wiepert <jonathan.wiepert@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
Link: https://lore.kernel.org/bpf/20250424221457.793068-1-jonathan.wiepert@gmail.com

authored by

Jonathan Wiepert and committed by
Andrii Nakryiko
91dbac40 64821d25

+1 -1
+1 -1
tools/lib/bpf/libbpf.c
··· 286 286 old_errno = errno; 287 287 288 288 va_start(args, format); 289 - __libbpf_pr(level, format, args); 289 + print_fn(level, format, args); 290 290 va_end(args); 291 291 292 292 errno = old_errno;