Skip to contentSkip to conversation

Test cmdline measurement and IMA buffer passing through kexec

PATCH In review Lachlan Sneff 3 participants 10 messages Jul 2, 2020 – Jul 15, 2020 Keys-trusted

lore
Share & tools
lore
#0 lore raw

cover Test cmdline measurement and IMA buffer passing through kexec

This patchset adds two tests that verify that data is passed correctly through a kexec. Since the machine reboots several times when running these tests, they must be run standalone and cannot be run with runltp.

The first test verifies that the kernel command line is measured correctly when using kexec. The second test verifies that the IMA buffer is being passed through kexec correctly.

Support for passing the IMA buffer through kexec has only been upstreamed on powerpc so far, with a patchset in the process of being upstreamed for support on arm64. Therefore, the only architectures that the tests allow you to run them on (via uname -m) are ppc, ppc64, ppcle, ppc64le, and aarch64.

The tests have been verified on ARM64. Would appreciate if someone can execute the tests on a PowerPC machine and validate.

Lachlan Sneff (2):
IMA: Verify that the kernel cmdline is passed and measured correctly
through the kexec barrier.
IMA: Verify IMA buffer passing through the kexec barrier

 testcases/kexec/README.md     | 30 ++++++++++++++
 testcases/kexec/cmdline.sh    | 78 +++++++++++++++++++++++++++++++++++
 testcases/kexec/ima_buffer.sh | 42 +++++++++++++++++++
 testcases/kexec/utils.sh      | 47 +++++++++++++++++++++
 4 files changed, 197 insertions(+)
 create mode 100644 testcases/kexec/README.md
 create mode 100755 testcases/kexec/cmdline.sh
 create mode 100755 testcases/kexec/ima_buffer.sh
 create mode 100755 testcases/kexec/utils.sh
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 IMA: Verify that the kernel cmdline is passed and measured correctly through the kexec barrier.

Add a testcase that verifies that kexec correctly logs the kernel command line to the IMA buffer and that the command line is then correctly measured.

This test must be run standalone, since it runs kexec multiple times (and therefore reboots several times).

---
 testcases/kexec/README.md  | 26 +++++++++++++
 testcases/kexec/cmdline.sh | 78 ++++++++++++++++++++++++++++++++++++++
 testcases/kexec/utils.sh   | 47 +++++++++++++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 testcases/kexec/README.md
 create mode 100755 testcases/kexec/cmdline.sh
 create mode 100755 testcases/kexec/utils.sh
testcases/kexec/README.md new file +26 -0
new file mode 100644
index 000000000..42988cd7b
@@ -0,0 +1,26 @@
+# IMA + Kexec Tests
+
+Since these tests cannot be run by the usual LTP machinery (runltp, etc)
+because the machine you run these on will reboot several times, these
+tests must be run standalone.
+
+To run these tests, you must first copy over either the entire LTP repo, or
+just the `testcases/kexec` directory.
+
+You must supply a kernel image that will be passed to kexec, either
+though the `IMAGE` environment variable, or placed at `testcases/kexec/Image`.
+
+If the kernel is built to require signed kernel images, you must supply
+a signed image.
+
+Currently, the only arch that has support in the upstream kernel to pass
+the IMA buffer through kexec is powerpc. A patchset that adds support for
+IMA buffer passing through kexec on aarch64 is in the process of being
+upstreamed. Therefore, these tests will not let you run them on
+architectures other than powerpc or aarch64.
+
+Running
+-------
+- kexec cmdline measurement
+    1. `IMAGE=<path to kernel image> testcases/kexec/cmdline.sh start`
+    2. Runtime logs will be emitted in `testcases/kexec/kexec_cmdline.log`.
testcases/kexec/cmdline.sh new file +78 -0

78 lines not on this page · raw message

testcases/kexec/utils.sh new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH 1/2] IMA: Verify that the kernel cmdline is passed and measured correctly through the kexec barrier.

Quoted 6 lines · Lachlan Sneff

Add a testcase that verifies that kexec correctly logs the kernel command line to the IMA buffer and that the command line is then correctly measured.

