RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1873725 - UEFI: allow booting from luks encrypted /boot
Summary: UEFI: allow booting from luks encrypted /boot
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: grub2
Version: 8.2
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: 8.0
Assignee: Javier Martinez Canillas
QA Contact: Release Test Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-08-29 16:24 UTC by Gerd v. Egidy
Modified: 2021-05-18 15:00 UTC (History)
5 users (show)

Fixed In Version: grub2-2.02-91.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-05-18 14:59:39 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
patch which adds the necessary modules (504 bytes, patch)
2020-08-29 16:28 UTC, Gerd v. Egidy
no flags Details | Diff
[PATCH] Include in EFI build the modules needed for LUKS support (1.30 KB, application/mbox)
2020-11-16 16:27 UTC, Javier Martinez Canillas
no flags Details
grub2-efi-x64-2.02-91.el8.x86_64.rpm (455.08 KB, application/x-rpm)
2020-11-18 08:08 UTC, Javier Martinez Canillas
no flags Details
grub2-efi-x64-2.02-91.el8.x86_64.rpm (470.60 KB, application/x-rpm)
2020-11-18 11:08 UTC, Javier Martinez Canillas
no flags Details
anaconda update-image to allow a crypted /boot (1.16 KB, application/gzip)
2020-12-07 12:36 UTC, Gerd v. Egidy
no flags Details

Description Gerd v. Egidy 2020-08-29 16:24:04 UTC
Description of problem:

When using a UEFI x86_64 system, it is currently not possible to boot a system when
the partition containing /boot is encrypted. 

My goal is to have everything except the EFI system partition encrypted, especially 
the kernel and initramfs, to make modifying these harder.

With a classic BIOS system this is possible, as grub2-install will dynamically select
the necessary grub modules and install them into the biosboot partition.

Version-Release number of selected component (if applicable):
grub2-efi-x64-2.02-87.el8_2.x86_64

How reproducible:
always

