Blame SOURCES/0526-01fips-Properly-fix-creating-path-to-.hmac-of-kernel.patch

18971c
From 69a889ee675822102d04e99a25bdc92aa977263a Mon Sep 17 00:00:00 2001
18971c
From: Lukas Nykryn <lnykryn@redhat.com>
18971c
Date: Tue, 26 Dec 2017 12:18:47 +0100
18971c
Subject: [PATCH] 01fips: Properly fix creating path to .hmac of kernel based
18971c
 on BOOT_IMAGE
18971c
18971c
8f5c5 broke the case where BOOT_IMAGE is not set at all.
18971c
This code should handle following:
18971c
1) BOOT_IMAGE not set
18971c
2) BOOT_IMAGE set to something unrelated (s390)
18971c
3) BOOT_IMAGE=vmlinuz-4.14.7-300.fc27.x86_64
18971c
4) BOOT_IMAGE=/vmlinuz-4.14.7-300.fc27.x86_64
18971c
5) BOOT_IMAGE=/boot/vmlinuz-4.14.7-300.fc27.x86_64
18971c
6) BOOT_IMAGE=subdir/vmlinuz-4.14.7-300.fc27.x86_64
18971c
7) BOOT_IMAGE=/subdir/vmlinuz-4.14.7-300.fc27.x86_64
18971c
8) BOOT_IMAGE=/boot/subdir/vmlinuz-4.14.7-300.fc27.x86_64
18971c
18971c
https://bugzilla.redhat.com/show_bug.cgi?id=1415032
18971c
18971c
Cherry-picked from: d818986db485fc57a76a247a8475c3144acd33dc
18971c
Resolves: #1415032
18971c
---
18971c
 modules.d/01fips/fips.sh | 20 +++++++++++++++-----
18971c
 1 file changed, 15 insertions(+), 5 deletions(-)
18971c
18971c
diff --git a/modules.d/01fips/fips.sh b/modules.d/01fips/fips.sh
18971c
index 6c5dd60f..c72c1273 100755
18971c
--- a/modules.d/01fips/fips.sh
18971c
+++ b/modules.d/01fips/fips.sh
18971c
@@ -112,18 +112,28 @@ do_fips()
18971c
         do_rhevh_check /run/initramfs/live/isolinux/vmlinuz0 || return 1
18971c
     else
18971c
         BOOT_IMAGE="$(getarg BOOT_IMAGE)"
18971c
-        if ! [ -e "/boot/${BOOT_IMAGE}" ]; then
18971c
+        BOOT_IMAGE_NAME="${BOOT_IMAGE##*/}"
18971c
+        BOOT_IMAGE_PATH="${BOOT_IMAGE%${BOOT_IMAGE_NAME}}"
18971c
+
18971c
+        if [ -z "$BOOT_IMAGE_NAME" ]; then
18971c
+            BOOT_IMAGE_NAME="vmlinuz-${KERNEL}"
18971c
+        elif ! [ -e "/boot/${BOOT_IMAGE_PATH}/${BOOT_IMAGE}" ]; then
18971c
             #if /boot is not a separate partition BOOT_IMAGE might start with /boot
18971c
-            BOOT_IMAGE=${BOOT_IMAGE#"/boot"}
18971c
-            [ -e "/boot/${BOOT_IMAGE}" ] || BOOT_IMAGE="vmlinuz-${KERNEL}"
18971c
+            BOOT_IMAGE_PATH=${BOOT_IMAGE_PATH#"/boot"}
18971c
+            #on some achitectures BOOT_IMAGE does not contain path to kernel
18971c
+            #so if we can't find anything, let's treat it in the same way as if it was empty
18971c
+            if ! [ -e "/boot/${BOOT_IMAGE_PATH}/${BOOT_IMAGE_NAME}" ]; then
18971c
+                BOOT_IMAGE_NAME="vmlinuz-${KERNEL}"
18971c
+                BOOT_IMAGE_PATH=""
18971c
+            fi
18971c
         fi
18971c
-        
18971c
-        BOOT_IMAGE_HMAC="/boot/${BOOT_IMAGE%/*}/.${BOOT_IMAGE##*/}.hmac"
18971c
 
18971c
+        BOOT_IMAGE_HMAC="/boot/${BOOT_IMAGE_PATH}.${BOOT_IMAGE_NAME}.hmac"
18971c
         if ! [ -e "${BOOT_IMAGE_HMAC}" ]; then
18971c
             warn "${BOOT_IMAGE_HMAC} does not exist"
18971c
             return 1
18971c
         fi
18971c
+
18971c
         sha512hmac -c "${BOOT_IMAGE_HMAC}" || return 1
18971c
     fi
18971c