Skip to contentSkip to conversation

IMA: Add test for kexec cmdline measurement

PATCH Superseded Lachlan Sneff 3 participants 4 messages Jul 22, 2020 Keys-trusted

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 IMA: Add test for kexec cmdline measurement

IMA policy can be set to measure the command line passed in the kexec system call. There needs to be a test to validate this kexec command line measurement.

Add a testcase that verifies that the IMA subsystem has correctly measured the cmdline specified during a kexec.

Note that this test does not actually reboot.

---
 runtest/ima                                   |   1 +
 .../kernel/security/integrity/ima/README.md   |  11 ++
 .../security/integrity/ima/tests/ima_kexec.sh | 121 ++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 testcases/kernel/security/integrity/ima/tests/ima_kexec.sh
runtest/ima +1 -0
index 309d47420..5f4b4a7a1 100644
@@ -4,4 +4,5 @@ ima_policy ima_policy.sh
 ima_tpm ima_tpm.sh
 ima_violations ima_violations.sh
 ima_keys ima_keys.sh
+ima_kexec ima_kexec.sh
 evm_overlay evm_overlay.sh
testcases/kernel/security/integrity/ima/README.md +11 -0
index db8819a99..926eb8478 100644
@@ -30,6 +30,17 @@ measure func=KEY_CHECK keyrings=key_import_test template=ima-buf
 
 The test also requires loaded policy with `func=KEY_CHECK`, see example in `keycheck.policy`.
 
+### IMA kexec test
+
+This test requires that the ima policy contains:
+```
+measure func=KEXEC_CMDLINE
+```
+
+Even though the test does not actually reboot, it does require a valid,
+signed kernel image. By default, the test will look in `/boot/vmlinuz-$(uname r)`,
+but if no image is accessible there, a valid image be must be placed at `/tmp/Image`.
+
 ## EVM tests
 
 `evm_overlay.sh` requires a builtin IMA appraise tcb policy (e.g. `ima_policy=appraise_tcb`
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Lachlan Sneff

IMA policy can be set to measure the command line passed in the kexec system call. There needs to be a test to validate this kexec command line measurement.

Add a testcase that verifies that the IMA subsystem has correctly measured the cmdline specified during a kexec.

Note that this test does not actually reboot.

Other than the patch not applying cleanly and leading blanks,?

#2 lore raw
Quoted 7 lines · Mimi Zohar
Quoted 6 lines · Lachlan Sneff

IMA policy can be set to measure the command line passed in the kexec system call. There needs to be a test to validate this kexec command line measurement.

Add a testcase that verifies that the IMA subsystem has correctly measured the cmdline specified during a kexec.

Quoted 7 lines
Quoted 3 lines

Note that this test does not actually reboot.

Other than the patch not applying cleanly and leading blanks,?

Oops, the kexec load is using the '-s' option, similarly the unload should use it too. ?Please change all the "kexec -u" occurences to "kexec -su".

+ if ! kexec -sl $IMAGE --reuse-cmdline; then

Quoted 34 lines
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh new file +34 -0
+        tst_res TCONF "kexec failed: $?"
+        
+        local sb_status="$(bootctl status 2>/dev/null | grep 'Secure Boot' \
+            | tr -d ' ' | sed 's/SecureBoot:*//')"
+        
+        if [ "$sb_status" = "enabled" ]; then
+            tst_res TINFO "secure boot is enabled, the specified kernel image may not be signed"
+        fi
+
+        return
+    fi
+
+    kexec -u
+
+    if ! measure "$cmdline"; then
+        tst_res TFAIL "unable to find a correct entry in the IMA log"
+        
+        if [ ! -r $IMA_POLICY ]; then
+            tst_brk TCONF "cannot read IMA policy (CONFIG_IMA_READ_POLICY=y required) to give contextual information"
+        fi
+
+        if ! grep "measure func=KEXEC_CMDLINE" $IMA_POLICY >/dev/null; then
+            tst_brk TCONF "The IMA policy does not specify 'measure func=KEXEC_CMDLINE', see IMA test README"
+        fi
+
+        return
+    fi
+
+    cmdline="foo"cmldine
+    if ! kexec -sl $IMAGE --append=$cmdline; then
+        tst_brk TCONF "kexec failed: $?"
+    fi
+
+    kexec -u
#3 lore raw
In reply to Mimi Zohar

Thank you for signing off on this patch!

I apologize for the issues on applying. I should've caught the trailing spaces, but the inability to apply the README
is actually a result of this patch being based on the custom keyring patch that I sent out last Friday [1].

[1]: [PATCH] IMA: Add a test to verify importing a certificate into custom keyring

Quoted 13 lines · Mimi Zohar
Quoted 9 lines · Lachlan Sneff

IMA policy can be set to measure the command line passed in the kexec system call. There needs to be a test to validate this kexec command line measurement.

Add a testcase that verifies that the IMA subsystem has correctly measured the cmdline specified during a kexec.

Note that this test does not actually reboot.

Other than the patch not applying cleanly and leading blanks,