bpf: Fix a crash when btf_parse_base() returns an error pointer
Martin KaFai Lau
reviewerPATCH 1/1 bpf: Fix a crash when btf_parse_base() returns an error pointer
From: Martin KaFai Lau <[email protected]>
The pointer returned by btf_parse_base could be an error pointer. IS_ERR() check is needed before calling btf_free(base_btf).
---
It was discovered in a bpf CI run that crashed in s390 due to the wrong endian in the btf header. It caused the btf_parse_base() to fail and triggered this crash.
This patch is tested in the bpf CI. It fails to load the bpf_testmod but does not crash the kernel:
https://github.com/kernel-patches/bpf/actions/runs/10623574366/job/29450422150?pr=7630
kernel/bpf/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
@@ -6283,7 +6283,7 @@ static struct btf *btf_parse_module(const char *module_name, const void *data, errout:btf_verifier_env_free (env); -if (base_btf != vmlinux_btf) +if (!IS_ERR (base_btf) && base_btf != vmlinux_btf)btf_free (base_btf);if (btf) {kvfree (btf->data);
Signature · 1 line
2.43.5
Quoted 9 lines · Martin KaFai Lau
From: Martin KaFai Lau <[email protected]>
The pointer returned by
btf_parse_basecould be an error pointer.IS_ERR()check is needed before callingbtf_free(base_btf).Cc Alan Maguire <[email protected]>Fixes 8646db238997 ("libbpf,bpf: Share BTF relocate-related code with kernel")Signed-off-by Martin KaFai Lau <[email protected]>---
[...]
Quoted 8 lines · Martin KaFai Lau
From: Martin KaFai Lau <[email protected]>
The pointer returned by
btf_parse_basecould be an error pointer.IS_ERR()check is needed before callingbtf_free(base_btf).Cc Alan Maguire <[email protected]>Fixes 8646db238997 ("libbpf,bpf: Share BTF relocate-related code with kernel")Signed-off-by Martin KaFai Lau <[email protected]>
Thanks!
Alan
This patch was applied to bpf/bpf.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Andrii Nakryiko <[email protected]>:
Quoted 10 lines · On Thu, 29 Aug 2024 18:22:14 -0700 you wrote:
From: Martin KaFai Lau <[email protected]>
The pointer returned by
btf_parse_basecould be an error pointer.IS_ERR()check is needed before callingbtf_free(base_btf).Cc Alan Maguire <[email protected]>Fixes 8646db238997 ("libbpf,bpf: Share BTF relocate-related code with kernel")Signed-off-by Martin KaFai Lau <[email protected]>[...]
Here is the summary with links:
- [bpf] bpf: Fix a crash when btf_parse_base() returns an error pointer
https://git.kernel.org/bpf/bpf/c/b408473ea01b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html