]> git.ipfire.org Git - thirdparty/grub.git/log
thirdparty/grub.git
31 hours agodocs: Write how to import new libgcrypt master
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:21 +0000 (14:52 +0000)] 
docs: Write how to import new libgcrypt

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agolibgcrypt: Fix a memory leak
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:20 +0000 (14:52 +0000)] 
libgcrypt: Fix a memory leak

Fixes: CID 468917
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agolibgcrypt: Don't use 64-bit division on platforms where it's slow
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:19 +0000 (14:52 +0000)] 
libgcrypt: Don't use 64-bit division on platforms where it's slow

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agoutil/import_gcry: Fix pylint warnings
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:18 +0000 (14:52 +0000)] 
util/import_gcry: Fix pylint warnings

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agoutil/import_gcry: Make compatible with Python 3.4
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:17 +0000 (14:52 +0000)] 
util/import_gcry: Make compatible with Python 3.4

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agolibgcrypt: Import blake family of hashes
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:16 +0000 (14:52 +0000)] 
libgcrypt: Import blake family of hashes

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agolibgcrypt: Ignore sign-compare warnings
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:15 +0000 (14:52 +0000)] 
libgcrypt: Ignore sign-compare warnings

libgcrypt itself is compiled with -Wno-sign-compare. Do the same for consistency.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agolibgcrypt: Remove now unneeded compilation flag
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:14 +0000 (14:52 +0000)] 
libgcrypt: Remove now unneeded compilation flag

HAVE_STRTOUL is now defined in stdlib.h. Include it in g10lib.h rather
than defining on command line.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agolibgcrypt: Fix Coverity warnings
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:13 +0000 (14:52 +0000)] 
libgcrypt: Fix Coverity warnings

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agokeccak: Disable acceleration with SSE asm
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:12 +0000 (14:52 +0000)] 
keccak: Disable acceleration with SSE asm

Libgcrypt code assumes that on x64 all SSE registers are fair game.
While it's true that CPUs in question support it, we disable it in
our compilation options. Disable the offending optimization.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agotests: Add DSA and RSA SEXP tests
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:11 +0000 (14:52 +0000)] 
tests: Add DSA and RSA SEXP tests

This allows us to test purely the integration of the implementation of
DSA and RSA from libgcrypt without concerning with additional code.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agolibgcrypt: Adjust import script, definitions and API users for libgcrypt 1.11
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:10 +0000 (14:52 +0000)] 
libgcrypt: Adjust import script, definitions and API users for libgcrypt 1.11

This patches modifies the GRUB-libgcrypt API to match new libgcrypt 1.11.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agob64dec: Add harness for compilation in GRUB environment
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:09 +0000 (14:52 +0000)] 
b64dec: Add harness for compilation in GRUB environment

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agob64dec: Import b64dec from gpg-error
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:08 +0000 (14:52 +0000)] 
b64dec: Import b64dec from gpg-error

Imported from libgpg-error 1.51.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agolibgcrypt: Import libgcrypt 1.11
Vladimir Serbinenko [Mon, 7 Jul 2025 14:52:07 +0000 (14:52 +0000)] 
libgcrypt: Import libgcrypt 1.11

We currently use an old version of libgcrypt which results in us having
fewer ciphers and missing on many other improvements.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
31 hours agoloader/efi/linux: Use shim loader image handle where available
Mate Kukri [Tue, 8 Jul 2025 20:21:17 +0000 (21:21 +0100)] 
loader/efi/linux: Use shim loader image handle where available

Not reusing these handles will result in image measurements showing up
twice in the event log.

On the occasion add missing grub_free() call.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
37 hours agoloader/efi/chainloader: Use shim loader image handle where available
Mate Kukri [Tue, 8 Jul 2025 20:21:16 +0000 (21:21 +0100)] 
loader/efi/chainloader: Use shim loader image handle where available

Not reusing these handles will result in image measurements showing up
twice in the event log.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
37 hours agoefi/sb: Add API for retrieving shim loader image handles
Mate Kukri [Tue, 8 Jul 2025 20:21:15 +0000 (21:21 +0100)] 
efi/sb: Add API for retrieving shim loader image handles

Not reusing these handles will result in image measurements showing up
twice in the event log.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
37 hours agoefi/sb: Add support for the shim loader protocol
Mate Kukri [Tue, 8 Jul 2025 20:21:14 +0000 (21:21 +0100)] 
efi/sb: Add support for the shim loader protocol

Use loader protocol for image verification where available, otherwise
fall back to the old shim lock protocol.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
37 hours agoefi: Provide wrappers for load_image, start_image and unload_image
Julian Andres Klode [Tue, 8 Jul 2025 20:21:13 +0000 (21:21 +0100)] 
efi: Provide wrappers for load_image, start_image and unload_image

These can be used to register a different implementation later,
for example, when shim provides a protocol with those functions.

Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
38 hours agoloader/arm64/xen_boot: Consider alignment calling grub_arch_efi_linux_boot_image()
Frediano Ziglio [Fri, 4 Jul 2025 14:06:16 +0000 (15:06 +0100)] 
loader/arm64/xen_boot: Consider alignment calling grub_arch_efi_linux_boot_image()

The Xen image is loaded with an alignment, not always at "start".

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
38 hours agoloader/arm64/xen_boot: Use bool instead of int
Frediano Ziglio [Fri, 4 Jul 2025 14:05:12 +0000 (15:05 +0100)] 
loader/arm64/xen_boot: Use bool instead of int

More readable, could consume less space.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
38 hours agoloader/arm64/xen_boot: Remove correctly all modules loaded by xen_module command
Frediano Ziglio [Fri, 4 Jul 2025 08:39:08 +0000 (09:39 +0100)] 
loader/arm64/xen_boot: Remove correctly all modules loaded by xen_module command

We need to use FOR_LIST_ELEMENTS_SAFE() instead of FOR_LIST_ELEMENTS()
as single_binary_unload(), called during the loop, is changing the list
using grub_list_remove(). Given the environment probably the old code
simply removed only the first module on the list not freeing all the others.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
38 hours agodl: Fix grub_dl_is_persistent() for emu
Gary Lin [Thu, 3 Jul 2025 06:09:41 +0000 (14:09 +0800)] 
dl: Fix grub_dl_is_persistent() for emu

When attempting to build grub-emu the compilation failed with the
following error message:

  include/grub/dl.h: In function â€˜grub_dl_is_persistent’:
  include/grub/dl.h:262:1: error: no return statement in function returning non-void [-Werror=return-type]

