* [PATCH ltp v4 1/3] IMA: Move check_policy_writable to ima_setup.sh and rename it
@ 2021-09-21 0:41 Alex Henrie
2021-09-21 0:41 ` [PATCH ltp v4 2/3] IMA: Move ima_check to ima_setup.sh Alex Henrie
2021-09-21 0:41 ` [PATCH ltp v4 3/3] IMA: Add tests for uid, gid, fowner, and fgroup options Alex Henrie
0 siblings, 2 replies; 4+ messages in thread
From: Alex Henrie @ 2021-09-21 0:41 UTC (permalink / raw)
To: linux-integrity, ltp, zohar, pvorel, alexhenrie24; +Cc: Alex Henrie
Signed-off-by: Alex Henrie <alexh@vpitech.com>
---
.../security/integrity/ima/tests/ima_policy.sh | 16 +++-------------
.../security/integrity/ima/tests/ima_setup.sh | 10 ++++++++++
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_policy.sh b/testcases/kernel/security/integrity/ima/tests/ima_policy.sh
index 244cf081d..8924549df 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_policy.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_policy.sh
@@ -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=$?
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index 565f0bc3e..9c25d634d 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -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"
--
2.33.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH ltp v4 2/3] IMA: Move ima_check to ima_setup.sh
2021-09-21 0:41 [PATCH ltp v4 1/3] IMA: Move check_policy_writable to ima_setup.sh and rename it Alex Henrie
@ 2021-09-21 0:41 ` Alex Henrie
2021-09-21 0:41 ` [PATCH ltp v4 3/3] IMA: Add tests for uid, gid, fowner, and fgroup options Alex Henrie
1 sibling, 0 replies; 4+ messages in thread
From: Alex Henrie @ 2021-09-21 0:41 UTC (permalink / raw)
To: linux-integrity, ltp, zohar, pvorel, alexhenrie24; +Cc: Alex Henrie
Signed-off-by: Alex Henrie <alexh@vpitech.com>
---
.../integrity/ima/tests/ima_measurements.sh | 28 -------------------
.../security/integrity/ima/tests/ima_setup.sh | 28 +++++++++++++++++++
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh b/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
index 1927e937c..807c5f57b 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
@@ -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
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index 9c25d634d..976c6a86c 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -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()
--
2.33.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH ltp v4 3/3] IMA: Add tests for uid, gid, fowner, and fgroup options
2021-09-21 0:41 [PATCH ltp v4 1/3] IMA: Move check_policy_writable to ima_setup.sh and rename it Alex Henrie
2021-09-21 0:41 ` [PATCH ltp v4 2/3] IMA: Move ima_check to ima_setup.sh Alex Henrie
@ 2021-09-21 0:41 ` Alex Henrie
2021-09-21 7:45 ` Petr Vorel
1 sibling, 1 reply; 4+ messages in thread
From: Alex Henrie @ 2021-09-21 0:41 UTC (permalink / raw)
To: linux-integrity, ltp, zohar, pvorel, alexhenrie24; +Cc: Alex Henrie
Requires "ima: add gid support".
Signed-off-by: Alex Henrie <alexh@vpitech.com>
---
v4:
- Put new tests in their own file
- Check for policy writability before each test instead of once before
all tests
---
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
diff --git a/runtest/ima b/runtest/ima
index 29caa034a..01942eefa 100644
--- a/runtest/ima
+++ b/runtest/ima
@@ -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
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh b/testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh
new file mode 100755
index 000000000..5eb8859b2
--- /dev/null
+++ b/testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 VPI Technology
+# Author: Alex Henrie <alexh@vpitech.com>
+#
+# Verify that conditional rules work.
+
+TST_NEEDS_CMDS="awk chgrp chown cut sg sudo"
+TST_CNT=1
+TST_NEEDS_DEVICE=1
+
+. ima_setup.sh
+
+test1()
+{
+ local user="nobody"
+
+ require_policy_writable
+ ROD rm -f $TEST_FILE
+ tst_res TINFO "verify measuring user files when requested via uid"
+ ROD echo "measure uid=$(id -u $user)" \> $IMA_POLICY
+ ROD echo "$(date) uid test" \> $TEST_FILE
+ sudo -n -u $user sh -c "cat $TEST_FILE > /dev/null"
+ ima_check
+
+ require_policy_writable
+ ROD rm -f $TEST_FILE
+ tst_res TINFO "verify measuring user files when requested via fowner"
+ ROD echo "measure fowner=$(id -u $user)" \> $IMA_POLICY
+ ROD echo "$(date) fowner test" \> $TEST_FILE
+ chown $user $TEST_FILE
+ cat $TEST_FILE > /dev/null
+ ima_check
+
+ if tst_kvcmp -lt 5.16; then
+ tst_brk TCONF "gid and fgroup options require kernel 5.16 or newer"
+ fi
+
+ require_policy_writable
+ ROD rm -f $TEST_FILE
+ tst_res TINFO "verify measuring user files when requested via gid"
+ ROD echo "measure gid=$(id -g $user)" \> $IMA_POLICY
+ ROD echo "$(date) gid test" \> $TEST_FILE
+ sudo sg $user "sh -c 'cat $TEST_FILE > /dev/null'"
+ ima_check
+
+ require_policy_writable
+ ROD rm -f $TEST_FILE
+ tst_res TINFO "verify measuring user files when requested via fgroup"
+ ROD echo "measure fgroup=$(id -g $user)" \> $IMA_POLICY
+ ROD echo "$(date) fgroup test" \> $TEST_FILE
+ chgrp $user $TEST_FILE
+ cat $TEST_FILE > /dev/null
+ ima_check
+}
+
+tst_run
--
2.33.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH ltp v4 3/3] IMA: Add tests for uid, gid, fowner, and fgroup options
2021-09-21 0:41 ` [PATCH ltp v4 3/3] IMA: Add tests for uid, gid, fowner, and fgroup options Alex Henrie
@ 2021-09-21 7:45 ` Petr Vorel
0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2021-09-21 7:45 UTC (permalink / raw)
To: Alex Henrie; +Cc: linux-integrity, ltp, zohar, alexhenrie24
Hi Alex,
...
> +++ b/testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh
> @@ -0,0 +1,57 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2021 VPI Technology
> +# Author: Alex Henrie <alexh@vpitech.com>
> +#
> +# Verify that conditional rules work.
> +
> +TST_NEEDS_CMDS="awk chgrp chown cut sg sudo"
awk, cut are not used. Or is that a dependency from some helpers in
ima_setup.sh? (these should check the dependency themselves via tst_require_cmds).
The rest LGTM, I just need to retest it.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-21 7:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-21 0:41 [PATCH ltp v4 1/3] IMA: Move check_policy_writable to ima_setup.sh and rename it Alex Henrie
2021-09-21 0:41 ` [PATCH ltp v4 2/3] IMA: Move ima_check to ima_setup.sh Alex Henrie
2021-09-21 0:41 ` [PATCH ltp v4 3/3] IMA: Add tests for uid, gid, fowner, and fgroup options Alex Henrie
2021-09-21 7:45 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).