^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2020 Google LLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/lsm_hooks.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/bpf_lsm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) static struct security_hook_list bpf_lsm_hooks[] __lsm_ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) LSM_HOOK_INIT(NAME, bpf_lsm_##NAME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/lsm_hook_defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #undef LSM_HOOK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) LSM_HOOK_INIT(inode_free_security, bpf_inode_storage_free),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static int __init bpf_lsm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) security_add_hooks(bpf_lsm_hooks, ARRAY_SIZE(bpf_lsm_hooks), "bpf");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) pr_info("LSM support for eBPF active\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct lsm_blob_sizes bpf_lsm_blob_sizes __lsm_ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .lbs_inode = sizeof(struct bpf_storage_blob),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) DEFINE_LSM(bpf) = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .name = "bpf",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .init = bpf_lsm_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .blobs = &bpf_lsm_blob_sizes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };