Skip to contentSkip to conversation

Backport several IMA fixes to LTS dunfell

PATCH In review Ming Liu 2 participants 6 messages Apr 19, 2021 – Apr 28, 2021

lore
Share & tools
lore

Ming Liu

author
#0 lore raw

cover Backport several IMA fixes to LTS dunfell

From: Ming Liu <[email protected]>

Ming Liu (3):
ima-evm-keys: add file-checksums to IMA_EVM_X509
meta: drop IMA_POLICY from policy recipes
initramfs-framework-ima: introduce IMA_FORCE

 .../initrdscripts/initramfs-framework-ima.bb             | 5 +++++
 .../initrdscripts/initramfs-framework-ima/ima            | 9 +++++++--
 .../recipes-security/ima-evm-keys/ima-evm-keys_1.0.bb    | 1 +
 .../ima-policy-appraise-all_1.0.bb                       | 9 ++-------
 .../ima_policy_hashed/ima-policy-hashed_1.0.bb           | 9 ++-------
 .../ima_policy_simple/ima-policy-simple_1.0.bb           | 9 ++-------
 6 files changed, 19 insertions(+), 23 deletions(-)
Signature · 1 line
2.29.0
author
#1 lore raw

PATCH 1/3 ima-evm-keys: add file-checksums to IMA_EVM_X509

From: Ming Liu <[email protected]>

This ensures when a end user change the IMA_EVM_X509 key file, ima-evm-keys recipe will be rebuilt.

---
 meta-integrity/recipes-security/ima-evm-keys/ima-evm-keys_1.0.bb | 1 +
 1 file changed, 1 insertion(+)
meta-integrity/recipes-security/ima-evm-keys/ima-evm-keys_1.0.bb +1 -0
index 62685bb..7708aef 100644
@@ -14,3 +14,4 @@ do_install () {
         lnr ${D}${sysconfdir}/keys/x509_evm.der ${D}${sysconfdir}/keys/x509_ima.der
     fi
 }
+do_install[file-checksums] += "${@'${IMA_EVM_X509}:%s' % os.path.exists('${IMA_EVM_X509}')}"
Signature · 1 line
2.29.0
author
#2 lore raw

PATCH 2/3 meta: drop IMA_POLICY from policy recipes

In reply to Ming Liu

From: Ming Liu <[email protected]>

IMA_POLICY is being referred as policy recipe name in some places and it is also being referred as policy file in other places, they are conflicting with each other which make it impossible to set a IMA_POLICY global variable in config file.

Fix it by dropping IMA_POLICY definitions from policy recipes

---
 .../ima-policy-appraise-all_1.0.bb                       | 9 ++-------
 .../ima_policy_hashed/ima-policy-hashed_1.0.bb           | 9 ++-------
 .../ima_policy_simple/ima-policy-simple_1.0.bb           | 9 ++-------
 3 files changed, 6 insertions(+), 21 deletions(-)
meta-integrity/recipes-security/ima_policy_appraise_all/ima-policy-appraise-all_1.0.bb +2 -7
index da62a4c..84ea161 100644
@@ -2,19 +2,14 @@ SUMMARY = "IMA sample simple appraise policy "
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
 
-# This policy file will get installed as /etc/ima/ima-policy.
-# It is located via the normal file search path, so a .bbappend
-# to this recipe can just point towards one of its own files.
-IMA_POLICY ?= "ima_policy_appraise_all"
-
-SRC_URI = " file://${IMA_POLICY}"
+SRC_URI = " file://ima_policy_appraise_all"
 
 inherit features_check
 REQUIRED_DISTRO_FEATURES = "ima"
 
 do_install () {
     install -d ${D}/${sysconfdir}/ima
-    install ${WORKDIR}/${IMA_POLICY}  ${D}/${sysconfdir}/ima/ima-policy
+    install ${WORKDIR}/ima_policy_appraise_all ${D}/${sysconfdir}/ima/ima-policy
 }
 
 FILES_${PN} = "${sysconfdir}/ima"
meta-integrity/recipes-security/ima_policy_hashed/ima-policy-hashed_1.0.bb +2 -7
index ebb0426..ff7169e 100644
@@ -2,13 +2,8 @@ SUMMARY = "IMA sample hash policy"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
 
-# This policy file will get installed as /etc/ima/ima-policy.
-# It is located via the normal file search path, so a .bbappend
-# to this recipe can just point towards one of its own files.
-IMA_POLICY ?= "ima_policy_hashed"
-
 SRC_URI = " \
-    file://${IMA_POLICY} \
+    file://ima_policy_hashed \
 "
 
 inherit features_check
@@ -16,7 +11,7 @@ REQUIRED_DISTRO_FEATURES = "ima"
 
 do_install () {
     install -d ${D}/${sysconfdir}/ima
-    install ${WORKDIR}/${IMA_POLICY}  ${D}/${sysconfdir}/ima/ima-policy
+    install ${WORKDIR}/ima_policy_hashed ${D}/${sysconfdir}/ima/ima-policy
 }
 
 FILES_${PN} = "${sysconfdir}/ima"
meta-integrity/recipes-security/ima_policy_simple/ima-policy-simple_1.0.bb +2 -7
index cb4b6b8..0e56aec 100644
@@ -2,19 +2,14 @@ SUMMARY = "IMA sample simple policy"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
 
-# This policy file will get installed as /etc/ima/ima-policy.
-# It is located via the normal file search path, so a .bbappend
-# to this recipe can just point towards one of its own files.
-IMA_POLICY ?= "ima_policy_simple"
-
-SRC_URI = " file://${IMA_POLICY}"
+SRC_URI = " file://ima_policy_simple"
 
 inherit features_check
 REQUIRED_DISTRO_FEATURES = "ima"
 
 do_install () {
     install -d ${D}/${sysconfdir}/ima
-    install ${WORKDIR}/${IMA_POLICY}  ${D}/${sysconfdir}/ima/ima-policy
+    install ${WORKDIR}/ima_policy_simple ${D}/${sysconfdir}/ima/ima-policy
 }
 
 FILES_${PN} = "${sysconfdir}/ima"
Signature · 1 line
2.29.0
author
#3 lore raw

PATCH 3/3 initramfs-framework-ima: introduce IMA_FORCE

In reply to Ming Liu

From: Ming Liu <[email protected]>

Introduce IMA_FORCE to allow the IMA policy be applied forcely even 'no_ima' boot parameter is available.

This ensures the end users have a way to disable 'no_ima' support if they want to, because it may expose a security risk if an attacker can find a way to change kernel arguments, it will easily bypass rootfs authenticity checks.

---
 .../initrdscripts/initramfs-framework-ima.bb             | 5 +++++
 .../initrdscripts/initramfs-framework-ima/ima            | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
meta-integrity/recipes-core/initrdscripts/initramfs-framework-ima.bb +5 -0
index 77f6f7c..6471c53 100644
@@ -14,6 +14,9 @@ LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384
 # to this recipe can just point towards one of its own files.
 IMA_POLICY ?= "ima-policy-hashed"
 
+# Force proceed IMA procedure even 'no_ima' boot parameter is available.
+IMA_FORCE ?= "false"
+
 SRC_URI = " file://ima"
 
 inherit features_check
@@ -23,6 +26,8 @@ do_install () {
     install -d ${D}/${sysconfdir}/ima
     install -d ${D}/init.d
     install ${WORKDIR}/ima  ${D}/init.d/20-ima
+
+    sed -i "s/@@FORCE_IMA@@/${IMA_FORCE}/g" ${D}/init.d/20-ima
 }
 
 FILES_${PN} = "/init.d ${sysconfdir}"
meta-integrity/recipes-core/initrdscripts/initramfs-framework-ima/ima +7 -2
index cff26a3..8971494 100644
@@ -2,11 +2,16 @@
 #
 # Loads IMA policy into the kernel.
 
+force_ima=@@FORCE_IMA@@
+
 ima_enabled() {
-    if [ "$bootparam_no_ima" = "true" ]; then
+    if [ "$force_ima" = "true" ]; then
+        return 0
+    elif [ "$bootparam_no_ima" = "true" ]; then
         return 1
+    else
+        return 0
     fi
-    return 0
 }
 
 ima_run() {
Signature · 1 line
2.29.0
#4 lore raw
In reply to Ming Liu
Quoted 1 line · On 4/18/21 11:41 PM, [email protected] wrote:

From: Ming Liu <[email protected]>

I have not forgotten about these. My build system is backlogged.

I hope to process these by this weekend.

-armin

Quoted 14 lines

Ming Liu (3):
ima-evm-keys: add file-checksums to IMA_EVM_X509
meta: drop IMA_POLICY from policy recipes
initramfs-framework-ima: introduce IMA_FORCE

 .../initrdscripts/initramfs-framework-ima.bb             | 5 +++++
 .../initrdscripts/initramfs-framework-ima/ima            | 9 +++++++--
 .../recipes-security/ima-evm-keys/ima-evm-keys_1.0.bb    | 1 +
 .../ima-policy-appraise-all_1.0.bb                       | 9 ++-------
 .../ima_policy_hashed/ima-policy-hashed_1.0.bb           | 9 ++-------
 .../ima_policy_simple/ima-policy-simple_1.0.bb           | 9 ++-------
 6 files changed, 19 insertions(+), 23 deletions(-)
#5 lore raw
In reply to Ming Liu

merged.

thanks

Quoted 15 lines · On 4/18/21 11:41 PM, [email protected] wrote:

From: Ming Liu <[email protected]>

Ming Liu (3):
ima-evm-keys: add file-checksums to IMA_EVM_X509
meta: drop IMA_POLICY from policy recipes
initramfs-framework-ima: introduce IMA_FORCE

 .../initrdscripts/initramfs-framework-ima.bb             | 5 +++++
 .../initrdscripts/initramfs-framework-ima/ima            | 9 +++++++--
 .../recipes-security/ima-evm-keys/ima-evm-keys_1.0.bb    | 1 +
 .../ima-policy-appraise-all_1.0.bb                       | 9 ++-------
 .../ima_policy_hashed/ima-policy-hashed_1.0.bb           | 9 ++-------
 .../ima_policy_simple/ima-policy-simple_1.0.bb           | 9 ++-------
 6 files changed, 19 insertions(+), 23 deletions(-)