IMA: Move check_policy_writable() to ima_setup.sh and rename it
PATCH v7 1/3 IMA: Move check_policy_writable() to ima_setup.sh and rename it
Suggested-by Petr Vorel <[email protected]>
Reviewed-by Petr Vorel <[email protected]>
Signed-off-by Alex Henrie <[email protected]>
Signed-off-by Petr Vorel <[email protected]>
--- .../security/integrity/ima/tests/ima_policy.sh | 16 +++------------- .../security/integrity/ima/tests/ima_setup.sh | 10 ++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-)
testcases/kernel/security/integrity/ima/tests/ima_policy.sh +3 -13
@@ -11,19 +11,9 @@ TST_CNT=2 . ima_setup.sh -check_policy_writable() -{ - local err="IMA policy already loaded and kernel not configured to enable multiple writes to it (need CONFIG_IMA_WRITE_POLICY=y)" - - [ -f $IMA_POLICY ] || tst_brk TCONF "$err" - # CONFIG_IMA_READ_POLICY - echo "" 2> log > $IMA_POLICY - grep -q "Device or resource busy" log && tst_brk TCONF "$err" -} - setup() { - check_policy_writable + require_policy_writable VALID_POLICY="$TST_DATAROOT/measure.policy" [ -f $VALID_POLICY ] || tst_brk TCONF "missing $VALID_POLICY"
@@ -55,7 +45,7 @@ test1() local p1 - check_policy_writable + require_policy_writable load_policy $INVALID_POLICY & p1=$! wait "$p1" if [ $? -ne 0 ]; then
@@ -71,7 +61,7 @@ test2() local p1 p2 rc1 rc2 - check_policy_writable + require_policy_writable load_policy $VALID_POLICY & p1=$! load_policy $VALID_POLICY & p2=$! wait "$p1"; rc1=$?
testcases/kernel/security/integrity/ima/tests/ima_setup.sh +10 -0
@@ -73,6 +73,16 @@ require_policy_readable() fi } +require_policy_writable() +{ + local err="IMA policy already loaded and kernel not configured to enable multiple writes to it (need CONFIG_IMA_WRITE_POLICY=y)" + + [ -f $IMA_POLICY ] || tst_brk TCONF "$err" + # CONFIG_IMA_READ_POLICY + echo "" 2> log > $IMA_POLICY + grep -q "Device or resource busy" log && tst_brk TCONF "$err" +} + check_ima_policy_content() { local pattern="$1"
Signature · 1 line
2.33.0
PATCH v7 2/3 IMA: Move ima_check to ima_setup.sh
Reviewed-by Petr Vorel <[email protected]>
Signed-off-by Alex Henrie <[email protected]>
[ pvorel: add test_file parameter to ima_check(), keep $TEST_FILE in ima_measurements.sh ]
Signed-off-by Petr Vorel <[email protected]>
--- .../integrity/ima/tests/ima_measurements.sh | 31 ++----------------- .../security/integrity/ima/tests/ima_setup.sh | 28 +++++++++++++++++ 2 files changed, 30 insertions(+), 29 deletions(-)
testcases/kernel/security/integrity/ima/tests/ima_measurements.sh +2 -29
@@ -21,33 +21,6 @@ setup() [ -f "$IMA_POLICY" ] || tst_res TINFO "not using default policy" } -ima_check() -{ - local algorithm digest expected_digest line tmp - - # need to read file to get updated $ASCII_MEASUREMENTS - cat $TEST_FILE > /dev/null - - line="$(grep $TEST_FILE $ASCII_MEASUREMENTS | tail -1)" - - if tmp=$(get_algorithm_digest "$line"); then - algorithm=$(echo "$tmp" | cut -d'|' -f1) - digest=$(echo "$tmp" | cut -d'|' -f2) - else - tst_res TBROK "failed to get algorithm/digest for '$TEST_FILE': $tmp" - fi - - tst_res TINFO "computing digest for $algorithm algorithm" - expected_digest="$(compute_digest $algorithm $TEST_FILE)" || \ - tst_brk TCONF "cannot compute digest for $algorithm algorithm" - - if [ "$digest" = "$expected_digest" ]; then - tst_res TPASS "correct digest found" - else - tst_res TFAIL "digest not found" - fi -} - check_iversion_support() { local device mount fs
@@ -83,7 +56,7 @@ test1() { tst_res TINFO "verify adding record to the IMA measurement list" ROD echo "$(date) this is a test file" \> $TEST_FILE - ima_check + ima_check $TEST_FILE } test2()
@@ -92,7 +65,7 @@ test2() tst_res TINFO "verify updating record in the IMA measurement list" check_iversion_support || return ROD echo "$(date) modified file" \> $TEST_FILE - ima_check + ima_check $TEST_FILE } test3()
testcases/kernel/security/integrity/ima/tests/ima_setup.sh +28 -0
@@ -279,6 +279,34 @@ get_algorithm_digest() echo "$algorithm|$digest" } +ima_check() +{ + local test_file="$1" + local algorithm digest expected_digest line tmp + + # need to read file to get updated $ASCII_MEASUREMENTS + cat $test_file > /dev/null + + line="$(grep $test_file $ASCII_MEASUREMENTS | tail -1)" + + if tmp=$(get_algorithm_digest "$line"); then + algorithm=$(echo "$tmp" | cut -d'|' -f1) + digest=$(echo "$tmp" | cut -d'|' -f2) + else + tst_res TBROK "failed to get algorithm/digest for '$test_file': $tmp" + fi + + tst_res TINFO "computing digest for $algorithm algorithm" + expected_digest="$(compute_digest $algorithm $test_file)" || \ + tst_brk TCONF "cannot compute digest for $algorithm algorithm" + + if [ "$digest" = "$expected_digest" ]; then + tst_res TPASS "correct digest found" + else + tst_res TFAIL "digest not found" + fi +} + # check_evmctl REQUIRED_TPM_VERSION # return: 0: evmctl is new enough, 1: version older than required (or version < v0.9) check_evmctl()
Signature · 1 line
2.33.0
PATCH v7 3/3 IMA: Add tests for uid, gid, fowner, and fgroup options
In reply to Alex HenrieRequires "ima: add gid support".
Reviewed-by Petr Vorel <[email protected]>
Signed-off-by Alex Henrie <[email protected]>
[ pvorel: add test_file parameter to ima_check(), add verify_measurement() (DRY) ]
Signed-off-by Petr Vorel <[email protected]>
---
v7: Change "Copyright (c) 2021 VPI Technology" to "Copyright (c) 2021 VPI Engineering" per internal feedback from VPI
--- runtest/ima | 1 + .../integrity/ima/tests/ima_conditionals.sh | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh
runtest/ima +1 -0
@@ -6,4 +6,5 @@ ima_violations ima_violations.sh ima_keys ima_keys.sh ima_kexec ima_kexec.sh ima_selinux ima_selinux.sh +ima_conditionals ima_conditionals.sh evm_overlay evm_overlay.sh
testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.33.0