initrd: work around a bug in busybox sha256sum

busybox sha256sum will create a checksum file for uncommon file names
(e.g. /boot/foo"$\n"bar), but fail to verify that exact file.
https://bugs.busybox.net/show_bug.cgi?id=14226

Thus disallow all files in /boot/ with strange file names at the time of
signing for now. Verifying in the presence of new files with such file
names in /boot/ is no issue for the kexec_tree verification due to the
previously implemented escaping mechanism.
This commit is contained in:
3hhh 2023-01-12 17:31:31 +01:00
parent e368c3f6ea
commit 4ce8f664ad
No known key found for this signature in database
GPG Key ID: EB03A691DB2F0833
3 changed files with 22 additions and 0 deletions

View File

@ -23,6 +23,8 @@ paramsdir="${paramsdir%%/}"
confirm_gpg_card
assert_signable
# update hashes in /boot before signing
if [ "$update" = "y" ]; then
(

View File

@ -558,6 +558,8 @@ if ! gpg --card-status >/dev/null 2>&1 ; then
fi
fi
assert_signable
# Action time...
# detect and set /boot device

View File

@ -397,6 +397,24 @@ escape_zero() {
}
}
# Currently heads doesn't support signing file names with certain characters
# due to https://bugs.busybox.net/show_bug.cgi?id=14226. Also, certain characters
# may be intepreted by `whiptail`, `less` et al (e.g. \n, \b, ...).
assert_signable() {
# ensure /boot mounted
if ! grep -q /boot /proc/mounts ; then
mount -o ro /boot || die "Unable to mount /boot"
fi
find /boot -print0 > /tmp/signable.ref
local del='\001-\037\134\177-\377'
LC_ALL=C tr -d "$del" < /tmp/signable.ref > /tmp/signable.del || die "Failed to execute tr."
if ! cmp -s "/tmp/signable.ref" "/tmp/signable.del" &> /dev/null ; then
die "Some /boot file names contain characters that are currently not supported by heads: $del"$'\n'"Please investigate!"
fi
rm -f /tmp/signable.*
}
verify_checksums()
{
local boot_dir="$1"