Skip to content

Commit 49b1831

Browse files
sinkapkkdwvd
authored andcommitted
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: 865b056 ("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>
1 parent 201166d commit 49b1831

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

kernel/bpf/helpers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,8 +4241,13 @@ __bpf_kfunc int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_p,
42414241

42424242
data_len = __bpf_dynptr_size(data_ptr);
42434243
data = __bpf_dynptr_data(data_ptr, data_len);
4244+
if (!data)
4245+
return -EINVAL;
4246+
42444247
sig_len = __bpf_dynptr_size(sig_ptr);
42454248
sig = __bpf_dynptr_data(sig_ptr, sig_len);
4249+
if (!sig)
4250+
return -EINVAL;
42464251

42474252
return verify_pkcs7_signature(data, data_len, sig, sig_len,
42484253
trusted_keyring->key,

tools/testing/selftests/bpf/prog_tests/kfunc_dynptr_param.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static struct {
1414
const char *prog_name;
1515
int expected_runtime_err;
1616
} kfunc_dynptr_tests[] = {
17-
{"dynptr_data_null", -EBADMSG},
17+
{"dynptr_data_null", -EINVAL},
1818
};
1919

2020
static bool kfunc_not_supported;

0 commit comments

Comments
 (0)