Skip to content

Commit 78557f0

Browse files
jlebonjohannbg
authored andcommitted
fix(fips): handle s390x OSTree systems
On s390x, the `BOOT_IMAGE` karg injected by the bootloader is not a path to the kernel image, but rather an integer describing the index of the menu entry selected. Because of the way the s390x bootloader works, there is no information retained about e.g. the path of the kernel that was loaded. This causes issues for the FIPS code which assumes that `BOOT_IMAGE` is a path to the kernel image to derive the HMAC path. In non-OSTree systems, this ends up working anyway, because the kernel is located at the root of the boot partition. In OSTree systems, this is not the case. However, OSTree systems use BLS configs, and they are named in reverse order of precedence (i.e. menu ordering). So from the `BOOT_IMAGE` integer, we can figure out which BLS entry was selected. Add some code to do just this on s390x. This isn't completely foolproof, because it presumes that (1) BLS configs were used to populate the bootloader (and that they were exactly in the same state they currently are when `zipl` was run), and (2) there are no other menu entries originating from outside the BLS configs. However, if these assumptions are wrong we would simply fail the boot, which is currently what is happening anyway. See also: openshift/os#546 ibm-s390-linux/s390-tools#78 Tested-by: Muhammad Adeel <muhammad.adeel@ibm.com>
1 parent 2e3c544 commit 78557f0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

modules.d/01fips/fips.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ do_fips() {
124124
else
125125
BOOT_IMAGE="$(getarg BOOT_IMAGE)"
126126

127+
# On s390x, BOOT_IMAGE isn't a path but an integer representing the
128+
# entry number selected. Let's try the root of /boot first, and
129+
# otherwise fallback to trying to parse the BLS entries if it's a
130+
# BLS-based system.
131+
if [ "$(uname -m)" = s390x ]; then
132+
if [ -e "/boot/vmlinuz-${KERNEL}" ]; then
133+
BOOT_IMAGE="vmlinuz-${KERNEL}"
134+
elif [ -d /boot/loader/entries ]; then
135+
bls=$(find /boot/loader/entries -name '*.conf' | sort -rV | sed -n "$((BOOT_IMAGE + 1))p")
136+
if [ -e "${bls}" ]; then
137+
BOOT_IMAGE=$(grep ^linux "${bls}" | cut -d' ' -f2)
138+
fi
139+
fi
140+
fi
141+
127142
# Trim off any leading GRUB boot device (e.g. ($root) )
128143
BOOT_IMAGE="$(echo "${BOOT_IMAGE}" | sed 's/^(.*)//')"
129144

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ install() {
6767
inst_hook pre-udev 01 "$moddir/fips-load-crypto.sh"
6868
inst_script "$moddir/fips.sh" /sbin/fips.sh
6969

70-
inst_multiple sha512hmac rmmod insmod mount uname umount
70+
inst_multiple sha512hmac rmmod insmod mount uname umount grep sed cut find sort
7171

7272
inst_simple /etc/system-fips
7373
[ -c "${initdir}"/dev/random ] || mknod "${initdir}"/dev/random c 1 8 \

0 commit comments

Comments
 (0)