Skip to contentSkip to conversation

Automatic Disk Unlock with TPM2

PATCH Superseded Gary Lin via Grub-devel 3 participants 82 messages Sep 6, 2024 – Oct 18, 2024 Kbuild Page 2 of 2

v19 of 23 Superseded Latest is v23 →

lore
Share & tools
lore
#66 lore raw

Re: [PATCH v19 33/33] docs: Document TPM2 key protector

In reply to Stefan Berger
Quoted 28 lines · Stefan Berger
Quoted 25 lines · Gary Lin

Update the user manual to address TPM2 key protector including the two related commands, tpm2_key_protector_init and tpm2_key_protector_clear, and the user-space utility: grub-protect.

---
  docs/grub.texi | 507 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 507 insertions(+)
docs/grub.texi +2 -0
index 3e6f602b2..30548ac57 100644
@@ -6443,6 +6443,8 @@ you forget a command, you can run the command @command{help}
  * smbios::                      Retrieve SMBIOS information
  * source::                      Read a configuration file in same context
  * test::                        Check file types and compare values
+* tpm2_key_protector_init::     Initialize the TPM2 key protector
+* tpm2_key_protector_clear::    Clear the TPM2 key protector
  * true::                        Do nothing, successfully
  * trust::                       Add public key to list of trusted keys
  * unset::                       Unset an environment variable
@@ -8000,6 +8002,56 @@ either @var{expression1} or @var{expression2} is true
  @end table
  @end deffn
Quoted 9 lines

docs/grub.texi either @var{expression1} or @var{expression2} is true · line 8010

Quoted 6 lines
docs/grub.texi +6 -0
+@node tpm2_key_protector_init
+@subsection tpm2_key_protector_init
+
+@deffn Command tpm2_key_protector_init [@option{-m} mode] | [@option{-p} pcrlist] | [@option{-b} pcrbank] | [ [@option{-T} tpm2key_file] | [@option{-k} keyfile] ] | [@option{-s} handle] | [@option{-a} srk_type] | [@option{-n} nv_index]
+Initialize the TPM2 key protector to unseal the key for the @command{cryptomount}
+(@pxref{cryptomount}) command. There are two supported mode,

s/mode/modes

Will fix it in the next version.

Quoted 5 lines

docs/grub.texi either @var{expression1} or @var{expression2} is true · line 8012

Quoted 2 lines
docs/grub.texi +2 -0
+SRK(@kbd{srk}) and NV index(@kbd{nv}), to be specified by the option
+@option{-m}. The default mode is srk. The main difference between SRK mode

s/srk/SRK

ditto

Quoted 9 lines

docs/grub.texi either @var{expression1} or @var{expression2} is true · line 8018

Quoted 6 lines
docs/grub.texi +6 -0
+and NV index mode is the storage of the sealed key. For SRK mode, the sealed
+key is stored in a file while NV index mode stores the sealed key in the
+non-volatile memory inside TPM with a given NV index.
+
+The @option{-p} and @option{-b} options are used to supply the PCR list and
+bank that the key sealed with. The PCR list is a comma-separated list, e.g.,

key is sealed with (?)

ditto

Quoted 5 lines

docs/grub.texi either @var{expression1} or @var{expression2} is true · line 8020

Quoted 2 lines
docs/grub.texi +2 -0
+'0,2,4,7,9', to represent the involved PCRs, and the default is '7'. The PCR
+bank is marked by the hash algorithms. The current supported PCR banks are

bank is chosen by selecting a hash algorithm (?)

ditto

Quoted 4 lines
Quoted 4 lines
docs/grub.texi +4 -0
+SHA1, SHA256, SHA384, and SHA512, and the default is SHA256.
+
+There are some options only available for the specific mode. The SRK-specific
+options are @option{-T}, @option{-k}, @option{-a}, and @option{-s}. On the
Quoted 9 lines

docs/grub.texi either @var{expression1} or @var{expression2} is true · line 8030

Quoted 6 lines
docs/grub.texi +6 -0
+other hand, the NV index-specific option is @option{-n}.
+
+The key file for SRK mode can be supplied with either @option{-T} or
+@option{-k}. The @option{-T} option is for the path to the key file in
+the TPM 2.0 Key File format. Since the parameters for the TPM commands are
+written in the policy sequences, there is no need to set the PCR

What is 'the policy sequences' ?

It's the TPMPolicy sequence which contains the command code and the parameters.

https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html#name-tpmpolicy-syntax

Quoted 4 lines

docs/grub.texi either @var{expression1} or @var{expression2} is true · line 8031

Quoted 1 line
docs/grub.texi +1 -0
+list(@option{-p}) and bank(@option{-b}) when using @option{-T} option. The

the @option{-T} option

Will fix it in the next version.

Quoted 42 lines
Quoted 42 lines
docs/grub.texi +31 -0
+@option{-k} option is for the key file in the raw format, and the @option{-p}
+and @option{-b} options are necessary for the non-default PCR list or bank.
+
+Besides the key file, there are two options, @option{-a} and @option{-s}, to
+tweak the TPM Storage Root Key (SRK). The SRK can be either created at
+runtime or stored in the non-volatile memory. When creating SRK at runtime,
+GRUB provides the SRK template to TPM to create the key. There are two SRK
+templates, ECC and RSA, for the @option{-a} option and the default is ECC.
+If the SRK is stored in a specific handle, e.g. @code{0x81000001}, the
+@option{-s} option can be used to set the handle to notify GRUB to load
+the SRK from the given handle.
+
+The only nvindex-specific option is the option @option{-n} which is used to
+set the NV index containing the sealed key, so that GRUB can load the sealed
+key and unseal it with the given PCR list and bank.
+@end deffn
+
+@node tpm2_key_protector_clear
+@subsection tpm2_key_protector_clear
+
+@deffn Command tpm2_key_protector_clear
+Clear the TPM2 key protector if previously initialized.
+@end deffn
  @node true
  @subsection true
@@ -8528,6 +8580,7 @@ environment variables and commands are listed in the same order.
  * Secure Boot Advanced Targeting::   Embedded information for generation number based revocation
  * Measured Boot::                    Measuring boot components
  * Lockdown::                         Lockdown when booting on a secure setup
+* TPM2 key protector::               Managing disk key with TPM2 key protector
  @end menu
  @node Authentication and authorisation
@@ -8771,6 +8824,295 @@ be restricted and some operations/commands cannot be executed.
  The @samp{lockdown} variable is set to @samp{y} when the GRUB is locked down.
  Otherwise it does not exit.
+@node TPM2 key protector
+@section TPM2 key protector in GRUB
+
+TPM2 key protector extends measured boot to unlock the encrypted partition
+without user intervention. It uses the TPM Storage Root Key (SRK) to seal
+the disk key with a given set of PCR values. If the system state matches,
+i.e. PCR values match the sealed PCR set, TPM2 key protector unseals the
Quoted 9 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8839

Quoted 6 lines
docs/grub.texi +6 -0
+disk key for @command{cryptomount} (@pxref{cryptomount}) to unlock the
+encrypted partition. (In case the unsealed key fails to unlock the
+partition, @command{cryptomount} falls back to the passphrase prompt.)
+
+There are two supported modes to store the sealed key, SRK and NV index,
+and the details will be addressed in the latter sections.

