From 47fcb869609bc015ce6eca65d5b3e835d8e6132d Mon Sep 17 00:00:00 2001 From: Motomu Utsumi Date: Mon, 28 Jul 2025 11:19:54 +0900 Subject: [PATCH] NetBpfLoad: Prevent libbpf log truncation The liblog logger truncates messages over 1024 bytes, which was cutting off kernel verifier logs. This change bypasses the limit by splitting the log by newline and logging each line individually. Bug: 428792764 Flag: EXEMPT logging only change Test: TH Change-Id: I327c7e6d717b93bad0ef3e0e9b2e45a5208728ae --- bpf/loader/NetBpfLoad.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 36598d7c82..f7a58b6952 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -1848,11 +1848,23 @@ static int libbpfPrint(enum libbpf_print_level lvl, const char *const formatStr, prio = ANDROID_LOG_DEBUG; break; } - char *s = strdup(formatStr ?: "(no format string)"); + if (!formatStr) { + LOG_PRI(prio, LOG_TAG, "libbpf (null format string)"); + return 0; + } + + // Print each line to avoid being truncated. + char *s = NULL; + int ret = vasprintf(&s, formatStr, argList); + if (ret == -1) { + LOG_PRI(prio, LOG_TAG, "libbpf (format failure)"); + return 0; + } int len = strlen(s); if (len && s[len - 1] == '\n') s[len - 1] = 0; - LOG_PRI_VA(prio, LOG_TAG, s, argList); + vector lines = Split(s, "\n"); + for (const auto& line : lines) LOG_PRI(prio, LOG_TAG, "%s", line.c_str()); free(s); return 0; }