Commit 380044c
libbpf: Prevent double close and leak of btf objects
Sashiko found possible double close of btf object fd [1],
which happens when strdup in load_module_btfs fails at which
point the obj->btf_module_cnt is already incremented.
The error path close btf fd and so does later cleanup code in
bpf_object_post_load_cleanup function.
Also libbpf_ensure_mem failure leaves btf object not assigned
and it's leaked.
Replacing the err_out label with break to make the error path
less confusing as suggested by Alan.
Incrementing obj->btf_module_cnt only if there's no failure
and releasing btf object in error path.
Fixes: 91abb4a ("libbpf: Support attachment of BPF tracing programs to kernel modules")
[1] https://sashiko.dev/#/patchset/20260324081846.2334094-1-jolsa%40kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20260416100034.1610852-1-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>1 parent d6f5841 commit 380044c
1 file changed
Lines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5852 | 5852 | | |
5853 | 5853 | | |
5854 | 5854 | | |
| 5855 | + | |
5855 | 5856 | | |
5856 | 5857 | | |
5857 | 5858 | | |
5858 | 5859 | | |
5859 | | - | |
| 5860 | + | |
5860 | 5861 | | |
5861 | 5862 | | |
5862 | 5863 | | |
| |||
5870 | 5871 | | |
5871 | 5872 | | |
5872 | 5873 | | |
5873 | | - | |
| 5874 | + | |
5874 | 5875 | | |
5875 | 5876 | | |
5876 | 5877 | | |
5877 | 5878 | | |
5878 | 5879 | | |
5879 | | - | |
| 5880 | + | |
5880 | 5881 | | |
5881 | | - | |
| 5882 | + | |
5882 | 5883 | | |
5883 | 5884 | | |
5884 | 5885 | | |
5885 | 5886 | | |
5886 | 5887 | | |
5887 | 5888 | | |
5888 | 5889 | | |
5889 | | - | |
| 5890 | + | |
5890 | 5891 | | |
5891 | | - | |
| 5892 | + | |
| 5893 | + | |
5892 | 5894 | | |
5893 | | - | |
| 5895 | + | |
| 5896 | + | |
5894 | 5897 | | |
5895 | | - | |
5896 | 5898 | | |
5897 | | - | |
5898 | | - | |
| 5899 | + | |
5899 | 5900 | | |
5900 | 5901 | | |
5901 | 5902 | | |
| |||
0 commit comments