Harald Hoyer 2e4662
From 6f4c2dada400f455cf7ee0afcd6bf41974c712d4 Mon Sep 17 00:00:00 2001
Harald Hoyer 2e4662
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 2e4662
Date: Thu, 25 Apr 2013 19:44:01 +0200
Harald Hoyer 2e4662
Subject: [PATCH] fixed fips mode
Harald Hoyer 2e4662
Harald Hoyer 2e4662
- preserve timestamps
Harald Hoyer 2e4662
- copy /lib*/hmaccalc files
Harald Hoyer 2e4662
- run sha512hmac after kernel module loading
Harald Hoyer 2e4662
- add more fips kernel modules
Harald Hoyer 2e4662
---
Harald Hoyer 2e4662
 dracut.sh                        |  2 ++
Harald Hoyer 2e4662
 install/dracut-install.c         | 10 +++++++++-
Harald Hoyer 2e4662
 modules.d/01fips/fips.sh         |  7 ++++---
Harald Hoyer 2e4662
 modules.d/01fips/module-setup.sh |  8 +++++---
Harald Hoyer 2e4662
 modules.d/99base/dracut-lib.sh   |  2 +-
Harald Hoyer 2e4662
 5 files changed, 21 insertions(+), 8 deletions(-)
Harald Hoyer 2e4662
Harald Hoyer 2e4662
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer 2e4662
index 586172c..82b4a5f 100755
Harald Hoyer 2e4662
--- a/dracut.sh
Harald Hoyer 2e4662
+++ b/dracut.sh
Harald Hoyer 2e4662
@@ -1179,6 +1179,8 @@ if [[ $do_strip = yes ]] ; then
Harald Hoyer 2e4662
             -executable -not -path '*/lib/modules/*.ko' -print0 \
Harald Hoyer 2e4662
             | while read -r -d $'\0' f; do
Harald Hoyer 2e4662
             if ! [[ -e "${f%/*}/.${f##*/}.hmac" ]] \
Harald Hoyer 2e4662
+                && ! [[ -e "/lib/hmaccalc/${f##*/}.hmac" ]] \
Harald Hoyer 2e4662
+                && ! [[ -e "/lib64/hmaccalc/${f##*/}.hmac" ]] \
Harald Hoyer 2e4662
                 && ! [[ -e "/lib/fipscheck/${f##*/}.hmac" ]] \
Harald Hoyer 2e4662
                 && ! [[ -e "/lib64/fipscheck/${f##*/}.hmac" ]]; then
Harald Hoyer 2e4662
                 echo -n "$f"; echo -n -e "\000"
Harald Hoyer 2e4662
diff --git a/install/dracut-install.c b/install/dracut-install.c
Harald Hoyer 2e4662
index 2d0412c..2fad6df 100644
Harald Hoyer 2e4662
--- a/install/dracut-install.c
Harald Hoyer 2e4662
+++ b/install/dracut-install.c
Harald Hoyer 2e4662
@@ -214,8 +214,14 @@ static int cp(const char *src, const char *dst)
Harald Hoyer 2e4662
                 ret = clone_file(dest_desc, source_desc);
Harald Hoyer 2e4662
                 close(source_desc);
Harald Hoyer 2e4662
                 if (ret == 0) {
Harald Hoyer 2e4662
+                        struct timeval tv[2];
Harald Hoyer 2e4662
                         if (fchown(dest_desc, sb.st_uid, sb.st_gid) != 0)
Harald Hoyer 2e4662
                                 fchown(dest_desc, -1, sb.st_gid);
Harald Hoyer 2e4662
+                        tv[0].tv_sec = sb.st_atime;
Harald Hoyer 2e4662
+                        tv[0].tv_usec = 0;
Harald Hoyer 2e4662
+                        tv[1].tv_sec = sb.st_mtime;
Harald Hoyer 2e4662
+                        tv[1].tv_usec = 0;
Harald Hoyer 2e4662
+                        futimes(dest_desc, tv);
Harald Hoyer 2e4662
                         close(dest_desc);
Harald Hoyer 2e4662
                         return ret;
Harald Hoyer 2e4662
                 }
Harald Hoyer 2e4662
@@ -230,7 +236,7 @@ static int cp(const char *src, const char *dst)
Harald Hoyer 2e4662
  normal_copy:
Harald Hoyer 2e4662
         pid = fork();
Harald Hoyer 2e4662
         if (pid == 0) {
Harald Hoyer 2e4662
-                execlp("cp", "cp", "--reflink=auto", "--sparse=auto", "--preserve=mode", "-fL", src, dst, NULL);
Harald Hoyer 2e4662
+                execlp("cp", "cp", "--reflink=auto", "--sparse=auto", "--preserve=mode,timestamps", "-fL", src, dst, NULL);
Harald Hoyer 2e4662
                 _exit(EXIT_FAILURE);
Harald Hoyer 2e4662
         }
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
@@ -350,6 +356,8 @@ static int hmac_install(const char *src, const char *dst, const char *hmacpath)
Harald Hoyer 2e4662
 	if (!hmacpath) {
Harald Hoyer 2e4662
                 hmac_install(src, dst, "/lib/fipscheck");
Harald Hoyer 2e4662
                 hmac_install(src, dst, "/lib64/fipscheck");
Harald Hoyer 2e4662
+                hmac_install(src, dst, "/lib/hmaccalc");
Harald Hoyer 2e4662
+                hmac_install(src, dst, "/lib64/hmaccalc");
Harald Hoyer 2e4662
         }
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
         srcpath[dlen] = '\0';
