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

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