Steps to Reproduce:
1. encrypt /boot with luks (you have to do this by hand as anaconda won't let you)
2. boot

Actual results:
grub shell, the system can't boot

Expected results:
password prompt and then regular boot

Additional info:

The problem is that the grubx64.efi file in the grub2-efi-x64 subpackage is 
missing some modules required to open and mount the crypted disk. Unlike the 
biosboot, for which the necessary modules are automatically detected and 
installed, the grubx64.efi file is created at compile time and contains a 
fixed set of grub modules.

Please add these grub modules to the grubx64.efi file to allow booting a
luks cryptodisk encrypted with the default settings:

crypto cryptodisk gcry_crc gcry_rijndael gcry_sha256 luks pbkdf2

Comment 1 Gerd v. Egidy 2020-08-29 16:28:58 UTC
Created attachment 1713048 [details]
patch which adds the necessary modules

This patch adds the necessary modules. I rebuilt grub with it and I can boot from an encrypted /boot afterwards.

Size increase of grubx64.efi with this patch is 87768 bytes, which I think is negligible on a 600 MB default sized efi system partition.

Comment 4 Javier Martinez Canillas 2020-11-16 16:27:01 UTC
Created attachment 1729811 [details]
[PATCH] Include in EFI build the modules needed for LUKS support

Thanks for the report and the diff.

The modules needed for LUKS support are already included in Fedora so I took the list of modules from there. The list is more or less what you shared minus some modules that are already pulled as dependencies in current builds.

I also changed the order so they are sorted alphabetically and match how are defined in the Fedora package. I'm attaching the patch for reference.

Comment 5 Gerd v. Egidy 2020-11-16 16:53:26 UTC
Hi Javier,

thank you very much for working on this.

Sorry for not sorting the modules in my patch alphabetically, it makes of course more sense to do this.

I just compared the modules that you added to the ones I added and some are missing:

crypto 
gcry_crc
gcry_sha256
pbkdf2

I guess the grub2 version you built is a bit different than the one I used, that could explain the difference.
But it could also be that a module is still missing.

Did you check if you can boot from a /boot that is encrypted with the default luks crypto settings?

I can also offer you that I can do this test if you upload me your rpms somewhere.

Comment 8 Javier Martinez Canillas 2020-11-18 08:08:43 UTC
Created attachment 1730489 [details]
grub2-efi-x64-2.02-91.el8.x86_64.rpm

You can extract the grubx64.efi from the attached RPM.

I will try to test later today unlocking a LUKS volume but I verified that the missing modules you mentioned are already pulled as dependencies of other modules included.

Comment 9 Gerd v. Egidy 2020-11-18 10:06:29 UTC
Thanks for posting the file. I just tried it.

Unfortunately I couldn't boot it, as the gcry_sha256 module seems to be missing. 

gcry_sha512 seems to be included though.

The luks defaults for me (as taken from "cryptsetup --help") are:
LUKS: aes-xts-plain64, Key: 256 bits, LUKS header hashing: sha256, RNG: /dev/urandom

This is what I used and I suggest to make it boot at least with the default values,
also adding sha512 won't hurt of course.

Comment 10 Javier Martinez Canillas 2020-11-18 10:45:20 UTC
(In reply to Gerd v. Egidy from comment #9)
> Thanks for posting the file. I just tried it.
> 
> Unfortunately I couldn't boot it, as the gcry_sha256 module seems to be
> missing. 
>

Sigh, I meant to include that one explicitly as well since is also
included in the Fedora package but somehow I missed it. The Fedora
package also includes gcry_twofish and gcry_whirlpool, I think it
makes sense to include those too.

Comment 11 Javier Martinez Canillas 2020-11-18 11:08:03 UTC
Created attachment 1730524 [details]
grub2-efi-x64-2.02-91.el8.x86_64.rpm

Can you please test the new attach RPM instead? It's just a test build so you will need to disable Secure Boot.

Comment 12 Gerd v. Egidy 2020-11-18 13:43:23 UTC
Your l(In reply to Javier Martinez Canillas from comment #11)
> Can you please test the new attach RPM instead?

Now it boots, thank you.

> It's just a test build so
> you will need to disable Secure Boot.

I don't expect anything that is not published through the official channels to work with secure boot. I had it disabled for all my tests.

These changes are planned to be included in RHEL 8.4 or is there a chance to get it into an update for 8.3? I'm not too familiar with your processes and criteria for this so I'm asking.

Comment 13 Petr Janda 2020-11-27 10:16:51 UTC
Current plan is to include it in 8.4.
We could try to include it in 8.3, but it depends on consideration why we should make (potentially harmful) change in already tested product. I don't think it is a security update. So there is a chance is, but it isn't high.
Is there any reason why you have to stick with 8.3 after 8.4 is released?

Comment 14 Petr Janda 2020-11-30 13:50:21 UTC
Hello Gerd,

I have a bit issue to verify fix for this bug ...
Can you describe steps needed to fulfil step 
"1. encrypt /boot with luks (you have to do this by hand as anaconda won't let you)"
a bit more in detail, please.

I'm in state that system has either crypted /boot nor can boot, but not both together, which is in contrast with your comment 12

I suppose some modification of grub.cfg is needed as well as I cannot see any command to load crypto modules in the one from installation.

Thank you
Petr Janda

Comment 15 Gerd v. Egidy 2020-12-01 20:53:48 UTC
Hi Petr,

sorry, my description was indeed a bit sparse.

Here is a more complete description:

# - fresh install on UEFI hardware or vm
# - custom partitioning selected in anaconda:
#    - automatically created LVM setup
#    - encrypt the LVM
# - boot the machine
# - download the latest RPM attached by Javier
# - force-install the rpm or unpack it and overwrite grubx64.efi in /boot/EFI/redhat with the file from the RPM
# - reboot just to make sure everything is still working 
mkdir /boot-copy
umount /boot/efi
rsync -r -a -H -A -X /boot/ /boot-copy
umount /boot
lsblk
# check the path of /boot, it was /dev/vda2 for me
BOOTPART=/dev/vda2
# type luks1 is crucial here as grub can't yet decrypt luks2
cryptsetup --type=luks1 --force-password luksFormat $BOOTPART
cryptsetup open $BOOTPART cryptedboot
mkfs.ext4 /dev/mapper/cryptedboot
# note down the UUID of the new filesystem
nano /etc/fstab
# change the UUID for /boot to the new one
mount /boot
rsync -r -a -H -A -X /boot-copy/ /boot
mount /boot/efi
cryptsetup luksUUID $BOOTPART
# note down the UUID for the crypted partition
nano /etc/default/grub
# add the UUID for the crypted partition to the kernel cmdline
# prepend it with "rd.luks.uuid=luks-"
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
# check if grub properly picked up the crypted boot
grep cryptomount /boot/efi/EFI/redhat/grub.cfg
reboot
# grub should now ask you for the password
# wait long enough, grub is much slower deriving the crypto key
# the system should boot

Comment 16 Gerd v. Egidy 2020-12-01 21:20:36 UTC
About the question if to include it in 8.4 or 8.3:

I think I'll explain my reason for wanting this in a bit more detail,
then you can decide for yourself.

UEFI Secure Boot protects shim, grub, the kernel and any kernel modules.
Encrypting the local partitions protects the rest of the system.
The EFI System Partition has obviously to be left unencrypted, also /boot
unless the changes discussed here are applied.

Since initramfs is on /boot, it is left unprotected.

Anyone with limited physical access (access to disk drives, but no
soldering of firmware flash chips) to a machine can modify initramfs
to make it store the password for disk encryption and later send it to the
attacker through a covert channel. This allows to decrypt the whole
disks.

Encypting /boot protects against this. 

Although aes-xts used in LUKS does not
have a cryptographic protection against modification, it is still good
enough for this purpose. An attacker could modify one block if they new
the exact data that was in it before. But the attacker has no indication
if their guess of the former data was correct. The attacker has only one try in
this scenario, also there is enough randomization on /boot as it is a live
filesystem and also initramfs contains data unique to this installation and
unknown to the attacker like filesystem/LVM UUIDs.

So implementing encryption for /boot allows users to protect their systems
against the attacks outlined here. I don't know if this accounts for a security
update in your criteria.

Having it in 8.3 would mean it is available much faster. I plan to roll out
a few new servers soon where I want to use this. Being able to directly install
on a encrypted /boot (I have an easy to deploy update-image for the installer
that patches anaconda to allow this) would save me the hassle of having to 
encrypt /boot later on when 8.4 is released.

> Is there any reason why you have to stick with 8.3 after 8.4 is released?

Once a new released point version like 8.4 passes internal testing, all existing machines
of this major release are upgraded within a few weeks. I do not run older point
releases.

Comment 17 Zdenek Veleba 2020-12-03 22:20:39 UTC
I'm trying to verify this on nightly compose with grub2-efi-x64-2.02-92.
The grub2-mkconfig adds insmod cryptodisk and sets root='cryptouuid/57ae37...' but doesn't add cryptomount. So after reboot I have to manually decrypt the partition, reload grub configuration and then it can boot.
I don't know if I'm doing something wrong or the mkconfig doesn't work correctly.

Comment 18 Gerd v. Egidy 2020-12-03 22:55:10 UTC
The cryptomount option seems to be created by grub2-probe which is part of the grub2-tools package.

I tested it with the procedure written above on CentOS 8.2, which has grub2-tools-2.02-87.

So either the grub2-tools changed in a way that this doesn't work anymore, or there needs to be some yet unknown package installed that was on my system, but not on yours. Or some other yet unknown prerequisite.

Could you retry it with downgrading the whole grub to 2.02-87, but then overwriting the grubx64.efi from the new grub2-efi-x64?

I think that should show if it has to do with something in the newer grub2-tools.

I'd like to offer further help with this, but I guess this nightly compose and it's sources are for Redhat employees only.

Comment 19 Zdenek Veleba 2020-12-04 14:34:08 UTC
I'm changing status to Verified, as grub can now use encrypted /boot. Any usability issues should be fixed when this feature is properly integrated.

Comment 20 Petr Janda 2020-12-07 11:00:46 UTC
Thank you Gerd for detailed steps.

Just for record
I believe that missing cryptomount in grub.cfg is due missing GRUB_ENABLE_CRYPTODISK=y in /etc/default/grub when running grub2-mkconfig.
I also had to run mkinitrd -f /boot/initramfs-`uname -r`.img `uname -r` to update fstab in initrd so systemd is willing to mount /boot

Comment 21 Gerd v. Egidy 2020-12-07 12:35:14 UTC
Hi Petr,

good that you got it working too.

You are right, I forgot about the GRUB_ENABLE_CRYPTODISK. This is something my update-image-patch for anaconda adds, among other things like allowing a crypted /boot in anaconda and allowing to drop /boot altogehter.

So I'm adding the source of this patch here, in case someone else later stumbles upon this bugzilla entry.

To use it, build it with the included script, then add it to the installer commandline like this: 
inst.updates=http://your-local-repo-server.example/rhel8/i2n-updates.img

This should allow you to directly create the crypted boot while installing with anaconda.

Comment 22 Gerd v. Egidy 2020-12-07 12:36:53 UTC
Created attachment 1737292 [details]
anaconda update-image to allow a crypted /boot

Comment 24 Gerd v. Egidy 2021-04-09 15:07:52 UTC
Is there still some info requested from me as the one who opened the bug? Or is the needinfo just some part of a redhat-internal process?

I can just report that I use the grubx64.efi that Javier posted above on a test system with 8.3. It works as expected and I run this system with a fully encrypted /boot.

Comment 25 Petr Janda 2021-04-09 15:16:11 UTC
Hello Gerd,

someone else attached a customer case to this bz and I wanted to ask him something. As there was a change in bug you've got a notification, I set needinfo wrongly, probably. So sorry for that, nothing is needed from you, but thank you for answering and your confirmation.

Petr

Comment 28 errata-xmlrpc 2021-05-18 14:59:39 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (grub2 bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:1648


Note You need to log in before you can comment on or make changes to this bug.