bpf: reject NULL data/sig in bpf_verify_pkcs7_signature
Subsystems (4)
PATCH v2 1/1 bpf: reject NULL data/sig in bpf_verify_pkcs7_signature
__bpf_dynptr_data() can return NULL (FILE dynptrs, any non-contiguous backing). bpf_verify_pkcs7_signature() forwards the pointer to verify_pkcs7_signature() unchecked, causing a NULL deref in asn1_ber_decoder() reachable from a sleepable BPF LSM at lsm.s/bpf.
NULL-check both pointers and reject with -EINVAL. Mirrors the guards already in kernel/bpf/crypto.c.
--- kernel/bpf/helpers.c | 5 +++++ tools/testing/selftests/bpf/prog_tests/kfunc_dynptr_param.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
kernel/bpf/helpers.c +5 -0
@@ -4241,8 +4241,13 @@ __bpf_kfunc int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_p, data_len =__bpf_dynptr_size (data_ptr); data =__bpf_dynptr_data (data_ptr, data_len); +if (!data) +return -EINVAL ; + sig_len =__bpf_dynptr_size (sig_ptr); sig =__bpf_dynptr_data (sig_ptr, sig_len); +if (!sig) +return -EINVAL ; return verify_pkcs7_signature(data, data_len, sig, sig_len, trusted_keyring->key,
tools/testing/selftests/bpf/prog_tests/kfunc_dynptr_param.c +1 -1
@@ -14,7 +14,7 @@ static struct {const char *prog_name;int expected_runtime_err; } kfunc_dynptr_tests[] = { - {"dynptr_data_null", -EBADMSG}, + {"dynptr_data_null", -EINVAL}, }; static bool kfunc_not_supported;
Signature · 1 line
2.53.0
Kumar Kartikeya Dwivedi
maintainerQuoted 5 lines · KP Singh
__bpf_dynptr_data()can return NULL (FILE dynptrs, any non-contiguous backing).bpf_verify_pkcs7_signature()forwards the pointer toverify_pkcs7_signature()unchecked, causing a NULL deref inasn1_ber_decoder()reachable from a sleepable BPF LSM at lsm.s/bpf.
Quoted 7 lines
NULL-check both pointers and reject with
-EINVAL. Mirrors the guards already inkernel/bpf/crypto.c.Fixes 865b0566d8f1 ("bpf: Add bpf_verify_pkcs7_signature() kfunc")Reported-by Xianrui Dong <[email protected]>Signed-off-by KP Singh <[email protected]>---
Added missing acks before pushing.
Quoted 1 line
[...]
This patch was applied to bpf/bpf.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Kumar Kartikeya Dwivedi <[email protected]>:
Quoted 9 lines · On Wed, 20 May 2026 04:40:59 +0200 you wrote:
__bpf_dynptr_data()can return NULL (FILE dynptrs, any non-contiguous backing).bpf_verify_pkcs7_signature()forwards the pointer toverify_pkcs7_signature()unchecked, causing a NULL deref inasn1_ber_decoder()reachable from a sleepable BPF LSM at lsm.s/bpf.NULL-check both pointers and reject with
-EINVAL. Mirrors the guards already inkernel/bpf/crypto.c.[...]
Here is the summary with links:
- [v2] bpf: reject NULL data/sig in bpf_verify_pkcs7_signature
https://git.kernel.org/bpf/bpf/c/49b18315be4e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html