Fix segfaults related to missing BTF support
cover Fix segfaults related to missing BTF support
Hi,
While looking for reports to fix before release 1.28 I got to
Matthias reports about segfaults in systems where BTF isn't present, so I introduced a regression test and infrastructure to allow testing handling such a system, please take a look.
Thanks,
- Arnaldo
Arnaldo Carvalho de Melo (5):
core: Add method to get the vmlinux BTF filename, allow overriding it via env var tests default_vmlinux_btf: Introduce test for using BTF by default
pahole: Honour exclusive BTF loading
tests default_vmlinux_btf: Cover the no args segfault too
core, libctf: Check if constructor arguments are NULL before using them
dwarves.c | 33 ++++++++++++++++++++++++++++++--- dwarves.h | 2 ++ libctf.c | 3 +++ man-pages/pahole.1 | 4 ++++ pahole.c | 11 +++++++++-- tests/default_vmlinux_btf.sh | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 5 deletions(-) create mode 100755 tests/default_vmlinux_btf.sh
Signature · 1 line
2.47.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 4/5] tests default_vmlinux_btf: Cover the no args segfault too
Quoted 23 lines · Alan Maguire
Quoted 13 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
root@x1:/home/acme/git/pahole# pahole --running_kernel_vmlinux pahole: couldn't find a vmlinux that matches the running kernel HINT: Maybe you're inside a container or missing a debuginfo package? root@x1:/home/acme/git/pahole# tests/default_vmlinux_btf.sh Default BTF on a system without BTF: FAILED root@x1:/home/acme/git/pahole# pahole Segmentation fault (core dumped) root@x1:/home/acme/git/pahole#Now to fix this one as well.
Quoted 8 lines
Reported-by Matthias Schwarzott <[email protected]>Cc Alan Maguire <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Eduard Zingerman <[email protected]>Cc Jiri Olsa <[email protected]>Cc Song Liu <[email protected]>Cc Yonghong Song <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Quoted 1 line
Reviewed-by Alan Maguire <[email protected]>
Thanks, added.
- Arnaldo
Re: [PATCH 4/5] tests default_vmlinux_btf: Cover the no args segfault too
In reply to a message not in the archiveQuoted 23 lines · Alan Maguire
Quoted 13 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
root@x1:/home/acme/git/pahole# pahole --running_kernel_vmlinux pahole: couldn't find a vmlinux that matches the running kernel HINT: Maybe you're inside a container or missing a debuginfo package? root@x1:/home/acme/git/pahole# tests/default_vmlinux_btf.sh Default BTF on a system without BTF: FAILED root@x1:/home/acme/git/pahole# pahole Segmentation fault (core dumped) root@x1:/home/acme/git/pahole#Now to fix this one as well.
Quoted 8 lines
Reported-by Matthias Schwarzott <[email protected]>Cc Alan Maguire <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Eduard Zingerman <[email protected]>Cc Jiri Olsa <[email protected]>Cc Song Liu <[email protected]>Cc Yonghong Song <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Quoted 1 line
Reviewed-by Alan Maguire <[email protected]>
Thanks, added to the cset,
- Arnaldo
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): ZzyO9aibti18J6sK@x1
Re: [PATCH 1/5] core: Add method to get the vmlinux BTF filename, allow overriding it via env var
Quoted 10 lines · Arnaldo Carvalho de Melo
Quoted 8 lines · Alan Maguire
Quoted 7 lines · Arnaldo Carvalho de Melo
In systems where BTF isn't available there were reports that the simplest pahole call, without any args, segfaults.
To have a proper test before fixing this problem, allow overriding the
/sys/kernel/btf/vmlinuxfilename, so that even in systems with BTF we an point it to a invalid location, making pahole think that there is no BTF available and thus fallback to something that currently segfaults.
Quoted 5 lines
<SNIP>
Quoted 1 line
Reviewed-by Alan Maguire <[email protected]>Thanks!
Ah, thanks, added to the cset,
- Arnaldo
Quoted 32 lines
Quoted 2 lines
Small thing - would it be worth dropping the
_FILENAMEsuffix of the envvar to just havePAHOLE_VMLINUX_BTF? One other thing below..See below ends up being related to the other point you made.
Quoted 4 lines
Quoted 4 lines
+++
b/pahole.c(quoted diff) +0
-0@@ -3754,7 +3754,7 @@ try_sole_arg_as_class_names: if (filename && strstarts(filename, "/sys/kernel/btf/") &&Quoted 8 lines
Review try_sole_arg_as_class_names: · line 3757
Quoted 3 lines
(quoted diff) +1
-1strstr(filename, "/vmlinux") == NULL) { - base_btf_file = "/sys/kernel/btf/vmlinux"; + base_btf_file = vmlinux_path__btf_filename();so in this case, we are specifying a module in
/sys/kernel/btfand implicitly we use/sys/kernel/btf/vmlinuxas the base. I wonder if there's much value for the envvar override here; I guess it might allow us to test using a mismatched base vmlinux with split BTF?Right, that would be possible with this patch as-is, which may be useful, we may want to have
PAHOLE_VMLINUX_BTF_DIRas a counterpart toPAHOLE_VMLINUX_BTF_FILENAME, that would allow us to use some different directory with both vmlinux and modules.Having both allows more flexibility, picking some arbitrary vmlinux plust some arbitrary directory with modules, etc. So I'd keep the patch as is and at some point add the
PAHOLE_VMLINUX_BTF_DIRknob.- Arnaldo
Quoted 3 lines
Quoted 3 lines
(quoted diff) +0
-0conf_load.base_btf = btf__parse(base_btf_file, NULL); if (libbpf_get_error(conf_load.base_btf)) { fprintf(stderr, "Failed to parse base BTF '%s': %ld\n",
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 1/5] core: Add method to get the vmlinux BTF filename, allow overriding it via env var
Quoted 36 lines · Eduard Zingerman
Quoted 33 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
In systems where BTF isn't available there were reports that the simplest pahole call, without any args, segfaults.
To have a proper test before fixing this problem, allow overriding the
/sys/kernel/btf/vmlinuxfilename, so that even in systems with BTF we an point it to a invalid location, making pahole think that there is no BTF available and thus fallback to something that currently segfaults.Using it:
$ pahole list_head struct list_head { struct list_head * next; /* 0 8 */ struct list_head * prev; /* 8 8 *//* size: 16, cachelines: 1, members: 2 */ /* last cacheline: 16 bytes */ }; $ $ PAHOLE_VMLINUX_BTF_FILENAME=foobar pahole list_head Segmentation fault (core dumped) $Reported-by Matthias Schwarzott <[email protected]>Cc Alan Maguire <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Eduard Zingerman <[email protected]>Cc Jiri Olsa <[email protected]>Cc Song Liu <[email protected]>Cc Yonghong Song <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>Quoted 1 line
---
Quoted 5 lines
Lgtm, tried setting
PAHOLE_VMLINUX_BTF_FILENAMEto unrelated selftests with some BTF, pahole works as expected (prints structures defined in the selftest).Tested-by Eduard Zingerman <[email protected]>
Thanks a lot, added to the cset!
- Arnaldo
Quoted 1 line
[...]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default
Quoted 31 lines · Alan Maguire
Quoted 21 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
On a system without any debugging info or when one specifies BTF as the only BTF info desired but no BTF is available (or invalidated using
PAHOLE_VMLINUX_BTF_FILENAMEto an invalid/non-existent file), we're getting a segfault:root@x1:/home/acme/git/pahole# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent root@x1:/home/acme/git/pahole# pahole --running_kernel_vmlinux pahole: couldn't find a vmlinux that matches the running kernel HINT: Maybe you're inside a container or missing a debuginfo package? root@x1:/home/acme/git/pahole# pahole Segmentation fault (core dumped) root@x1:/home/acme/git/pahole#So add a test that checks for that before we fix it:
root@x1:/home/acme/git/pahole# tests/default_vmlinux_btf.sh Default BTF on a system without BTF: FAILED root@x1:/home/acme/git/pahole#Quoted 8 lines
Reported-by Matthias Schwarzott <[email protected]>Cc Alan Maguire <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Eduard Zingerman <[email protected]>Cc Jiri Olsa <[email protected]>Cc Song Liu <[email protected]>Cc Yonghong Song <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Quoted 1 line
Reviewed-by Alan Maguire <[email protected]>
Thanks, added to the cset,
- Arnaldo
Quoted 32 lines
Quoted 32 lines
--- tests/default_vmlinux_btf.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tests/default_vmlinux_btf.shtests/default_vmlinux_btf.sh new file +21
-0@@ -0,0 +1,21 @@ +#!/bin/bash + +echo -n "Default BTF on a system without BTF: " + +ulimit -c 0 + +# To suppress the "Segmentation fault core dumped" message in bash we +# pipe it to some other command, if it segfaults it will not produce any +# lines and thus we can infer from the number of lines that the segfault +# took place, tricky, but couldn't find any other way to check this +# while suppressing the core dumped message. -acme + +nr_lines=$(PAHOLE_VMLINUX_BTF_FILENAME=foobar pahole -F btf list_head 2>&1 | wc -l) + +if [ $nr_lines -eq 0 ] ; then + echo "FAILED" + exit 1 +fi + +echo "Ok" +exit 0
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default
Quoted 32 lines · Eduard Zingerman
Quoted 29 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
On a system without any debugging info or when one specifies BTF as the only BTF info desired but no BTF is available (or invalidated using
PAHOLE_VMLINUX_BTF_FILENAMEto an invalid/non-existent file), we're getting a segfault:root@x1:/home/acme/git/pahole# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent root@x1:/home/acme/git/pahole# pahole --running_kernel_vmlinux pahole: couldn't find a vmlinux that matches the running kernel HINT: Maybe you're inside a container or missing a debuginfo package? root@x1:/home/acme/git/pahole# pahole Segmentation fault (core dumped) root@x1:/home/acme/git/pahole#So add a test that checks for that before we fix it:
root@x1:/home/acme/git/pahole# tests/default_vmlinux_btf.sh Default BTF on a system without BTF: FAILED root@x1:/home/acme/git/pahole#Reported-by Matthias Schwarzott <[email protected]>Cc Alan Maguire <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Eduard Zingerman <[email protected]>Cc Jiri Olsa <[email protected]>Cc Song Liu <[email protected]>Cc Yonghong Song <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>Quoted 1 line
---
Quoted 3 lines
Lgtm.
Would it make sense to move this patch to the end of the series? In case someone does a bisect and runs the tests to find some regression.
Humm?
So you think it should be introduced only when it passes? I.e. when the problem is fixed?
My practice so far has been to reproduce the problem manually, write a test, show that it detects the problem, fix, then show that the regression test shows that the problem is not present anymore.
I see your point about a bisection when running in the cset that introduces the test case and in all before the fix is added will fail, confusing the bisector or not allowing it to be automated :-\
So, yeah, probably, for automated bisection we should move it to after the fix, when finishing the devel cycle, which is now, will do.
If someone disagrees, please holer.
- Arnaldo
Re: [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default
On Tue, 2024-11-19 at 16:49 -0300, Arnaldo Carvalho de Melo wrote:
[...]
Quoted 8 lines
Quoted 3 lines
Lgtm.
Would it make sense to move this patch to the end of the series? In case someone does a bisect and runs the tests to find some regression.Humm?
So you think it should be introduced only when it passes? I.e. when the problem is fixed?
Right.
Quoted 3 lines
My practice so far has been to reproduce the problem manually, write a test, show that it detects the problem, fix, then show that the regression test shows that the problem is not present anymore.
Yes, the downside would be that anyone trying out the fix would need to do some rebase to try the test w/o fix.
Quoted 6 lines
I see your point about a bisection when running in the cset that introduces the test case and in all before the fix is added will fail, confusing the bisector or not allowing it to be automated :-\
So, yeah, probably, for automated bisection we should move it to after the fix, when finishing the devel cycle, which is now, will do.
Fwiw, that's what folks enforce for bpf selftests ¯\_(ツ)_/¯.
Re: [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default
Quoted 22 lines · Eduard Zingerman
On Tue, 2024-11-19 at 16:49 -0300, Arnaldo Carvalho de Melo wrote:
[...]
Quoted 8 lines
Quoted 3 lines
Lgtm.
Would it make sense to move this patch to the end of the series? In case someone does a bisect and runs the tests to find some regression.Humm?
So you think it should be introduced only when it passes? I.e. when the problem is fixed?
Right.
Quoted 3 lines
My practice so far has been to reproduce the problem manually, write a test, show that it detects the problem, fix, then show that the regression test shows that the problem is not present anymore.
Yes, the downside would be that anyone trying out the fix would need to do some rebase to try the test w/o fix.
Quoted 8 lines
Quoted 6 lines
I see your point about a bisection when running in the cset that introduces the test case and in all before the fix is added will fail, confusing the bisector or not allowing it to be automated :-\
So, yeah, probably, for automated bisection we should move it to after the fix, when finishing the devel cycle, which is now, will do.
Fwiw, that's what folks enforce for bpf selftests ¯\_(ツ)_/¯.
Makes sense, automated bisection trumps old practices :-)
- Arnaldo
Re: [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default
In reply to Eduard ZingermanQuoted 5 lines · Eduard Zingerman
On Tue, 2024-11-19 at 16:49 -0300, Arnaldo Carvalho de Melo wrote:
[...]
Quoted 1 line
Quoted 1 line
Lgtm.
And I'm taking the lgtm as an Acked-by, maybe a Reviewed-by?
- Arnaldo
Quoted 25 lines
Quoted 7 lines
Quoted 2 lines
Would it make sense to move this patch to the end of the series? In case someone does a bisect and runs the tests to find some regression.
Humm?
So you think it should be introduced only when it passes? I.e. when the problem is fixed?
Right.
Quoted 3 lines
My practice so far has been to reproduce the problem manually, write a test, show that it detects the problem, fix, then show that the regression test shows that the problem is not present anymore.
Yes, the downside would be that anyone trying out the fix would need to do some rebase to try the test w/o fix.
Quoted 6 lines
I see your point about a bisection when running in the cset that introduces the test case and in all before the fix is added will fail, confusing the bisector or not allowing it to be automated :-\
So, yeah, probably, for automated bisection we should move it to after the fix, when finishing the devel cycle, which is now, will do.
Fwiw, that's what folks enforce for bpf selftests ¯\_(ツ)_/¯.
Eduard Zingerman
Acked-byRe: [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default
Quoted 8 lines · Arnaldo Carvalho de Melo
Quoted 5 lines · Eduard Zingerman
On Tue, 2024-11-19 at 16:49 -0300, Arnaldo Carvalho de Melo wrote:
[...]
Quoted 1 line
Quoted 1 line
Lgtm.
And I'm taking the lgtm as an Acked-by, maybe a Reviewed-by?
Sorry for confusion, let's go with Acked-by.
Re: [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default
Quoted 6 lines · Eduard Zingerman
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 4 lines · Eduard Zingerman
On Tue, 2024-11-19 at 16:49 -0300, Arnaldo Carvalho de Melo wrote:
[...]
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Lgtm.
And I'm taking the lgtm as an Acked-by, maybe a Reviewed-by?
Sorry for confusion, let's go with Acked-by.
Acked-by Eduard Zingerman <[email protected]>
Thats what I tentatively had added, and already pushed to the next branch, thanks!
- Arnaldo
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 5/5] core, libctf: Check if constructor arguments are NULL before using them
Quoted 33 lines · Alan Maguire
Quoted 23 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
# pahole Segmentation fault (core dumped) #Now we have:
# ls -la bla ls: cannot access 'bla': No such file or directory # export PAHOLE_VMLINUX_BTF_FILENAME=bla # pahole pahole: couldn't find any debug information on this system. # pahole list_head pahole: couldn't find any debug information on this system. # pahole -F btf list_head pahole: couldn't find any btf debug information on this system. # pahole -F dwarf list_head pahole: couldn't find any dwarf debug information on this system. # tests/default_vmlinux_btf.sh Default BTF on a system without BTF: Ok #Quoted 8 lines
Reported-by Matthias Schwarzott <[email protected]>Cc Alan Maguire <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Eduard Zingerman <[email protected]>Cc Jiri Olsa <[email protected]>Cc Song Liu <[email protected]>Cc Yonghong Song <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Quoted 2 lines
Reviewed-by Alan Maguire <[email protected]>Tested-by Alan Maguire <[email protected]>
Thanks, added to the cset,
- Arnaldo