s/in the latter sections/in later sections?

Will fix it in the next version.

Quoted 8 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8840

Quoted 2 lines
docs/grub.texi +2 -0
+
+TPM2 key protector is currently only supported on EFI and EMU platforms.

When I looked through the patches I did not see anything particularly related to EFI. Is it only available on EFI and EMU platforms because you did not test it with a (Sea)BIOS for example ? I was actually going to try it on PPC64 on KVM that has SLOF firmware.

It's related to the tcg2 functions defined in grub-core/lib/tss2/tcg2.h. Currently, there is only two implementations:

EFI: grub-core/lib/efi/tcg2.c
EMU: grub-core/lib/tss2/tcg2_emu.c

Quoted 57 lines
Quoted 57 lines
docs/grub.texi +57 -0
+
+@subsection TPM PCR usage
+
+Since TPM2 key protector relies on PCRs to check the system state, it is
+important to decide which PCRs to seal the key with. The following table
+shows the users of PCRs and the measured objects on EFI platforms.
+
+@multitable @columnfractions 0.1 0.2 0.7
+@headitem PCR @tab Used by @tab Measured Objects
+@item 0
+@tab Firmware
+@tab Core system firmware executable code
+@item 1
+@tab Firmware
+@tab Core system firmware data/host platform configuration; typically
+contains serial and model numbers
+@item 2
+@tab Firmware
+@tab Extended or pluggable executable code; includes option ROMs on
+pluggable hardware
+@item 3
+@tab Firmware
+@tab Extended or pluggable firmware data; includes information about
+pluggable hardware
+@item 4
+@tab Firmware
+@tab Boot loader and additional drivers; binaries and extensions loaded
+by the boot loader
+@item 5
+@tab Firmware
+@tab GPT/Partition table
+@item 7
+@tab Firmware
+@tab SecureBoot state
+@item 8
+@tab GRUB
+@tab Commands and kernel command line
+@item 9
+@tab GRUB
+@tab All files read (including kernel image)
+@item 9
+@tab Linux Kernel
+@tab All passed initrds (when the new LOAD_FILE2 initrd protocol is used)
+@item 10
+@tab Linux Kernel
+@tab Protection of the IMA measurement log
+@item 14
+@tab shim
+@tab “MOK” certificates and hashes
+@end multitable
+
+PCR 0, 2, 4, and 7 can be used to check the integrity of the firmware code
+and bootloaders. PCR 8 and 9 are useful to check the file and data processed
+by GRUB. PCRs 10, 11, 12, 13, and 15 are controlled by the operating system,
+so those PCRs are usually still in the initial state when GRUB is running.
+
+In general, it is nice to include PCR 0, 2, 4, and 7 to ensure the integrity
Quoted 9 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8904

Quoted 6 lines
docs/grub.texi +6 -0
+of the firmware and bootloaders. For PCR 8 and 9, a sophisticated tool is
+required to examine the GRUB configuration files and the files to be loaded
+to calculate the correct PCR values.
+
+Please note that PCRs are sensitive to any change, so an update of a component
+could invalidate the sealed key, and it is so-called PCR brittleness. For the

, due to the so-called ..

Will fix it in the next version.

Quoted 50 lines
Quoted 50 lines
docs/grub.texi +50 -0
+bootloader update, PCR 4 may be affected. This can be mitigated by extracting
+the events from the TPM event log and predict the value with the updated
+bootloader binary. On the other hand, it is difficult to predict PCR 0~7 after
+a firmware update since the content of the code and the order of drivers may
+not follow the TPM event log from the previous firmware version, so it is
+necessary to reboot the system to update the measurement results of PCR 0~7
+and seal or sign the sealed key again.
+
+Reference: @url{https://uapi-group.org/specifications/specs/linux_tpm_pcr_registry/, Linux TPM PCR Registry}
+
+@subsection Setting up the extra disk key
+
+Instead of using the existing password, it is recommended to seal a new
+random disk key and use the existing password for recovery.
+
+Here are the sample commands to create a 128 random bytes key file and
+enroll the key into the target partition (sda2).
+
+@example
+# @kbd{dd if=/dev/urandom of=luks.key bs=1 count=128}
+# @kbd{cryptsetup luksAddKey /dev/sda2 luks.key --pbkdf=pbkdf2 --hash=sha512}
+@end example
+
+@subsection SRK mode
+
+To unlock the partition with SRK mode, assume that the sealed key is in
+@file{(hd0,gpt1)/boot/grub2/sealed.tpm}, the following GRUB commands
+unseal the disk key with SRK mode and supply it to @command{cryptomount}.
+
+@example
+@kbd{tpm2_key_protector_init --keyfile=(hd0,gpt1)/boot/grub2/sealed.tpm}
+@kbd{cryptomount -u <UUID> -P tpm2}
+@end example
+
+There are two programs to create the sealed key for SRK mode: @command{grub-protect}
+and @command{pcr-oracle} (@url{https://github.com/okirch/pcr-oracle}).
+
+The following sample command uses @command{grub-protect} to seal the random
+key, @file{luks.key}, with PCR 0, 2, 4 and 7 in TPM 2.0 Key File format.
+
+@example
+@group
+# @kbd{grub-protect --action=add \
+               --protector=tpm2 \
+               --tpm2-pcrs=0,2,4,7 \
+               --tpm2key \
+               --tpm2-keyfile=luks.key \
+               --tpm2-outfile=/boot/efi/boot/grub2/sealed.tpm}
+@end group
+@end example
Quoted 9 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8957

Quoted 3 lines
docs/grub.texi +3 -0
+
+Since @command{grub-protect} only seals the key with the current PCR values,
+when a boot component updates such as shim or GRUB, it requires to reboot the

@command{grub-protect} only seals the key with the current PCR values. Therefore, when a boot component, such as shim or GRUB, are updated, it is neccessary to reboot the system to update the measurement results and seal the key again.

ditto

Quoted 6 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8960

Quoted 3 lines
docs/grub.texi +3 -0
+system to update the measurement results and seal the key again. That means
+the random disk key has to be stored in cleartext for the next key sealing.
+Besides, the measurement result of some PCRs may differ between boot time and

Besides this, ...

ditto

Quoted 5 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8962

Quoted 2 lines
docs/grub.texi +2 -0
+OS runtime. For example, PCR 9 measures the files loaded by GRUB including the
+linux kernel and initrd. To unlock the disk containing the kernel and initrd,

s/linux/Linux

ditto

Quoted 8 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8967

Quoted 5 lines
docs/grub.texi +5 -0
+the key has to be sealed with PCR 9 value before loading the kernel and
+initrd. However, PCR 9 changes after GRUB loading the kernel and initrd, so
+PCR 9 at OS runtime cannot be used directly for key sealing.
+
+To solve the problems, @command{pcr-oracle} takes a different approach. It

s/the/these/

ditto

Quoted 11 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8972

Quoted 5 lines
docs/grub.texi +5 -0
+reads the TPM eventlog and predicts the PCR values. Besides,
+@command{pcr-oracle} also supports ``authorized policy'' which allows the
+PCR policy to be updated with a valid signature, so that the user only
+needs to seal the random disk key once and then updates the signature
+of PCR policy for the later changes.

... and then the user needs to update the signature of the PCR policy for the later changes. (?)

I am not sure what this means though in practice.

The random disk key is first sealed with the user's public key, and then the user signs the 'policy', i.e. the hash of the PCR hashes, and appends the signature into the key file as the parameter for TPM2_PolicyAuthorize. For the later PCR changes, the user only needs to sign the new policy and update the signature.

https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html#name-tpm2_policyauthorize

How about rewriting the paragragh like this:

@command{pcr-oracle} also supports ``authorized policy'' which allows the PCR policy to be updated with a valid signature, so that the user only seals the random disk key once. For the later changes, the user just needs to update the signature of PCR policy.

Quoted 5 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8973

Quoted 2 lines
docs/grub.texi +2 -0
+
+To seal the key with authorized policy, the first thing is to generate

the authorized policyt

Will fix it in the next version.

Quoted 22 lines
Quoted 22 lines
docs/grub.texi +22 -0
+the RSA policy key, @file{policy-key.pem}, and the authorized policy file,
+@file{authorized.policy}. In this example, PCR 0, 2, 4, 7 and 9 are chosen
+for key sealing.
+
+@example
+@group
+# @kbd{pcr-oracle --rsa-generate-key \
+             --private-key policy-key.pem \
+             --auth authorized.policy \
+             create-authorized-policy 0,2,4,7,9}
+@end group
+@end example
+
+Then, we seal the random disk key, @file{luks.key}, with the authorized
+policy file and save the sealed key in @file{sealed.key}.
+
+@example
+@group
+# @kbd{pcr-oracle --key-format tpm2.0 \
+             --auth authorized.policy \
+             --input luks.key \
+             --output sealed.key \
Quoted 9 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 9001

Quoted 5 lines
docs/grub.texi +5 -0
+             seal-secret}
+@end group
+@end example
+
+The random disk key file, @file{luks.key}, now can be removed for good.

