1755ca
From 9b1d79993dbed054c5069f97204280a39ed61219 Mon Sep 17 00:00:00 2001
1755ca
From: Lukas Nykryn <lnykryn@redhat.com>
1755ca
Date: Mon, 18 Dec 2017 14:48:59 +0100
1755ca
Subject: [PATCH] 01fips: Fix creating path to .hmac of kernel based on
1755ca
 BOOT_IMAGE
1755ca
1755ca
Old code did not work for two most common use-cases.
1755ca
On most machines BOOT_IMAGE is set to something like
1755ca
/vmlinuz-4.11.3-202.fc25.x86_64. So if we just add prefix "/boot/."
1755ca
it won't work. Also on machines without /boot on separate partition
1755ca
BOOT_IMAGE already has the /boot/ prefix (/boot/vmlinuz-3.10.0-799.el7.x86_64).
1755ca
So let's strip it in such case.
1755ca
1755ca
https://bugzilla.redhat.com/show_bug.cgi?id=1415032
1755ca
1755ca
Cherry-picked from: 8f5c564cb30966878b0d90025568253016e1402f
1755ca
Resolves: #1415032
1755ca
---
1755ca
 modules.d/01fips/fips.sh | 14 ++++++++++----
1755ca
 1 file changed, 10 insertions(+), 4 deletions(-)
1755ca
1755ca
diff --git a/modules.d/01fips/fips.sh b/modules.d/01fips/fips.sh
1755ca
index ecd711c2..6c5dd60f 100755
1755ca
--- a/modules.d/01fips/fips.sh
1755ca
+++ b/modules.d/01fips/fips.sh
1755ca
@@ -112,13 +112,19 @@ do_fips()
1755ca
         do_rhevh_check /run/initramfs/live/isolinux/vmlinuz0 || return 1
1755ca
     else
1755ca
         BOOT_IMAGE="$(getarg BOOT_IMAGE)"
1755ca
-        [ -e "/boot/.${BOOT_IMAGE}.hmac" ] || BOOT_IMAGE="vmlinuz-${KERNEL}"
1755ca
+        if ! [ -e "/boot/${BOOT_IMAGE}" ]; then
1755ca
+            #if /boot is not a separate partition BOOT_IMAGE might start with /boot
1755ca
+            BOOT_IMAGE=${BOOT_IMAGE#"/boot"}
1755ca
+            [ -e "/boot/${BOOT_IMAGE}" ] || BOOT_IMAGE="vmlinuz-${KERNEL}"
1755ca
+        fi
1755ca
+        
1755ca
+        BOOT_IMAGE_HMAC="/boot/${BOOT_IMAGE%/*}/.${BOOT_IMAGE##*/}.hmac"
1755ca
 
1755ca
-        if ! [ -e "/boot/.${BOOT_IMAGE}.hmac" ]; then
1755ca
-            warn "/boot/.${BOOT_IMAGE}.hmac does not exist"
1755ca
+        if ! [ -e "${BOOT_IMAGE_HMAC}" ]; then
1755ca
+            warn "${BOOT_IMAGE_HMAC} does not exist"
1755ca
             return 1
1755ca
         fi
1755ca
-        sha512hmac -c "/boot/.${BOOT_IMAGE}.hmac" || return 1
1755ca
+        sha512hmac -c "${BOOT_IMAGE_HMAC}" || return 1
1755ca
     fi
1755ca
 
1755ca
     info "All initrd crypto checks done"