summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.ibm.com>2023-04-28 08:23:11 -0400
committerArmin Kuster <akuster808@gmail.com>2023-05-06 07:54:09 -0400
commitf4f7624d2e50e19249e7a2a3798c1120e5183424 (patch)
tree2c3a5b997857d1a7431f94a5cc1882a4ab4a5d41
parentcb8f26d82a35ba56f3bd40cd6ba105de03602a4b (diff)
downloadmeta-security-f4f7624d2e50e19249e7a2a3798c1120e5183424.tar.gz
ima: Fix the IMA kernel feature
Fix the IMA kernel feature. Remove outdated patches and add ima.cfg holding kernel configuration options for IMA and EVM. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Signed-off-by: Armin Kuster <akuster808@gmail.com>
-rw-r--r--meta-integrity/classes/ima-evm-rootfs.bbclass5
-rw-r--r--meta-integrity/recipes-kernel/linux/linux/0001-ima-fix-ima_inode_post_setattr.patch51
-rw-r--r--meta-integrity/recipes-kernel/linux/linux/0002-ima-add-support-for-creating-files-using-the-mknodat.patch138
-rw-r--r--meta-integrity/recipes-kernel/linux/linux/Revert-ima-limit-file-hash-setting-by-user-to-fix-an.patch60
-rw-r--r--meta-integrity/recipes-kernel/linux/linux/ima.cfg46
-rw-r--r--meta-integrity/recipes-kernel/linux/linux/ima.scc4
-rw-r--r--meta-integrity/recipes-kernel/linux/linux_ima.inc10
7 files changed, 63 insertions, 251 deletions
diff --git a/meta-integrity/classes/ima-evm-rootfs.bbclass b/meta-integrity/classes/ima-evm-rootfs.bbclass
index 57de2f6..3cb0d07 100644
--- a/meta-integrity/classes/ima-evm-rootfs.bbclass
+++ b/meta-integrity/classes/ima-evm-rootfs.bbclass
@@ -17,7 +17,7 @@ IMA_EVM_X509 ?= "${IMA_EVM_KEY_DIR}/x509_ima.der"
17# with a .x509 suffix. See linux-%.bbappend for details. 17# with a .x509 suffix. See linux-%.bbappend for details.
18# 18#
19# ima-local-ca.x509 is what ima-gen-local-ca.sh creates. 19# ima-local-ca.x509 is what ima-gen-local-ca.sh creates.
20IMA_EVM_ROOT_CA ?= "" 20IMA_EVM_ROOT_CA ?= "${IMA_EVM_KEY_DIR}/ima-local-ca.pem"
21 21
22# Sign all regular files by default. 22# Sign all regular files by default.
23IMA_EVM_ROOTFS_SIGNED ?= ". -type f" 23IMA_EVM_ROOTFS_SIGNED ?= ". -type f"
@@ -31,6 +31,9 @@ IMA_EVM_ROOTFS_IVERSION ?= ""
31# Avoid re-generating fstab when ima is enabled. 31# Avoid re-generating fstab when ima is enabled.
32WIC_CREATE_EXTRA_ARGS:append = "${@bb.utils.contains('DISTRO_FEATURES', 'ima', ' --no-fstab-update', '', d)}" 32WIC_CREATE_EXTRA_ARGS:append = "${@bb.utils.contains('DISTRO_FEATURES', 'ima', ' --no-fstab-update', '', d)}"
33 33
34# Add necessary tools (e.g., keyctl) to image
35IMAGE_INSTALL:append = "${@bb.utils.contains('DISTRO_FEATURES', 'ima', ' ima-evm-utils', '', d)}"
36
34ima_evm_sign_rootfs () { 37ima_evm_sign_rootfs () {
35 cd ${IMAGE_ROOTFS} 38 cd ${IMAGE_ROOTFS}
36 39
diff --git a/meta-integrity/recipes-kernel/linux/linux/0001-ima-fix-ima_inode_post_setattr.patch b/meta-integrity/recipes-kernel/linux/linux/0001-ima-fix-ima_inode_post_setattr.patch
deleted file mode 100644
index 64016dd..0000000
--- a/meta-integrity/recipes-kernel/linux/linux/0001-ima-fix-ima_inode_post_setattr.patch
+++ /dev/null
@@ -1,51 +0,0 @@
1From 45ea681ebc0dd44aaec5d3cc4143b9722070d3ac Mon Sep 17 00:00:00 2001
2From: Mimi Zohar <zohar@linux.vnet.ibm.com>
3Date: Tue, 8 Mar 2016 16:43:55 -0500
4Subject: [PATCH] ima: fix ima_inode_post_setattr
5
6Changing file metadata (eg. uid, guid) could result in having to
7re-appraise a file's integrity, but does not change the "new file"
8status nor the security.ima xattr. The IMA_PERMIT_DIRECTIO and
9IMA_DIGSIG_REQUIRED flags are policy rule specific. This patch
10only resets these flags, not the IMA_NEW_FILE or IMA_DIGSIG flags.
11
12With this patch, changing the file timestamp will not remove the
13file signature on new files.
14
15Upstream-Status: Accepted [https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/security/integrity/ima/ima_appraise.c?id=42a4c603198f0d45b7aa936d3ac6ba1b8bd14a1b]
16
17Reported-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
18Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
19---
20 security/integrity/ima/ima_appraise.c | 2 +-
21 security/integrity/integrity.h | 1 +
22 2 files changed, 2 insertions(+), 1 deletion(-)
23
24diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
25index 4df493e..a384ba1 100644
26--- a/security/integrity/ima/ima_appraise.c
27+++ b/security/integrity/ima/ima_appraise.c
28@@ -327,7 +327,7 @@ void ima_inode_post_setattr(struct dentry *dentry)
29 if (iint) {
30 iint->flags &= ~(IMA_APPRAISE | IMA_APPRAISED |
31 IMA_APPRAISE_SUBMASK | IMA_APPRAISED_SUBMASK |
32- IMA_ACTION_FLAGS);
33+ IMA_ACTION_RULE_FLAGS);
34 if (must_appraise)
35 iint->flags |= IMA_APPRAISE;
36 }
37diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h
38index 0fc9519..f9decae 100644
39--- a/security/integrity/integrity.h
40+++ b/security/integrity/integrity.h
41@@ -28,6 +28,7 @@
42
43 /* iint cache flags */
44 #define IMA_ACTION_FLAGS 0xff000000
45+#define IMA_ACTION_RULE_FLAGS 0x06000000
46 #define IMA_DIGSIG 0x01000000
47 #define IMA_DIGSIG_REQUIRED 0x02000000
48 #define IMA_PERMIT_DIRECTIO 0x04000000
49--
502.5.0
51
diff --git a/meta-integrity/recipes-kernel/linux/linux/0002-ima-add-support-for-creating-files-using-the-mknodat.patch b/meta-integrity/recipes-kernel/linux/linux/0002-ima-add-support-for-creating-files-using-the-mknodat.patch
deleted file mode 100644
index 6ab7ce2..0000000
--- a/meta-integrity/recipes-kernel/linux/linux/0002-ima-add-support-for-creating-files-using-the-mknodat.patch
+++ /dev/null
@@ -1,138 +0,0 @@
1From baaec960e9e7be0b526eaf831b079ddfe5c15124 Mon Sep 17 00:00:00 2001
2From: Mimi Zohar <zohar@linux.vnet.ibm.com>
3Date: Thu, 10 Mar 2016 18:19:20 +0200
4Subject: [PATCH] ima: add support for creating files using the mknodat
5 syscall
6
7Commit 3034a14 "ima: pass 'opened' flag to identify newly created files"
8stopped identifying empty files as new files. However new empty files
9can be created using the mknodat syscall. On systems with IMA-appraisal
10enabled, these empty files are not labeled with security.ima extended
11attributes properly, preventing them from subsequently being opened in
12order to write the file data contents. This patch marks these empty
13files, created using mknodat, as new in order to allow the file data
14contents to be written.
15
16Files with security.ima xattrs containing a file signature are considered
17"immutable" and can not be modified. The file contents need to be
18written, before signing the file. This patch relaxes this requirement
19for new files, allowing the file signature to be written before the file
20contents.
21
22Upstream-Status: Accepted [https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/security/integrity/ima/ima_appraise.c?id=05d1a717ec0430c916a749b94eb90ab74bbfa356]
23
24Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
25---
26 fs/namei.c | 2 ++
27 include/linux/ima.h | 7 ++++++-
28 security/integrity/ima/ima_appraise.c | 3 +++
29 security/integrity/ima/ima_main.c | 32 +++++++++++++++++++++++++++++++-
30 4 files changed, 42 insertions(+), 2 deletions(-)
31
32diff --git a/fs/namei.c b/fs/namei.c
33index ccd7f98..19502da 100644
34--- a/fs/namei.c
35+++ b/fs/namei.c
36@@ -3526,6 +3526,8 @@ retry:
37 switch (mode & S_IFMT) {
38 case 0: case S_IFREG:
39 error = vfs_create(path.dentry->d_inode,dentry,mode,true);
40+ if (!error)
41+ ima_post_path_mknod(dentry);
42 break;
43 case S_IFCHR: case S_IFBLK:
44 error = vfs_mknod(path.dentry->d_inode,dentry,mode,
45diff --git a/include/linux/ima.h b/include/linux/ima.h
46index 120ccc5..7f51971 100644
47--- a/include/linux/ima.h
48+++ b/include/linux/ima.h
49@@ -20,7 +20,7 @@ extern void ima_file_free(struct file *file);
50 extern int ima_file_mmap(struct file *file, unsigned long prot);
51 extern int ima_module_check(struct file *file);
52 extern int ima_fw_from_file(struct file *file, char *buf, size_t size);
53-
54+extern void ima_post_path_mknod(struct dentry *dentry);
55 #else
56 static inline int ima_bprm_check(struct linux_binprm *bprm)
57 {
58@@ -52,6 +52,11 @@ static inline int ima_fw_from_file(struct file *file, char *buf, size_t size)
59 return 0;
60 }
61
62+static inline void ima_post_path_mknod(struct dentry *dentry)
63+{
64+ return;
65+}
66+
67 #endif /* CONFIG_IMA */
68
69 #ifdef CONFIG_IMA_APPRAISE
70diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
71index 4df493e..20806ea 100644
72--- a/security/integrity/ima/ima_appraise.c
73+++ b/security/integrity/ima/ima_appraise.c
74@@ -274,6 +274,11 @@ out:
75 xattr_value->type != EVM_IMA_XATTR_DIGSIG)) {
76 if (!ima_fix_xattr(dentry, iint))
77 status = INTEGRITY_PASS;
78+ } else if ((inode->i_size == 0) &&
79+ (iint->flags & IMA_NEW_FILE) &&
80+ (xattr_value &&
81+ xattr_value->type == EVM_IMA_XATTR_DIGSIG)) {
82+ status = INTEGRITY_PASS;
83 }
84 integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode, filename,
85 op, cause, rc, 0);
86diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
87index eeee00dc..705bf78 100644
88--- a/security/integrity/ima/ima_main.c
89+++ b/security/integrity/ima/ima_main.c
90@@ -242,7 +242,8 @@ static int process_measurement(struct file *file, int mask, int function,
91 ima_audit_measurement(iint, pathname);
92
93 out_digsig:
94- if ((mask & MAY_WRITE) && (iint->flags & IMA_DIGSIG))
95+ if ((mask & MAY_WRITE) && (iint->flags & IMA_DIGSIG) &&
96+ !(iint->flags & IMA_NEW_FILE))
97 rc = -EACCES;
98 kfree(xattr_value);
99 out_free:
100@@ -310,6 +311,35 @@ int ima_file_check(struct file *file, int mask, int opened)
101 EXPORT_SYMBOL_GPL(ima_file_check);
102
103 /**
104+ * ima_post_path_mknod - mark as a new inode
105+ * @dentry: newly created dentry
106+ *
107+ * Mark files created via the mknodat syscall as new, so that the
108+ * file data can be written later.
109+ */
110+void ima_post_path_mknod(struct dentry *dentry)
111+{
112+ struct integrity_iint_cache *iint;
113+ struct inode *inode;
114+ int must_appraise;
115+
116+ if (!dentry || !dentry->d_inode)
117+ return;
118+
119+ inode = dentry->d_inode;
120+ if (inode->i_size != 0)
121+ return;
122+
123+ must_appraise = ima_must_appraise(inode, MAY_ACCESS, FILE_CHECK);
124+ if (!must_appraise)
125+ return;
126+
127+ iint = integrity_inode_get(inode);
128+ if (iint)
129+ iint->flags |= IMA_NEW_FILE;
130+}
131+
132+/**
133 * ima_module_check - based on policy, collect/store/appraise measurement.
134 * @file: pointer to the file to be measured/appraised
135 *
136--
1372.5.0
138
diff --git a/meta-integrity/recipes-kernel/linux/linux/Revert-ima-limit-file-hash-setting-by-user-to-fix-an.patch b/meta-integrity/recipes-kernel/linux/linux/Revert-ima-limit-file-hash-setting-by-user-to-fix-an.patch
deleted file mode 100644
index 157c007..0000000
--- a/meta-integrity/recipes-kernel/linux/linux/Revert-ima-limit-file-hash-setting-by-user-to-fix-an.patch
+++ /dev/null
@@ -1,60 +0,0 @@
1From a34d61850b680c152e1dcc958ee83c3ab3261c3d Mon Sep 17 00:00:00 2001
2From: Patrick Ohly <patrick.ohly@intel.com>
3Date: Tue, 15 Nov 2016 10:10:23 +0100
4Subject: [PATCH] Revert "ima: limit file hash setting by user to fix and log
5 modes"
6
7This reverts commit c68ed80c97d9720f51ef31fe91560fdd1e121533.
8
9The original motivation was security hardening ("File hashes are
10automatically set and updated and should not be manually set.")
11
12However, that hardening ignores and breaks some valid use cases:
13- File hashes might not be set because the file is currently
14 outside of the policy and therefore have to be set by the
15 creator. Examples:
16 - Booting into an initramfs with an IMA-enabled kernel but
17 without setting an IMA policy, then installing
18 the OS onto the target partition by unpacking a rootfs archive
19 which has the file hashes pre-computed.
20 - Unpacking a file into a staging area with meta data (like owner)
21 that leaves the file outside of the current policy, then changing
22 the meta data such that it becomes part of the current policy.
23- "should not be set manually" implies that the creator is aware
24 of IMA semantic, the current system's configuration, and then
25 skips setting file hashes in security.ima if (and only if) the
26 kernel would prevent it. That's not the case for standard, unmodified
27 tools. Example: unpacking an archive with security.ima xattrs with
28 bsdtar or GNU tar.
29
30Upstream-Status: Submitted [https://sourceforge.net/p/linux-ima/mailman/message/35492824/]
31
32Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
33---
34 security/integrity/ima/ima_appraise.c | 8 ++------
35 1 file changed, 2 insertions(+), 6 deletions(-)
36
37diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
38index 4b9b4a4..b8b2dd9 100644
39--- a/security/integrity/ima/ima_appraise.c
40+++ b/security/integrity/ima/ima_appraise.c
41@@ -385,14 +385,10 @@ int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name,
42 result = ima_protect_xattr(dentry, xattr_name, xattr_value,
43 xattr_value_len);
44 if (result == 1) {
45- bool digsig;
46-
47 if (!xattr_value_len || (xvalue->type >= IMA_XATTR_LAST))
48 return -EINVAL;
49- digsig = (xvalue->type == EVM_IMA_XATTR_DIGSIG);
50- if (!digsig && (ima_appraise & IMA_APPRAISE_ENFORCE))
51- return -EPERM;
52- ima_reset_appraise_flags(d_backing_inode(dentry), digsig);
53+ ima_reset_appraise_flags(d_backing_inode(dentry),
54+ (xvalue->type == EVM_IMA_XATTR_DIGSIG) ? 1 : 0);
55 result = 0;
56 }
57 return result;
58--
592.1.4
60
diff --git a/meta-integrity/recipes-kernel/linux/linux/ima.cfg b/meta-integrity/recipes-kernel/linux/linux/ima.cfg
new file mode 100644
index 0000000..86fb3aa
--- /dev/null
+++ b/meta-integrity/recipes-kernel/linux/linux/ima.cfg
@@ -0,0 +1,46 @@
1CONFIG_SQUASHFS_XATTR=y
2CONFIG_KEYS=y
3CONFIG_ASYMMETRIC_KEY_TYPE=y
4CONFIG_SYSTEM_TRUSTED_KEYRING=y
5CONFIG_SYSTEM_TRUSTED_KEYS="${IMA_EVM_ROOT_CA}"
6CONFIG_SECONDARY_TRUSTED_KEYRING=y
7CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y
8CONFIG_X509_CERTIFICATE_PARSER=y
9CONFIG_PKCS8_PRIVATE_KEY_PARSER=y
10CONFIG_CRYPTO_ECDSA=y
11CONFIG_SECURITY=y
12CONFIG_SECURITYFS=y
13CONFIG_INTEGRITY=y
14CONFIG_INTEGRITY_SIGNATURE=y
15CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y
16CONFIG_INTEGRITY_TRUSTED_KEYRING=y
17CONFIG_IMA=y
18CONFIG_IMA_MEASURE_PCR_IDX=10
19CONFIG_IMA_LSM_RULES=y
20# CONFIG_IMA_TEMPLATE is not set
21# CONFIG_IMA_NG_TEMPLATE is not set
22CONFIG_IMA_SIG_TEMPLATE=y
23CONFIG_IMA_DEFAULT_TEMPLATE="ima-sig"
24# CONFIG_IMA_DEFAULT_HASH_SHA1 is not set
25CONFIG_IMA_DEFAULT_HASH_SHA256=y
26# CONFIG_IMA_DEFAULT_HASH_SHA512 is not set
27CONFIG_IMA_DEFAULT_HASH="sha256"
28CONFIG_IMA_WRITE_POLICY=y
29CONFIG_IMA_READ_POLICY=y
30CONFIG_IMA_APPRAISE=y
31CONFIG_IMA_ARCH_POLICY=y
32CONFIG_IMA_APPRAISE_BUILD_POLICY=y
33CONFIG_IMA_APPRAISE_REQUIRE_POLICY_SIGS=y
34# CONFIG_IMA_APPRAISE_BOOTPARAM is not set
35# CONFIG_IMA_APPRAISE_MODSIG is not set
36CONFIG_IMA_TRUSTED_KEYRING=y
37CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY=y
38# CONFIG_IMA_BLACKLIST_KEYRING is not set
39# CONFIG_IMA_LOAD_X509 is not set
40CONFIG_IMA_APPRAISE_SIGNED_INIT=y
41CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS=y
42CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS=y
43CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT=y
44# CONFIG_IMA_DISABLE_HTABLE is not set
45CONFIG_EVM=y
46# CONFIG_EVM_LOAD_X509 is not set
diff --git a/meta-integrity/recipes-kernel/linux/linux/ima.scc b/meta-integrity/recipes-kernel/linux/linux/ima.scc
new file mode 100644
index 0000000..6eb84b0
--- /dev/null
+++ b/meta-integrity/recipes-kernel/linux/linux/ima.scc
@@ -0,0 +1,4 @@
1define KFEATURE_DESCRIPTION "Enable IMA"
2
3kconf non-hardware ima.cfg
4
diff --git a/meta-integrity/recipes-kernel/linux/linux_ima.inc b/meta-integrity/recipes-kernel/linux/linux_ima.inc
index 3ab53e5..0b6f530 100644
--- a/meta-integrity/recipes-kernel/linux/linux_ima.inc
+++ b/meta-integrity/recipes-kernel/linux/linux_ima.inc
@@ -1,4 +1,12 @@
1KERNEL_FEATURES:append = " ${@bb.utils.contains("DISTRO_FEATURES", "ima", " features/ima/ima.scc", "" ,d)}" 1FILESEXTRAPATHS:append := "${THISDIR}/linux:"
2
3SRC_URI += " \
4 ${@bb.utils.contains('DISTRO_FEATURES', 'ima', 'file://ima.scc', '', d)} \
5"
6
7do_configure() {
8 sed -i "s|^CONFIG_SYSTEM_TRUSTED_KEYS=.*|CONFIG_SYSTEM_TRUSTED_KEYS=\"${IMA_EVM_ROOT_CA}\"|" .config
9}
2 10
3KERNEL_FEATURES:append = " ${@bb.utils.contains('DISTRO_FEATURES', 'modsign', ' features/ima/modsign.scc', '', d)}" 11KERNEL_FEATURES:append = " ${@bb.utils.contains('DISTRO_FEATURES', 'modsign', ' features/ima/modsign.scc', '', d)}"
4 12