Since we now have the sealed key we can now remove the random disk key file @file{lukes.key}.

ditto

Quoted 20 lines
Quoted 20 lines
docs/grub.texi +20 -0
+The last step is to sign the predicted PCR policy and save the final key
+file, @file{sealed.tpm}.
+
+@example
+@group
+# @kbd{pcr-oracle --key-format tpm2.0 \
+             --private-key policy-key.pem \
+             --from eventlog \
+             --stop-event "grub-file=grub.cfg" \
+             --after \
+             --input sealed.key \
+             --output /boot/efi/boot/grub2/sealed.tpm \
+             sign 0,2,4,7,9}
+@end group
+@end example
+
+Here we also set a stop event for the prediction. With
+@kbd{--stop-event grub-file=grub.cfg --after}, @command{pcr-oracle} stops
+the calculation of PCR values right after GRUB loads @file{grub.cfg}.
+
Quoted 9 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 9027

Quoted 6 lines
docs/grub.texi +6 -0
+When shim or GRUB updates, it only requires to run the last @command{pcr-oracle}
+command to update the predicted PCR policy.
+
+@subsection NV index mode
+
+Instead of storing the sealed key in the file, NV index mode uses the TPM

in a file

ditto

Quoted 4 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 9028

Quoted 1 line
docs/grub.texi +1 -0
+non-volatile memory for the sealed key.

to store the sealed key

ditto

