Skip to content

Commit 82fe793

Browse files
robertosassupcmoore
authored andcommitted
ima,evm: move initcalls to the LSM framework
This patch converts IMA and EVM to use the LSM frameworks's initcall mechanism. It moved the integrity_fs_init() call to ima_fs_init() and evm_init_secfs(), to work around the fact that there is no "integrity" LSM, and introduced integrity_fs_fini() to remove the integrity directory, if empty. Both integrity_fs_init() and integrity_fs_fini() support the scenario of being called by both the IMA and EVM LSMs. This patch does not touch any of the platform certificate code that lives under the security/integrity/platform_certs directory as the IMA/EVM developers would prefer to address that in a future patchset. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Acked-by: Mimi Zohar <zohar@linux.ibm.com> [PM: adjust description as discussed over email] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 77ebff0 commit 82fe793

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

security/integrity/evm/evm_main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,5 @@ DEFINE_LSM(evm) = {
11791179
.init = init_evm_lsm,
11801180
.order = LSM_ORDER_LAST,
11811181
.blobs = &evm_blob_sizes,
1182+
.initcall_late = init_evm,
11821183
};
1183-
1184-
late_initcall(init_evm);

security/integrity/evm/evm_secfs.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,16 @@ int __init evm_init_secfs(void)
302302
int error = 0;
303303
struct dentry *dentry;
304304

305-
evm_dir = securityfs_create_dir("evm", integrity_dir);
306-
if (IS_ERR(evm_dir))
305+
error = integrity_fs_init();
306+
if (error < 0)
307307
return -EFAULT;
308308

309+
evm_dir = securityfs_create_dir("evm", integrity_dir);
310+
if (IS_ERR(evm_dir)) {
311+
error = -EFAULT;
312+
goto out;
313+
}
314+
309315
dentry = securityfs_create_file("evm", 0660,
310316
evm_dir, NULL, &evm_key_ops);
311317
if (IS_ERR(dentry)) {
@@ -329,5 +335,6 @@ int __init evm_init_secfs(void)
329335
out:
330336
securityfs_remove(evm_symlink);
331337
securityfs_remove(evm_dir);
338+
integrity_fs_fini();
332339
return error;
333340
}

security/integrity/iint.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ void __init integrity_load_keys(void)
4242
evm_load_x509();
4343
}
4444

45-
static int __init integrity_fs_init(void)
45+
int __init integrity_fs_init(void)
4646
{
47+
if (integrity_dir)
48+
return 0;
49+
4750
integrity_dir = securityfs_create_dir("integrity", NULL);
4851
if (IS_ERR(integrity_dir)) {
4952
int ret = PTR_ERR(integrity_dir);
@@ -58,4 +61,11 @@ static int __init integrity_fs_init(void)
5861
return 0;
5962
}
6063

61-
late_initcall(integrity_fs_init)
64+
void __init integrity_fs_fini(void)
65+
{
66+
if (!integrity_dir || !simple_empty(integrity_dir))
67+
return;
68+
69+
securityfs_remove(integrity_dir);
70+
integrity_dir = NULL;
71+
}

security/integrity/ima/ima_fs.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,15 @@ int __init ima_fs_init(void)
499499
struct dentry *dentry;
500500
int ret;
501501

502+
ret = integrity_fs_init();
503+
if (ret < 0)
504+
return ret;
505+
502506
ima_dir = securityfs_create_dir("ima", integrity_dir);
503-
if (IS_ERR(ima_dir))
504-
return PTR_ERR(ima_dir);
507+
if (IS_ERR(ima_dir)) {
508+
ret = PTR_ERR(ima_dir);
509+
goto out;
510+
}
505511

506512
ima_symlink = securityfs_create_symlink("ima", NULL, "integrity/ima",
507513
NULL);
@@ -555,6 +561,7 @@ int __init ima_fs_init(void)
555561
out:
556562
securityfs_remove(ima_symlink);
557563
securityfs_remove(ima_dir);
564+
integrity_fs_fini();
558565

559566
return ret;
560567
}

security/integrity/ima/ima_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,6 @@ DEFINE_LSM(ima) = {
12831283
.init = init_ima_lsm,
12841284
.order = LSM_ORDER_LAST,
12851285
.blobs = &ima_blob_sizes,
1286+
/* Start IMA after the TPM is available */
1287+
.initcall_late = init_ima,
12861288
};
1287-
1288-
late_initcall(init_ima); /* Start IMA after the TPM is available */

security/integrity/integrity.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ struct ima_file_id {
114114

115115
int integrity_kernel_read(struct file *file, loff_t offset,
116116
void *addr, unsigned long count);
117+
int __init integrity_fs_init(void);
118+
void __init integrity_fs_fini(void);
117119

118120
#define INTEGRITY_KEYRING_EVM 0
119121
#define INTEGRITY_KEYRING_IMA 1

0 commit comments

Comments
 (0)