IMA: Add test for kexec cmdline measurement
PATCH v3 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
@@ -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
@@ -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
Hi,
...
Quoted 9 lines
+++
b/testcases/kernel/security/integrity/ima/tests/ima_kexec.shtestcases/kernel/security/integrity/ima/tests/ima_kexec.sh new file +7
-0@@ -0,0 +1,121 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2020 Microsoft Corporation +# Author: Lachlan Sneff <[email protected]> +# +# Verify that kexec cmdline is measured correctly. +
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh line 17
Quoted 10 lines
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh new file +10
-0+TST_NEEDS_CMDS="kexec sed xargs printf grep tr" +TST_CNT=1 +TST_NEEDS_DEVICE=1 + +. ima_setup.sh + +# Since the test is executed inside some sort of +# separate shell, *most* environment variables are +# not accessible, so there's no way to set it from +# the outside.
Do you mean that using this will not work? IMA_KEXEC_IMAGE="${IMA_KEXEC_IMAGE:-/boot/vmlinuz-$(uname -r)}"
I don't understand that as I'm able to set variables even I run some tests in dracut.
Also writing same docs doc on 2 places is not good. High level info should go to README.md, implementation details to shell script.
Please hold on with posting new version. I have several fixes, thus I'd like to send it after we sort this (trying to save you time).
Kind regards,
Petr
Hi Petr,
Thank you for reviewing
Quoted 18 lines · Petr Vorel
Hi,
...
Quoted 15 lines
+++
b/testcases/kernel/security/integrity/ima/tests/ima_kexec.shtestcases/kernel/security/integrity/ima/tests/ima_kexec.sh new file +13
-0@@ -0,0 +1,121 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2020 Microsoft Corporation +# Author: Lachlan Sneff <[email protected]> +# +# Verify that kexec cmdline is measured correctly. + +TST_NEEDS_CMDS="kexec sed xargs printf grep tr" +TST_CNT=1 +TST_NEEDS_DEVICE=1 + +. ima_setup.sh +
Quoted 8 lines
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh line 17
Quoted 4 lines
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh new file +4
-0+# Since the test is executed inside some sort of +# separate shell, *most* environment variables are +# not accessible, so there's no way to set it from +# the outside.Do you mean that using this will not work? IMA_KEXEC_IMAGE="${IMA_KEXEC_IMAGE:-/boot/vmlinuz-$(uname -r)}"
I don't understand that as I'm able to set variables even I run some tests in dracut.
I tried doing this in the past, and couldn't get it to work, but I just tried it again
and was able to get it working. Essentially, what I tried before was SOME_VAR="..." sudo runltp ..., which doesn't work, but sudo SOME_VAR="..." runltp does pass the variable
to the test. So, that should be added to this patch.
Quoted 3 lines
Also writing same docs doc on 2 places is not good. High level info should go to README.md, implementation details to shell script.
This is a good point. I'll reorganize the documentation of this patch.
Quoted 2 lines
Please hold on with posting new version. I have several fixes, thus I'd like to send it after we sort this (trying to save you time).
Okay :)
Quoted 2 lines
Kind regards,
Petr
Thanks,
Lachlan
Quoted 2 lines
Hi Petr,
Thank you for reviewing
Thanks for your time as well :).
Quoted 27 lines · Petr Vorel
Quoted 18 lines
Hi,
...
Quoted 15 lines
+++
b/testcases/kernel/security/integrity/ima/tests/ima_kexec.shtestcases/kernel/security/integrity/ima/tests/ima_kexec.sh new file +13
-0@@ -0,0 +1,121 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2020 Microsoft Corporation +# Author: Lachlan Sneff <[email protected]> +# +# Verify that kexec cmdline is measured correctly. + +TST_NEEDS_CMDS="kexec sed xargs printf grep tr" +TST_CNT=1 +TST_NEEDS_DEVICE=1 + +. ima_setup.sh +Quoted 8 lines
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh line 17
Quoted 4 lines
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh new file +4
-0+# Since the test is executed inside some sort of +# separate shell, *most* environment variables are +# not accessible, so there's no way to set it from +# the outside.Do you mean that using this will not work? IMA_KEXEC_IMAGE="${IMA_KEXEC_IMAGE:-/boot/vmlinuz-$(uname -r)}"
I don't understand that as I'm able to set variables even I run some tests in dracut.
Quoted 6 lines
I tried doing this in the past, and couldn't get it to work, but I just tried it again
and was able to get it working. Essentially, what I tried before wasSOME_VAR="..." sudo runltp ..., which doesn't work, butsudo SOME_VAR="..." runltpdoes pass the variable
to the test. So, that should be added to this patch.
OK, so no any dracut / initramfs involved :).
Passing variables really works as expected, you need to export it first:
$ sudo su # export IMA_KEXEC_IMAGE=/tmp/foo # PATH="/opt/ltp/testcases/bin:$PATH" runltp ...
or just run the script directly:
$ sudo su # IMA_KEXEC_IMAGE=/tmp/foo PATH="/opt/ltp/testcases/bin:$PATH" ima_kexec.sh
Quoted 10 lines
Quoted 2 lines
Also writing same docs doc on 2 places is not good. High level info should go to README.md, implementation details to shell script.
This is a good point. I'll reorganize the documentation of this patch.
Quoted 2 lines
Please hold on with posting new version. I have several fixes, thus I'd like to send it after we sort this (trying to save you time).
Okay :)
Quoted 2 lines
Kind regards,
PetrThanks,
Lachlan
Kind regards,
Petr