Skip to contentSkip to conversation

ima_kexec.sh: Use %s in printf to prevent evaluating cmdline backslashes

PATCH In review Avinesh Kumar via ltp 3 participants 3 messages Apr 15 – Apr 16

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ima_kexec.sh: Use %s in printf to prevent evaluating cmdline backslashes

On systemd-boot systems, the kernel command line contains EFI paths with backslashes (e.g., initrd=\opensuse...\6.19...).

Writing this to a file using printf "$cmdline" inadvertently evaluates these backslashes as escape sequences, corrupting the expected digest and causing a false test failure:

+ printf 'initrd=\opensuse-tumbleweed\6.19.11-1-default\initrd-...'
+ cat -v file1 initrd=\opensuse-tumbleweed^F.19.11-1-default\initrd-...

ima_kexec 1 TINFO: testing kexec -s -l /boot/Image-6.19.11-1-default --reuse-cmdline ima_kexec 1 TFAIL: unable to find a correct measurement

Fix this by using printf "%s" "$cmdline" to ensure the command line is treated as literal data.

---
 testcases/kernel/security/integrity/ima/tests/ima_kexec.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/security/integrity/ima/tests/ima_kexec.sh +1 -1
index 4732df653..bbc82f30c 100755
@@ -24,7 +24,7 @@ measure()
 	local cmdline="$1"
 	local algorithm digest expected_digest found
 
-	printf "$cmdline" > file1
+	printf "%s" "$cmdline" > file1
 	grep "kexec-cmdline" $ASCII_MEASUREMENTS > file2
 
 	while read found
Signature · 5 lines
2.53.0


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

Hi Avinesh,

testcases/kernel/security/integrity/ima/tests/ima_kexec.sh measure() · line 27

Quoted 4 lines · Avinesh Kumar

ima_kexec.sh: Use %s in printf to prevent evaluating cmdline backslashes

testcases/kernel/security/integrity/ima/tests/ima_kexec.sh +1 -1
-       printf "$cmdline" > file1
+       printf "%s" "$cmdline" > file1

Fix is correct. Please add a Fixes: tag pointing to the commit that introduced printf "$cmdline".

---
Note:

Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/24437929854

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
In reply to Avinesh Kumar via ltp

Hi Avinesh,

Quoted 11 lines

On systemd-boot systems, the kernel command line contains EFI paths with backslashes (e.g., initrd=\opensuse...\6.19...).

Writing this to a file using printf "$cmdline" inadvertently evaluates these backslashes as escape sequences, corrupting the expected digest and causing a false test failure:

+ printf 'initrd=\opensuse-tumbleweed\6.19.11-1-default\initrd-...'
+ cat -v file1 initrd=\opensuse-tumbleweed^F.19.11-1-default\initrd-...

Quoted 5 lines

ima_kexec 1 TINFO: testing kexec -s -l /boot/Image-6.19.11-1-default --reuse-cmdline ima_kexec 1 TFAIL: unable to find a correct measurement

Fix this by using printf "%s" "$cmdline" to ensure the command line is treated as literal data.

Thanks a lot, merged!

Kind regards,
Petr

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