1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2020 Google LLC.
7 #include <linux/filter.h>
10 #include <linux/lsm_hooks.h>
11 #include <linux/bpf_lsm.h>
12 #include <linux/kallsyms.h>
13 #include <linux/bpf_verifier.h>
15 /* For every LSM hook that allows attachment of BPF programs, declare a nop
16 * function where a BPF program can be attached.
18 #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
19 noinline RET bpf_lsm_##NAME(__VA_ARGS__) \
24 #include <linux/lsm_hook_defs.h>
27 #define BPF_LSM_SYM_PREFX "bpf_lsm_"
29 int bpf_lsm_verify_prog(struct bpf_verifier_log
*vlog
,
30 const struct bpf_prog
*prog
)
32 if (!prog
->gpl_compatible
) {
34 "LSM programs must have a GPL compatible license\n");
38 if (strncmp(BPF_LSM_SYM_PREFX
, prog
->aux
->attach_func_name
,
39 sizeof(BPF_LSM_SYM_PREFX
) - 1)) {
40 bpf_log(vlog
, "attach_btf_id %u points to wrong type name %s\n",
41 prog
->aux
->attach_btf_id
, prog
->aux
->attach_func_name
);
48 const struct bpf_prog_ops lsm_prog_ops
= {
51 const struct bpf_verifier_ops lsm_verifier_ops
= {
52 .get_func_proto
= tracing_prog_func_proto
,
53 .is_valid_access
= btf_ctx_access
,