This test must be run standalone, since it runs kexec multiple times (and therefore reboots several times).

Verifying the kexec boot command line doesn't require rebooting. ?Just loading the kexec kernel image should be enough (kexec -s -l). ?Verifying that the measurement list, including the kexec boot command line, is carried across kexec could be a separate test.

Mimi

#3 lore raw

Re: [PATCH 1/2] IMA: Verify that the kernel cmdline is passed and measured correctly through the kexec barrier.

Quoted 5 lines · Lachlan Sneff
Quoted 3 lines

Add a testcase that verifies that kexec correctly logs the kernel command line to the IMA buffer and that the command line is then correctly measured.

Quoted 7 lines
Quoted 2 lines

This test must be run standalone, since it runs kexec multiple times (and therefore reboots several times).

Verifying the kexec boot command line doesn't require rebooting. ?Just loading the kexec kernel image should be enough (kexec -s -l). ?Verifying that the measurement list, including the kexec boot command line, is carried across kexec could be a separate test.

Mimi, thanks for a confirmation.
Lachlan, so is it possible to turn it as a normal LTP test? And the test looks like IMA specific now, thus I'd move it into IMA tests.

I'll post some comments to the test itself.

Kind regards,
Petr

#4 lore raw

Re: [PATCH 1/2] IMA: Verify that the kernel cmdline is passed and measured correctly through the kexec barrier.

In reply to Mimi Zohar
Quoted 11 lines · Mimi Zohar
Quoted 6 lines · Lachlan Sneff

Add a testcase that verifies that kexec correctly logs the kernel command line to the IMA buffer and that the command line is then correctly measured.

This test must be run standalone, since it runs kexec multiple times (and therefore reboots several times).

Verifying the kexec boot command line doesn't require rebooting. ?Just loading the kexec kernel image should be enough (kexec -s -l).
?Verifying that the measurement list, including the kexec boot command
line, is carried across kexec could be a separate test.

This is true. However, it only appends to the IMA log once, even if you unload (kexec -u) the kexec kernel after kexec -s -l ....

Therefore, the test would only be able to check kexec with the cmdline supplied in one way.

I will have to check internally if that's the right way to go. If it didn't need to reboot, then the test could be integrated into the normal IMA tests,
which would definitely be a good thing.

Regards,

Lachlan

maintainer
#5 lore raw

Re: [PATCH 1/2] IMA: Verify that the kernel cmdline is passed and measured correctly through the kexec barrier.

Quoted 16 lines · Lachlan Sneff
Quoted 11 lines · Mimi Zohar
Quoted 6 lines · Lachlan Sneff

Add a testcase that verifies that kexec correctly logs the kernel command line to the IMA buffer and that the command line is then correctly measured.

This test must be run standalone, since it runs kexec multiple times (and therefore reboots several times).

Verifying the kexec boot command line doesn't require rebooting. ?Just loading the kexec kernel image should be enough (kexec -s -l).
?Verifying that the measurement list, including the kexec boot command
line, is carried across kexec could be a separate test.

This is true. However, it only appends to the IMA log once, even if you unload (kexec -u) the kexec kernel after kexec -s -l ....

Quoted 7 lines

Therefore, the test would only be able to check kexec with the cmdline supplied in one way.

I will have to check internally if that's the right way to go. If it didn't need to reboot, then the test could be integrated into the normal IMA tests,
which would definitely be a good thing.

For files, there is a single measurement unless the file changes. I would assume that would be the same for the kexec command line as well. ?You could modify the command line a bit to force it to be re- measured.

Mimi

#6 lore raw

Re: [PATCH 1/2] IMA: Verify that the kernel cmdline is passed and measured correctly through the kexec barrier.

In reply to Lachlan Sneff
Quoted 8 lines

Add a testcase that verifies that kexec correctly logs the kernel command line to the IMA buffer and that the command line is then correctly measured.

This test must be run standalone, since it runs kexec multiple times (and therefore reboots several times).

...

testcases/kexec/utils.sh line 8

Quoted 10 lines

+++ b/testcases/kexec/utils.sh

