1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2022 Huawei Technologies Duesseldorf GmbH
11 #include <bpf/bpf_helpers.h>
12 #include <bpf/bpf_tracing.h>
15 extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
16 extern void bpf_key_put(struct bpf_key *key) __ksym;
17 extern int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_ptr,
18 struct bpf_dynptr *sig_ptr,
19 struct bpf_key *trusted_keyring) __ksym;
22 __uint(type, BPF_MAP_TYPE_RINGBUF);
23 __uint(max_entries, 4096);
24 } ringbuf SEC(".maps");
27 __uint(type, BPF_MAP_TYPE_ARRAY);
28 __uint(max_entries, 1);
31 } array_map SEC(".maps");
35 char _license[] SEC("license") = "GPL";
38 __failure __msg("cannot pass in dynptr at an offset=-8")
39 int BPF_PROG(not_valid_dynptr, int cmd, union bpf_attr *attr, unsigned int size)
43 return bpf_verify_pkcs7_signature((struct bpf_dynptr *)&val,
44 (struct bpf_dynptr *)&val, NULL);
48 __failure __msg("arg#0 expected pointer to stack or const struct bpf_dynptr")
49 int BPF_PROG(not_ptr_to_stack, int cmd, union bpf_attr *attr, unsigned int size)
51 unsigned long val = 0;
53 return bpf_verify_pkcs7_signature((struct bpf_dynptr *)val,
54 (struct bpf_dynptr *)val, NULL);
58 int BPF_PROG(dynptr_data_null, int cmd, union bpf_attr *attr, unsigned int size)
60 struct bpf_key *trusted_keyring;
61 struct bpf_dynptr ptr;
65 if (bpf_get_current_pid_tgid() >> 32 != pid)
68 value = bpf_map_lookup_elem(&array_map, &zero);
72 /* Pass invalid flags. */
73 ret = bpf_dynptr_from_mem(value, sizeof(*value), ((__u64)~0ULL), &ptr);
77 trusted_keyring = bpf_lookup_system_key(0);
81 err = bpf_verify_pkcs7_signature(&ptr, &ptr, trusted_keyring);
83 bpf_key_put(trusted_keyring);