Harald Hoyer 2e4662
diff --git a/modules.d/01fips/fips.sh b/modules.d/01fips/fips.sh
Harald Hoyer 2e4662
index 48ad0e6..ce3e49c 100755
Harald Hoyer 2e4662
--- a/modules.d/01fips/fips.sh
Harald Hoyer 2e4662
+++ b/modules.d/01fips/fips.sh
Harald Hoyer 2e4662
@@ -51,7 +51,6 @@ mount_boot()
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
 do_fips()
Harald Hoyer 2e4662
 {
Harald Hoyer 2e4662
-    info "Checking integrity of kernel"
Harald Hoyer 2e4662
     KERNEL=$(uname -r)
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
     if ! [ -e "/boot/.vmlinuz-${KERNEL}.hmac" ]; then
Harald Hoyer 2e4662
@@ -59,8 +58,6 @@ do_fips()
Harald Hoyer 2e4662
         return 1
Harald Hoyer 2e4662
     fi
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
-    sha512hmac -c "/boot/.vmlinuz-${KERNEL}.hmac" || return 1
Harald Hoyer 2e4662
-
Harald Hoyer 2e4662
     FIPSMODULES=$(cat /etc/fipsmodules)
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
     info "Loading and integrity checking all crypto modules"
Harald Hoyer 2e4662
@@ -72,6 +69,10 @@ do_fips()
Harald Hoyer 2e4662
     info "Self testing crypto algorithms"
Harald Hoyer 2e4662
     modprobe tcrypt || return 1
Harald Hoyer 2e4662
     rmmod tcrypt
Harald Hoyer 2e4662
+
Harald Hoyer 2e4662
+    info "Checking integrity of kernel"
Harald Hoyer 2e4662
+    sha512hmac -c "/boot/.vmlinuz-${KERNEL}.hmac" || return 1
Harald Hoyer 2e4662
+
Harald Hoyer 2e4662
     info "All initrd crypto checks done"
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
     > /tmp/fipsdone
Harald Hoyer 2e4662
diff --git a/modules.d/01fips/module-setup.sh b/modules.d/01fips/module-setup.sh
Harald Hoyer 2e4662
index 8953132..a7f5be8 100755
Harald Hoyer 2e4662
--- a/modules.d/01fips/module-setup.sh
Harald Hoyer 2e4662
+++ b/modules.d/01fips/module-setup.sh
Harald Hoyer 2e4662
@@ -12,9 +12,11 @@ depends() {
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
 installkernel() {
Harald Hoyer 2e4662
     local _fipsmodules _mod
Harald Hoyer 2e4662
-    _fipsmodules="aead aes_generic xts aes-x86_64 ansi_cprng cbc ccm chainiv ctr gcm ghash_generic"
Harald Hoyer 2e4662
-    _fipsmodules+=" des deflate ecb eseqiv hmac seqiv sha256 sha256_generic sha512 sha512_generic"
Harald Hoyer 2e4662
-    _fipsmodules+=" cryptomgr crypto_null tcrypt dm-mod dm-crypt lzo"
Harald Hoyer 2e4662
+    _fipsmodules="aead aes_generic aes-x86_64 ansi_cprng arc4 blowfish camellia cast6 cbc ccm "
Harald Hoyer 2e4662
+    _fipsmodules+="chainiv crc32c cryptomgr crypto_null ctr cts deflate des des3_ede dm-crypt dm-mod "
Harald Hoyer 2e4662
+    _fipsmodules+="ecb eseqiv fcrypt gcm ghash_generic hmac khazad lzo md4 md5 michael_mic rmd128 "
Harald Hoyer 2e4662
+    _fipsmodules+="rmd160 rmd256 rmd320 rot13 salsa20 seed seqiv serpent sha1 sha224 sha256 sha256_generic "
Harald Hoyer 2e4662
+    _fipsmodules+="sha384 sha512 sha512_generic tcrypt tea tnepres twofish wp256 wp384 wp512 xeta xtea xts zlib"
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
     mkdir -m 0755 -p "${initdir}/etc/modprobe.d"
Harald Hoyer 2e4662
 
Harald Hoyer 2e4662
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer 2e4662
index ae79a82..9bd25f4 100755
Harald Hoyer 2e4662
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer 2e4662
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer 2e4662
@@ -384,7 +384,7 @@ die() {
Harald Hoyer 2e4662
         echo "warn dracut: FATAL: \"$*\"";
Harald Hoyer 2e4662
         echo "warn dracut: Refusing to continue";
Harald Hoyer 2e4662
     } >> $hookdir/emergency/01-die.sh
Harald Hoyer 2e4662
-
Harald Hoyer 2e4662
+    [ -d /run/initramfs ] || mkdir -p /run/initramfs
Harald Hoyer 2e4662
     > /run/initramfs/.die
Harald Hoyer 2e4662
     emergency_shell
Harald Hoyer 2e4662
     exit 1