To avoid the error make the function always return 0.

Fixes: ba8eadde6be1 (dl: Provide a fake grub_dl_set_persistent() and grub_dl_is_persistent() for the emu target)
Signed-off-by: Gary Lin <glin@suse.com>
Cc: Daniel Axtens <dja@axtens.net>
Cc: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoloader/i386/pc/linux: Fix resource leak
Lidong Chen [Mon, 23 Jun 2025 17:46:01 +0000 (17:46 +0000)] 
loader/i386/pc/linux: Fix resource leak

In grub_cmd_initrd(), memory is allocated for variable initrd_ctx
before calling grub_relocator_alloc_chunk_align_safe(). When the
function call fails, initrd_ctx should be freed before exiting
grub_cmd_initrd().

Fixes: CID 473852
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoloader/efi/linux: Unload previous Linux kernel/initrd before updating kernel size
Adriano Cordova [Wed, 18 Jun 2025 15:38:14 +0000 (11:38 -0400)] 
loader/efi/linux: Unload previous Linux kernel/initrd before updating kernel size

Unload previous Linux kernel/initrd before updating the global variable
kernel_size. Otherwise the previous Linux kernel gets deallocated with
the kernel_size of the Linux kernel that is being currently loaded.

Signed-off-by: Adriano Cordova <adriano.cordova@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoloader/efi/linux: Correctly terminate load_options member
Frediano Ziglio [Wed, 25 Jun 2025 13:42:43 +0000 (14:42 +0100)] 
loader/efi/linux: Correctly terminate load_options member

If a simple string for arguments are passed it should be NUL terminated.
This is true for other code but not for "linux" command.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoloader/efi/linux: Use sizeof() instead of constant
Frediano Ziglio [Wed, 25 Jun 2025 13:42:42 +0000 (14:42 +0100)] 
loader/efi/linux: Use sizeof() instead of constant

This is more consistent with the above code using sizeof(grub_efi_char16_t).

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoloader/efi/linux: Use proper type for len variable
Frediano Ziglio [Wed, 25 Jun 2025 13:42:41 +0000 (14:42 +0100)] 
loader/efi/linux: Use proper type for len variable

Although the length should not exceed 2^31 grub_size_t is more
suitable for that variable. len is used to compute the size
of buffers which in C is a size_t, not a int. It is used
for GRUB_EFI_BYTES_TO_PAGES which expects unsigned values.
It is assigned to load_options_size which is unsigned, not signed.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoloader/efi/linux: Do not pass excessive size for source string
Frediano Ziglio [Wed, 25 Jun 2025 13:42:40 +0000 (14:42 +0100)] 
loader/efi/linux: Do not pass excessive size for source string

The size passed to grub_utf8_to_utf16() for the source string is
used as a limit for the string if NUL character is not encountered.
However, len, which is "strlen(src) * 2 + 2" is surely greater than
strlen(src). Pass the exact correct length.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoloader/efi/linux: Remove useless assignment
Frediano Ziglio [Wed, 25 Jun 2025 13:42:38 +0000 (14:42 +0100)] 
loader/efi/linux: Remove useless assignment

If the following allocation fails this would leave load_options NULL
while load_options_size not valid. If the allocation succeed
load_options_size is overwritten.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoinclude/grub/charset.h: Update documentation
Frediano Ziglio [Wed, 25 Jun 2025 13:42:39 +0000 (14:42 +0100)] 
include/grub/charset.h: Update documentation

(grub_size_t) -1 is never returned, the function always return
a not negative values. This is important for overflows considerations.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoRevert "lzma: Make sure we don't dereference past array"
Lidong Chen [Mon, 23 Jun 2025 17:42:32 +0000 (17:42 +0000)] 
Revert "lzma: Make sure we don't dereference past array"

