Skip to content

Commit 13523be

Browse files
committed
LoadPin: Rename boot param "enabled" to "enforce"
LoadPin's "enabled" setting is really about enforcement, not whether or not the LSM is using LSM hooks. Instead, split this out so that LSM enabling can be logically distinct from whether enforcement is happening (for example, the pinning happens when the LSM is enabled, but the pin is only checked when "enforce" is set). This allows LoadPin to continue to operate sanely in test environments once LSM enable/disable is centrally handled (i.e. we want LoadPin to be enabled separately from its enforcement). Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: John Johansen <john.johansen@canonical.com>
1 parent f4b626d commit 13523be

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

security/loadpin/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ config SECURITY_LOADPIN
1010
have a root filesystem backed by a read-only device such as
1111
dm-verity or a CDROM.
1212

13-
config SECURITY_LOADPIN_ENABLED
13+
config SECURITY_LOADPIN_ENFORCE
1414
bool "Enforce LoadPin at boot"
1515
depends on SECURITY_LOADPIN
1616
help
1717
If selected, LoadPin will enforce pinning at boot. If not
1818
selected, it can be enabled at boot with the kernel parameter
19-
"loadpin.enabled=1".
19+
"loadpin.enforce=1".

security/loadpin/loadpin.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void report_load(const char *origin, struct file *file, char *operation)
4444
kfree(pathname);
4545
}
4646

47-
static int enabled = IS_ENABLED(CONFIG_SECURITY_LOADPIN_ENABLED);
47+
static int enforce = IS_ENABLED(CONFIG_SECURITY_LOADPIN_ENFORCE);
4848
static struct super_block *pinned_root;
4949
static DEFINE_SPINLOCK(pinned_root_spinlock);
5050

@@ -60,8 +60,8 @@ static struct ctl_path loadpin_sysctl_path[] = {
6060

6161
static struct ctl_table loadpin_sysctl_table[] = {
6262
{
63-
.procname = "enabled",
64-
.data = &enabled,
63+
.procname = "enforce",
64+
.data = &enforce,
6565
.maxlen = sizeof(int),
6666
.mode = 0644,
6767
.proc_handler = proc_dointvec_minmax,
@@ -100,7 +100,7 @@ static void check_pinning_enforcement(struct super_block *mnt_sb)
100100
loadpin_sysctl_table))
101101
pr_notice("sysctl registration failed!\n");
102102
else
103-
pr_info("load pinning can be disabled.\n");
103+
pr_info("enforcement can be disabled.\n");
104104
} else
105105
pr_info("load pinning engaged.\n");
106106
}
@@ -131,7 +131,7 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id)
131131

132132
/* This handles the older init_module API that has a NULL file. */
133133
if (!file) {
134-
if (!enabled) {
134+
if (!enforce) {
135135
report_load(origin, NULL, "old-api-pinning-ignored");
136136
return 0;
137137
}
@@ -154,7 +154,7 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id)
154154
* Unlock now since it's only pinned_root we care about.
155155
* In the worst case, we will (correctly) report pinning
156156
* failures before we have announced that pinning is
157-
* enabled. This would be purely cosmetic.
157+
* enforcing. This would be purely cosmetic.
158158
*/
159159
spin_unlock(&pinned_root_spinlock);
160160
check_pinning_enforcement(pinned_root);
@@ -164,7 +164,7 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id)
164164
}
165165

166166
if (IS_ERR_OR_NULL(pinned_root) || load_root != pinned_root) {
167-
if (unlikely(!enabled)) {
167+
if (unlikely(!enforce)) {
168168
report_load(origin, file, "pinning-ignored");
169169
return 0;
170170
}
@@ -189,10 +189,11 @@ static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = {
189189

190190
void __init loadpin_add_hooks(void)
191191
{
192-
pr_info("ready to pin (currently %sabled)", enabled ? "en" : "dis");
192+
pr_info("ready to pin (currently %senforcing)\n",
193+
enforce ? "" : "not ");
193194
security_add_hooks(loadpin_hooks, ARRAY_SIZE(loadpin_hooks), "loadpin");
194195
}
195196

196197
/* Should not be mutable after boot, so not listed in sysfs (perm == 0). */
197-
module_param(enabled, int, 0);
198-
MODULE_PARM_DESC(enabled, "Pin module/firmware loading (default: true)");
198+
module_param(enforce, int, 0);
199+
MODULE_PARM_DESC(enforce, "Enforce module/firmware pinning");

0 commit comments

Comments
 (0)