Re: [PATCH bpf-next v2] libbpf: fix build error introduced by legacy kprobe feature
From: Andrii Nakryiko <hidden>
Date: 2021-09-14 21:48:38
On Tue, Sep 14, 2021 at 2:39 PM Rafael David Tinoco [off-list ref] wrote:
quoted
- char cmd[192], probename[128], probefunc[128]; + char cmd[288] = "\0", probename[128] = "\0", probefunc[128] = "\0"; const char *file = "/sys/kernel/debug/tracing/kprobe_events";I had gcc-10 with: libbpf.c: In function ‘poke_kprobe_events’: libbpf.c:9012:37: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 62 and 189 [-Werror=format-truncation=] 9012 | snprintf(cmd, sizeof(cmd), "%c:%s %s", | ^~ In file included from /usr/include/stdio.h:866, from libbpf.c:17: /usr/include/x86_64-linux-gnu/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 4 and 258 bytes into a destination of size 192 71 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 72 | __glibc_objsize (__s), __fmt, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 | __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors locally AND it fixed the issue for me but Alexei reported: https://github.com/kernel-patches/bpf/runs/3603448190 with a truncation of max 258 bytes. I raised cmd size to 288.
Right, if offset != 0 GCC is able to deduce that sizeof(probename) + sizeof(probefunc) add up to 256 (plus few more characters in format string) and that will be truncated in cmd. It completely ignores such possibility when offset == 0 and we use name as is. Either way, I bumped the cmd size to 256 and force-pushed. It should build fine now. Sorry for delay.
Let's see if that fixes the issue.