2020-03-29 00:43:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Google LLC.
|
|
|
|
*/
|
|
|
|
#include <linux/lsm_hooks.h>
|
|
|
|
#include <linux/bpf_lsm.h>
|
2023-09-12 20:56:46 +00:00
|
|
|
#include <uapi/linux/lsm.h>
|
2020-03-29 00:43:53 +00:00
|
|
|
|
selinux: remove the runtime disable functionality
After working with the larger SELinux-based distros for several
years, we're finally at a place where we can disable the SELinux
runtime disable functionality. The existing kernel deprecation
notice explains the functionality and why we want to remove it:
The selinuxfs "disable" node allows SELinux to be disabled at
runtime prior to a policy being loaded into the kernel. If
disabled via this mechanism, SELinux will remain disabled until
the system is rebooted.
The preferred method of disabling SELinux is via the "selinux=0"
boot parameter, but the selinuxfs "disable" node was created to
make it easier for systems with primitive bootloaders that did not
allow for easy modification of the kernel command line.
Unfortunately, allowing for SELinux to be disabled at runtime makes
it difficult to secure the kernel's LSM hooks using the
"__ro_after_init" feature.
It is that last sentence, mentioning the '__ro_after_init' hardening,
which is the real motivation for this change, and if you look at the
diffstat you'll see that the impact of this patch reaches across all
the different LSMs, helping prevent tampering at the LSM hook level.
From a SELinux perspective, it is important to note that if you
continue to disable SELinux via "/etc/selinux/config" it may appear
that SELinux is disabled, but it is simply in an uninitialized state.
If you load a policy with `load_policy -i`, you will see SELinux
come alive just as if you had loaded the policy during early-boot.
It is also worth noting that the "/sys/fs/selinux/disable" file is
always writable now, regardless of the Kconfig settings, but writing
to the file has no effect on the system, other than to display an
error on the console if a non-zero/true value is written.
Finally, in the several years where we have been working on
deprecating this functionality, there has only been one instance of
someone mentioning any user visible breakage. In this particular
case it was an individual's kernel test system, and the workaround
documented in the deprecation notice ("selinux=0" on the kernel
command line) resolved the issue without problem.
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2023-03-17 16:43:07 +00:00
|
|
|
static struct security_hook_list bpf_lsm_hooks[] __ro_after_init = {
|
2020-03-29 00:43:53 +00:00
|
|
|
#define LSM_HOOK(RET, DEFAULT, NAME, ...) \
|
|
|
|
LSM_HOOK_INIT(NAME, bpf_lsm_##NAME),
|
|
|
|
#include <linux/lsm_hook_defs.h>
|
|
|
|
#undef LSM_HOOK
|
2020-08-25 18:29:17 +00:00
|
|
|
LSM_HOOK_INIT(inode_free_security, bpf_inode_storage_free),
|
2020-11-06 10:37:40 +00:00
|
|
|
LSM_HOOK_INIT(task_free, bpf_task_storage_free),
|
2020-03-29 00:43:53 +00:00
|
|
|
};
|
|
|
|
|
2023-11-10 17:09:33 +00:00
|
|
|
static const struct lsm_id bpf_lsmid = {
|
2023-09-12 20:56:46 +00:00
|
|
|
.name = "bpf",
|
|
|
|
.id = LSM_ID_BPF,
|
|
|
|
};
|
|
|
|
|
2020-03-29 00:43:53 +00:00
|
|
|
static int __init bpf_lsm_init(void)
|
|
|
|
{
|
2023-09-12 20:56:46 +00:00
|
|
|
security_add_hooks(bpf_lsm_hooks, ARRAY_SIZE(bpf_lsm_hooks),
|
|
|
|
&bpf_lsmid);
|
2020-03-29 00:43:53 +00:00
|
|
|
pr_info("LSM support for eBPF active\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
selinux: remove the runtime disable functionality
After working with the larger SELinux-based distros for several
years, we're finally at a place where we can disable the SELinux
runtime disable functionality. The existing kernel deprecation
notice explains the functionality and why we want to remove it:
The selinuxfs "disable" node allows SELinux to be disabled at
runtime prior to a policy being loaded into the kernel. If
disabled via this mechanism, SELinux will remain disabled until
the system is rebooted.
The preferred method of disabling SELinux is via the "selinux=0"
boot parameter, but the selinuxfs "disable" node was created to
make it easier for systems with primitive bootloaders that did not
allow for easy modification of the kernel command line.
Unfortunately, allowing for SELinux to be disabled at runtime makes
it difficult to secure the kernel's LSM hooks using the
"__ro_after_init" feature.
It is that last sentence, mentioning the '__ro_after_init' hardening,
which is the real motivation for this change, and if you look at the
diffstat you'll see that the impact of this patch reaches across all
the different LSMs, helping prevent tampering at the LSM hook level.
From a SELinux perspective, it is important to note that if you
continue to disable SELinux via "/etc/selinux/config" it may appear
that SELinux is disabled, but it is simply in an uninitialized state.
If you load a policy with `load_policy -i`, you will see SELinux
come alive just as if you had loaded the policy during early-boot.
It is also worth noting that the "/sys/fs/selinux/disable" file is
always writable now, regardless of the Kconfig settings, but writing
to the file has no effect on the system, other than to display an
error on the console if a non-zero/true value is written.
Finally, in the several years where we have been working on
deprecating this functionality, there has only been one instance of
someone mentioning any user visible breakage. In this particular
case it was an individual's kernel test system, and the workaround
documented in the deprecation notice ("selinux=0" on the kernel
command line) resolved the issue without problem.
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2023-03-17 16:43:07 +00:00
|
|
|
struct lsm_blob_sizes bpf_lsm_blob_sizes __ro_after_init = {
|
2020-08-25 18:29:17 +00:00
|
|
|
.lbs_inode = sizeof(struct bpf_storage_blob),
|
|
|
|
};
|
|
|
|
|
2020-03-29 00:43:53 +00:00
|
|
|
DEFINE_LSM(bpf) = {
|
|
|
|
.name = "bpf",
|
|
|
|
.init = bpf_lsm_init,
|
2020-08-25 18:29:17 +00:00
|
|
|
.blobs = &bpf_lsm_blob_sizes
|
2020-03-29 00:43:53 +00:00
|
|
|
};
|