Skip to contentSkip to conversation

tst_security.sh: Use enforce toggle to trigger SELinux measurement

PATCH Superseded Avinesh Kumar via ltp 2 participants 8 messages Jun 12 – Jun 30

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tst_security.sh: Use enforce toggle to trigger SELinux measurement

Upstream kernel commit
644132a48f4e ("selinux: prune /sys/fs/selinux/checkreqprot") [0] removed the selinux_ima_measure_state() call from the checkreqprot write handler.
This broke tst_update_selinux_state() which relied on writing to checkreqprot to trigger IMA measurements of SELinux state.

Switch to toggling the enforce value instead, which still triggers selinux_ima_measure_state() on all kernel versions >= 5.12.

[0] https://github.com/torvalds/linux/commit/644132a48f4e28a1d949d162160869286f3e75de

---
 testcases/lib/tst_security.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
testcases/lib/tst_security.sh +5 -2
index 820736c72..e9f7147e3 100644
@@ -146,6 +146,9 @@ tst_update_selinux_state()
 	local dir=$(tst_get_selinux_dir)
 	[ -n "$dir" ] || return 1
 
-	val=$(cat $dir/checkreqprot)
-	echo $val > $dir/checkreqprot
+	# Toggle enforce to trigger SELinux state measurement
+	orig_val=$(cat $dir/enforce)
+	val=$((1 - orig_val))
+	echo $val > $dir/enforce
+	echo $orig_val > $dir/enforce
 }
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Avinesh,

testcases/lib/tst_security.sh tst_update_selinux_state() · line 153

Quoted 6 lines · Avinesh Kumar

tst_security.sh: Use enforce toggle to trigger SELinux measurement

testcases/lib/tst_security.sh +4 -0
+	orig_val=$(cat $dir/enforce)
+	val=$((1 - orig_val))
+	echo $val > $dir/enforce
+	echo $orig_val > $dir/enforce

orig_val is not declared local, unlike val and dir in the same function. This leaks orig_val into the caller's scope.

Should the declaration on line 145 be:

local val orig_val

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 1/1 tst_security.sh: Use enforce toggle to trigger SELinux measurement

Upstream kernel commit
644132a48f4e ("selinux: prune /sys/fs/selinux/checkreqprot") [0] removed the selinux_ima_measure_state() call from the checkreqprot write handler.
This broke tst_update_selinux_state() which relied on writing to checkreqprot to trigger IMA measurements of SELinux state.

Switch to toggling the enforce value instead, which still triggers selinux_ima_measure_state() on all kernel versions >= 5.12.

[0] https://github.com/torvalds/linux/commit/644132a48f4e28a1d949d162160869286f3e75de

---
 testcases/lib/tst_security.sh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
testcases/lib/tst_security.sh +6 -3
index 820736c72..8c23bc5a0 100644
@@ -142,10 +142,13 @@ tst_get_enforce()
 
 tst_update_selinux_state()
 {
-	local val
+	local val orig_val
 	local dir=$(tst_get_selinux_dir)
 	[ -n "$dir" ] || return 1
 
-	val=$(cat $dir/checkreqprot)
-	echo $val > $dir/checkreqprot
+	# Toggle enforce to trigger SELinux state measurement
+	orig_val=$(cat $dir/enforce)
+	val=$((1 - orig_val))
+	echo $val > $dir/enforce
+	echo $orig_val > $dir/enforce
 }
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Avinesh,

Quoted 1 line · Avinesh Kumar

tst_security.sh: Use enforce toggle to trigger SELinux measurement

Verdict - Reviewed

Pre-existing issue (not introduced by this patch):

tst_disable_selinux() at line 122 uses "cat 0 > $f", which tries to read a file named "0" rather than writing the value 0 to the enforce file. This should be "echo 0 > $f".

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
In reply to Avinesh Kumar via ltp

Hi Avinesh,

The patch looks good. For some reason we didn't receive the agent review which spotted a bug in the test as well. I think this is wroth to fix on a separate patch as well. WDYT?

---
Pre-existing issue (not introduced by this patch):

tst_disable_selinux() at line 122 uses "cat 0 > $f", which tries to read a file named "0" rather than writing the value 0 to the enforce file. This should be "echo 0 > $f".

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Hi Andrea,

Quoted 6 lines · Andrea Cervesato via ltp

Hi Avinesh,

The patch looks good. For some reason we didn't receive the agent review which spotted a bug in the test as well. I think this is wroth to fix on a separate patch as well. WDYT?

Thank you for the review.
I have sent that fix here - https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Regards,
Avinesh

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp