libtraceevent utest: exit test if mmap fails
PATCH 1/1 libtraceevent utest: exit test if mmap fails
CU_TEST() continues execution even if the test fails. It just records that the test has failed and moves on.
So, when libtraceevent is built in a chroot, it can open /sys/kernel/btf/vmlinux but fails in mmap stage and since CU_TEST() does not stop so we get a segfault when tep_load_btf() tries to use the mapped buffer.
--- utest/traceevent-utest.c | 6 ++++++ 1 file changed, 6 insertions(+)
utest/traceevent-utest.c +6 -0
@@ -397,6 +397,12 @@ static void test_btf_read(void)CU_TEST (fstat (fd, &st) ==0 ); buf =mmap (NULL , st.st_size,PROT_READ ,MAP_PRIVATE , fd,0 ); +if (buf ==MAP_FAILED ) { +printf ("kernel has btf, but it might be a chroot and mmap has failed\n" ); +close (fd); +return ; + } +CU_TEST (buf !=MAP_FAILED );CU_TEST (tep_load_btf (test_tep, buf, st.st_size) ==0 );
Signature · 1 line
2.39.5
Quoted 8 lines · On Tue, 26 May 2026 19:42:19 +0100 Sudip Mukherjee…
CU_TEST()continues execution even if the test fails. It just records that the test has failed and moves on.
So, when libtraceevent is built in a chroot, it can open/sys/kernel/btf/vmlinuxbut fails in mmap stage and sinceCU_TEST()does not stop so we get a segfault whentep_load_btf()tries to use the mapped buffer.Signed-off-by Sudip Mukherjee <[email protected]>
Thanks, but the real fix is here and I'm applying that one:
https://lore.kernel.org/all/[email protected]/
-- Steve
Hi Steve,
Quoted 11 lines · Steven Rostedt
Quoted 7 lines · On Tue, 26 May 2026 19:42:19 +0100 Sudip Mukherjee…
CU_TEST()continues execution even if the test fails. It just records that the test has failed and moves on.
So, when libtraceevent is built in a chroot, it can open/sys/kernel/btf/vmlinuxbut fails in mmap stage and sinceCU_TEST()does not stop so we get a segfault whentep_load_btf()tries to use the mapped buffer.
Quoted 5 lines
Quoted 1 line
Signed-off-by Sudip Mukherjee <[email protected]>Thanks, but the real fix is here and I'm applying that one:
Tried it today, and the test still fails for me.
Suite: traceevent library
Test: parse dynamic string event ...irq=0 handler=hellopassed
Test: parse old dynamic string event ...irq=0 handler=hellopassed
Test: parse full cpumask ...cpumask=0-63passed
Test: parse empty cpumask ...cpumask=passed
Test: parse half-filled cpumask
...cpumask=0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62passed
Test: parse cpumask spanning 2 bytes ...cpumask=0,15passed
Test: parse cpumask spanning 3 bytes ...cpumask=0,23passed
Test: parse cpumask spanning all bytes ...cpumask=0,63passed
Test: parse sizeof() 8byte values ...int=4 unsigned=4 unsigned int=4
long=8 unsigned long=8 long long=8 unsigned long long=8 s4=4 u4=4 s8=8
u8=8passed
Test: parse sizeof() 4byte values ...int=4 unsigned=4 unsigned int=4
long=4 unsigned long=4 long long=8 unsigned long long=8 s4=4 u4=4 s8=8
u8=8passed
Test: parse sizeof() no long size defined ...[FAILED TO PARSE] s4=0
u4=0 s8=0 u8=0x0passed
Test: read BTF ...FAILED
1. traceevent-utest.c:410 - read(fd, buf, st.st_size) == st.st_size
2. traceevent-utest.c:412 - tep_load_btf(test_tep, buf, st.st_size) == 0
3. traceevent-utest.c:429 - strcmp(s->buffer,"getname_flags(filename=0x7ffe7d33f3d0, flags=0)\n") == 0
Run Summary: Type Total Ran Passed Failed Inactive
suites 1 1 n/a 0 0
tests 12 12 11 1 0
asserts 46 46 43 3 n/aSignature · 2 lines
Regards Sudip
Quoted 14 lines · On Mon, 15 Jun 2026 20:25:08 +0100 Sudip Mukherjee…
Hi Steve,
Quoted 11 lines · Steven Rostedt
Quoted 7 lines · On Tue, 26 May 2026 19:42:19 +0100 Sudip Mukherjee…
CU_TEST()continues execution even if the test fails. It just records that the test has failed and moves on.
So, when libtraceevent is built in a chroot, it can open/sys/kernel/btf/vmlinuxbut fails in mmap stage and sinceCU_TEST()does not stop so we get a segfault whentep_load_btf()tries to use the mapped buffer.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Sudip Mukherjee <[email protected]>Thanks, but the real fix is here and I'm applying that one:
Tried it today, and the test still fails for me.
Thanks for letting me know. I currently just started a new job and I'm a bit overwhelmed. It may be a couple more weeks before I get to this.
-- Steve
Hi Steve,
Quoted 19 lines · Steven Rostedt
Quoted 16 lines · On Mon, 15 Jun 2026 20:25:08 +0100 Sudip Mukherjee…
Hi Steve,
Quoted 13 lines · Steven Rostedt
Quoted 8 lines · On Tue, 26 May 2026 19:42:19 +0100 Sudip Mukherjee…
CU_TEST()continues execution even if the test fails. It just records that the test has failed and moves on.
So, when libtraceevent is built in a chroot, it can open/sys/kernel/btf/vmlinuxbut fails in mmap stage and sinceCU_TEST()does not stop so we get a segfault whentep_load_btf()tries to use the mapped buffer.Signed-off-by Sudip Mukherjee <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Thanks, but the real fix is here and I'm applying that one:
Tried it today, and the test still fails for me.
Thanks for letting me know. I currently just started a new job and I'm a bit overwhelmed. It may be a couple more weeks before I get to this.
Not sure if you had a chance to look at it. I was looking at it now while updating the Debian package. It seems like btf_init() is failing when its doing if (btf->hdr->hdr_len < sizeof(*btf->hdr)). Adding a debug there shows, btf->hdr->hdr_len is 24 whereas sizeof(*btf->hdr) is 32.
Tried on a chroot and also on a VM, both shows the same problem in Debian.
Signature · 2 lines
Regards Sudip
Quoted 31 lines · On Sat, 7 Nov 2026 16:24:32 +0000 Sudip Mukherjee <[email protected]>…
Hi Steve,
Quoted 19 lines · Steven Rostedt
Quoted 16 lines · On Mon, 15 Jun 2026 20:25:08 +0100 Sudip Mukherjee…
Hi Steve,
Quoted 13 lines · Steven Rostedt
Quoted 8 lines · On Tue, 26 May 2026 19:42:19 +0100 Sudip Mukherjee…
CU_TEST()continues execution even if the test fails. It just records that the test has failed and moves on.
So, when libtraceevent is built in a chroot, it can open/sys/kernel/btf/vmlinuxbut fails in mmap stage and sinceCU_TEST()does not stop so we get a segfault whentep_load_btf()tries to use the mapped buffer.Signed-off-by Sudip Mukherjee <[email protected]>Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Thanks, but the real fix is here and I'm applying that one:
Tried it today, and the test still fails for me.
Thanks for letting me know. I currently just started a new job and I'm a bit overwhelmed. It may be a couple more weeks before I get to this.
Quoted 7 lines
Not sure if you had a chance to look at it. I was looking at it now while updating the Debian package. It seems like
btf_init()is failing when its doing if (btf->hdr->hdr_len<sizeof(*btf->hdr)). Adding a debug there shows,btf->hdr->hdr_lenis 24 whereassizeof(*btf->hdr)is 32.Tried on a chroot and also on a VM, both shows the same problem in Debian.
Bah, because I thought the fix was elsewhere I marked it as "superseded" and forgot I did that. When you said it was different, I was traveling and didn't bother to check patchwork to reset it back to New.
https://patchwork.kernel.org/project/linux-trace-devel/patch/[email protected]/
If it's not visible in patchwork, it's not visible to me :-/
I'll go and set it now to New. Thanks for keeping up on it.
-- Steve
Quoted 43 lines · Steven Rostedt
Quoted 31 lines · On Sat, 7 Nov 2026 16:24:32 +0000 Sudip Mukherjee <[email protected]>…
Hi Steve,
Quoted 19 lines · Steven Rostedt
Quoted 16 lines · On Mon, 15 Jun 2026 20:25:08 +0100 Sudip Mukherjee…
Hi Steve,
Quoted 13 lines · Steven Rostedt
Quoted 8 lines · On Tue, 26 May 2026 19:42:19 +0100 Sudip Mukherjee…
CU_TEST()continues execution even if the test fails. It just records that the test has failed and moves on.
So, when libtraceevent is built in a chroot, it can open/sys/kernel/btf/vmlinuxbut fails in mmap stage and sinceCU_TEST()does not stop so we get a segfault whentep_load_btf()tries to use the mapped buffer.Signed-off-by Sudip Mukherjee <[email protected]>Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Thanks, but the real fix is here and I'm applying that one:
Tried it today, and the test still fails for me.
Thanks for letting me know. I currently just started a new job and I'm a bit overwhelmed. It may be a couple more weeks before I get to this.
Quoted 7 lines
Not sure if you had a chance to look at it. I was looking at it now while updating the Debian package. It seems like
btf_init()is failing when its doing if (btf->hdr->hdr_len<sizeof(*btf->hdr)). Adding a debug there shows,btf->hdr->hdr_lenis 24 whereassizeof(*btf->hdr)is 32.Tried on a chroot and also on a VM, both shows the same problem in Debian.
Quoted 6 lines
Bah, because I thought the fix was elsewhere I marked it as "superseded" and forgot I did that. When you said it was different, I was traveling and didn't bother to check patchwork to reset it back to New.
https://patchwork.kernel.org/project/linux-trace-devel/patch/[email protected]/
The patch which superseded it seems to be correct, mmap fails and it copies the content to a buffer and uses that buffer.
But for some reason the len and size does not match. So decided to flag it to you instead of disabling the test in Debian package. So, it should ideally be a new issue.
Signature · 2 lines
Regards Sudip