Quoted 147 lines
Quoted 147 lines
docs/grub.texi +137 -0
+
+The following sample commands use tpm2-tools (@url{https://github.com/tpm2-software/tpm2-tools})
+commands to seal @file{luks.key} into the specific NV index: @kbd{0x81000000}.
+
+First, we need to create the object file for the primary key, i.e. storage
+root key (SRK) with the default key settings in GRUB: SHA256 hash algorithm
+and ECC key algorithm.
+
+@example
+# @kbd{tpm2_createprimary -C o -g sha256 -G ecc -c primary.ctx}
+@end example
+
+The next commands collect the current values of PCR 0, 2, 4, and 7 and saves
+them in @file{pcr.dat}.
+
+@example
+# @kbd{tpm2_startauthsession -S session.dat}
+# @kbd{tpm2_policypcr -S session.dat -l sha256:0,2,4,7 -f pcrs.dat -L policy.dat}
+# @kbd{tpm2_flushcontext session.dat}
+@end example
+
+The last commands seal @file{luks.key} with the primary key and stores the
+result in @kbd{0x81000000}.
+
+@example
+# @kbd{cat luks.key | tpm2_create -C primary.ctx -u key.pub -r key.priv -L policy.dat -i-}
+# @kbd{tpm2_load -C primary.ctx -u key.pub -r key.priv -n sealing.name -c sealing.ctx}
+# @kbd{tpm2_evictcontrol -C o -c sealing.ctx 0x81000000}
+@end example
+
+To unseal the key, we have to specify the mode, @kbd{nv}, the NV index,
+@kbd{0x81000000}, and the PCRs, @kbd{0,2,4,7} for @command{tpm2_key_protector_init}
+command.
+
+@example
+@kbd{tpm2_key_protector_init --mode=nv --nvindex=0x81000000 --pcrs=0,2,4,7}
+@kbd{cryptomount -u <UUID> --protector tpm2}
+@end example
+
+@subsection Setting up software TPM for EMU platform
+
+In order to test TPM2 key protector and TPM2 Software Stack (TSS2), it is
+handy to set up a software TPM (swtpm) instance and run the commands on the
+EMU platform.
+
+Here are the commands to start a swtpm instance which provides a character
+device interface. To store the TPM states, the directory, @file{swtpm-state},
+is created before the @command{swtpm} command.  All the messages are stored
+in @file{swtpm.log} including the name of the character device.
+
+@example
+# @kbd{mkdir swtpm-state}
+@group
+# @kbd{swtpm chardev --vtpm-proxy --tpmstate dir=swtpm-state \
+        --tpm2 --ctrl type=unixio,path="swtpm-state/ctrl" \
+        --flags startup-clear --daemon > swtpm.log}
+@end group
+@end example
+
+Then, we extract the name of the character device from @file{swtpm.log} and
+save it to the variable, @samp{tpm2dev}.
+
+@example
+# @kbd{tpm2dev=$(grep "New TPM device" swtpm.log | cut -d' ' -f 4)}
+@end example
+
+Now we can start @kbd{grub-emu} with @kbd{--tpm-device $tpm2dev} to interact
+with the swtpm instance.
+
+@example
+# @kbd{grub-emu --tpm-device $tpm2dev}
+@end example
+
+On the host, the tpm2-tools commands can interact with the swtpm instance by
+setting @samp{TPM2TOOLS_TCTI}.
+
+@example
+# @kbd{export TPM2TOOLS_TCTI="device:$tpm2dev"}
+@end example
+
+When the test is done, use @kbd{swtpm_ioctl} to send the shutdown
+command through the swtpm control channel.
+
+@example
+# @kbd{swtpm_ioctl -s --unix swtpm-state/ctrl}
+@end example
+
  @node Platform limitations
  @chapter Platform limitations
@@ -9211,6 +9553,7 @@ bootability on other machines.
  * Invoking grub-mkrescue::      Make a GRUB rescue image
  * Invoking grub-mount::         Mount a file system using GRUB
  * Invoking grub-probe::         Probe device information for GRUB
+* Invoking grub-protect::       Protect a disk key with a key protector
  * Invoking grub-script-check::  Check GRUB script file for syntax errors
  @end menu
@@ -9593,6 +9936,170 @@ Print verbose messages.
  @end table
+@node Invoking grub-protect
+@section Invoking grub-protect
+
+The program @command{grub-protect} protects a disk encryption key with
+a specified key protector.
+
+@table @option
+@item --help
+Print a summary of the command-line options and exit.
+
+@item --version
+Print the version number of GRUB and exit.
+
+@item -a
+@itemx --action=add|remove
+Add or remove a key protector to or from a key.
+
+@item -p
+@itemx --protector=@var{protector}
+Set the key protector. Currently, @samp{tpm2} is the only supported key
+protector.
+
+@item --tpm2-asymmetric=@var{type}
+Choose the the type of SRK. The valid options are @samp{RSA} (@samp{RSA2048})
+and @samp{ECC} (@samp{ECC_NIST_P256}).(default: @samp{ECC})
+
+@item --tpm2-bank=@var{alg}
+Choose bank of PCRs used to authorize key release: @samp{SHA1}, @samp{SHA256},
+@samp{SHA384}, or @samp{SHA512}. (default: @samp{SHA256})
+
+@item --tpm2-device=@var{device}
+Set the path to the TPM2 device. (default: @samp{/dev/tpm0})
+
+@item --tpm2-evict
+Evict a previously persisted SRK from the TPM, if any.
+
+@item --tpm2-keyfile=@var{file}
+Set the path to a file that contains the cleartext key to protect.
+
+@item --tpm2-outfile=@var{file}
+Set the path to the file that will contain the key after sealing
+(must be accessible to GRUB during boot).
+
+@item --tpm2-pcrs=@var{pcrs}
+Set a comma-separated list of PCRs used to authorize key release e.g., @samp{7,11}.
+Please be aware that PCR 0~7 are used by the firmware and the measurement result
+may change after a firmware update (for baremetal systems) or a package
+(OVMF/SeaBIOS/SLOF) update in the VM host. This may lead to the failure of key
+unsealing. (default: @samp{7})
Quoted 9 lines

docs/grub.texi Print verbose messages. · line 9993

Quoted 6 lines
docs/grub.texi +6 -0
+
+@item --tpm2-srk=@var{handle}
+Set the SRK handle, e.g. @samp{0x81000000}, if the SRK is to be made persistent.
+
+@item --tpm2key
+Use TPM 2.0 Key File format instead of the raw format.

TPM 2.0 key file (?)

Hmmmm, then I have to update the help string of grub-protect either.

Quoted 11 lines

docs/grub.texi Print verbose messages. · line 10001

Quoted 8 lines
docs/grub.texi +8 -0
+
+@end table
+
+Before sealing the key, please check the TPM PCR usage
+(@pxref{TPM2 key protector, TPM PCR usage}) to choose a proper set of PCRs.
+
+Assume that there is a key file, @file{luks.key}, to be sealed with PCR 0, 2,
+4, and 7, here is the @command{grub-protect} command to create the sealed

, then here ...

Will fix it in the next version.

Quoted 84 lines
Quoted 84 lines
docs/grub.texi +84 -0
+key file:
+
+@example
+@group
+# @kbd{grub-protect --action=add \
+               --protector=tpm2 \
+               --tpm2-pcrs=0,2,4,7 \
+               --tpm2key \
+               --tpm2-keyfile=luks.key \
+               --tpm2-outfile=/boot/efi/boot/grub2/sealed.tpm}
+@end group
+@end example
+
+Then, GRUB can unlock the target partition with the following commands:
+
+@example
+@kbd{tpm2_key_protector_init --keyfile=(hd0,gpt1)/boot/grub2/sealed.tpm}
+@kbd{cryptomount -u <UUID> -P tpm2}
+@end example
+
+In most of cases, the user only needs to create the key with the `add' action.
+If auto-unlocking is unwanted, just remove the file and restore the GRUB
+commands.
+
+The only case for the `remove' action is when the SRK is made persistent.
+
+There are two supported SRKs in @command{grub-protect}: @samp{RSA} and @samp{ECC}.
+Due to slower key generation, some users of the @samp{RSA} SRK would prefer
+making it persistent so that the TPM can skip the SRK generation when GRUB tries
+to unseal the key.
+
+The available persistent handles can be checked with @command{tpm2_getcap}.
+
+@example
+@group
+# @kbd{tpm2_getcap properties-variable}
+...
+TPM2_PT_HR_PERSISTENT: 0x0
+TPM2_PT_HR_PERSISTENT_AVAIL: 0x41
+...
+@end group
+@end example
+
+In this system, there is no persistent handle. A TPM handle is an unsigned
+32-bit integer, and the persistent handles starts with @samp{0x81}. Here
+we choose the well-known persistent handle: @samp{0x81000000}.
+
+@example
+@group
+# @kbd{grub-protect --action=add \
+               --protector=tpm2 \
+               --tpm2-pcrs=0,2,4,7 \
+               --tpm2-asymmetric=RSA \
+               --tpm2-srk=0x81000000 \
+               --tpm2key \
+               --tpm2-keyfile=luks.key \
+               --tpm2-outfile=/boot/efi/boot/grub2/sealed.tpm}
+@end group
+@end example
+
+The additional @kbd{--tpm2-asymmetric=RSA} and @kbd{--tpm2-srk=0x81000000}
+options are used to make the key sealed with the RSA SRK and store the SRK
+in @samp{0x81000000}.
+
+For the @command{tpm2_key_protector_init} command, the additional @kbd{-s 0x81000000}
+informs the TPM2 key protector to fetch the SRK from @samp{0x81000000}.
+
+@example
+@kbd{tpm2_key_protector_init -s 0x81000000 --keyfile=(hd0,gpt1)/boot/grub2/sealed.tpm}
+@kbd{cryptomount -u <UUID> -P tpm2}
+@end example
+
+After making the SRK handle persistent, we can check the status of the
+persistent handles with @command{tpm2_getcap}.
+
+@example
+@group
+# @kbd{tpm2_getcap properties-variable}
+...
+TPM2_PT_HR_PERSISTENT: 0x1
+TPM2_PT_HR_PERSISTENT_AVAIL: 0x40
+...
+# @kbd{tpm2_getcap handles-persistent}
+- 0x81000000
Quoted 9 lines

docs/grub.texi Print verbose messages. · line 10090

Quoted 5 lines
docs/grub.texi +5 -0
+@end group
+@end example
+
+In case the user doesn't want to use the TPM2 key protector anymore, besides
+removing the sealed key file, here is the command to remove the persistent

The sealed key can be remove once the user does not want to use the TPM2 key protector anymore. Here is the command to remove the persistent ...

ditto

Quoted 6 lines
Quoted 6 lines
docs/grub.texi +6 -0
+SRK handle (@samp{0x81000000}.) with @kbd{--tpm2-srk} and @kbd{--tpm2-evict}.
+
+@example
+@group
+# @kbd{grub-protect --action=remove \
+               --protector=tpm2 \
Quoted 8 lines

docs/grub.texi Print verbose messages. · line 10104

Quoted 8 lines
docs/grub.texi +6 -0
+               --tpm2-srk 0x81000000 \
+               --tpm2-evict}
+@end group
+@end example
+
+
  @node Invoking grub-script-check
  @section Invoking grub-script-check

