selftests/bpf: Close fd on unexpected success in signed loader
Subsystems (3)
Daniel Borkmann
maintainerPATCH 1/1 selftests/bpf: Close fd on unexpected success in signed loader
The signature_enforced, signature_too_large, signature_zero_size and signature_bad_keyring subtests load a program that must be rejected, but leave the fd open if the kernel unexpectedly accepts the load:test_progs asserts record the failure and continue, so the fd would linger for the rest of the run. Just close it.
--- tools/testing/selftests/bpf/prog_tests/signed_loader.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/testing/selftests/bpf/prog_tests/signed_loader.c +8 -0
@@ -326,6 +326,8 @@ static void signature_enforced(void) fd =load_loader (f.gopts.insns, f.gopts.insns_sz,-1 , junk,sizeof (junk),KEY_SPEC_SESSION_KEYRING ,0 );ASSERT_EQ (fd, -EBADMSG ,"invalid signature rejected at load" ); +if (fd >=0 ) +close (fd); }gen_loader_fixture_fini (&f); }
@@ -575,6 +577,8 @@ static void signature_too_large(void) fd =load_loader (f.gopts.insns, f.gopts.insns_sz,-1 , junk,64 <<20 ,KEY_SPEC_SESSION_KEYRING ,0 );ASSERT_EQ (fd, -EINVAL ,"oversized signature rejected" ); +if (fd >=0 ) +close (fd); }gen_loader_fixture_fini (&f); }
@@ -594,6 +598,8 @@ static void signature_zero_size(void) fd =load_loader (f.gopts.insns, f.gopts.insns_sz,-1 , junk,0 ,KEY_SPEC_SESSION_KEYRING ,0 );ASSERT_EQ (fd, -EINVAL ,"zero-size signature rejected" ); +if (fd >=0 ) +close (fd); }gen_loader_fixture_fini (&f); }
@@ -614,6 +620,8 @@ static void signature_bad_keyring(void) fd =load_loader (f.gopts.insns, f.gopts.insns_sz,-1 , junk,sizeof (junk),INT_MAX ,0 );ASSERT_EQ (fd, -EINVAL ,"signature with bad keyring_id rejected" ); +if (fd >=0 ) +close (fd); }gen_loader_fixture_fini (&f); }
Signature · 1 line
2.43.0
This patch was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:
Quoted 9 lines · On Wed, 8 Jul 2026 20:41:07 +0200 you wrote:
The
signature_enforced,signature_too_large,signature_zero_sizeandsignature_bad_keyringsubtests load a program that must be rejected, but leave the fd open if the kernel unexpectedly accepts the load:test_progsasserts record the failure and continue, so the fd would linger for the rest of the run. Just close it.Signed-off-by Daniel Borkmann <[email protected]>[...]
Here is the summary with links:
- [bpf-next] selftests/bpf: Close fd on unexpected success in signed loader
https://git.kernel.org/bpf/bpf-next/c/43f129d21489
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html