[LTP] [PATCH v5 1/2] IMA: Add a test to verify measurment of keys

Petr Vorel pvorel@suse.cz
Wed Jul 15 15:00:41 CEST 2020


Hi Lachlan, Mimi,

> Add a testcase that verifies that the IMA subsystem has correctly
> measured keys added to keyrings specified in the IMA policy file.

> Additionally, add support for handling a new IMA template descriptor,
> namely ima-buf[1], in the IMA measurement tests.

To speedup things, based on Mimi's comments and review of v4 I pushed this first
commit with few changes (below diff, only ima_keys.sh part)
* simplify error handling ($fail is not needed; I used tst_res and return
  because there will be second test, otherwise I'd use tst_brk)
* added modified docs into this commit
* fix commit title

TODO
* I'll send a patch to read CONFIG_IMA_X509_PATH (I've amended the commit
already enough)

* @Lachlan: expect you send another version for test2.

* @Lachlan: would you also implement Mimi's suggestion? [1]:
An additional test might be to verify that only the keys in the
measurement list are actually on the specified keyring and nothing
else.

Kind regards,
Petr

[1] http://lists.linux.it/pipermail/ltp/2020-July/018018.html

diff --git testcases/kernel/security/integrity/ima/tests/ima_keys.sh testcases/kernel/security/integrity/ima/tests/ima_keys.sh
index 4d53cd04f..904b7515b 100755
--- testcases/kernel/security/integrity/ima/tests/ima_keys.sh
+++ testcases/kernel/security/integrity/ima/tests/ima_keys.sh
@@ -15,7 +15,7 @@ TST_NEEDS_DEVICE=1
 # (450d0fd51564 - "IMA: Call workqueue functions to measure queued keys")
 test1()
 {
-	local keyrings keycheck_lines keycheck_line templates test_file="file.txt" fail
+	local keyrings keycheck_lines keycheck_line templates test_file="file.txt"
 
 	tst_res TINFO "verifying key measurement for keyrings and templates specified in IMA policy file"
 
@@ -57,15 +57,12 @@ test1()
 			tst_brk TCONF "cannot compute digest for $algorithm"
 
 		if [ "$digest" != "$expected_digest" ]; then
-			fail=1
 			tst_res TFAIL "incorrect digest was found for the ($keyring) keyring"
-			break
+			return
 		fi
 	done
 
-	if [ "$fail" ]; then
-		tst_res TPASS "specified keyrings were measured correctly"
-	fi
+	tst_res TPASS "specified keyrings were measured correctly"
 }
 
 tst_run


More information about the ltp mailing list