Skip to contentSkip to conversation

bpf: fix possible file descriptor leaks in verifier

PATCH Applied Anton Protopopov 4 participants 4 messages Mar 29, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bpf: fix possible file descriptor leaks in verifier

The resolve_pseudo_ldimm64() function might have leaked file descriptors when BPF_MAP_TYPE_ARENA was used in a program (some error paths missed a corresponding fdput). Add missing fdputs.

v2:
remove unrelated changes from the fix

Fixes 6082b6c328b5 ("bpf: Recognize addr_space_cast instruction in the verifier.")
---
 kernel/bpf/verifier.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/bpf/verifier.c +3 -0
index edb650667f44..58952f040761 100644
@@ -18383,15 +18383,18 @@ static int resolve_pseudo_ldimm64(struct bpf_verifier_env *env)
 				}
 				if (!env->prog->jit_requested) {
 					verbose(env, "JIT is required to use arena\n");
+					fdput(f);
 					return -EOPNOTSUPP;
 				}
 				if (!bpf_jit_supports_arena()) {
 					verbose(env, "JIT doesn't support arena\n");
+					fdput(f);
 					return -EOPNOTSUPP;
 				}
 				env->prog->aux->arena = (void *)map;
 				if (!bpf_arena_get_user_vm_start(env->prog->aux->arena)) {
 					verbose(env, "arena's user address must be set via map_extra or mmap()\n");
+					fdput(f);
 					return -EINVAL;
 				}
 			}
Signature · 1 line
2.34.1
reviewer Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Anton Protopopov

The resolve_pseudo_ldimm64() function might have leaked file descriptors when BPF_MAP_TYPE_ARENA was used in a program (some error paths missed a corresponding fdput). Add missing fdputs.

v2:
remove unrelated changes from the fix

Fixes 6082b6c328b5 ("bpf: Recognize addr_space_cast instruction in the verifier.")

Thanks for the dedicated patch for the bug fix. LGTM.

Acked-by on v2 1/1
#2 lore raw
In reply to Anton Protopopov
Quoted 9 lines · Anton Protopopov

The resolve_pseudo_ldimm64() function might have leaked file descriptors when BPF_MAP_TYPE_ARENA was used in a program (some error paths missed a corresponding fdput). Add missing fdputs.

v2:
remove unrelated changes from the fix

Fixes 6082b6c328b5 ("bpf: Recognize addr_space_cast instruction in the verifier.")
#3 lore raw
In reply to Anton Protopopov
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Fri, 29 Mar 2024 07:11:06 +0000 you wrote:

The resolve_pseudo_ldimm64() function might have leaked file descriptors when BPF_MAP_TYPE_ARENA was used in a program (some error paths missed a corresponding fdput). Add missing fdputs.

v2:
remove unrelated changes from the fix

[...]

Here is the summary with links:
- [v2,bpf-next] bpf: fix possible file descriptor leaks in verifier

    https://git.kernel.org/bpf/bpf/c/6dae957c8eef

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html