Skip to contentSkip to conversation

Use thread-safe function pointer in libbpf_print

PATCH In review > 3 participants 3 messages Apr 24, 2025 – Apr 25, 2025

Subsystems (2)
lore
Share & tools
lore

>

author
#0 lore raw

PATCH 1/1 Use thread-safe function pointer in libbpf_print

From: Jonathan Wiepert <[email protected]>

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.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 56250b5ac5b0..ea97a84460cd 100644
@@ -284,7 +284,7 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)
 	old_errno = errno;
 
 	va_start(args, format);
-	__libbpf_pr(level, format, args);
+	print_fn(level, format, args);
 	va_end(args);
 
 	errno = old_errno;
Signature · 1 line
2.42.0
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · On 4/24/25 23:14, > wrote:

From: Jonathan Wiepert <[email protected]>

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.

---
  tools/lib/bpf/libbpf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +0 -0
index 56250b5ac5b0..ea97a84460cd 100644

tools/lib/bpf/libbpf.c void libbpf_print(enum libbpf_print_level level, const char *format, ...) · line 290

Quoted 8 lines
tools/lib/bpf/libbpf.c +1 -1
@@ -284,7 +284,7 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)
  	old_errno = errno;
 
  	va_start(args, format);
-	__libbpf_pr(level, format, args);
+	print_fn(level, format, args);
  	va_end(args);
 
  	errno = old_errno;
#2 lore raw
In reply to >
Quoted 12 lines · On Thu, Apr 24, 2025 at 3:15 PM > <[email protected]> wrote:

From: Jonathan Wiepert <[email protected]>

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.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Added

Fixes f1cb927cdb62 ("libbpf: Ensure print callback usage is thread-safe")

and applied to bpf-next, thanks.

Quoted 16 lines
tools/lib/bpf/libbpf.c +1 -2
index 56250b5ac5b0..ea97a84460cd 100644
@@ -284,7 +284,7 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)
        old_errno = errno;
 
        va_start(args, format);
-       __libbpf_pr(level, format, args);
+       print_fn(level, format, args);
        va_end(args);
 
        errno = old_errno;
--

2.42.0