Commit e8bd827
libbpf: Prevent double close and leak of btf objects
[ Upstream commit 380044c ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 8abad85 commit e8bd827
1 file changed
Lines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5746 | 5746 | | |
5747 | 5747 | | |
5748 | 5748 | | |
| 5749 | + | |
5749 | 5750 | | |
5750 | 5751 | | |
5751 | 5752 | | |
5752 | 5753 | | |
5753 | | - | |
| 5754 | + | |
5754 | 5755 | | |
5755 | 5756 | | |
5756 | 5757 | | |
| |||
5764 | 5765 | | |
5765 | 5766 | | |
5766 | 5767 | | |
5767 | | - | |
| 5768 | + | |
5768 | 5769 | | |
5769 | 5770 | | |
5770 | 5771 | | |
5771 | 5772 | | |
5772 | 5773 | | |
5773 | | - | |
| 5774 | + | |
5774 | 5775 | | |
5775 | | - | |
| 5776 | + | |
5776 | 5777 | | |
5777 | 5778 | | |
5778 | 5779 | | |
5779 | 5780 | | |
5780 | 5781 | | |
5781 | 5782 | | |
5782 | 5783 | | |
5783 | | - | |
| 5784 | + | |
5784 | 5785 | | |
5785 | | - | |
| 5786 | + | |
| 5787 | + | |
5786 | 5788 | | |
5787 | | - | |
| 5789 | + | |
| 5790 | + | |
5788 | 5791 | | |
5789 | | - | |
5790 | 5792 | | |
5791 | | - | |
5792 | | - | |
| 5793 | + | |
5793 | 5794 | | |
5794 | 5795 | | |
5795 | 5796 | | |
| |||
0 commit comments