testcases/kexec/utils.sh new file +8 -0
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+install() {
+    local arg="$1"
+
+    if [ ! -d "/etc/init.d" ]; then
+        mkdir /etc/init.d
+    fi

I'm not sure if tests like this are suitable for LTP.
Ideal LTP test is a normal test, which is able to run with runltp, cleanup after itself and use LTP C or/and shell API. LTP is full of tests which needs special handling and thus not being run, not sure if it's a good idea to introduce yet another one.

Also test shouldn't not significantly modify SUT to make it unbootable, which I'm not sure in this case. This is a big difference to kselftests which are meant to help during kernel development which somehow expects some system modifications (as you install your custom build kernel).

I wonder if using QEMU would help to implement this test while not touching SUT (thus be able to run this test with runltp). If you miss something in LTP API just let us know.

Kind regards,
Petr

#7 lore raw

Re: [PATCH 1/2] IMA: Verify that the kernel cmdline is passed and measured correctly through the kexec barrier.

Quoted 16 lines · Petr Vorel

testcases/kexec/utils.sh line 8

Quoted 10 lines

+++ b/testcases/kexec/utils.sh

testcases/kexec/utils.sh new file +8 -0
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+install() {
+    local arg="$1"
+
+    if [ ! -d "/etc/init.d" ]; then
+        mkdir /etc/init.d
+    fi

I'm not sure if tests like this are suitable for LTP.
Ideal LTP test is a normal test, which is able to run with runltp, cleanup after itself and use LTP C or/and shell API. LTP is full of tests which needs special handling and thus not being run, not sure if it's a good idea to introduce yet another one.

Quoted 8 lines

Also test shouldn't not significantly modify SUT to make it unbootable, which I'm not sure in this case. This is a big difference to kselftests which are meant to help during kernel development which somehow expects some system modifications (as you install your custom build kernel).

I wonder if using QEMU would help to implement this test while not touching SUT (thus be able to run this test with runltp). If you miss something in LTP API just let us know.

Using qemu is an interesting idea, but would be difficult to generalize.

I actually do agree with you that a test like this may not be appropriate for
LTP since it's so separate and alien to the rest of the LTP suite.

I need to confirm internally before I make a decision here, but is there a better place to put a test like this?

Thanks for your review,

Lachlan :)

#8 lore raw

PATCH 2/2 IMA: Verify IMA buffer passing through the kexec barrier

In reply to Lachlan Sneff

Add a testcase that verifies that kexec correctly passes the IMA buffer through the soft reboot.

This test must be run standalone, since it runs kexec.

---
 testcases/kexec/README.md     |  4 ++++
 testcases/kexec/ima_buffer.sh | 42 +++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100755 testcases/kexec/ima_buffer.sh
testcases/kexec/README.md +4 -0
index 42988cd7b..f4018387e 100644
@@ -24,3 +24,7 @@ Running
 - kexec cmdline measurement
     1. `IMAGE=<path to kernel image> testcases/kexec/cmdline.sh start`
     2. Runtime logs will be emitted in `testcases/kexec/kexec_cmdline.log`.
+
+- kexec ima buffer passing
+    1. `IMAGE=<path to kernel image> testcases/kexec/ima_buffer.sh start`
+    2. Runtime logs will be emitted in `testcases/kexec/kexec_ima_buffer.log`.
testcases/kexec/ima_buffer.sh new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#9 lore raw

Re: [PATCH 2/2] IMA: Verify IMA buffer passing through the kexec barrier

Quoted 6 lines · Lachlan Sneff

Add a testcase that verifies that kexec correctly passes the IMA buffer through the soft reboot.

This test must be run standalone, since it runs kexec.

Depending on the policy, the measurement list could be exactly the same from one boot to the next. ?This test simply checks that the first N number of measurements are the same. ?It doesn't verify that there are additional measurements, nor does it check that there is an additional "boot_aggregate" after the kexec. ?At minimum the test should verify the existence of multiple "boot_aggregate" values in the measurement list.

A more complete test would walk the measurement list, re-calculating the PCR digests, and then compare the recalculated PCRS against the TPM PCRs. ?If all the measurements were properly carried across the kexec, the PCR digests should match.

Mimi