Commit 40e261b89b71 (lib/LzmaEnc: Validate "len" before subtracting)
ensures that the variable len is at least 2. As a result, GetLenToPosState(len)
never returns a value greater than or equal to kNumLenToPosStates,
making the changes introduced in the commit 16c0dbf4bc6a (lzma: Make
sure we don't dereference past array) unreachable and no longer necessary.

This reverts commit 16c0dbf4bc6a (lzma: Make sure we don't dereference past array).

Fixes: CID 481982
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agotests/util/grub-shell: Correct netboot and file_filter test failure
Andrew Hamilton [Sat, 21 Jun 2025 15:50:38 +0000 (10:50 -0500)] 
tests/util/grub-shell: Correct netboot and file_filter test failure

Correct a test failure in netboot_test and file_filter_test caused by an
issue cleaning up the tmp directory created for netboot. Netboot creates
a subdirectory in the tmp folder that causes the rmdir to fail - so
cleanup the subdirectory first.

Fixes: 1d59f39b5f1b (tests/util/grub-shell: Remove the work directory on successful run and debug is not on)
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Tested-by: Leo Sandoval <lsandova@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agonormal/charset: Fix underflow and overflow in loop init
Lidong Chen [Wed, 18 Jun 2025 19:24:23 +0000 (19:24 +0000)] 
normal/charset: Fix underflow and overflow in loop init

In bidi_line_wrap(), "kk - 1" in the for loop init, "i = kk - 1",
underflows when "kk" (unsigned int) is 0. Assigning the result of
"kk - 1" to signed int "i" may cause overflow. To address both
issues, cast "kk" to a signed type before subtraction to ensure
safe arithmetic and assignment.

Fixed: CID 473874

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
2 weeks agodl: Provide a fake grub_dl_set_persistent() and grub_dl_is_persistent() for the emu...
Daniel Axtens [Tue, 10 Jun 2025 15:50:38 +0000 (21:20 +0530)] 
dl: Provide a fake grub_dl_set_persistent() and grub_dl_is_persistent() for the emu target

Trying to start grub-emu with a module that calls grub_dl_set_persistent()
and grub_dl_is_persistent() will crash because grub-emu fakes modules and
passes NULL to the module init function.

Provide an empty function for the emu case.

Fixes: ee7808e2197c (dl: Add support for persistent modules)
Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/grub-protect: Correct uninit "err" variable
Andrew Hamilton [Wed, 18 Jun 2025 01:58:26 +0000 (20:58 -0500)] 
util/grub-protect: Correct uninit "err" variable

In function protect_tpm2_export_tpm2key(), the "err" variable
is uninitialized in the normal (error free) path, so ensure this
defaults to GRUB_ERR_NONE.

This causes the GRUB build to fail with clang (observed with clang-14).

Fixes: 5934bf51c (util/grub-protect: Support NV index mode)
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agognulib: Bring back the fix for resolving unused variable issue
Lidong Chen [Thu, 26 Jun 2025 15:05:01 +0000 (17:05 +0200)] 
gnulib: Bring back the fix for resolving unused variable issue

This patch resolved a minor issue spotted by Coverity:
  a983d36bd917 (gnulib/regexec: Resolve unused variable)

But, it was removed by the Gnulib update:
  2b7902459803 (Update gnulib version and drop most gnulib patches)

It caused Coverity to continue to flag the issue. Daniel Kiper
suggested to bring back the patch a983d36bd917 (gnulib/regexec: Resolve
unused variable).

Fixes: CID 292459
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agognulib: Add patch to allow GRUB w/GCC-15 compile
Andrew Hamilton [Wed, 18 Jun 2025 01:58:25 +0000 (20:58 -0500)] 
gnulib: Add patch to allow GRUB w/GCC-15 compile

Pull in Gnulib fix to allow lib/base64.c to compile using GCC 15 or newer.

Pulled from Gnulib commit 25df6dc425 (Silence some
-Wunterminated-string-initialization warnings.)

GCC 15 adds a new compiler warning "-Wunterminated-string-initialization"
that will trigger what is considered a false-positive in lib/base64.c as
this array is not treated as a string but an array of characters so the
lack of NUL string terminator is expected.

GCC team has added ability to flag such instances of arrays that the
compiler may think are strings as "nonstring" arrays to avoid this
warning: __attribute__((nonstring)).

Fixes: https://savannah.gnu.org/bugs/?66470
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agognulib/regexec: Fix resource leak
Alec Brown [Tue, 10 Jun 2025 15:19:45 +0000 (15:19 +0000)] 
gnulib/regexec: Fix resource leak

In the function merge_state_with_log(), memory is allocated for the variable
next_nodes when creating a union of the variables table_nodes and log_nodes.
However, if next_state->entrance_nodes is NULL, then table_nodes becomes NULL
and we still allocate memory to copy the content of log_nodes. This can cause
a resource leak since we only free the memory for next_nodes if table_nodes
isn't NULL. To prevent this, we need to check that next_state->entrance_nodes
isn't NULL before allocating memory for the union.

This issue has been fixed in the latest version of gnulib and I've backported
this change to maintain consistency.

This issue was found by a Coverity scan of GRUB2 under the CID 473887.

Fixes: CID 473887
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agognulib/regcomp: Fix resource leak
Alec Brown [Tue, 10 Jun 2025 15:19:44 +0000 (15:19 +0000)] 
gnulib/regcomp: Fix resource leak

In the functions create_initial_state() and calc_eclosure_iter(), memory
is allocated for the elems member of a re_node_set structure but that
memory isn't freed on error. Before returning an error, a call to
re_node_set_free() should be made to prevent the resource leak.

This issue has been fixed in the latest version of gnulib and I've
backported this change to maintain consistency.

This issue was found by a Coverity scan of GRUB2 under the following
CIDs: 473869, 473888.

Fixes: CID 473869
Fixes: CID 473888
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agotests/tpm2_key_protector_test: Add tests for SHA-384 PCR bank
Gary Lin [Fri, 13 Jun 2025 07:02:35 +0000 (15:02 +0800)] 
tests/tpm2_key_protector_test: Add tests for SHA-384 PCR bank

Add a few more tests to seal and unseal the key with the SHA-384 PCR
bank instead of the default SHA-256 PCR bank.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agotpm2_key_protector: Dump the PCR bank for key unsealing
Gary Lin [Fri, 13 Jun 2025 07:02:34 +0000 (15:02 +0800)] 
tpm2_key_protector: Dump the PCR bank for key unsealing

TPM 2.0 Key File format stores the PCR selection in the parameters
for TPM2_PolicyPCR and it already contains the selected PCR bank.
Currently, tpm2_key_protector dumped the PCR bank specified by the
--bank option, and it may not be the PCR bank for key unsealing.

To dump the real PCR bank for key unsealing, this commit records the PCR
bank used by TPM2_PolicyPCR and dumps PCR values from that bank when
necessary.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoutil/grub-protect: Fix the hash algorithm of PCR digest
Gary Lin [Fri, 13 Jun 2025 07:02:33 +0000 (15:02 +0800)] 
util/grub-protect: Fix the hash algorithm of PCR digest

For tpm2_key_protector and grub-protect, SHA-256 is chosen as the hash
algorithm for the TPM session. However, grub-protect mistakenly used the
hash algorithm of the PCR bank to calculate PCR digest. If the user
chose a PCR bank other than SHA-256, grub-protect created a non-SHA-256
PCR digest to seal the key. But, tpm2_key_protector expects a SHA-256
PCR digest to the TPM unsealing session, so it would fail due to digest
mismatch.

This commit fixes the hash algorithm of PCR digest in grub-protect to
avoid the potential unsealing failure.

Fixes: https://github.com/lcp/grub2/issues/4
Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agobuild: Add new header files to dist to allow building from tar
Andrew Hamilton [Wed, 11 Jun 2025 03:15:46 +0000 (22:15 -0500)] 
build: Add new header files to dist to allow building from tar

Several new header files have been added to GRUB which need
to be manually added to the dist archive. This allows building
from the tar archive created by "make dist".

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agobuild: Remove extra_deps.lst from EXTRA_DIST
Andrew Hamilton [Wed, 11 Jun 2025 03:15:45 +0000 (22:15 -0500)] 
build: Remove extra_deps.lst from EXTRA_DIST

This file is auto-generated based on the selected platform and should
not be included in the source tarball.

Fixes: 6744840b (build: Track explicit module dependencies in Makefile.core.def)
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agolib/LzmaEnc: Validate "len" before subtracting
Lidong Chen [Thu, 12 Jun 2025 00:03:58 +0000 (00:03 +0000)] 
lib/LzmaEnc: Validate "len" before subtracting

In LzmaEnc_CodeOneBlock(), both GetOptimumFast() and GetOptimum()
returns a value of greater or equal to 1, which is assigned to
"len". But since LZMA_MATCH_LEN_MIN == 2, "len" should be validated
before performing "len - LZMA_MATCH_LEN_MIN" to avoid underflow
when "len" equals to 1.

Fixes: CID 51508
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
4 weeks agoosdep/unix/hostdisk: Fix signed integer overflow
Lidong Chen [Thu, 5 Jun 2025 05:03:19 +0000 (05:03 +0000)] 
osdep/unix/hostdisk: Fix signed integer overflow

The potential overflow issue arises at "size += ret;" because "size"
is of type ssize_t (signed) while "len" is size_t (unsigned). Repeatedly
adding read sizes, "ret", to "size" can potentially exceed the maximum
value of ssize_t, causing it to overflow into a negative or incorrect value.
The fix is to ensure "len" is within the range of SSIZE_MAX.

Fixes: CID 473850
Fixes: CID 473863
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agodisk/luks2: Add attempting to decrypt message to align with luks and geli modules
Egor Ignatov [Tue, 27 May 2025 08:28:45 +0000 (11:28 +0300)] 
disk/luks2: Add attempting to decrypt message to align with luks and geli modules

Signed-off-by: Egor Ignatov <egori@altlinux.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agoosdep/linux/getroot: Detect DDF container similar to IMSM
Renaud Métrich [Thu, 24 Apr 2025 09:43:28 +0000 (11:43 +0200)] 
osdep/linux/getroot: Detect DDF container similar to IMSM

Similarly to Intel IMSM, there are BIOS and UEFI implementations that
support DDF containers natively.

DDF and IMSM are very similar in handling, especially these should not
be considered as RAID abstraction. This fixes the requirement of having
a device map when probing DDF containers.

Fixes: https://issues.redhat.com/browse/RHEL-44336
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agofs/fshelp: Avoid possible NULL pointer deference
Andrew Hamilton [Thu, 22 May 2025 03:20:41 +0000 (22:20 -0500)] 
fs/fshelp: Avoid possible NULL pointer deference

Avoid attempting to defererence a NULL pointer to call read_symlink() when
the given filesystem does not provide a read_symlink() function. This could
be triggered if the calling filesystem had a file marked as a symlink.
This appears possible for HFS and was observed during fuzzing of NTFS.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agofs/ntfs: Correct possible infinite loops/hangs
Andrew Hamilton [Thu, 22 May 2025 03:20:40 +0000 (22:20 -0500)] 
fs/ntfs: Correct possible infinite loops/hangs

Correct several infinite loops/hangs found during fuzzing. The issues
fixed here could occur if certain specific malformed NTFS file systems
were presented to GRUB. Currently, GRUB does not allow NTFS file system
access when lockdown mode is enforced, so these should be of minimal
impact.

The changes made in this commit generally correct issues such as attempting
to iterate through a buffer using a length read from the NTFS file system
without confirming the length is larger than 0.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agofs/ntfs: Correct possible access violations
Andrew Hamilton [Thu, 22 May 2025 03:20:39 +0000 (22:20 -0500)] 
fs/ntfs: Correct possible access violations

Correct several memory access violations found during fuzzing.
The issues fixed here could occur if certain specific malformed NTFS
file systems were presented to GRUB. Currently, GRUB does not allow NTFS
file system access when lockdown mode is enforced, so these should be of
minimal impact.

The changes made in this commit generally correct issues where pointers
into data buffers were being calculated using lengths read from the
NTFS file system without sufficient bounds/sanity checking; or
attempting to access elements of a structure to free them, when the
structure pointer is NULL.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agofs/ntfs: Correct attribute vs attribute list validation
Andrew Hamilton [Thu, 22 May 2025 03:20:38 +0000 (22:20 -0500)] 
fs/ntfs: Correct attribute vs attribute list validation

Correct ntfs_test test failures around attempting to validate attribute
list entries as attributes. The NTFS code uses common logic in some
places to parse both attributes and attribute_lists which complicates
validation. Attribute lists contain different headers including a
different size of the length field (2 bytes) at offset 4 instead of the
4 byte length field used in attributes at offset 4. There are other
differences as well, but attempting to validate attribute list types
using attribute header validation was causing failure of the NTFS test
suite. This change restores some of the validation logic which may be
shared between attributes and attribute lists to be closer to the
original logic prior to fixes for previous CVEs. A following commit will
address some of the implications of removing this validation logic by
correcting some fuzzer failures (some which are exposed by removing the
validation in some of the cases).

Fixes: 067b6d225 (fs/ntfs: Implement attribute verification)
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agofs/ntfs: Correct regression with run list calculation
Andrew Hamilton [Thu, 22 May 2025 03:20:37 +0000 (22:20 -0500)] 
fs/ntfs: Correct regression with run list calculation

Correct ntfs_test test failures around attempting to validate attribute
run list values. The calculation was incorrect for the "curr" variable.
With previous calculation, some file systems would fail validation
despite being well-formed and valid. This was caused by incrementing
"curr" by min_size which included both the (already accounted for)
min_size as well as the size of the run list. Correct by making a new
variable "run_size" to denote the current run list size to increment
both "curr" and "min_size" separately.

Fixes: 067b6d225 (fs/ntfs: Implement attribute verification)
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agolib/envblk: Ignore empty new lines while parsing env files
Shreenidhi Shedi [Mon, 19 May 2025 18:19:54 +0000 (23:49 +0530)] 
lib/envblk: Ignore empty new lines while parsing env files

Environment files may contain empty lines, which should be ignored
during parsing. Currently, these lines are not skipped and resulting in
incorrect behavior. This patch adds a check to skip empty lines along
with those starting with "#".

Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Reviewed-by: Alexey Makhalov <alexey.makhalov@broadcom.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agofs/zfs: Fix another memory leak in ZFS code
Glenn Washburn [Mon, 5 May 2025 22:09:19 +0000 (17:09 -0500)] 
fs/zfs: Fix another memory leak in ZFS code

Commit b66c6f918 (fs/zfs: Fix a number of memory leaks in ZFS code)
fixes many of the same leaks detected in bug #63846 except one, which
is fixed here.

Fixes: https://savannah.gnu.org/bugs/?63846
Fixes: b66c6f918 (fs/zfs: Fix a number of memory leaks in ZFS code)
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 weeks agotests: Disable gfxterm_menu and cmdline_cat tests
Glenn Washburn [Mon, 5 May 2025 21:11:36 +0000 (16:11 -0500)] 
tests: Disable gfxterm_menu and cmdline_cat tests

Those tests fail depending on the version of unifont. As we don't distribute
our own unifont it fails for most users. Disable them so that they don't mask
real failures. They can be reinstated once we solve unifont problem.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agocryptocheck: Add --quiet option
Michael Chang [Fri, 14 Mar 2025 11:03:39 +0000 (19:03 +0800)] 
cryptocheck: Add --quiet option

The option can be used to suppress output if we only want to test the
return value of the command.

Also, mention this option in the documentation.

Signed-off-by: Michael Chang <mchang@suse.com>
Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agodisk/cryptodisk: Wipe the passphrase from memory
Maxim Suhanov [Tue, 4 Mar 2025 12:27:59 +0000 (15:27 +0300)] 
disk/cryptodisk: Wipe the passphrase from memory

Switching to another EFI boot application while there are secrets in
RAM is dangerous, because not all firmware is wiping memory on free.

To reduce the attack surface, wipe the passphrase acquired when
unlocking an encrypted volume.

Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agodisk/cryptodisk: Add the "erase secrets" function
Maxim Suhanov [Tue, 4 Mar 2025 11:02:25 +0000 (14:02 +0300)] 
disk/cryptodisk: Add the "erase secrets" function

This commit adds the grub_cryptodisk_erasesecrets() function to wipe
master keys from all cryptodisks. This function is EFI-only.

Since there is no easy way to "force unmount" a given encrypted disk,
this function renders all mounted cryptodisks unusable. An attempt to
read them will return garbage.

This is why this function must be used in "no way back" conditions.

Currently, it is used when unloading the cryptodisk module and when
performing the "exit" command (it is often used to switch to the next
EFI application). This function is not called when performing the
"chainloader" command, because the callee may return to GRUB. For this
reason, users are encouraged to use "exit" instead of "chainloader" to
execute third-party boot applications.

This function does not guarantee that all secrets are wiped from RAM.
Console output, chunks from disk read requests and other may remain.

This function does not clear the IV prefix and rekey key for geli disks.

Also, this commit adds the relevant documentation improvements.

Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agodocs: Document available crypto disks checks
Maxim Suhanov [Mon, 10 Mar 2025 12:33:46 +0000 (15:33 +0300)] 
docs: Document available crypto disks checks

Document the --cryptodisk-only argument. Also, document the
"cryptocheck" command invoked when that argument is processed.

Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agocommands/search: Add the diskfilter support
Maxim Suhanov [Sun, 2 Mar 2025 20:32:43 +0000 (23:32 +0300)] 
commands/search: Add the diskfilter support

When the --cryptodisk-only argument is given, also check the target
device using the "cryptocheck" command, if available.

This extends the checks to common layouts like LVM-on-LUKS, so the
--cryptodisk-only argument transparently handles such setups.

Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agodisk/diskfilter: Introduce the "cryptocheck" command
Maxim Suhanov [Sun, 2 Mar 2025 15:08:22 +0000 (18:08 +0300)] 
disk/diskfilter: Introduce the "cryptocheck" command

This command examines a given diskfilter device, e.g., an LVM disk,
and checks if underlying disks, physical volumes, are cryptodisks,
e.g., LUKS disks, this layout is called "LVM-on-LUKS".

The return value is 0 when all underlying disks (of a given device)
are cryptodisks (1 if at least one disk is unencrypted or in an
unknown state).

Users are encouraged to include the relevant check before loading
anything from an LVM disk that is supposed to be encrypted.

This further supports the CLI authentication, blocking bypass
attempts when booting from an encrypted LVM disk.

Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agocommands/search: Introduce the --cryptodisk-only argument
Maxim Suhanov [Sat, 1 Mar 2025 11:16:48 +0000 (14:16 +0300)] 
commands/search: Introduce the --cryptodisk-only argument

This allows users to restrict the "search" command's scope to
encrypted disks only.

Typically, this command is used to "rebase" $root and $prefix
before loading additional configuration files via "source" or
"configfile". Unfortunately, this leads to security problems,
like CVE-2023-4001, when an unexpected, attacker-controlled
device is chosen by the "search" command.

The --cryptodisk-only argument allows users to ensure that the
file system picked is encrypted.

This feature supports the CLI authentication, blocking bypass
attempts.

Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agokern/rescue_reader: Block the rescue mode until the CLI authentication
Maxim Suhanov [Fri, 28 Feb 2025 14:00:53 +0000 (17:00 +0300)] 
kern/rescue_reader: Block the rescue mode until the CLI authentication

This further mitigates potential misuse of the CLI after the
root device has been successfully unlocked via TPM.

Fixes: CVE-2025-4382
Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 months agofs/xfs: Fix large extent counters incompat feature support
Eric Sandeen [Wed, 4 Dec 2024 13:50:28 +0000 (07:50 -0600)] 
fs/xfs: Fix large extent counters incompat feature support

When large extent counter / NREXT64 support was added to GRUB, it missed
a couple of direct reads of nextents which need to be changed to the new
NREXT64-aware helper as well. Without this, we'll have mis-reads of some
directories with this feature enabled.

The large extent counter fix likely raced on merge with commit 07318ee7e
(fs/xfs: Fix XFS directory extent parsing) which added the new direct
nextents reads just prior, causing this issue.

Fixes: aa7c1322671e (fs/xfs: Add large extent counters incompat feature support)
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Anthony Iliopoulos <ailiop@suse.com>
Reviewed-by: Jon DeVree <nuxi@vault24.org>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agoutil/grub-install: Include raid5rec module for RAID 4 as well
Egor Ignatov [Thu, 10 Apr 2025 07:55:02 +0000 (10:55 +0300)] 
util/grub-install: Include raid5rec module for RAID 4 as well

RAID 4 requires the same recovery module as RAID 5. Extend the condition to
cover both RAID levels.

Signed-off-by: Egor Ignatov <egori@altlinux.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agoloader/ia64/efi/linux: Reset grub_errno on failure to allocate
Vladimir Serbinenko [Mon, 7 Apr 2025 19:05:40 +0000 (22:05 +0300)] 
loader/ia64/efi/linux: Reset grub_errno on failure to allocate

The code goes on to allocate memory in another region on failure, hence
it should discard the error.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agolib/datetime: Specify license in emu module
Vladimir Serbinenko [Sat, 5 Apr 2025 17:45:23 +0000 (20:45 +0300)] 
lib/datetime: Specify license in emu module

Other platforms specify license in platform-specific files but corresponding
code for emu is in kernel, so datetime ends up without license section.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agoconfigure: Add -mno-relax on riscv*
Vladimir Serbinenko [Thu, 27 Mar 2025 16:32:23 +0000 (19:32 +0300)] 
configure: Add -mno-relax on riscv*

Without this option compiler sometimes emits R_RISCV_ALIGN relocs.
Unlike other relocs this one requires the linker to do NOP deletions
and we can't ignore them. Just instruct compiler not to emit them.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agodocs: Document the long options of tpm2_key_protect_init
Gary Lin [Mon, 7 Apr 2025 08:29:27 +0000 (16:29 +0800)] 
docs: Document the long options of tpm2_key_protect_init

Add the long options of tpm2_key_protect_init along with the short options.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agoINSTALL: Document the packages needed for TPM2 key protector tests
Gary Lin [Mon, 7 Apr 2025 08:29:26 +0000 (16:29 +0800)] 
INSTALL: Document the packages needed for TPM2 key protector tests

The TPM2 key protector tests require two external packages: swtpm-tools
and tpm2-tools. Add those two packages to the INSTALL file to inform
the user to install those packages before starting the TPM2 key protector
tests.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
3 months agodocs: Update NV index mode of TPM2 key protector
Gary Lin [Mon, 7 Apr 2025 08:29:25 +0000 (16:29 +0800)] 
docs: Update NV index mode of TPM2 key protector

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>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests/tpm2_key_protector_test: Add more NV index mode tests
Gary Lin [Mon, 7 Apr 2025 08:29:24 +0000 (16:29 +0800)] 
tests/tpm2_key_protector_test: Add more NV index mode tests

Two more NV index test cases are added to test key sealing and
unsealing with the NV index handle 0x1000000.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests/tpm2_key_protector_test: Reset "ret" on fail
Gary Lin [Mon, 7 Apr 2025 08:29:23 +0000 (16:29 +0800)] 
tests/tpm2_key_protector_test: Reset "ret" on fail

Reset "ret" to 0 when a test case fails so that the other test cases
could continue.

Also set the exit status to 1 when encountering a failure to reflect the
test result.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests/tpm2_key_protector_test: Simplify the NV index mode test
Gary Lin [Mon, 7 Apr 2025 08:29:22 +0000 (16:29 +0800)] 
tests/tpm2_key_protector_test: Simplify the NV index mode test

Since grub-protect already supports NV index mode, tpm2_seal_nv() is
replaced with one grub-protect command to simplify the test script.

"tpm2_evictcontrol" is also replaced with "grub-protect --tpm2-evict".

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agoutil/grub-protect: Support NV index mode
Gary Lin [Mon, 7 Apr 2025 08:29:21 +0000 (16:29 +0800)] 
util/grub-protect: Support NV index mode

This commit implements the missing NV index mode support in grub-protect.
NV index mode stores the sealed key in the TPM non-volatile memory (NVRAM)
instead of a file. There are two supported types of TPM handles.

1. Persistent handle (0x81000000~0x81FFFFFF)
   Only the raw format is supported due to the limitation of persistent
   handles. This grub-protect command seals the key into the
   persistent handle 0x81000000.

  # grub-protect \
      --protector=tpm2 \
      --action=add \
      --tpm2-bank=sha256 \
      --tpm2-pcrs=7,11 \
      --tpm2-keyfile=luks-key \
      --tpm2-nvindex=0x81000000

2. NV index handle (0x1000000~0x1FFFFFF)
   Both TPM 2.0 Key File format and the raw format are supported by NV
   index handles. Here is the grub-protect command to seal the key in
   TPM 2.0 Key File format into the NV index handle 0x1000000.

  # grub-protect \
      --protector=tpm2 \
      --action=add \
      --tpm2key \
      --tpm2-bank=sha256 \
      --tpm2-pcrs=7,11 \
      --tpm2-keyfile=luks-key \
      --tpm2-nvindex=0x1000000

Besides the "add" action, the corresponding "remove" action is also
introduced. To remove the data from a persistent or NV index handle,
just use "--tpm2-nvindex=HANDLE" combining with "--tpm2-evict". This
sample command removes the data from the NV index handle 0x1000000.

  # grub-protect \
      --protector=tpm2 \
      --action=remove \
      --tpm2-evict \
      --tpm2-nvindex=0x1000000

Also set and check the boolean variables with true/false instead of 1/0.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotpm2_key_protector: Support NV index handles
Gary Lin [Mon, 7 Apr 2025 08:29:20 +0000 (16:29 +0800)] 
tpm2_key_protector: Support NV index handles

Previously, NV index mode only supported persistent handles which are
only for TPM objects.

On the other hand, the "NV index" handle allows the user-defined data,
so it can be an alternative to the key file and support TPM 2.0 Key
File format immediately.

The following tpm2-tools commands store the given key file, sealed.tpm,
in either TPM 2.0 Key File format or the raw format into the NV index
handle 0x1000000.

  # tpm2_nvdefine -C o \
      -a "ownerread|ownerwrite" \
      -s $(stat -c %s sealed.tpm) \
      0x1000000
  # tpm2_nvwrite -C o -i sealed.tpm 0x1000000

To unseal the key in GRUB, add the "tpm2_key_protector_init" command to
grub.cfg:

  tpm2_key_protector_init --mode=nv --nvindex=0x1000000
  cryptomount -u <UUID> --protector tpm2

To remove the NV index handle:

  # tpm2_nvundefine -C o 0x1000000

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotpm2_key_protector: Unseal key from a buffer
Gary Lin [Mon, 7 Apr 2025 08:29:19 +0000 (16:29 +0800)] 
tpm2_key_protector: Unseal key from a buffer

Extract the logic to handle the file buffer from the SRK recover
function to prepare to load the sealed key from the NV index handle,
so the NV index mode can share the same code path in the later patch.
The SRK recover function now only reads the file and sends the file
buffer to the new function.

Besides this, to avoid introducing more options for the NV index mode,
the file format is detected automatically before unmarshaling the data,
so there is no need to use the command option to specify the file format
anymore. In other words, "-T" and "-k" are the same now.

Also update grub.text to address the change.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotss2: Add TPM 2.0 NV index commands
Gary Lin [Mon, 7 Apr 2025 08:29:18 +0000 (16:29 +0800)] 
tss2: Add TPM 2.0 NV index commands

The following TPM 2.0 commands are introduced to tss2 to access the
TPM non-volatile memory associated with the NV index handles:
  - TPM2_NV_DefineSpace,
  - TPM2_NV_UndefineSpace,
  - TPM2_NV_ReadPublic,
  - TPM2_NV_Read,
  - TPM2_NV_Write.

The related marshal/unmarshal functions are also introduced.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotss2: Fix the missing authCommand
Gary Lin [Mon, 7 Apr 2025 08:29:17 +0000 (16:29 +0800)] 
tss2: Fix the missing authCommand

grub_tpm2_readpublic() and grub_tpm2_testparms() didn't check
authCommand when marshaling the input data buffer. Currently, there is
no caller using non-NULL authCommand. However, to avoid the potential
issue, the conditional check is added to insert authCommand into the
input buffer if necessary.

Also fix a few pointer checks.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotpm2_key_protector: Add tpm2_dump_pcr command
Gary Lin [Mon, 7 Apr 2025 08:29:16 +0000 (16:29 +0800)] 
tpm2_key_protector: Add tpm2_dump_pcr command

The user may need to inspect the TPM 2.0 PCR values with the GRUB shell,
so the new tpm2_dump_pcr command is added to print all PCRs of the
specified bank.

Also update the document for the new command.

Signed-off-by: Gary Lin <glin@suse.com>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotpm2_key_protector: Dump PCRs on policy fail
Gary Lin [Mon, 7 Apr 2025 08:29:15 +0000 (16:29 +0800)] 
tpm2_key_protector: Dump PCRs on policy fail

PCR mismatch is one common cause of TPM key unsealing fail. Since the
system may be compromised, it is not safe to boot into OS to get the PCR
values and TPM eventlog for the further investigation.

To provide some hints, GRUB now dumps PCRs on policy fail, so the user
can check the current PCR values. PCR 0~15 are chosen to cover the
firmware, bootloader, and OS.

The sample output:

PCR Mismatch! Check firmware and bootloader before typing passphrase!
TPM PCR [sha256]:
  00: 17401f37710984c1d8a03a81fff3ab567ae9291bac61e21715b890ee28879738
  01: 7a114329ba388445a96e8db2a072785937c1b7a8803ed7cc682b87f3ff3dd7a8
  02: 11c2776849e8e24b7d80c926cbc4257871bffa744dadfefd3ed049ce25143e05
  03: 6c33b362073e28e30b47302bbdd3e6f9cee4debca3a304e646f8c68245724350
  04: 62d38838483ecfd2484ee3a2e5450d8ca3b35fc72cda6a8c620f9f43521c37d1
  05: d8a85cb37221ab7d1f2cc5f554dbe0463acb6784b5b8dc3164ccaa66d8fff0e1
  06: 9262e37cbe71ed4daf815b4a4881fb7251c9d371092dde827557d5368121e10e
  07: 219d542233be492d62b079ffe46cf13396a8c27e520e88b08eaf2e6d3b7e70f5
  08: de1f61c973b673e505adebe0d7e8fb65fde6c24dd4ab4fbaff9e28b18df6ecd3
  09: c1de7274fa3e879a16d7e6e7629e3463d95f68adcfd17c477183846dccc41c89
  10: 0000000000000000000000000000000000000000000000000000000000000000
  11: 0000000000000000000000000000000000000000000000000000000000000000
  12: 0000000000000000000000000000000000000000000000000000000000000000
  13: 0000000000000000000000000000000000000000000000000000000000000000
  14: 9ab9ebe4879a7f4dd00c04f37e79cfd69d0dd7a8bcc6b01135525b67676a3e40
  15: 0000000000000000000000000000000000000000000000000000000000000000
  16: 0000000000000000000000000000000000000000000000000000000000000000
  17: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  18: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  19: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  20: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  21: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  22: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  23: 0000000000000000000000000000000000000000000000000000000000000000
error: failed to unseal sealed key (TPM2_Unseal: 0x99d).
error: no key protector provided a usable key for luks (af16e48f-746b-4a12-aae1-c14dcee429e0).

If the user happens to have the PCR values for key sealing, the PCR dump
can be used to identify the changed PCRs and narrow down the scope for
closer inspection.

Please note that the PCR dump is trustworthy only if the GRUB binary is
authentic, so the user has to check the GRUB binary thoroughly before
using the PCR dump.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agoloader/i386/linux: Update linux_kernel_params to match upstream
Patrick Colp [Thu, 3 Apr 2025 21:04:11 +0000 (14:04 -0700)] 
loader/i386/linux: Update linux_kernel_params to match upstream

Update linux_kernel_params to match the v6.13.7 upstream version of boot_params.
Refactor most things out into structs, as the Linux kernel does.

edid_info should be a struct with "unsigned char dummy[128]" and efi_info should
be a struct as well, starting at 0x1c0. However, for backwards compatibility,
GRUB can have efi_systab at 0x1b8 and padding at 0x1bc (or padding at both spots).
This cuts into the end of edid_info. Make edid_info inline and only make it go
up to 0x1b8.

Signed-off-by: Patrick Colp <patrick.colp@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agoloader/xnu: Fix memory leak
Lidong Chen [Thu, 27 Mar 2025 17:56:35 +0000 (17:56 +0000)] 
loader/xnu: Fix memory leak

In grub_xnu_load_kext_from_dir(), when the call to grub_device_open()
failed, it simply cleaned up previously allocated memory and returned
GRUB_ERR_NONE. However, it neglected to free ctx->newdirname which is
allocated before the call to grub_device_open().

Fixes: CID 473859
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agofs/btrfs: Fix memory leaks
Lidong Chen [Thu, 27 Mar 2025 17:56:34 +0000 (17:56 +0000)] 
fs/btrfs: Fix memory leaks

Fix memory leaks in grub_btrfs_extent_read() and grub_btrfs_dir().

Fixes: CID 473842
Fixes: CID 473871
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agoloader/i386/linux: Fix resource leak
Lidong Chen [Thu, 27 Mar 2025 17:56:33 +0000 (17:56 +0000)] 
loader/i386/linux: Fix resource leak

In grub_cmd_initrd(), initrd_ctx is allocated before calling
grub_relocator_alloc_chunk_align(). When that function fails,
initrd_ctx should be freed before exiting grub_cmd_initrd().

Fixes: CID 473852
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agolib/reloacator: Fix memory leaks
Lidong Chen [Thu, 27 Mar 2025 17:56:32 +0000 (17:56 +0000)] 
lib/reloacator: Fix memory leaks

Fix memory leaks in grub_relocator_alloc_chunk_align().

Fixes: CID 473844
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agodisk/ldm: Fix memory leaks
Lidong Chen [Thu, 27 Mar 2025 17:56:31 +0000 (17:56 +0000)] 
disk/ldm: Fix memory leaks

Fix memory leaks in make_vg() with new helper functions, free_pv()
and free_lv(). Additionally, correct a check after allocating
comp->segments->nodes that mistakenly checked lv->segments->nodes
instead, likely due to a copy-paste error.

Fixes: CID 473878
Fixes: CID 473884
Fixes: CID 473889
Fixes: CID 473890
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agofs/ntfs: Fix NULL pointer dereference and possible infinite loop
Andrew Hamilton [Thu, 20 Mar 2025 23:28:00 +0000 (18:28 -0500)] 
fs/ntfs: Fix NULL pointer dereference and possible infinite loop

A regression was introduced recently as a part of the series of
filesystem related patches to address some CVEs found in GRUB.

This issue may cause either an infinite loop at startup when
accessing certain valid NTFS filesystems, or may cause a crash
due to a NULL pointer dereference on systems where NULL address
is invalid (such as may happen when calling grub-mount from
the operating system level).

Correct this issue by checking that at->attr_cur is within bounds
inside find_attr().

Fixes: https://savannah.gnu.org/bugs/?66855
Fixes: aff263187 (fs/ntfs: Fix out-of-bounds read)
Signed-off-by: B Horn <b@horn.uk>
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
3 months agonet/drivers/ieee1275/ofnet: Add missing grub_malloc()
Nicolas Frayer [Wed, 19 Mar 2025 16:39:41 +0000 (17:39 +0100)] 
net/drivers/ieee1275/ofnet: Add missing grub_malloc()

The grub_malloc() has been inadvertently removed from the code after it
has been modified to use safe math functions.

Fixes: 4beeff8a (net: Use safe math macros to prevent overflows)
Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
Tested-by: Marta Lewandowska <mlewando@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agokern/ieee1275/init: Increase MIN_RMA size for CAS negotiation on PowerPC machines
Avnish Chouhan [Thu, 13 Mar 2025 14:15:50 +0000 (19:45 +0530)] 
kern/ieee1275/init: Increase MIN_RMA size for CAS negotiation on PowerPC machines

Change RMA size from 512 MB to 768 MB which will result in more memory
at boot time for PowerPC. When vTPM, Secure Boot or FADump are enabled
on PowerPC the 512 MB RMA memory is not sufficient for boot. With this
512 MB RMA, GRUB runs out of memory and fails to boot the machine.
Sometimes even usage of CDROM requires more memory for installation and
along with the options mentioned above exhausts the boot memory which
results in boot failures. Increasing the RMA size will resolves multiple
out of memory issues observed on PowerPC machines.

Failure details (GRUB debug console dump):

  kern/ieee1275/init.c:550: mm requested region of size 8513000, flags 1
  kern/ieee1275/init.c:563: Cannot satisfy allocation and retain minimum runtime space
  kern/ieee1275/init.c:550: mm requested region of size 8513000, flags 0
  kern/ieee1275/init.c:563: Cannot satisfy allocation and retain minimum runtime space
  kern/file.c:215: Closing `/ppc/ppc64/initrd.img' ...
  kern/disk.c:297: Closing `ieee1275//vdevice/v-scsi@30000067/disk@8300000000000000'...
  kern/disk.c:311: Closing `ieee1275//vdevice/v-scsi@30000067/disk@8300000000000000' succeeded.
  kern/file.c:225: Closing `/ppc/ppc64/initrd.img' failed with 3.
  kern/file.c:148: Opening `/ppc/ppc64/initrd.img' succeeded.
  error: ../../grub-core/kern/mm.c:552:out of memory.

Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agofs/zfs: Fix a number of memory leaks in ZFS code
Stuart Hayes [Mon, 10 Mar 2025 16:23:59 +0000 (11:23 -0500)] 
fs/zfs: Fix a number of memory leaks in ZFS code

Without this fix the GRUB failed to boot linux with "out of memory" after
trying to run a "search --fs-uuid..." on a system that has 7 ZFS pools
across about 80 drives.

Signed-off-by: Stuart Hayes <stuart.w.hayes@gmail.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests/util/grub-shell: Remove the work directory on successful run and debug is not on
Glenn Washburn [Mon, 3 Mar 2025 08:12:06 +0000 (02:12 -0600)] 
tests/util/grub-shell: Remove the work directory on successful run and debug is not on

This removes a lot of empty grub-shell working directories in the TMPDIR directory.

Signed-off-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Tested-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests/grub_cmd_cryptomount: Remove temporary directories if successful and debug...
Thomas Schmitt [Mon, 3 Mar 2025 08:12:05 +0000 (02:12 -0600)] 
tests/grub_cmd_cryptomount: Remove temporary directories if successful and debug is not on

grub_cmd_cryptomount creates a directory per subtest. If a subtest is
successful and debugging is not on, the directory should be empty.
So, it can be deleted.

Signed-off-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Tested-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests/grub_cmd_cryptomount: Default TMPDIR to /tmp
Glenn Washburn [Mon, 3 Mar 2025 08:12:04 +0000 (02:12 -0600)] 
tests/grub_cmd_cryptomount: Default TMPDIR to /tmp

This fixes behavior where grub_cmd_cryptomount temporary files, which are
some times not cleaned up, are left in the / directory. Set TMPDIR if your
system does not have /tmp or it can not be used for some reason.

Reported-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Tested-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests/grub_cmd_cryptomount: Cleanup the cryptsetup script unless debug is enabled
Glenn Washburn [Mon, 3 Mar 2025 08:12:03 +0000 (02:12 -0600)] 
tests/grub_cmd_cryptomount: Cleanup the cryptsetup script unless debug is enabled

This fixes an issue where the grub_cmd_cryptomount test leaves a file
with an ambiguous name in the / directory when TMPDIR is not set.

Reported-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Tested-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests: Cleanup generated files on expected failure in grub_cmd_cryptomount
Glenn Washburn [Mon, 3 Mar 2025 08:12:02 +0000 (02:12 -0600)] 
tests: Cleanup generated files on expected failure in grub_cmd_cryptomount

grub-shell-luks-tester only cleans up generated files when the test it
runs returns success. Sometimes tests are run that should fail. Add
a --xfail argument to grub-shell-luks-tester and pass it from
grub_cmd_cryptomount when invoking a test that is expected to fail.

Reported-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Tested-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 months agotests/util/grub-shell-luks-tester: Add missing line to create RET variable in cleanup
Glenn Washburn [Mon, 3 Mar 2025 08:12:01 +0000 (02:12 -0600)] 
tests/util/grub-shell-luks-tester: Add missing line to create RET variable in cleanup

Set the RET variable to the exit status of the script, as was assumed in
the cleanup() function.

Reported-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Tested-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>