Skip to content

Commit

Permalink
fix(fips): only unmount /boot if it was mounted by the fips module
Browse files Browse the repository at this point in the history
The `do_fips` method should only unmount /boot if it was mounted in the
`mount_boot` method.

In addition, now the `mount_boot` method checks if /boot is already mounted.

Signed-off-by: Raymund Will <rw@suse.com>
  • Loading branch information
aafeijoo-suse authored and johannbg committed Feb 13, 2023
1 parent 68d0653 commit ab26ad2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion modules.d/01fips/fips.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ mount_boot() {
boot=$(getarg boot=)

if [ -n "$boot" ]; then
if [ -d /boot ] && ismounted /boot; then
boot_dev=
if command -v findmnt > /dev/null; then
boot_dev=$(findmnt -n -o SOURCE /boot)
fi
fips_info "Ignoring 'boot=$boot' as /boot is already mounted ${boot_dev:+"from '$boot_dev'"}"
return 0
fi

case "$boot" in
LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
boot="$(label_uuid_to_dev "$boot")"
Expand Down Expand Up @@ -47,10 +56,13 @@ mount_boot() {
mkdir -p /boot
fips_info "Mounting $boot as /boot"
mount -oro "$boot" /boot || return 1
FIPS_MOUNTED_BOOT=1
elif ! ismounted /boot && [ -d "$NEWROOT/boot" ]; then
# shellcheck disable=SC2114
rm -fr -- /boot
ln -sf "$NEWROOT/boot" /boot
else
die "You have to specify boot=<boot device> as a boot option for fips=1"
fi
}

Expand Down Expand Up @@ -172,7 +184,12 @@ do_fips() {

: > /tmp/fipsdone

umount /boot > /dev/null 2>&1
if [ "$FIPS_MOUNTED_BOOT" = 1 ]; then
fips_info "Unmounting /boot"
umount /boot > /dev/null 2>&1
else
fips_info "Not unmounting /boot"
fi

return 0
}

0 comments on commit ab26ad2

Please sign in to comment.