Really thanks for helping me improve this document.

Gary Lin

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#67 lore raw

Re: [PATCH v19 33/33] docs: Document TPM2 key protector

Quoted 17 lines · Gary Lin
Quoted 16 lines · Stefan Berger

docs/grub.texi either @var{expression1} or @var{expression2} is true · line 8030

Quoted 13 lines
docs/grub.texi +10 -0
+SHA1, SHA256, SHA384, and SHA512, and the default is SHA256.
+
+There are some options only available for the specific mode. The SRK-specific
+options are @option{-T}, @option{-k}, @option{-a}, and @option{-s}. On the
+other hand, the NV index-specific option is @option{-n}.
+
+The key file for SRK mode can be supplied with either @option{-T} or
+@option{-k}. The @option{-T} option is for the path to the key file in
+the TPM 2.0 Key File format. Since the parameters for the TPM commands are
+written in the policy sequences, there is no need to set the PCR

What is 'the policy sequences' ?

Quoted 2 lines

It's the TPMPolicy sequence which contains the command code and the parameters.

So sequence is an ASN.1 sequence? 0x30 iirc. I think people will have a hard time understanding this. You have to describe this in some other way without the word 'policy sequence'.

Quoted 9 lines

https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html#name-tpmpolicy-syntax

Quoted 5 lines

When I looked through the patches I did not see anything particularly related to EFI. Is it only available on EFI and EMU platforms because you did not test it with a (Sea)BIOS for example ? I was actually going to try it on PPC64 on KVM that has SLOF firmware.

Quoted 5 lines

It's related to the tcg2 functions defined in grub-core/lib/tss2/tcg2.h. Currently, there is only two implementations:

EFI: grub-core/lib/efi/tcg2.c
EMU: grub-core/lib/tss2/tcg2_emu.c

Right. I have a version of ieee1275 powerpc now.

Quoted 18 lines
Quoted 10 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8972

Quoted 6 lines
docs/grub.texi +5 -0
+reads the TPM eventlog and predicts the PCR values. Besides,
+@command{pcr-oracle} also supports ``authorized policy'' which allows the
+PCR policy to be updated with a valid signature, so that the user only
+needs to seal the random disk key once and then updates the signature
+of PCR policy for the later changes.

... and then the user needs to update the signature of the PCR policy for the later changes. (?)

Quoted 2 lines

I am not sure what this means though in practice.

The random disk key is first sealed with the user's public key, and then the user signs the 'policy', i.e. the hash of the PCR hashes, and appends the signature into the key file as the parameter for TPM2_PolicyAuthorize. For the later PCR changes, the user only needs to sign the new policy and update the signature.

Quoted 8 lines

https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html#name-tpm2_policyauthorize

How about rewriting the paragragh like this:

@command{pcr-oracle} also supports ``authorized policy'' which allows the PCR policy to be updated with a valid signature, so that the user only seals the random disk key once. For the later changes, the user just needs to update the signature of PCR policy.

You have to describe what you mean with 'the later changes'. Something like this maybe:

If at some later time the PCR values change due to an updated of the system's firmware, the user just need to ... ??

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#68 lore raw

Re: [PATCH v19 33/33] docs: Document TPM2 key protector

Quoted 1 line · Stefan Berger

Sorry for my late reply. Just back from vacation.

Quoted 19 lines · Gary Lin
Quoted 17 lines · Stefan Berger
Quoted 16 lines

docs/grub.texi either @var{expression1} or @var{expression2} is true · line 8030

Quoted 13 lines
docs/grub.texi +10 -0
+SHA1, SHA256, SHA384, and SHA512, and the default is SHA256.
+
+There are some options only available for the specific mode. The SRK-specific
+options are @option{-T}, @option{-k}, @option{-a}, and @option{-s}. On the
+other hand, the NV index-specific option is @option{-n}.
+
+The key file for SRK mode can be supplied with either @option{-T} or
+@option{-k}. The @option{-T} option is for the path to the key file in
+the TPM 2.0 Key File format. Since the parameters for the TPM commands are
+written in the policy sequences, there is no need to set the PCR

What is 'the policy sequences' ?

Quoted 7 lines
Quoted 2 lines

It's the TPMPolicy sequence which contains the command code and the parameters.

So sequence is an ASN.1 sequence? 0x30 iirc. I think people will have a hard time understanding this. You have to describe this in some other way without the word 'policy sequence'.

I'm considering to replace 'policy sequence' with 'file'.

Quoted 44 lines
Quoted 9 lines

https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html#name-tpmpolicy-syntax

Quoted 5 lines

When I looked through the patches I did not see anything particularly related to EFI. Is it only available on EFI and EMU platforms because you did not test it with a (Sea)BIOS for example ? I was actually going to try it on PPC64 on KVM that has SLOF firmware.

Quoted 5 lines

It's related to the tcg2 functions defined in grub-core/lib/tss2/tcg2.h. Currently, there is only two implementations:

EFI: grub-core/lib/efi/tcg2.c
EMU: grub-core/lib/tss2/tcg2_emu.c

Right. I have a version of ieee1275 powerpc now.

Quoted 18 lines
Quoted 10 lines

docs/grub.texi be restricted and some operations/commands cannot be executed. · line 8972

Quoted 6 lines
docs/grub.texi +5 -0
+reads the TPM eventlog and predicts the PCR values. Besides,
+@command{pcr-oracle} also supports ``authorized policy'' which allows the
+PCR policy to be updated with a valid signature, so that the user only
+needs to seal the random disk key once and then updates the signature
+of PCR policy for the later changes.

... and then the user needs to update the signature of the PCR policy for the later changes. (?)

Quoted 2 lines

I am not sure what this means though in practice.

The random disk key is first sealed with the user's public key, and then the user signs the 'policy', i.e. the hash of the PCR hashes, and appends the signature into the key file as the parameter for TPM2_PolicyAuthorize. For the later PCR changes, the user only needs to sign the new policy and update the signature.

Quoted 8 lines

https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html#name-tpm2_policyauthorize

How about rewriting the paragragh like this:

@command{pcr-oracle} also supports ``authorized policy'' which allows the PCR policy to be updated with a valid signature, so that the user only seals the random disk key once. For the later changes, the user just needs to update the signature of PCR policy.

Quoted 5 lines

You have to describe what you mean with 'the later changes'. Something like this maybe:

If at some later time the PCR values change due to an updated of the
system's firmware, the user just need to ... ??

It includes whatever changes to PCRs such as firmware update, bootloader update, or config file update, so I'd extend the statement a bit:

If at some later time the PCR values change due to an update of the system firmware, bootloader, or config file, the user just needs to ...

Gary Lin

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by Daniel Kiper on the v19 series
#69 lore raw
In reply to Gary Lin via Grub-devel
Quoted 11 lines · Gary Lin

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I was going to try it out now (on a ppc64 machine) but fail to configure it. The configure and build work on tip of master.

Quoted 1 line

git clean -xdf ; ./bootstrap && ./configure --prefix=/usr

