Skip to contentSkip to conversation

lsm,bpf: fix security_bpf_prog_load() error handling

PATCH Applied Paul Moore 3 participants 7 messages May 23 – Jun 1

Subsystems (3)
lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/1 lsm,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.

---
 kernel/bpf/syscall.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/bpf/syscall.c +1 -3
index a3c0214ca934..ac07280098e9 100644
@@ -3076,7 +3076,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
 
 	err = security_bpf_prog_load(prog, attr, token, uattr.is_kernel);
 	if (err)
-		goto free_prog_sec;
+		goto free_prog;
 
 	/* run eBPF verifier */
 	err = bpf_check(&prog, attr, uattr, uattr_size);
@@ -3122,8 +3122,6 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
 	__bpf_prog_put_noref(prog, prog->aux->real_func_cnt);
 	return err;
 
-free_prog_sec:
-	security_bpf_prog_free(prog);
 free_prog:
 	free_uid(prog->aux->user);
 	if (prog->aux->attach_btf)
Signature · 1 line
2.54.0
author maintainer
#1 lore raw
Quoted 8 lines · Paul Moore

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.

Quoted 6 lines
---
 kernel/bpf/syscall.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Alexei, I'm assuming you would prefer to take this via the BPF tree?

Signature · 1 line
paul-moore.com
#2 lore raw
Quoted 10 lines · Paul Moore
Quoted 8 lines · Paul Moore

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.

Quoted 8 lines
Quoted 6 lines
---
 kernel/bpf/syscall.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Alexei, I'm assuming you would prefer to take this via the BPF tree?

Paul, I see that you're intentionally trying to piss me off. It's not going to work :)

author maintainer
#3 lore raw
Quoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Paul Moore
Quoted 14 lines · Paul Moore

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.

---
kernel/bpf/syscall.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 4 lines
Quoted 1 line

Alexei, I'm assuming you would prefer to take this via the BPF tree?

Paul, I see that you're intentionally trying to piss me off. It's not going to work :)

I promise you that is not the case. I was looking at the sashiko results of the latest Hornet patch and it identified this potential issue in the error handling code that is an issue independent of Hornet. I posted the quick little patch above to fix the issue, and since the diffstat is solely in kernel/bpf/syscall.c I figured you would want to merge it via the BPF tree; if that is not the case let me know.

--
paul-moore.com

#4 lore raw
Quoted 25 lines · Paul Moore
Quoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Paul Moore
Quoted 14 lines · Paul Moore

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.

---
kernel/bpf/syscall.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 4 lines
Quoted 1 line

Alexei, I'm assuming you would prefer to take this via the BPF tree?

Paul, I see that you're intentionally trying to piss me off. It's not going to work :)

Quoted 6 lines

I promise you that is not the case. I was looking at the sashiko results of the latest Hornet patch and it identified this potential issue in the error handling code that is an issue independent of Hornet. I posted the quick little patch above to fix the issue, and since the diffstat is solely in kernel/bpf/syscall.c I figured you would want to merge it via the BPF tree; if that is not the case let me know.

It's in a queue. You can monitor it here:
https://patchwork.kernel.org/project/netdevbpf/list/?series=&submitter=&state=&q=&archive=&delegate=121173

But please be advised that when submitters ignore issues found by bots and maintainers agree with bot findings we mark patches as changes requested.

#5 lore raw
Quoted 34 lines · Alexei Starovoitov
Quoted 25 lines · Paul Moore
Quoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Paul Moore
Quoted 14 lines · Paul Moore

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.

---
kernel/bpf/syscall.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 4 lines
Quoted 1 line

Alexei, I'm assuming you would prefer to take this via the BPF tree?

Paul, I see that you're intentionally trying to piss me off. It's not going to work :)

Quoted 6 lines

I promise you that is not the case. I was looking at the sashiko results of the latest Hornet patch and it identified this potential issue in the error handling code that is an issue independent of Hornet. I posted the quick little patch above to fix the issue, and since the diffstat is solely in kernel/bpf/syscall.c I figured you would want to merge it via the BPF tree; if that is not the case let me know.

Quoted 6 lines

It's in a queue. You can monitor it here:
https://patchwork.kernel.org/project/netdevbpf/list/?series=&submitter=&state=&q=&archive=&delegate=121173

But please be advised that when submitters ignore issues found by bots and maintainers agree with bot findings we mark patches as changes requested.

Applied.

#6 lore raw
In reply to Paul Moore
This looks like a bug fix for the error handling logic introduced in commit b3beebbe6154 which imported the kernel/bpf/syscall.c file with incorrect error handling for security_bpf_prog_load()…
Quoted 13 lines

commit a03af62bb4a3613aadacc8cb75f0007d761e785a

Author: Paul Moore <[email protected]>
Date:   Sat May 23 12:00:26 2026 -0400

lsm,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.

Quoted 3 lines

This looks like a bug fix for the error handling logic introduced in commit b3beebbe6154 which imported the kernel/bpf/syscall.c file with incorrect error handling for security_bpf_prog_load() failure. Should this include:

Fixes b3beebbe6154 ("adding ci files")

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26337503379