IMA: Move check_policy_writable to ima_setup.sh and rename it
PATCH v5 1/3 IMA: Move check_policy_writable to ima_setup.sh and rename it
--- .../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 v5 2/3 IMA: Move ima_check to ima_setup.sh
--- .../integrity/ima/tests/ima_measurements.sh | 28 ------------------- .../security/integrity/ima/tests/ima_setup.sh | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 28 deletions(-)
testcases/kernel/security/integrity/ima/tests/ima_measurements.sh +0 -28
@@ -17,38 +17,10 @@ setup() { require_ima_policy_cmdline "tcb" - TEST_FILE="$PWD/test.txt" POLICY="$IMA_DIR/policy" [ -f "$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
testcases/kernel/security/integrity/ima/tests/ima_setup.sh +28 -0
@@ -188,6 +188,7 @@ ima_setup() if [ "$TST_NEEDS_DEVICE" = 1 ]; then tst_res TINFO "\$TMPDIR is on tmpfs => run on loop device" mount_loop_device + TEST_FILE="$PWD/test.txt" fi [ -n "$TST_SETUP_CALLER" ] && $TST_SETUP_CALLER
@@ -279,6 +280,33 @@ get_algorithm_digest() echo "$algorithm|$digest" } +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_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
Re: [PATCH ltp v5 2/3] IMA: Move ima_check to ima_setup.sh
Quoted 54 lines
Signed-off-by Alex Henrie <[email protected]>--- .../integrity/ima/tests/ima_measurements.sh | 28 ------------------- .../security/integrity/ima/tests/ima_setup.sh | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 28 deletions(-)testcases/kernel/security/integrity/ima/tests/ima_measurements.sh +0
-28@@ -17,38 +17,10 @@ setup() { require_ima_policy_cmdline "tcb" - TEST_FILE="$PWD/test.txt" POLICY="$IMA_DIR/policy" [ -f "$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 fstestcases/kernel/security/integrity/ima/tests/ima_setup.sh +0
-0
testcases/kernel/security/integrity/ima/tests/ima_setup.sh ima_setup() · line 191
Quoted 4 lines
testcases/kernel/security/integrity/ima/tests/ima_setup.sh +1
-0@@ -188,6 +188,7 @@ ima_setup() if [ "$TST_NEEDS_DEVICE" = 1 ]; then tst_res TINFO "\$TMPDIR is on tmpfs => run on loop device" mount_loop_device + TEST_FILE="$PWD/test.txt"
This is wrong, it's causing error, unless you have $TMPDIR (usually /tmp) on tmpfs it's not defined and leads to error:
ima_measurements 1 TINFO: verify adding record to the IMA measurement listtst_rod: Missing filename after >ima_measurements 1 TBROK: echo Wed Sep 22 12:24:17 CEST 2021 this is a test file > failed
And even on tmpfs it fails (maybe caused by old kernel 3.10):
ima_measurements 1 TINFO: $TMPDIR is on tmpfs => run on loop deviceima_measurements 1 TINFO: Formatting /dev/loop0 with ext3 extra opts=''ima_measurements 1 TINFO: not using default policyima_measurements 1 TINFO: verify adding record to the IMA measurement listima_measurements 1 TBROK: failed to get algorithm/digest for '/tmp/LTP_ima_measurements.dLS7yCTHLY/mntpoint/test.txt': measurement record not found ima_measurements 1 TINFO: computing digest for algorithm
^
=> notice space - algorithm not detectedima_measurements 1 TCONF: cannot compute digest for algorithm
^
=> also here.
It's also wrong that $PWD is unique for each test and TMPDIR is removed after test, thus TEST_FILE will not exist for the second test (ima_conditionals.sh). Also, ima_setup(). Also, I put into ima_setup.sh IMA related variables. TEST_FILE is not that case thus I'd keep $TEST_FILE in ima_measurements.sh and define local test_file="$PWD/test.txt" in the only function in ima_conditionals.sh.
Also I intent do remove duplicity in ima_conditionals.sh, thus I'll send v6 in a minute.
Kind regards,
Petr
PATCH v5 3/3 IMA: Add tests for uid, gid, fowner, and fgroup options
In reply to Alex HenrieRequires "ima: add gid support".
---
v5: Omit awk and cut from TST_NEEDS_CMDS
--- runtest/ima | 1 + .../integrity/ima/tests/ima_conditionals.sh | 57 +++++++++++++++++++ 2 files changed, 58 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 +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.33.0