| 1 | |
| 2 |
|
| 3 | |
| 4 | * Copyright (C) 2020 Google LLC.
|
| 5 |
|
| 6 | #include <linux/lsm_hooks.h>
|
| 7 | #include <linux/bpf_lsm.h>
|
| 8 | #include <uapi/linux/lsm.h>
|
| 9 |
|
| 10 | bool bpf_lsm_initialized __ro_after_init;
|
| 11 |
|
| 12 | static struct security_hook_list bpf_lsm_hooks[] __ro_after_init = {
|
| 13 | #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
|
| 14 | LSM_HOOK_INIT(NAME, bpf_lsm_##NAME),
|
| 15 | #include <linux/lsm_hook_defs.h>
|
| 16 | #undef LSM_HOOK
|
| 17 | LSM_HOOK_INIT(inode_free_security, bpf_inode_storage_free),
|
| 18 | };
|
| 19 |
|
| 20 | static const struct lsm_id bpf_lsmid = {
|
| 21 | .name = "bpf",
|
| 22 | .id = LSM_ID_BPF,
|
| 23 | };
|
| 24 |
|
| 25 | static int __init bpf_lsm_init(void)
|
| 26 | {
|
| 27 | security_add_hooks(bpf_lsm_hooks, ARRAY_SIZE(bpf_lsm_hooks),
|
| 28 | &bpf_lsmid);
|
| 29 | bpf_lsm_initialized = true;
|
| 30 | pr_info("LSM support for eBPF active\n");
|
| 31 | return 0;
|
| 32 | }
|
| 33 |
|
| 34 | struct lsm_blob_sizes bpf_lsm_blob_sizes __ro_after_init = {
|
| 35 | .lbs_inode = sizeof(struct bpf_storage_blob),
|
| 36 | };
|
| 37 |
|
| 38 | DEFINE_LSM(bpf) = {
|
| 39 | .id = &bpf_lsmid,
|
| 40 | .init = bpf_lsm_init,
|
| 41 | .blobs = &bpf_lsm_blob_sizes
|
| 42 | };
|