[...]
Using python3...
Importing unicode...
Importing libgcrypt...
Importing libtasn1...
cp: cannot stat 'grub-core/lib/libtasn1/lib/*.[ch]': No such file or directory
running: AUTOPOINT=true LIBTOOLIZE=true autoreconf --verbose --install --force -I m4 --no-recursive
autoreconf: Entering directory `.'
autoreconf: running: true --force
autoreconf: running: aclocal -I m4 --force -I m4
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --include=m4 --force
autoreconf: running: /usr/bin/autoheader --include=m4 --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:50: installing 'build-aux/config.guess'
configure.ac:50: installing 'build-aux/config.sub'
configure.ac:56: installing 'build-aux/install-sh'
configure.ac:56: installing 'build-aux/missing'
automake: error: cannot open < Makefile.util.am: No such file or directory
autoreconf: automake failed with exit status: 1
./bootstrap: autoreconf failed

Bisecting the series of patches with the above command line run at each step leads to:

70fff1f0d04f576921619fddaf066d1f2c73255c is the first bad commit commit 70fff1f0d04f576921619fddaf066d1f2c73255c

Author: Daniel Axtens <[email protected]>
Date:   Fri Sep 6 17:11:07 2024 +0800

libtasn1: compile into asn1 module

Create a wrapper file that specifies the module license. Set up the makefile so it is built.

 autogen.sh                         | 19 +++++++++++++++++++
 grub-core/Makefile.core.def        | 15 +++++++++++++++
 grub-core/lib/libtasn1_wrap/wrap.c | 27 +++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 grub-core/lib/libtasn1_wrap/wrap.c

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#70 lore raw
Quoted 19 lines · Stefan Berger
Quoted 11 lines · Gary Lin

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I was going to try it out now (on a ppc64 machine) but fail to configure it. The configure and build work on tip of master.

Quoted 8 lines
Quoted 1 line

git clean -xdf ; ./bootstrap && ./configure --prefix=/usr

[...]
Using python3...
Importing unicode...
Importing libgcrypt...
Importing libtasn1...
cp: cannot stat 'grub-core/lib/libtasn1/lib/*.[ch]': No such file or directory

That's weird. The second patch, "libtasn1: import libtasn1-4.19.0", imports the libtasn1 files into grub-core/lib/libtasn1/, and those source files are supposed to exist when applying the patch mentioned below.

I'll do a thorough check for that...

Gary Lin

Quoted 37 lines

running: AUTOPOINT=true LIBTOOLIZE=true autoreconf --verbose --install --force -I m4 --no-recursive
autoreconf: Entering directory `.'
autoreconf: running: true --force
autoreconf: running: aclocal -I m4 --force -I m4
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --include=m4 --force
autoreconf: running: /usr/bin/autoheader --include=m4 --force
autoreconf: running: automake --add-missing --copy --force-missing configure.ac:50: installing 'build-aux/config.guess' configure.ac:50: installing 'build-aux/config.sub' configure.ac:56: installing 'build-aux/install-sh' configure.ac:56: installing 'build-aux/missing'
automake: error: cannot open < Makefile.util.am: No such file or directory
autoreconf: automake failed with exit status: 1
./bootstrap: autoreconf failed

Bisecting the series of patches with the above command line run at each step leads to:

70fff1f0d04f576921619fddaf066d1f2c73255c is the first bad commit commit 70fff1f0d04f576921619fddaf066d1f2c73255c

Author: Daniel Axtens <[email protected]>
Date:   Fri Sep 6 17:11:07 2024 +0800

libtasn1: compile into asn1 module

Create a wrapper file that specifies the module license. Set up the makefile so it is built.

Quoted 6 lines
 autogen.sh                         | 19 +++++++++++++++++++
 grub-core/Makefile.core.def        | 15 +++++++++++++++
 grub-core/lib/libtasn1_wrap/wrap.c | 27 +++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 grub-core/lib/libtasn1_wrap/wrap.c

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#71 lore raw
Quoted 28 lines · Gary Lin
Quoted 19 lines · Stefan Berger
Quoted 11 lines · Gary Lin

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I was going to try it out now (on a ppc64 machine) but fail to configure it. The configure and build work on tip of master.

Quoted 8 lines
Quoted 1 line

git clean -xdf ; ./bootstrap && ./configure --prefix=/usr

[...]
Using python3...
Importing unicode...
Importing libgcrypt...
Importing libtasn1...
cp: cannot stat 'grub-core/lib/libtasn1/lib/*.[ch]': No such file or directory

Quoted 7 lines

That's weird. The second patch, "libtasn1: import libtasn1-4.19.0", imports the libtasn1 files into grub-core/lib/libtasn1/, and those source files are supposed to exist when applying the patch mentioned below.

I'll do a thorough check for that...

I successfully built the patches on a freshly-cloned grub git repo. Since you mentioned ppc64, I wonder if it's caused by the conflicts with the PowerPC Secure Boot patches?

Gary Lin

Quoted 45 lines

Gary Lin

Quoted 43 lines

