121229
From 9c54932f590fd7accadc780c6ee946a94286b7e6 Mon Sep 17 00:00:00 2001
121229
From: Lukas Nykryn <lnykryn@redhat.com>
121229
Date: Tue, 14 May 2019 09:23:55 +0200
121229
Subject: [PATCH] fips: split loading the crypto modules and checking the
121229
 kernel
121229
121229
In e54ab383 we moved the fips script to a later pahse of boot, since
121229
the /boot might not be available early on.
121229
121229
The problem is that systemd-cryptsetup* services could be run now
121229
started before the do_fips is executed and need the crypto modules
121229
to decrypted the devices.
121229
121229
So let's split the do_fips and load the module before udev does the
121229
trigger.
121229
---
121229
 modules.d/01fips/fips-load-crypto.sh |  8 ++++++++
121229
 modules.d/01fips/fips.sh             | 19 +++++++++++--------
121229
 modules.d/01fips/module-setup.sh     |  1 +
121229
 3 files changed, 20 insertions(+), 8 deletions(-)
121229
121229
diff --git a/modules.d/01fips/fips-load-crypto.sh b/modules.d/01fips/fips-load-crypto.sh
121229
new file mode 100644
121229
index 00000000..82cbeee4
121229
--- /dev/null
121229
+++ b/modules.d/01fips/fips-load-crypto.sh
121229
@@ -0,0 +1,8 @@
121229
+#!/bin/sh
121229
+
121229
+if ! fipsmode=$(getarg fips) || [ $fipsmode = "0" ]; then
121229
+    rm -f -- /etc/modprobe.d/fips.conf >/dev/null 2>&1
121229
+else
121229
+    . /sbin/fips.sh
121229
+    fips_load_crypto || die "FIPS integrity test failed"
121229
+fi
121229
diff --git a/modules.d/01fips/fips.sh b/modules.d/01fips/fips.sh
121229
index 9bc089f2..beaa692b 100755
121229
--- a/modules.d/01fips/fips.sh
121229
+++ b/modules.d/01fips/fips.sh
121229
@@ -69,15 +69,8 @@ do_rhevh_check()
121229
     return 0
121229
 }
121229
 
121229
-do_fips()
121229
+fips_load_crypto()
121229
 {
121229
-    local _v
121229
-    local _s
121229
-    local _v
121229
-    local _module
121229
-
121229
-    KERNEL=$(uname -r)
121229
-
121229
     FIPSMODULES=$(cat /etc/fipsmodules)
121229
 
121229
     info "Loading and integrity checking all crypto modules"
121229
@@ -102,6 +95,16 @@ do_fips()
121229
     info "Self testing crypto algorithms"
121229
     modprobe tcrypt || return 1
121229
     rmmod tcrypt
121229
+}
121229
+
121229
+do_fips()
121229
+{
121229
+    local _v
121229
+    local _s
121229
+    local _v
121229
+    local _module
121229
+
121229
+    KERNEL=$(uname -r)
121229
 
121229
     info "Checking integrity of kernel"
121229
     if [ -e "/run/initramfs/live/vmlinuz0" ]; then
121229
diff --git a/modules.d/01fips/module-setup.sh b/modules.d/01fips/module-setup.sh
121229
index f3af4d90..18186d62 100755
121229
--- a/modules.d/01fips/module-setup.sh
121229
+++ b/modules.d/01fips/module-setup.sh
121229
@@ -54,6 +54,7 @@ install() {
121229
     local _dir
121229
     inst_hook pre-trigger 01 "$moddir/fips-boot.sh"
121229
     inst_hook pre-pivot 01 "$moddir/fips-noboot.sh"
121229
+    inst_hook pre-udev 01 "$moddir/fips-load-crypto.sh"
121229
     inst_script "$moddir/fips.sh" /sbin/fips.sh
121229
 
121229
     inst_multiple sha512hmac rmmod insmod mount uname umount
121229