Skip to contentSkip to conversation

bpf: reject NULL data/sig in bpf_verify_pkcs7_signature

PATCH Superseded KP Singh 4 participants 4 messages May 19

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

KP Singh

author
#0 lore raw

PATCH 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.

Fixes 865b0566d8f1 ("bpf: Add bpf_verify_pkcs7_signature() kfunc")
---
 kernel/bpf/helpers.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/bpf/helpers.c +5 -0
index 2bb60200c266..b5314c9fed3c 100644
@@ -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,
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · KP Singh

__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.

Quoted 6 lines

NULL-check both pointers and reject with -EINVAL. Mirrors the guards already in kernel/bpf/crypto.c.

Fixes 865b0566d8f1 ("bpf: Add bpf_verify_pkcs7_signature() kfunc")
Quoted 26 lines
---
 kernel/bpf/helpers.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/bpf/helpers.c +5 -1
index 2bb60200c266..b5314c9fed3c 100644
@@ -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,
--

2.53.0

reviewer Acked-by on v1 1/1
#2 lore raw
In reply to KP Singh
Quoted 6 lines · KP Singh

__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.

Quoted 6 lines

NULL-check both pointers and reject with -EINVAL. Mirrors the guards already in kernel/bpf/crypto.c.

Fixes 865b0566d8f1 ("bpf: Add bpf_verify_pkcs7_signature() kfunc")
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to KP Singh
Quoted 11 lines · KP Singh

__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.

Fixes 865b0566d8f1 ("bpf: Add bpf_verify_pkcs7_signature() kfunc")