running: AUTOPOINT=true LIBTOOLIZE=true autoreconf --verbose --install --force -I m4 --no-recursive
autoreconf: Entering directory `.'
autoreconf: running: true --force
autoreconf: running: aclocal -I m4 --force -I m4
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --include=m4 --force
autoreconf: running: /usr/bin/autoheader --include=m4 --force
autoreconf: running: automake --add-missing --copy --force-missing configure.ac:50: installing 'build-aux/config.guess' configure.ac:50: installing 'build-aux/config.sub' configure.ac:56: installing 'build-aux/install-sh' configure.ac:56: installing 'build-aux/missing'
automake: error: cannot open < Makefile.util.am: No such file or directory
autoreconf: automake failed with exit status: 1
./bootstrap: autoreconf failed

Bisecting the series of patches with the above command line run at each step leads to:

70fff1f0d04f576921619fddaf066d1f2c73255c is the first bad commit commit 70fff1f0d04f576921619fddaf066d1f2c73255c

Author: Daniel Axtens <[email protected]>
Date:   Fri Sep 6 17:11:07 2024 +0800

libtasn1: compile into asn1 module

Create a wrapper file that specifies the module license. Set up the makefile so it is built.

 autogen.sh                         | 19 +++++++++++++++++++
 grub-core/Makefile.core.def        | 15 +++++++++++++++
 grub-core/lib/libtasn1_wrap/wrap.c | 27 +++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 grub-core/lib/libtasn1_wrap/wrap.c

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#72 lore raw
Quoted 34 lines · Gary Lin
Quoted 33 lines · Gary Lin
Quoted 19 lines · Stefan Berger
Quoted 11 lines · Gary Lin

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I was going to try it out now (on a ppc64 machine) but fail to configure it. The configure and build work on tip of master.

Quoted 8 lines
Quoted 1 line

git clean -xdf ; ./bootstrap && ./configure --prefix=/usr

[...]
Using python3...
Importing unicode...
Importing libgcrypt...
Importing libtasn1...
cp: cannot stat 'grub-core/lib/libtasn1/lib/*.[ch]': No such file or directory

That's weird. The second patch, "libtasn1: import libtasn1-4.19.0", imports the libtasn1 files into grub-core/lib/libtasn1/, and those source files are supposed to exist when applying the patch mentioned below.

Quoted 5 lines
Quoted 2 lines

I'll do a thorough check for that...

I successfully built the patches on a freshly-cloned grub git repo. Since you mentioned ppc64, I wonder if it's caused by the conflicts with the PowerPC Secure Boot patches?

I took your series from the mailing list with the b4 tool. For some reason 02/33 is missing there, maybe because it is too big.

https://lore.kernel.org/grub-devel/20240916033543.gzfture5q4ljuw4b@GaryLaptop/T/#t

I checked out your repo branch and there I can configure but then run into this issue here:

tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]
48 | unsigned long num = ((long) GRUB_UINT_MAX) << 2;
| ^~
cc1: all warnings being treated as errors

It's the cast to 'long' that this gcc complains about. If I remove the cast then it works.

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#73 lore raw
Quoted 55 lines · Stefan Berger
Quoted 34 lines · Gary Lin
Quoted 33 lines · Gary Lin
Quoted 19 lines · Stefan Berger
Quoted 11 lines · Gary Lin

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I was going to try it out now (on a ppc64 machine) but fail to configure it. The configure and build work on tip of master.

Quoted 8 lines
Quoted 1 line

git clean -xdf ; ./bootstrap && ./configure --prefix=/usr

[...]
Using python3...
Importing unicode...
Importing libgcrypt...
Importing libtasn1...
cp: cannot stat 'grub-core/lib/libtasn1/lib/*.[ch]': No such file or directory

That's weird. The second patch, "libtasn1: import libtasn1-4.19.0", imports the libtasn1 files into grub-core/lib/libtasn1/, and those source files are supposed to exist when applying the patch mentioned below.

Quoted 5 lines
Quoted 2 lines

I'll do a thorough check for that...

I successfully built the patches on a freshly-cloned grub git repo. Since you mentioned ppc64, I wonder if it's caused by the conflicts with the PowerPC Secure Boot patches?

I took your series from the mailing list with the b4 tool. For some reason 02/33 is missing there, maybe because it is too big.

https://lore.kernel.org/grub-devel/20240916033543.gzfture5q4ljuw4b@GaryLaptop/T/#t

I checked out your repo branch and there I can configure but then run into this issue here:

tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]
   48 |       unsigned long num = ((long) GRUB_UINT_MAX) << 2;
      |                                                  ^~
cc1: all warnings being treated as errors

Quoted 7 lines

It's the cast to 'long' that this gcc complains about. If I remove the cast then it works.

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I got this error when libtasn1 was not installed on the host. Do you still need libtasn1 installed now that its part of the repo with your series?

checking for libnvpair.h... no
checking for libzfs_init in -lzfs... no
checking for asn1_write_value in -ltasn1... no
configure: error: grub-protect was explicitly requested but can't be compiled (need libtasn1 library)

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#74 lore raw
Quoted 74 lines · Stefan Berger
Quoted 62 lines · Stefan Berger
Quoted 38 lines · Gary Lin
Quoted 37 lines · Gary Lin
Quoted 23 lines · Stefan Berger
Quoted 8 lines · Gary Lin

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by
Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

Quoted 6 lines

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from
Daniel Axtens's "appended signature secure boot support" (*3) to import
libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I was going to try it out now (on a ppc64 machine) but fail to configure it.
The configure and build work on tip of master.

Quoted 8 lines
Quoted 1 line

git clean -xdf ; ./bootstrap && ./configure --prefix=/usr

[...]
Using python3...
Importing unicode...
Importing libgcrypt...
Importing libtasn1...
cp: cannot stat 'grub-core/lib/libtasn1/lib/*.[ch]': No such file or directory

That's weird. The second patch, "libtasn1: import libtasn1-4.19.0", imports the libtasn1 files into grub-core/lib/libtasn1/, and those source files are supposed to exist when applying the patch mentioned below.

Quoted 5 lines
Quoted 2 lines

I'll do a thorough check for that...

I successfully built the patches on a freshly-cloned grub git repo. Since you mentioned ppc64, I wonder if it's caused by the conflicts with the PowerPC Secure Boot patches?

I took your series from the mailing list with the b4 tool. For some reason 02/33 is missing there, maybe because it is too big.

https://lore.kernel.org/grub-devel/20240916033543.gzfture5q4ljuw4b@GaryLaptop/T/#t

I checked out your repo branch and there I can configure but then run into this issue here:

tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]
   48 |       unsigned long num = ((long) GRUB_UINT_MAX) << 2; |                                                  ^~
cc1: all warnings being treated as errors

Quoted 8 lines

It's the cast to 'long' that this gcc complains about. If I remove the cast then it works.

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Quoted 8 lines

I got this error when libtasn1 was not installed on the host. Do you still need libtasn1 installed now that its part of the repo with your series?

checking for libnvpair.h... no
checking for libzfs_init in -lzfs... no
checking for asn1_write_value in -ltasn1... no
configure: error: grub-protect was explicitly requested but can't be compiled (need libtasn1 library)

There are several disabled functions in the built-in libtasn1, and one of them is asn1_write_value(). Grub-protect needs the function to create the asn1 object, but GRUB itself only needs the parsing functions, so in the end I make grub-protect to use the external libtasn1.

Gary Lin

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#75 lore raw
In reply to Stefan Berger
Quoted 58 lines · Stefan Berger
Quoted 34 lines · Gary Lin
Quoted 33 lines · Gary Lin
Quoted 19 lines · Stefan Berger
Quoted 11 lines · Gary Lin

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I was going to try it out now (on a ppc64 machine) but fail to configure it. The configure and build work on tip of master.

Quoted 8 lines
Quoted 1 line

git clean -xdf ; ./bootstrap && ./configure --prefix=/usr

[...]
Using python3...
Importing unicode...
Importing libgcrypt...
Importing libtasn1...
cp: cannot stat 'grub-core/lib/libtasn1/lib/*.[ch]': No such file or directory

That's weird. The second patch, "libtasn1: import libtasn1-4.19.0", imports the libtasn1 files into grub-core/lib/libtasn1/, and those source files are supposed to exist when applying the patch mentioned below.

Quoted 5 lines
Quoted 2 lines

I'll do a thorough check for that...

I successfully built the patches on a freshly-cloned grub git repo. Since you mentioned ppc64, I wonder if it's caused by the conflicts with the PowerPC Secure Boot patches?

I took your series from the mailing list with the b4 tool. For some reason 02/33 is missing there, maybe because it is too big.

https://lore.kernel.org/grub-devel/20240916033543.gzfture5q4ljuw4b@GaryLaptop/T/#t

I checked out your repo branch and there I can configure but then run into this issue here:

tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]
48 | unsigned long num = ((long) GRUB_UINT_MAX) << 2;
| ^~
cc1: all warnings being treated as errors

Quoted 3 lines

It's the cast to 'long' that this gcc complains about. If I remove the cast then it works.

Urgh, the cast looks wrong. I'll remove the cast.

Gary Lin

Quoted 6 lines
$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#76 lore raw
Quoted 9 lines · Gary Lin
Quoted 7 lines · Stefan Berger

tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]

    48 |       unsigned long num = ((long) GRUB_UINT_MAX) << 2;
       |                                                  ^~

cc1: all warnings being treated as errors

Quoted 4 lines
Quoted 3 lines

It's the cast to 'long' that this gcc complains about. If I remove the cast then it works.

Urgh, the cast looks wrong. I'll remove the cast.

While I am trying things out...

grub-protect should display an error message when it cannot find --tpm2-keyfile. It exits with status code 5 but an error message is missing.

I also seem to have an issue with --tpm2key parameter passed to grub-protect per the documentation but then grub using 'tpm2_key_protector_init --keyfile=(hd0,gpt1)/boot/grub2/sealed.tp' complains about the TPM wire format not being correct. I had to omit this parameter from grub-protect for the key to be unmarshall'able. I also haven't looked whether there's a parameter to tpm2_key_protectore_init to hint at the different key format. Ideally it would figure this out by itself or there was only one format...

ppc64 runs grub in big endian mode, so there may be some issues due to that -- with bitfields for sure: Currently trying to figure out how it is unmarshalling the PCR selection (not a bitfield). When sealing to pcr 0 it marshalled 0x01 0x00 0x00, which is correct but when unmarshalling it is unmarshalls 0x80 0x00 0x00 - odd.

Quoted 9 lines

Gary Lin

Quoted 6 lines
$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Tested-by
#77 lore raw
Quoted 19 lines · Stefan Berger
Quoted 9 lines · Gary Lin
Quoted 7 lines · Stefan Berger

tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]
    48 |       unsigned long num = ((long) GRUB_UINT_MAX) << 2; |                                                  ^~
cc1: all warnings being treated as errors

Quoted 4 lines
Quoted 3 lines

It's the cast to 'long' that this gcc complains about. If I remove the cast then it works.

Urgh, the cast looks wrong. I'll remove the cast.

While I am trying things out...

Quoted 7 lines

grub-protect should display an error message when it cannot find --tpm2-keyfile. It exits with status code 5 but an error message is missing.

I also seem to have an issue with --tpm2key parameter passed to grub-protect per the documentation but then grub using 'tpm2_key_protector_init --keyfile=(hd0,gpt1)/boot/grub2/sealed.tp' complains about the TPM wire format not being correct. I had to omit this parameter from grub-protect for the key to be unmarshall'able. I also haven't looked whether there's a parameter to tpm2_key_protectore_init to hint at the different key format. Ideally it would figure this out by itself or there was only one format...

ppc64 runs grub in big endian mode, so there may be some issues due to that -- with bitfields for sure: Currently trying to figure out how it is unmarshalling the PCR selection (not a bitfield). When sealing to pcr 0 it marshalled 0x01 0x00 0x00, which is correct but when unmarshalling it is unmarshalls 0x80 0x00 0x00 - odd.

This 0x80 stems from the default value for selected PCRs (PCR 7) when none is selected. I had taken the line from the documentation and not added --pcrs 0 reflecting the same pcr selection I had chosen when using grub-protect and that's why it didn't work. So all is good.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#78 lore raw
In reply to Stefan Berger
Quoted 58 lines · Stefan Berger
Quoted 34 lines · Gary Lin
Quoted 33 lines · Gary Lin
Quoted 19 lines · Stefan Berger
Quoted 11 lines · Gary Lin

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I was going to try it out now (on a ppc64 machine) but fail to configure it. The configure and build work on tip of master.

Quoted 8 lines
Quoted 1 line

git clean -xdf ; ./bootstrap && ./configure --prefix=/usr

[...]
Using python3...
Importing unicode...
Importing libgcrypt...
Importing libtasn1...
cp: cannot stat 'grub-core/lib/libtasn1/lib/*.[ch]': No such file or directory

That's weird. The second patch, "libtasn1: import libtasn1-4.19.0", imports the libtasn1 files into grub-core/lib/libtasn1/, and those source files are supposed to exist when applying the patch mentioned below.

Quoted 5 lines
Quoted 2 lines

I'll do a thorough check for that...

I successfully built the patches on a freshly-cloned grub git repo. Since you mentioned ppc64, I wonder if it's caused by the conflicts with the PowerPC Secure Boot patches?

I took your series from the mailing list with the b4 tool. For some reason 02/33 is missing there, maybe because it is too big.

https://lore.kernel.org/grub-devel/20240916033543.gzfture5q4ljuw4b@GaryLaptop/T/#t

I checked out your repo branch and there I can configure but then run into this issue here:

tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]
48 | unsigned long num = ((long) GRUB_UINT_MAX) << 2;
| ^~
cc1: all warnings being treated as errors

Quoted 3 lines

It's the cast to 'long' that this gcc complains about. If I remove the cast then it works.

Hmm the cast is actually inherited from the original test from libtasn1, and my patch just replaces UINT_MAX with GRUB_UINT_MAX.

The original patch from Daniel Axtens replaces the if statement with '#if':

- if (LONG_MAX > INT_MAX)
+#if (GRUB_LONG_MAX > GRUB_INT_MAX)
+ {

+-      unsigned long num = ((long) UINT_MAX) << 2;
++      unsigned long num = ((long) GRUB_UINT_MAX) << 2;

...
+ }
++#endif

Maybe I should restore that part to avoid the cast error in some architectures.

Gary Lin

Quoted 6 lines
$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#79 lore raw
In reply to Gary Lin via Grub-devel
Quoted 11 lines · Gary Lin via Grub-devel

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I tried to build this patch set and got this errors:

./configure --target=i386 --with-platform=pc ...
make
...
tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]

         unsigned long num = ((long) GRUB_UINT_MAX) << 2;
                                                    ^~

cc1: all warnings being treated as errors

May I ask you to test 32-bit builds, e.g. as above, before posting next versions of patches?

I will send more comments in the following days. I will drop you a line when you can repost the patch set.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#80 lore raw
Quoted 20 lines · Daniel Kiper
Quoted 11 lines · Gary Lin via Grub-devel

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I tried to build this patch set and got this errors:

./configure --target=i386 --with-platform=pc ...
make
...
tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]

Quoted 7 lines
         unsigned long num = ((long) GRUB_UINT_MAX) << 2;
                                                    ^~

cc1: all warnings being treated as errors

May I ask you to test 32-bit builds, e.g. as above, before posting next versions of patches?

Sorry for that. Will do the 32-bit test build for the next version.

Quoted 3 lines

I will send more comments in the following days. I will drop you a line when you can repost the patch set.

Okay.

Gary Lin

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#81 lore raw
Quoted 28 lines · Gary Lin via Grub-devel
Quoted 20 lines · Daniel Kiper
Quoted 11 lines · Gary Lin via Grub-devel

GIT repo for v19: https://github.com/lcp/grub2/tree/tpm2-unlock-v19

This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.

To support TPM 2.0 Key File format(*2), patch 1~7,9-16 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.

I tried to build this patch set and got this errors:

./configure --target=i386 --with-platform=pc ...
make
...
tests/asn1/tests/Test_overflow.c: In function ‘test_overflow’:
tests/asn1/tests/Test_overflow.c:48:50: error: left shift of negative value [-Werror=shift-negative-value]

Quoted 7 lines
         unsigned long num = ((long) GRUB_UINT_MAX) << 2;
                                                    ^~

cc1: all warnings being treated as errors

May I ask you to test 32-bit builds, e.g. as above, before posting next versions of patches?

Quoted 6 lines

Sorry for that. Will do the 32-bit test build for the next version.

Quoted 3 lines

I will send more comments in the following days. I will drop you a line when you can repost the patch set.

Okay.

Go ahead... I will review updated documentation in v20.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel