[LTP] [PATCH] ima_kexec.sh: Use %s in printf to prevent evaluating cmdline backslashes

Avinesh Kumar avinesh.kumar@suse.com
Wed Apr 15 06:46:36 CEST 2026


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.

Signed-off-by: Avinesh Kumar <avinesh.kumar@suse.com>
---
 testcases/kernel/security/integrity/ima/tests/ima_kexec.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/security/integrity/ima/tests/ima_kexec.sh b/testcases/kernel/security/integrity/ima/tests/ima_kexec.sh
index 4732df653..bbc82f30c 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_kexec.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_kexec.sh
@@ -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
-- 
2.53.0



More information about the ltp mailing list