Skip to content

Commit 868d43c

Browse files
pcmooreAlexei Starovoitov
authored andcommitted
bpf: Fix security_bpf_prog_load() error handling
If security_bpf_prog_load() fails there is no need to call into security_bpf_prog_free() as the LSM will handle the cleanup of any partial LSM state before returning to the caller with an error. Thankfully this isn't an issue with any of the existing code as the LSMs which currently provide BPF hook callback implementations don't allocate any internal state, but this is something we want to fix for potential future users. Signed-off-by: Paul Moore <paul@paul-moore.com> Link: https://lore.kernel.org/r/20260523160025.16363-2-paul@paul-moore.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent de36adc commit 868d43c

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

kernel/bpf/syscall.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,7 +3136,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_at
31363136

31373137
err = security_bpf_prog_load(prog, attr, token, uattr.is_kernel);
31383138
if (err)
3139-
goto free_prog_sec;
3139+
goto free_prog;
31403140

31413141
/* run eBPF verifier */
31423142
err = bpf_check(&prog, attr, uattr, attr_log);
@@ -3182,8 +3182,6 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_at
31823182
__bpf_prog_put_noref(prog, prog->aux->real_func_cnt);
31833183
return err;
31843184

3185-
free_prog_sec:
3186-
security_bpf_prog_free(prog);
31873185
free_prog:
31883186
free_uid(prog->aux->user);
31893187
if (prog->aux->attach_btf)

0 commit comments

Comments
 (0)