From: Gary Lin via Grub-devel <grub-devel@gnu.org>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: Gary Lin <glin@suse.com>, Daniel Kiper <daniel.kiper@oracle.com>,
mchang@suse.com, patrick.colp@oracle.com,
Stefan Berger <stefanb@linux.ibm.com>,
jejb@linux.ibm.com, Glenn Washburn <development@efficientek.com>
Subject: [PATCH v4 11/12] docs: Update NV index mode of TPM2 key protector
Date: Fri, 21 Mar 2025 15:59:07 +0800 [thread overview]
Message-ID: <20250321075908.10523-12-glin@suse.com> (raw)
In-Reply-To: <20250321075908.10523-1-glin@suse.com>
This commit updates the NV index mode section and the grub-protect
section to reflect the recent changes in TPM2 key protector and
grub-protect.
Signed-off-by: Gary Lin <glin@suse.com>
---
docs/grub.texi | 188 +++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 166 insertions(+), 22 deletions(-)
diff --git a/docs/grub.texi b/docs/grub.texi
index ae89838bc..cf64c54c8 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -9142,46 +9142,120 @@ When/After the shim or GRUB are updated, it only requires to run the last
@subsection NV index mode
Instead of storing the sealed key in a file, NV index mode uses the TPM
-non-volatile memory to store the sealed key.
+non-volatile memory to store the sealed key and could be useful when accessing
+the file is not possible.
-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}.
+However, the Linux root user must be careful who she/he gives access to the
+TPM (tss group) since those users will also be able to modify the NV index
+that's holding the key.
-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.
+There are two types of TPM handles supported by NV index mode: persistent
+handle and NV index handle.
+
+@subsubsection Persistent handle
+
+The range of persistent handles is from @kbd{0x81000000} to @kbd{0x81FFFFFF}.
+The persistent handle is designed to make TPM objects persistent through
+power cycles, and only TPM objects, such as RSA or EC keys, are accepted.
+Thus, only the raw format is supported by persistent handles. The following
+shows the @command{grub-protect} command to seal the disk key @file{luks.key}
+into the persistent handle @kbd{0x81000000} with the PCRs @kbd{0,2,4,7}.
@example
-# @kbd{tpm2_createprimary -C o -g sha256 -G ecc -c primary.ctx}
+@group
+# @kbd{grub-protect \
+ --protector=tpm2 \
+ --action=add \
+ --tpm2-bank=sha256 \
+ --tpm2-pcrs=0,2,4,7 \
+ --tpm2-keyfile=luks.key \
+ --tpm2-nvindex=0x81000000}
+@end group
@end example
-The next commands collect the current values of PCR 0, 2, 4, and 7 and saves
-them in @file{pcr.dat}.
+To unseal the key, we have to specify the mode @kbd{nv}, the persistent handle
+@kbd{0x81000000}, and the PCRs @kbd{0,2,4,7} for the @command{tpm2_key_protector_init}
+command.
@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}
+grub> @kbd{tpm2_key_protector_init --mode=nv --nvindex=0x81000000 --pcrs=0,2,4,7}
+grub> @kbd{cryptomount -u <UUID> --protector tpm2}
@end example
-The last commands seal @file{luks.key} with the primary key and stores the
-result in @kbd{0x81000000}.
+If the key in the persistent handle becomes unwanted, the following
+@command{grub-protect} command removes the specified persistent handle
+@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}
+@group
+# @kbd{grub-protect \
+ --protector=tpm2 \
+ --action=remove \
+ --tpm2-evict \
+ --tpm2-nvindex=0x81000000}
+@end group
@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 the @command{tpm2_key_protector_init}
-command.
+@subsubsection NV index handle
+
+The range of NV index handles is from @kbd{0x1000000} to @kbd{0x1FFFFFF}.
+Unlike the persistent handle, the NV index handle allows user-defined data,
+so it can easily support both the TPM 2.0 Key File format as well as the raw
+format.
+
+The following @kbd{grub-protect} command seals the disk key @file{luks.key}
+into the NV index handle @kbd{0x1000000} with the PCRs @kbd{0,2,4,7} while
+using the TPM 2.0 Key File format.
@example
-grub> @kbd{tpm2_key_protector_init --mode=nv --nvindex=0x81000000 --pcrs=0,2,4,7}
+@group
+# @kbd{grub-protect \
+ --protector=tpm2 \
+ --action=add \
+ --tpm2key \
+ --tpm2-bank=sha256 \
+ --tpm2-pcrs=0,2,4,7 \
+ --tpm2-keyfile=luks.key \
+ --tpm2-nvindex=0x1000000}
+@end group
+@end example
+
+Furthermore, it is also possible to insert an existing key file,
+@file{sealed.tpm}, into a specific NV index handle using the following
+tpm2-tools (@url{https://github.com/tpm2-software/tpm2-tools}) commands.
+
+@example
+@group
+# @kbd{tpm2_nvdefine -C o \
+ -a "ownerread|ownerwrite" \
+ -s $(stat -c %s sealed.tpm) \
+ 0x1000000}
+@end group
+# @kbd{tpm2_nvwrite -C o -i sealed.tpm 0x1000000}
+@end example
+
+When unsealing the key in TPM 2.0 Key File format, only the mode @kbd{nv}
+and the NV index handle @kbd{0x1000000} have to be specified for the
+@command{tpm2_key_protector_init} command.
+
+@example
+grub> @kbd{tpm2_key_protector_init --mode=nv --nvindex=0x1000000}
grub> @kbd{cryptomount -u <UUID> --protector tpm2}
@end example
+The following @command{grub-protect} command allows to remove the specified
+NV index handle @kbd{0x1000000}.
+
+@example
+@group
+# @kbd{grub-protect \
+ --protector=tpm2 \
+ --action=remove \
+ --tpm2-evict \
+ --tpm2-nvindex=0x1000000}
+@end group
+@end example
+
@subsection Setting up software TPM for EMU platform
In order to test TPM2 key protector and TPM2 Software Stack (TSS2), it is
@@ -10136,11 +10210,16 @@ unsealing. (default: @samp{7})
@item --tpm2-srk=@var{handle}
Set the SRK handle, e.g. @samp{0x81000000}, if the SRK is to be made persistent.
+@item --tpm2-nvindex=@var{handle}
+Set the handle, e.g. @samp{0x81000000} or @samp{0x1000000}, for NV index mode.
+
@item --tpm2key
Use TPM 2.0 Key File format.
@end table
+@subsection 'Add' action
+
Before sealing the key, please check the TPM PCR usage
(@pxref{TPM2 key protector, TPM PCR usage}) to choose a proper set of PCRs.
@@ -10166,12 +10245,77 @@ grub> @kbd{tpm2_key_protector_init -T (hd0,gpt1)/efi/grub/sealed.tpm}
grub> @kbd{cryptomount -u <UUID> -P tpm2}
@end example
+Besides writing the PCR-sealed key into a file, @command{grub-protect} can
+write the sealed key into TPM non-volatile memory. Here is the
+@command{grub-protect} command to write the sealed key into the NV index
+handle @samp{0x1000000}.
+
+@example
+@group
+# @kbd{grub-protect --action=add \
+ --protector=tpm2 \
+ --tpm2-pcrs=0,2,4,7 \
+ --tpm2key \
+ --tpm2-keyfile=luks.key \
+ --tpm2-nvindex=0x1000000}
+@end group
+@end example
+
+Later, GRUB can fetch the key from @samp{0x1000000}.
+
+@example
+grub> @kbd{tpm2_key_protector_init --mode=nv --nvindex=0x1000000}
+grub> @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 the
@command{tpm2_key_protector_init} command and invoke the @command{cryptomount}
command without @kbd{-P tpm2}.
-The only use case for the `remove' action is when the SRK is made persistent.
+@subsection 'Remove' action
+
+The `remove' action is used to remove the handles for NV index mode and the
+persistent SRK.
+
+@subsubsection Handles for NV index mode
+
+There are two types of TPM handles supported by NV index mode: persistent
+handles and NV index handles, and @command{tpm2_getcap} can be used to
+check the existing handles.
+
+To display the list of existing persistent handles:
+
+@example
+@group
+# @kbd{tpm2_getcap handles-persistent}
+- 0x81000000
+@end group
+@end example
+
+Similarly, to display the list of existing NV index handles:
+
+@example
+@group
+# @kbd{tpm2_getcap handles-nv-index}
+- 0x1000000
+@end group
+@end example
+
+If the sealed key at an NV index handle is not needed anymore, the user can
+remove the handle with @kbd{--tpm2-nvindex} and @kbd{--tpm2-evict}. For
+example, this command removes the data from NV index @samp{0x1000000}:
+
+@example
+@group
+# @kbd{grub-protect --action=remove \
+ --protector=tpm2 \
+ --tpm2-evict \
+ --tpm2-nvindex 0x1000000} \
+@end group
+@end example
+
+@subsubsection Persistent SRK
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 may prefer
--
2.43.0
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2025-03-21 8:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 7:58 [PATCH v4 00/12] TPM2 key protector follow-up patches Gary Lin via Grub-devel
2025-03-21 7:58 ` [PATCH v4 01/12] tpm2_key_protector: dump PCRs on policy fail Gary Lin via Grub-devel
2025-03-21 7:58 ` [PATCH v4 02/12] tpm2_key_protector: Add 'tpm2_dump_pcr' command Gary Lin via Grub-devel
2025-03-21 7:58 ` [PATCH v4 03/12] tss2: Fix the missing authCommand Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 04/12] tss2: Add TPM 2.0 NV index commands Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 05/12] tpm2_key_protector: Unseal key from a buffer Gary Lin via Grub-devel
2025-03-25 16:01 ` Daniel Kiper via Grub-devel
2025-03-26 7:54 ` Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 06/12] tpm2_key_protector: Support NV index handles Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 07/12] util/grub-protect: Support NV index mode Gary Lin via Grub-devel
2025-03-26 16:14 ` Daniel Kiper via Grub-devel
2025-03-21 7:59 ` [PATCH v4 08/12] tests/tpm2_key_protector_test: Simplify the NV index mode test Gary Lin via Grub-devel
2025-03-24 14:21 ` Stefan Berger
2025-03-26 16:16 ` Daniel Kiper via Grub-devel
2025-03-21 7:59 ` [PATCH v4 09/12] tests/tpm2_key_protector_test: Reset 'ret' on fail Gary Lin via Grub-devel
2025-03-24 13:48 ` Stefan Berger
2025-03-24 14:29 ` Vladimir 'phcoder' Serbinenko
2025-03-24 14:35 ` Stefan Berger
2025-03-25 7:18 ` Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 10/12] tests/tpm2_key_protector_test: Add more NV index mode tests Gary Lin via Grub-devel
2025-03-24 14:19 ` Stefan Berger
2025-03-21 7:59 ` Gary Lin via Grub-devel [this message]
2025-03-21 7:59 ` [PATCH v4 12/12] INSTALL: Document the packages needed for TPM2 key protector tests Gary Lin via Grub-devel
2025-03-26 16:19 ` Daniel Kiper via Grub-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250321075908.10523-12-glin@suse.com \
--to=grub-devel@gnu.org \
--cc=daniel.kiper@oracle.com \
--cc=development@efficientek.com \
--cc=glin@suse.com \
--cc=jejb@linux.ibm.com \
--cc=mchang@suse.com \
--cc=patrick.colp@oracle.com \
--cc=stefanb@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.