diff mbox series

[2/2] ima_setup.sh: Check 'cat' exit code when loading policy

Message ID 20250219181926.2620960-2-pvorel@suse.cz (mailing list archive)
State New
Headers show
Series [1/2] ima_setup.sh: Postpone loading policy after test setup | expand

Commit Message

Petr Vorel Feb. 19, 2025, 6:19 p.m. UTC
Parsing stderr should be enough, but check also 'cat' exit code
in case of error message change or other problem.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
New in v2.

 testcases/kernel/security/integrity/ima/tests/ima_setup.sh | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index 9732aa7b43..83fcefb4fc 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -209,6 +209,7 @@  verify_ima_policy()
 load_ima_policy()
 {
 	local file="$TST_DATAROOT/$REQUIRED_POLICY_CONTENT"
+	local ret
 
 	if [ "$LTP_IMA_LOAD_POLICY" != 1 ]; then
 		if [ "$IMA_MISSING_POLICY_CONTENT" = 1 ]; then
@@ -228,6 +229,7 @@  load_ima_policy()
 	fi
 
 	cat "$file" 2> log > $IMA_POLICY
+	ret=$?
 	if grep -q "Device or resource busy" log; then
 		tst_brk TBROK "loading policy failed"
 	fi
@@ -236,6 +238,10 @@  load_ima_policy()
 		tst_brk TCONF "loading unsigned policy failed"
 	fi
 
+	if [ $ret -ne 0 ]; then
+		tst_brk TBROK "loading policy failed"
+	fi
+
 	IMA_POLICY_LOADED=1
 
 	tst_res TINFO "example policy successfully loaded"