Blame SOURCES/0562-fips-split-loading-the-crypto-modules-and-checking-t.patch

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