Skip to content

Commit 9f9dc69

Browse files
committed
lsm: replace the name field with a pointer to the lsm_id struct
Reduce the duplication between the lsm_id struct and the DEFINE_LSM() definition by linking the lsm_id struct directly into the individual LSM's DEFINE_LSM() instance. Linking the lsm_id into the LSM definition also allows us to simplify the security_add_hooks() function by removing the code which populates the lsm_idlist[] array and moving it into the normal LSM startup code where the LSM list is parsed and the individual LSMs are enabled, making for a cleaner implementation with less overhead at boot. Reviewed-by: Kees Cook <kees@kernel.org> Reviewed-by: John Johansen <john.johansen@canonical.com> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent faabedc commit 9f9dc69

File tree

16 files changed

+33
-42
lines changed

16 files changed

+33
-42
lines changed

include/linux/lsm_hooks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ enum lsm_order {
152152
};
153153

154154
struct lsm_info {
155-
const char *name; /* Required. */
155+
const struct lsm_id *id;
156156
enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */
157157
unsigned long flags; /* Optional: flags describing LSM */
158158
int *enabled; /* Optional: controlled by CONFIG_LSM */

security/apparmor/lsm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ static int __init apparmor_init(void)
25552555
}
25562556

25572557
DEFINE_LSM(apparmor) = {
2558-
.name = "apparmor",
2558+
.id = &apparmor_lsmid,
25592559
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
25602560
.enabled = &apparmor_enabled,
25612561
.blobs = &apparmor_blob_sizes,

security/bpf/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct lsm_blob_sizes bpf_lsm_blob_sizes __ro_after_init = {
3333
};
3434

3535
DEFINE_LSM(bpf) = {
36-
.name = "bpf",
36+
.id = &bpf_lsmid,
3737
.init = bpf_lsm_init,
3838
.blobs = &bpf_lsm_blob_sizes
3939
};

security/commoncap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ static int __init capability_init(void)
15051505
}
15061506

15071507
DEFINE_LSM(capability) = {
1508-
.name = "capability",
1508+
.id = &capability_lsmid,
15091509
.order = LSM_ORDER_FIRST,
15101510
.init = capability_init,
15111511
};

security/integrity/evm/evm_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ struct lsm_blob_sizes evm_blob_sizes __ro_after_init = {
11751175
};
11761176

11771177
DEFINE_LSM(evm) = {
1178-
.name = "evm",
1178+
.id = &evm_lsmid,
11791179
.init = init_evm_lsm,
11801180
.order = LSM_ORDER_LAST,
11811181
.blobs = &evm_blob_sizes,

security/integrity/ima/ima_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ struct lsm_blob_sizes ima_blob_sizes __ro_after_init = {
12791279
};
12801280

12811281
DEFINE_LSM(ima) = {
1282-
.name = "ima",
1282+
.id = &ima_lsmid,
12831283
.init = init_ima_lsm,
12841284
.order = LSM_ORDER_LAST,
12851285
.blobs = &ima_blob_sizes,

security/ipe/ipe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int __init ipe_init(void)
9292
}
9393

9494
DEFINE_LSM(ipe) = {
95-
.name = "ipe",
95+
.id = &ipe_lsmid,
9696
.init = ipe_init,
9797
.blobs = &ipe_blobs,
9898
};

security/landlock/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static int __init landlock_init(void)
7575
}
7676

7777
DEFINE_LSM(LANDLOCK_NAME) = {
78-
.name = LANDLOCK_NAME,
78+
.id = &landlock_lsmid,
7979
.init = landlock_init,
8080
.blobs = &landlock_blob_sizes,
8181
};

security/loadpin/loadpin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static int __init loadpin_init(void)
271271
}
272272

273273
DEFINE_LSM(loadpin) = {
274-
.name = "loadpin",
274+
.id = &loadpin_lsmid,
275275
.init = loadpin_init,
276276
};
277277

security/lockdown/lockdown.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@ DEFINE_EARLY_LSM(lockdown) = {
168168
#else
169169
DEFINE_LSM(lockdown) = {
170170
#endif
171-
.name = "lockdown",
171+
.id = &lockdown_lsmid,
172172
.init = lockdown_lsm_init,
173173
};

0 commit comments

Comments
 (0)