Skip to content

Commit 4257798

Browse files
committed
fips: forward port RHEL-6 fips changes
- also support FIPS on separate LVM partition - use small settle loop to get /boot - "set -e" has no effect, if we use "||" - make fips work with encrypted root and seperate boot - moved to pre-pivot to support /boot in /
1 parent 12b9736 commit 4257798

File tree

4 files changed

+72
-39
lines changed

4 files changed

+72
-39
lines changed

modules.d/01fips/fips-boot.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3+
# ex: ts=8 sw=4 sts=4 et filetype=sh
4+
5+
if ! fipsmode=$(getarg fips) || [ $fipsmode = "0" ]; then
6+
rm -f /etc/modprobe.d/fips.conf >/dev/null 2>&1
7+
elif getarg boot= >/dev/null; then
8+
. /sbin/fips.sh
9+
if mount_boot; then
10+
do_fips || die "FIPS integrity test failed"
11+
fi
12+
fi

modules.d/01fips/fips-noboot.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3+
# ex: ts=8 sw=4 sts=4 et filetype=sh
4+
5+
if ! fipsmode=$(getarg fips) || [ $fipsmode = "0" ]; then
6+
rm -f /etc/modprobe.d/fips.conf >/dev/null 2>&1
7+
elif ! [ -f /tmp/fipsdone ]; then
8+
. /sbin/fips.sh
9+
mount_boot
10+
do_fips || die "FIPS integrity test failed"
11+
fi

modules.d/01fips/fips.sh

+42-38
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
33
# ex: ts=8 sw=4 sts=4 et filetype=sh
44

5-
do_fipskernel()
5+
mount_boot()
66
{
77
boot=$(getarg boot=)
8-
KERNEL=$(uname -r)
9-
case "$boot" in
8+
9+
if [ -n "$boot" ]; then
10+
case "$boot" in
1011
LABEL=*)
1112
boot="$(echo $boot | sed 's,/,\\x2f,g')"
1213
boot="/dev/disk/by-label/${boot#LABEL=}"
@@ -18,45 +19,52 @@ do_fipskernel()
1819
;;
1920
*)
2021
die "You have to specify boot=<boot device> as a boot option for fips=1" ;;
21-
esac
22-
23-
if ! [ -e "$boot" ]; then
24-
udevadm trigger --action=add >/dev/null 2>&1
25-
[ -z "$UDEVVERSION" ] && UDEVVERSION=$(udevadm --version)
22+
esac
2623

27-
if [ $UDEVVERSION -ge 143 ]; then
28-
udevadm settle --exit-if-exists=$boot
29-
else
30-
udevadm settle --timeout=30
24+
if ! [ -e "$boot" ]; then
25+
udevadm trigger --action=add >/dev/null 2>&1
26+
[ -z "$UDEVVERSION" ] && UDEVVERSION=$(udevadm --version)
27+
i=0
28+
while ! [ -e $boot ]; do
29+
if [ $UDEVVERSION -ge 143 ]; then
30+
udevadm settle --exit-if-exists=$boot
31+
else
32+
udevadm settle --timeout=30
33+
fi
34+
[ -e $boot ] && break
35+
modprobe scsi_wait_scan && rmmod scsi_wait_scan
36+
[ -e $boot ] && break
37+
sleep 0.5
38+
i=$(($i+1))
39+
[ $i -gt 40 ] && break
40+
done
3141
fi
32-
fi
3342

34-
[ -e "$boot" ]
43+
[ -e "$boot" ] || return 1
3544

36-
mkdir -m 0755 /boot
37-
info "Mounting $boot as /boot"
38-
mount -oro "$boot" /boot
45+
mkdir /boot
46+
info "Mounting $boot as /boot"
47+
mount -oro "$boot" /boot || return 1
48+
fi
49+
}
3950

51+
do_fips()
52+
{
4053
info "Checking integrity of kernel"
54+
newroot=$NEWROOT
55+
KERNEL=$(uname -r)
4156

42-
if ! [ -e "/boot/.vmlinuz-${KERNEL}.hmac" ]; then
43-
warn "/boot/.vmlinuz-${KERNEL}.hmac does not exist"
57+
[ -e "$newroot/boot/.vmlinuz-${KERNEL}.hmac" ] || unset newroot
58+
59+
if ! [ -e "$newroot/boot/.vmlinuz-${KERNEL}.hmac" ]; then
60+
warn "$newroot/boot/.vmlinuz-${KERNEL}.hmac does not exist"
4461
return 1
4562
fi
4663

47-
sha512hmac -c "/boot/.vmlinuz-${KERNEL}.hmac" || return 1
48-
49-
info "Umounting /boot"
50-
umount /boot
51-
}
64+
sha512hmac -c "$newroot/boot/.vmlinuz-${KERNEL}.hmac" || return 1
5265

53-
do_fips()
54-
{
5566
FIPSMODULES=$(cat /etc/fipsmodules)
5667

57-
if ! getarg rd.fips.skipkernel >/dev/null; then
58-
do_fipskernel
59-
fi
6068
info "Loading and integrity checking all crypto modules"
6169
for module in $FIPSMODULES; do
6270
if [ "$module" != "tcrypt" ]; then
@@ -66,15 +74,11 @@ do_fips()
6674
info "Self testing crypto algorithms"
6775
modprobe tcrypt || return 1
6876
rmmod tcrypt
69-
info "All initrd crypto checks done"
77+
info "All initrd crypto checks done"
78+
79+
> /tmp/fipsdone
80+
81+
umount /boot >/dev/null 2>&1
7082

7183
return 0
7284
}
73-
74-
if ! fipsmode=$(getarg fips) || [ $fipsmode = "0" ]; then
75-
rm -f /etc/modprobe.d/fips.conf >/dev/null 2>&1
76-
else
77-
set -e
78-
do_fips || die "FIPS integrity test failed"
79-
set +e
80-
fi

modules.d/01fips/module-setup.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ installkernel() {
2626
}
2727

2828
install() {
29-
inst_hook pre-trigger 01 "$moddir/fips.sh"
29+
inst_hook pre-trigger 01 "$moddir/fips-boot.sh"
30+
inst_hook pre-pivot 01 "$moddir/fips-noboot.sh"
31+
inst "$moddir/fips.sh" /sbin/fips.sh
32+
3033
dracut_install sha512hmac rmmod insmod mount uname umount
3134

3235
for dir in "$usrlibdir" "$libdir"; do
@@ -37,5 +40,8 @@ install() {
3740
done
3841

3942
dracut_install $usrlibdir/hmaccalc/sha512hmac.hmac
43+
if command -v prelink >/dev/null; then
44+
dracut_install prelink
45+
fi
4046
}
4147

0 commit comments

Comments
 (0)