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: 865b0566d8 ("bpf: Add bpf_verify_pkcs7_signature() kfunc")
Reported-by: Xianrui Dong <dongxianrui1@gmail.com>
Signed-off-by: KP Singh <kpsingh@kernel.org>
Reviewed-by: Amery Hung <ameryhung@gmail.com>
Acked-by: Song Liu <song@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20260520024059.313468-1-kpsingh@kernel.org
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
master
parent
201166d79f
commit
49b18315be
|
|
@ -4241,8 +4241,13 @@ __bpf_kfunc int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_p,
|
||||||
|
|
||||||
data_len = __bpf_dynptr_size(data_ptr);
|
data_len = __bpf_dynptr_size(data_ptr);
|
||||||
data = __bpf_dynptr_data(data_ptr, data_len);
|
data = __bpf_dynptr_data(data_ptr, data_len);
|
||||||
|
if (!data)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
sig_len = __bpf_dynptr_size(sig_ptr);
|
sig_len = __bpf_dynptr_size(sig_ptr);
|
||||||
sig = __bpf_dynptr_data(sig_ptr, sig_len);
|
sig = __bpf_dynptr_data(sig_ptr, sig_len);
|
||||||
|
if (!sig)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
return verify_pkcs7_signature(data, data_len, sig, sig_len,
|
return verify_pkcs7_signature(data, data_len, sig, sig_len,
|
||||||
trusted_keyring->key,
|
trusted_keyring->key,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ static struct {
|
||||||
const char *prog_name;
|
const char *prog_name;
|
||||||
int expected_runtime_err;
|
int expected_runtime_err;
|
||||||
} kfunc_dynptr_tests[] = {
|
} kfunc_dynptr_tests[] = {
|
||||||
{"dynptr_data_null", -EBADMSG},
|
{"dynptr_data_null", -EINVAL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool kfunc_not_supported;
|
static bool kfunc_not_supported;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue