]> git.ipfire.org Git - thirdparty/grub.git/log
thirdparty/grub.git
9 days agoRelease 2.14~rc1 master grub-2.14-rc1
Daniel Kiper [Tue, 28 Oct 2025 12:19:47 +0000 (13:19 +0100)] 
Release 2.14~rc1

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
9 days agowindows: Fix symbol table generation during module conversion from PE to ELF
Daniel Kiper [Mon, 27 Oct 2025 16:17:01 +0000 (17:17 +0100)] 
windows: Fix symbol table generation during module conversion from PE to ELF

According to the System V Application Binary Interface specification [1]
the sections holding a symbol table, SHT_SYMTAB and SHT_DYNSYM, have to
have sh_info set to "One greater than the symbol table index of the last
local symbol (binding STB_LOCAL)". Current code converting PE images to
ELF files does not do that and readelf complains in following way:

  ...

  Section Headers:
    [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
    [ 0]                   NULL            00000000 000000 000000 00      0   0  0
    [ 1] .text             PROGBITS        00000000 000034 0014d4 00  AX  0   0  4
    [ 2] .data             PROGBITS        00000000 001508 000040 00  WA  0   0 32
    [ 3] .rdata            PROGBITS        00000000 001548 0006b8 00   A  0   0  4
    [ 4] .module_license   PROGBITS        00000000 001c00 000010 00      0   0  4
    [ 5] .bss              NOBITS          00000000 000000 000008 00  WA  0   0  4
    [ 6] .moddeps          PROGBITS        00000000 001c10 000010 00      0   0  4
    [ 7] .modname          PROGBITS        00000000 001c20 000008 00      0   0  4
    [ 8] .rel.text         REL             00000000 001c28 0008c8 08     11   1  4
    [ 9] .rel.data         REL             00000000 0024f0 000040 08     11   2  4
    [10] .rel.rdata        REL             00000000 002530 000070 08     11   3  4
    [11] .symtab           SYMTAB          00000000 0025a0 0001d0 10     12   0  4
    [12] .strtab           STRTAB          00000000 002770 000237 00      0   0  1

  ...

  Symbol table '.symtab' contains 29 entries:
     Num:    Value  Size Type    Bind   Vis      Ndx Name
       0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
  readelf: Warning: local symbol 0 found at index >= .symtab's sh_info value of 0
       1: 0000144a     0 FUNC    LOCAL  DEFAULT    1 grub_mod_init
  readelf: Warning: local symbol 1 found at index >= .symtab's sh_info value of 0
       2: 000014aa     0 FUNC    LOCAL  DEFAULT    1 grub_mod_fini
  readelf: Warning: local symbol 2 found at index >= .symtab's sh_info value of 0
       3: 00000000     0 SECTION LOCAL  DEFAULT    1 .text
  readelf: Warning: local symbol 3 found at index >= .symtab's sh_info value of 0
       4: 00000000     0 SECTION LOCAL  DEFAULT    2 .data
  readelf: Warning: local symbol 4 found at index >= .symtab's sh_info value of 0
       5: 00000000     0 SECTION LOCAL  DEFAULT    5 .bss
  readelf: Warning: local symbol 5 found at index >= .symtab's sh_info value of 0
       6: 00000000     0 SECTION LOCAL  DEFAULT    3 .rdata
  readelf: Warning: local symbol 6 found at index >= .symtab's sh_info value of 0
       7: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND grub_dma_get_phys
       8: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND grub_cs5536_write_msr
       9: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND grub_dma_free

  ...

Let's fix it...

[1] https://www.sco.com/developers/gabi/2012-12-31/contents.html

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
9 days agowindows: Fix relocation sections generation during module conversion from PE to ELF
Daniel Kiper [Mon, 27 Oct 2025 15:56:39 +0000 (16:56 +0100)] 
windows: Fix relocation sections generation during module conversion from PE to ELF

The commit 98ad84328 (kern/dl: Check for the SHF_INFO_LINK flag in
grub_dl_relocate_symbols()) revealed a bug in the code converting PE
module images to ELF files. The missing SHF_INFO_LINK flag for SHT_REL
and SHT_RELA sections lead to hangs during GRUB load. This only happens
for the GRUB images generated on Windows platforms. The *NIX platforms
are not affected due to lack of PE to ELF conversion step.

This patch fixes the issue...

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
9 days agoloader/efi/linux: Fix compile error with Clang
Andrew Hamilton [Sat, 25 Oct 2025 15:53:40 +0000 (10:53 -0500)] 
loader/efi/linux: Fix compile error with Clang

Clang will produce a warning, which is treated as an error, that
"vendor_defined_data" is uninitialized. This is a "zero length" array
member of this struct. Add conditional compile pragma to allow this to
compile with Clang.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 days agobuild: Add tpm2key.asn file for reference to dist archive
Andrew Hamilton [Sat, 25 Oct 2025 15:53:39 +0000 (10:53 -0500)] 
build: Add tpm2key.asn file for reference to dist archive

Add the tpm2key.asn file to the dist archive for reference by end users.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 days agobuild: Include new zstd test support files in dist archive
Andrew Hamilton [Sat, 25 Oct 2025 15:53:38 +0000 (10:53 -0500)] 
build: Include new zstd test support files in dist archive

Include the two new zstd test support files in the dist archive
so end users can successfully run this test.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 days agobuild: Include MAINTAINERS and SECURITY files in dist archive
Andrew Hamilton [Sat, 25 Oct 2025 15:53:37 +0000 (10:53 -0500)] 
build: Include MAINTAINERS and SECURITY files in dist archive

Include the MAINTAINERS and SECURITY files in the dist archive
for reference in distributed archives by end users.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agobuild: Add appended signatures header file to EXTRA_DIST
Daniel Kiper [Fri, 24 Oct 2025 18:11:14 +0000 (20:11 +0200)] 
build: Add appended signatures header file to EXTRA_DIST

This file was not added to EXTRA_DIST during the appended signatures merge.

Fixes: 3e4ff6ffb (appended signatures: Parse ASN1 node)
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
13 days agolib/xzembed/xz_dec_stream: Replace grub_memcpy() call with memcpy()
Daniel Kiper [Thu, 23 Oct 2025 17:37:49 +0000 (19:37 +0200)] 
lib/xzembed/xz_dec_stream: Replace grub_memcpy() call with memcpy()

Make the code consistent.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
13 days agobootstrap: Fix patching warnings
Daniel Kiper [Thu, 23 Oct 2025 17:18:17 +0000 (19:18 +0200)] 
bootstrap: Fix patching warnings

Currently bootstrap complains in the following way when
patching gnulib files:

  patching file regcomp.c
  Hunk #2 succeeded at 1029 with fuzz 2.
  Hunk #5 succeeded at 1716 with fuzz 2.
  patching file regexec.c
  patching file base64.c
  patching file regexec.c
  Hunk #1 succeeded at 807 (offset -21 lines).

Let's fix it by adding missing "\f" and amending line
numbers in the patches.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
13 days agotss2: Always init out buffer before calling tpm2_submit_command_real()
Yann Diorcet [Thu, 23 Oct 2025 12:02:50 +0000 (14:02 +0200)] 
tss2: Always init out buffer before calling tpm2_submit_command_real()

When tpm2_submit_command_real() is called for a retry, the content of
out buffer can already be set with previous tpm2_submit_command_real()
call's reply. Add a call to grub_tpm2_buffer_init() before tpm2_submit_command_real().

This solves the issues occurring during TPM_CC_Load command on the
integrated TPM 2.0 in Intel Elkhart Lake chip.

Signed-off-by: Yann Diorcet <diorcet.yann@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agofs/ntfs: Correct next_attribute validation
Andrew Hamilton [Sun, 1 Jun 2025 15:52:22 +0000 (10:52 -0500)] 
fs/ntfs: Correct next_attribute validation

Improved ad-hoc fuzzing coverage revealed a possible access violation
around line 342 of grub-core/fs/ntfs.c when accessing the attr_cur
pointer due to possibility of moving pointer "next" beyond of the end of
the valid buffer inside next_attribute. Prevent this for cases where
full attribute validation is not performed (such as on attribute lists)
by performing a sanity check on the newly calculated next pointer.

Fixes: 06914b614 (fs/ntfs: Correct attribute vs attribute list validation)
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agokern/ieee1275/init: Use net config for boot location instead of firmware bootpath
Michael Chang [Mon, 13 Oct 2025 06:52:24 +0000 (14:52 +0800)] 
kern/ieee1275/init: Use net config for boot location instead of firmware bootpath

On network boots grub_ieee1275_net_config() is used to determine the
boot device but the path continues to be taken from the Open Firmware
/chosen/bootpath property. This assumes the device node follows the
generic IEEE 1275 syntax which is not always the case. Different drivers
may extend or redefine the format and GRUB may then misinterpret the
argument as a filename and set $prefix incorrectly.

The generic Open Firmware device path format is:

  device-name[:device-argument]
  device-argument := [partition][,[filename]]

For example, a bootpath such as:

  /vdevice/l-lan@30000002:speed=auto,duplex=auto,1.2.243.345,,9.8.76.543,1.2.34.5,5,5,255.255.255.0,512

does not follow this form. The section after the colon (the device-argument)
contains driver-specific options and network parameters, not a valid filename.
The GRUB interprets this string as a filename which results in $prefix being
set to "/", effectively losing the intended boot directory.

The firmware is not at fault here since interpretation of device nodes
is driver-specific. Instead, GRUB should use the filename provided in
the cached DHCP packet which is consistent and reliable. This is also
the same mechanism already used on UEFI and legacy BIOS platforms.

This patch updates grub_machine_get_bootlocation() to prefer the result
from grub_ieee1275_net_config() when complete and only fall back to the
firmware bootpath otherwise.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agonet/tftp: Fix NULL pointer dereference in grub_net_udp_close()
Lidong Chen [Fri, 17 Oct 2025 18:35:59 +0000 (18:35 +0000)] 
net/tftp: Fix NULL pointer dereference in grub_net_udp_close()

A NULL pointer dereference can occur in grub_net_udp_close(data->sock)
when handling a malformed TFTP OACK packet.

This issue was discovered via fuzzing. When a malformed OACK packet
contains an invalid file size, "tsize", value tftp_receive() detects
the error and saves it via grub_error_save(&data->save_err). Later,
tftp_open() restores this error and calls grub_net_udp_close(data->sock)
assuming the socket is still valid.

However, the socket may have already been closed and set to NULL after
processing the final data block in tftp_receive() leading to a NULL
pointer dereference when attempting to close it again.

Fix it by checking if the socket is non-NULL before closing.

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>
13 days agonet/dns: Prevent UAF and double free
Lidong Chen [Tue, 21 Oct 2025 21:20:04 +0000 (21:20 +0000)] 
net/dns: Prevent UAF and double free

In recv_hook(), *data->addresses is freed without being set to NULL.
Since *data->addresses can be cached in dns_cache[h].addresses, this
can lead to UAF or double free if dns_cache[h].addresses is accessed
or cleared later.

The fix sets *data->addresses to NULL after freeing to avoid dangling
pointer.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agonet/bootp: Prevent a UAF in network interface unregister
Lidong Chen [Tue, 21 Oct 2025 21:20:03 +0000 (21:20 +0000)] 
net/bootp: Prevent a UAF in network interface unregister

A UAF occurs in grub_net_network_level_interface_unregister()
when inter->name is accessed after being freed in grub_cmd_bootp().
Fix it by deferring grub_free(ifaces[j].name) until after
grub_net_network_level_interface_unregister() completes.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agodocs: Document lsmemregions and memtools commands
Andrew Hamilton [Sun, 19 Oct 2025 13:46:20 +0000 (08:46 -0500)] 
docs: Document lsmemregions and memtools commands

Add documentation of the new lsmemregions command as well as
documenting the existing memtools module commands.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agocommands/memtools: Add lsmemregions command
Leo Sandoval [Tue, 21 Oct 2025 18:39:00 +0000 (12:39 -0600)] 
commands/memtools: Add lsmemregions command

Prints memory regions general information including size, number of
blocks, total free and total allocated memory per region. The reason
behind is to have a tool that shows general information about regions
and how fragmented the memory is at some particular time.

Below is an example showing how this tool before and after memory stress.

    grub> lsmemregions

    Region 0x78f6e000 (size 33554368 blocks 1048574 free 27325472 alloc 6232768)

    > stress_big_allocations
    ...

    grub> lsmemregions

    Region 0x7af8e000 (size 4032 blocks 126 free 2720 alloc 1312)
    Region 0x80c000 (size 81856 blocks 2558 free 81856 alloc 0)
    Region 0x7d165000 (size 167872 blocks 5246 free 167872 alloc 0)
    Region 0x7d0bf000 (size 655296 blocks 20478 free 655296 alloc 0)
    Region 0x7ee00000 (size 1331136 blocks 41598 free 1331136 alloc 0)
    Region 0x100000 (size 7385024 blocks 230782 free 7385024 alloc 0)
    Region 0x7af95000 (size 25382848 blocks 793214 free 25382848 alloc 0)
    Region 0x1780000 (size 2038357952 blocks 63698686 free 2077517536 alloc 5445568)

Signed-off-by: Leo Sandoval <lsandova@redhat.com>
Reviewed-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agotests/file_filter: Add zstd tests
Logan Gunthorpe [Tue, 21 Oct 2025 15:56:28 +0000 (09:56 -0600)] 
tests/file_filter: Add zstd tests

Test zstd decompression in the same way that other decompressors are tested.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agotests/file_filter: Add zstd test file
Logan Gunthorpe [Tue, 21 Oct 2025 15:56:27 +0000 (09:56 -0600)] 
tests/file_filter: Add zstd test file

Add a file.zstd similar to the other compression methods and generate
a gpg signature with "gpg --detach-sign".

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agotests/file_filter: Regenerate gpg keys
Logan Gunthorpe [Tue, 21 Oct 2025 15:56:26 +0000 (09:56 -0600)] 
tests/file_filter: Regenerate gpg keys

The "keys" file is not a valid GPG secret key so it is not possible to
generate new signatures.

Create a new key and use "gpg --export-secret-key" to export the key
and "gpg --export" to export the public key. Then resign all the
signatures with "gpg --detach-sign".

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 days agoio/zstdio: Implement zstdio decompression
Logan Gunthorpe [Tue, 21 Oct 2025 15:56:25 +0000 (09:56 -0600)] 
io/zstdio: Implement zstdio decompression

Add zstd based io decompression.

Based largely on the existing xzio, implement the same features using
the zstd library already included in the project.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agofs/btrfs: Update doc link for bootloader support
Michael Chang [Fri, 17 Oct 2025 09:01:43 +0000 (17:01 +0800)] 
fs/btrfs: Update doc link for bootloader support

The old wiki link is obsolete and no longer updated. Change it to the
current documentation.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agodocs: Add Btrfs env block and special env vars
Michael Chang [Fri, 17 Oct 2025 09:01:42 +0000 (17:01 +0800)] 
docs: Add Btrfs env block and special env vars

Update grub.texi to describe the external environment block in the
reserved area of Btrfs header used for grub-reboot and savedefault, and
add a section documenting the saved_entry, next_entry, and env_block
variables.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/grub.d/00_header.in: Wire grub.cfg to use env_block when present
Michael Chang [Fri, 17 Oct 2025 09:01:41 +0000 (17:01 +0800)] 
util/grub.d/00_header.in: Wire grub.cfg to use env_block when present

This patch extends the generated grub.cfg so that it can use the
external environment block when the variable env_block is defined.
During boot, if env_block is set, grub.cfg builds a device path for it,
exports the variable, and then loads its contents in addition to the
normal grubenv file.

When GRUB writes variables such as next_entry or saved_entry, the save
commands are changed to write into env_block if it is set, and to fall
back to the grubenv file otherwise. In this way the external environment
block is used automatically, and existing commands like savedefault or
save_env do not need to change.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agofs/btrfs: Add environment block to reserved header area
Michael Chang [Fri, 17 Oct 2025 09:01:40 +0000 (17:01 +0800)] 
fs/btrfs: Add environment block to reserved header area

This patch reserves space for the GRUB environment block inside the
Btrfs header. The block is placed at an offset of GRUB_ENV_BTRFS_OFFSET,
256 KiB from the start of the device, and occupies one sector. To
protect the space, overflow guard sectors are placed before and after
the reserved block.

The Btrfs header already defines regions for bootloader use. By adding
this entry, GRUB gains a fixed and safe location to store the environment
block without conflicting with other structures in the header.

Add Btrfs and its reserved area information to the fs_envblk_spec table.
With the groundworks done in previous patches, the function is now
complete and working in grub-editenv.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/grub-editenv: Add probe call for external envblk
Michael Chang [Fri, 17 Oct 2025 09:01:39 +0000 (17:01 +0800)] 
util/grub-editenv: Add probe call for external envblk

This patch adds the probe_fs_envblk() function to identify the root
filesystem and invoke fs_envblk_init() with the probed filesystem type
and device. This checks if the feature is available and initializes the
handle, fs_envblk, to access the external environment block. It avoids
configurations with diskfilter or cryptodisk where filesystem blocks may
be remapped or encrypted.

The probe is only invoked when grub-editenv is working on the default
environment file path. This restriction ensures that probing and
possible raw device access are not triggered for arbitrary user supplied
paths, but only for the standard grubenv file. In that case the code
checks if the filename equals DEFAULT_ENVBLK_PATH and then calls
probe_fs_envblk with fs_envblk_spec. The result is stored in the global
fs_envblk handle. At this stage the external environment block is only
detected and recorded, and the behavior of grub-editenv is unchanged.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/grub-editenv: Wire list_variables() to optional fs_envblk
Michael Chang [Fri, 17 Oct 2025 09:01:38 +0000 (17:01 +0800)] 
util/grub-editenv: Wire list_variables() to optional fs_envblk

This patch updates list_variables() so that it also prints entries from
the external environment block when one is present. The function first
lists all variables from the file based envblk, then iterates over the
external envblk and prints those as well.

The output format remains the same as before. The change makes it
possible to inspect variables regardless of whether they are stored in
the file envblk or in the reserved block.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/grub-editenv: Wire unset_variables() to optional fs_envblk
Michael Chang [Fri, 17 Oct 2025 09:01:37 +0000 (17:01 +0800)] 
util/grub-editenv: Wire unset_variables() to optional fs_envblk

This patch updates unset_variables() so that removals are also applied
to the external environment block when it is present. The code opens the
external block, deletes the same named keys there, and then writes the
external block back using fs_envblk_write(). The file based envblk is
still updated and written as before.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/grub-editenv: Wire set_variables() to optional fs_envblk
Michael Chang [Fri, 17 Oct 2025 09:01:36 +0000 (17:01 +0800)] 
util/grub-editenv: Wire set_variables() to optional fs_envblk

This patch changes set_variables() so that it can use an external
environment block when one is present. The variable next_entry is
written into the external block, env_block is treated as read only, and
all other variables are written into the normal file based envblk.

A cleanup step is added to handle cases where GRUB at runtime writes
variables into the external block because file based updates are not
safe on a copy on write filesystem such as Btrfs. For example, the
savedefault command can update saved_entry, and on Btrfs GRUB will place
that update in the external block instead of the file envblk. If an
older copy remains in the external block, it would override the newer
value from the file envblk when GRUB first loads the file and then
applies the external block on top of it. To avoid this, whenever
a variable is updated in the file envblk, any same named key in
the external block is deleted.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/grub-editenv: Add fs_envblk write helper
Michael Chang [Fri, 17 Oct 2025 09:01:35 +0000 (17:01 +0800)] 
util/grub-editenv: Add fs_envblk write helper

This patch adds the function fs_envblk_write to update the reserved
environment block on disk. The helper takes an in memory envblk buffer
and writes it back to the device at the location defined by the
fs_envblk specification. It performs size checks and uses file sync to
ensure that the updated data is flushed.

The helper is also added into the fs_envblk ops table, together with the
open helper from the previous patch. With this change the basic input
and output path for an external environment block is complete. The
choice of which variables should be written externally will be handled
by later patches.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/grub-editenv: Add fs_envblk open helper
Michael Chang [Fri, 17 Oct 2025 09:01:34 +0000 (17:01 +0800)] 
util/grub-editenv: Add fs_envblk open helper

This patch adds the logic to locate and open an environment block that
is stored in a reserved area on the device. It introduces the function
fs_envblk_open() together with helper routines to read the block pointed
to by the env_block variable, and to create the block on disk when it
does not exist yet. When a block is created, the code records its
location inside the file based envblk by setting env_block in block list
syntax of offset plus size in sectors.

The env_block variable acts as a link from the file envblk to the raw
disk region so that later runs of grub-editenv can follow it and access
the external block. The helper is exposed through a small ops table
attached to fs_envblk so that later patches can call
fs_envblk->ops->open() without touching core code again. At this stage
variables are still stored in the file envblk and no redirection has
been applied.

In relation to this, the fs_envblk_spec table defines the file-system
specific layout of the reserved raw blocks used for environment storage.
It is prepared to facilitate integration in grub-editenv, with Btrfs to
be added in the future once its reserved area is defined.

An fs_envblk_init() helper is added to prepare it for using the ops with
its associated data context if the feature is available. It is not used
yet, but will be used later when a filesystem and its device are probed
to initialize the fs_envblk handle and enable access to the feature.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agotests: Add "z" length modifier printf tests
Michael Chang [Fri, 17 Oct 2025 09:01:33 +0000 (17:01 +0800)] 
tests: Add "z" length modifier printf tests

Add unit tests for %zd, %zu and %zx to verify size_t and ssize_t
formatting matches system snprintf().

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agokern/misc: Add the "z" length modifier support
Michael Chang [Fri, 17 Oct 2025 09:01:32 +0000 (17:01 +0800)] 
kern/misc: Add the "z" length modifier support

Add support for the "z" length modifier in the printf code. This allows
printing of size_t and ssize_t values using %zu, %zd and related
formats. The parser maps "z" to the correct integer width based on
sizeof(size_t).

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agodisk/cryptodisk: Add --hw-accel to enable hardware acceleration
Gary Lin [Wed, 22 Oct 2025 01:29:00 +0000 (09:29 +0800)] 
disk/cryptodisk: Add --hw-accel to enable hardware acceleration

The --hw-accel option has been added to cryptomount to speed up
decryption by temporarily enabling hardware-specific instruction
sets (e.g., AVX, SSE) in libgcrypt.

A new feature, "feature_gcry_hw_accel", is also introduced to mark the
availability of the new option.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt: Add hardware acceleration for gcry_sha512
Gary Lin [Wed, 22 Oct 2025 01:28:59 +0000 (09:28 +0800)] 
libgcrypt: Add hardware acceleration for gcry_sha512

Enable hardware acceleration for the gcry_sha512 module when building
for the x86_64 EFI target.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt: Add hardware acceleration for gcry_sha256
Gary Lin [Wed, 22 Oct 2025 01:28:58 +0000 (09:28 +0800)] 
libgcrypt: Add hardware acceleration for gcry_sha256

Enable hardware acceleration for the gcry_sha256 module when building
for the x86_64 EFI target.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt: Declare the sha256 shaext function
Gary Lin [Wed, 22 Oct 2025 01:28:57 +0000 (09:28 +0800)] 
libgcrypt: Declare the sha256 shaext function

There is no prototype of _gcry_sha256_transform_intel_shaext() defined
in the header or libgcrypt-grub/cipher/sha256.c, and gcc may complain
the missing-prototypes error when compiling sha256-intel-shaext.c.

Declare the prototype in sha256-intel-shaext.c to avoid the error.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt: Implement _gcry_get_hw_features()
Gary Lin [Wed, 22 Oct 2025 01:28:56 +0000 (09:28 +0800)] 
libgcrypt: Implement _gcry_get_hw_features()

Implement _gcry_get_hw_features() and enable hardware feature detection
for x86_64.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt: Copy sha512 x86_64 assembly files
Gary Lin [Wed, 22 Oct 2025 01:28:55 +0000 (09:28 +0800)] 
libgcrypt: Copy sha512 x86_64 assembly files

Copy the selected x86_64 assembly files to support hardware
acceleration for sha512.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt: Copy sha256 x86_64 assembly files
Gary Lin [Wed, 22 Oct 2025 01:28:54 +0000 (09:28 +0800)] 
libgcrypt: Copy sha256 x86_64 assembly files

Copy the selected x86_64 assembly files to support hardware
acceleration for sha256.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI
Gary Lin [Wed, 22 Oct 2025 01:28:53 +0000 (09:28 +0800)] 
lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI

Implement the necessary functions to dynamically enable SSE and AVX
on x86_64 EFI systems when the hardware is capable.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolib/hwfeatures-gcry: Introduce functions to manage hardware features
Gary Lin [Wed, 22 Oct 2025 01:28:52 +0000 (09:28 +0800)] 
lib/hwfeatures-gcry: Introduce functions to manage hardware features

This commit introduces the generic functions to manage the hardware
features in libgcrypt. These functions are stubs for future
platform-specific implementations:
  - grub_gcry_hwf_enabled() returns __gcry_use_hwf which indicates if
    the hardware features are enabled specifically by grub_enable_gcry_hwf(),
  - grub_enable_gcry_hwf() invokes the architecture specific enablement
    functions and sets __gcry_use_hwf to true,
  - grub_reset_gcry_hwf() invokes the architecture specific reset
    functions and sets __gcry_use_hwf to false.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoconfigure: Tweak autoconf/automake files to detect x86_64 features
Gary Lin [Wed, 22 Oct 2025 01:28:51 +0000 (09:28 +0800)] 
configure: Tweak autoconf/automake files to detect x86_64 features

To enable hardware acceleration, this commit ports the feature detection
logic from libgcrypt. This allows us to check if the compiler supports
specific assembly instructions, including SSSE3, Intel SHA extensions,
SSE4.1, AVX, AVX2, AVX512, and BMI2.

To simplify the initial implementation, support for x86_64 feature
detection is currently limited to the x86_64 EFI target.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolib/pbkdf2: Optimize PBKDF2 by reusing HMAC handle
Gary Lin [Thu, 14 Aug 2025 06:32:42 +0000 (14:32 +0800)] 
lib/pbkdf2: Optimize PBKDF2 by reusing HMAC handle

The previous PBKDF2 implementation used grub_crypto_hmac_buffer() which
allocates and frees an HMAC handle on every call. This approach caused
significant performance overhead slowing down the boot process considerably.

This commit refactors the PBKDF2 code to use the new HMAC functions
allowing the HMAC handle and its buffers to be allocated once and reused
across multiple operations. This change significantly reduces disk
unlocking time.

In a QEMU/OVMF test environment this patch reduced the time to unlock
a LUKS2 (*) partition from approximately 15 seconds to 4 seconds.

  (*) PBKDF2 SHA256 with 3454944 iterations.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolib/crypto: Introduce new HMAC functions to reuse buffers
Gary Lin [Thu, 14 Aug 2025 06:32:41 +0000 (14:32 +0800)] 
lib/crypto: Introduce new HMAC functions to reuse buffers

To enable more efficient buffer reuse for HMAC operations three new
functions have been introduced. This change prevents the need to
reallocate memory for each HMAC operation:
  - grub_crypto_hmac_reset(): reinitializes the hash contexts in the HMAC handle,
  - grub_crypto_hmac_final(): provides the final HMAC result without freeing the
    handle allowing it to be reused immediately,
  - grub_crypto_hmac_free(): deallocates the HMAC handle and its associated memory.

To further facilitate buffer reuse ctx2 is now included within the HMAC handle
struct and the initialization of ctx2 is moved to grub_crypto_hmac_init().

The intermediate hash states, ctx and ctx2, for the inner and outer padded
keys are now cached. The grub_crypto_hmac_reset() restores these cached
states for new operations which avoids redundant hashing of the keys.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agodocs: Document argon2 and argon2_test modules
Gary Lin [Wed, 15 Oct 2025 03:00:27 +0000 (11:00 +0800)] 
docs: Document argon2 and argon2_test modules

Signed-off-by: Gary Lin <glin@suse.com>
Tested-By: Waldemar Brodkorb <wbx@openadk.org>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agokern/misc: Implement faster grub_memcpy() for aligned buffers
Gary Lin [Wed, 15 Oct 2025 03:00:28 +0000 (11:00 +0800)] 
kern/misc: Implement faster grub_memcpy() for aligned buffers

When both "dest" and "src" are aligned, copying the data in grub_addr_t
sized chunks is more efficient than a byte-by-byte copy.

Also tweak __aeabi_memcpy(), __aeabi_memcpy4(), and __aeabi_memcpy8(),
since grub_memcpy() is not inline anymore.

Optimization for unaligned buffers was omitted to maintain code
simplicity and readability. The current chunk-copy optimization
for aligned buffers already provides a noticeable performance
improvement (*) for Argon2 keyslot decryption.

  (*) On my system, for a LUKS2 keyslot configured with a 1 GB Argon2
      memory requirement, this patch reduces the decryption time from
      22 seconds to 12 seconds.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agotests/util/grub-fs-tester: Use Argon2id for LUKS2 test
Gary Lin [Wed, 15 Oct 2025 03:00:26 +0000 (11:00 +0800)] 
tests/util/grub-fs-tester: Use Argon2id for LUKS2 test

Given that the LUKS1 test already covers PBKDF2, the default KDF for the
LUKS2 test has been switched to Argon2id to ensure both algorithms are
validated.

Signed-off-by: Gary Lin <glin@suse.com>
Tested-By: Waldemar Brodkorb <wbx@openadk.org>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agotests: Integrate Argon2 tests into functional_test
Gary Lin [Wed, 15 Oct 2025 03:00:25 +0000 (11:00 +0800)] 
tests: Integrate Argon2 tests into functional_test

Refactor the Argon2 tests to enable the module build and integrate the
tests into function_test.

Signed-off-by: Gary Lin <glin@suse.com>
Tested-By: Waldemar Brodkorb <wbx@openadk.org>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agotests: Import Argon2 tests from libgcrypt
Gary Lin [Wed, 15 Oct 2025 03:00:24 +0000 (11:00 +0800)] 
tests: Import Argon2 tests from libgcrypt

Copy the Argon2 test function, check_argon2(), from t-kdf.c in libgcrypt
to grub-core/tests/argon2_test.c.

Signed-off-by: Gary Lin <glin@suse.com>
Tested-By: Waldemar Brodkorb <wbx@openadk.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agodisk/luks2: Add Argon2 support
Gary Lin [Wed, 15 Oct 2025 03:00:23 +0000 (11:00 +0800)] 
disk/luks2: Add Argon2 support

Leverage the new grub_crypto_argon2() function to add support for the
Argon2i and Argon2id KDFs in LUKS2.

Signed-off-by: Gary Lin <glin@suse.com>
Tested-By: Waldemar Brodkorb <wbx@openadk.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoargon2: Introduce grub_crypto_argon2()
Gary Lin [Wed, 15 Oct 2025 03:00:22 +0000 (11:00 +0800)] 
argon2: Introduce grub_crypto_argon2()

This commit introduces grub_crypto_argon2() which leverages the
_gcry_kdf_*() functions from libgcrypt to provide Argon2 support.

Due to the dependency of the _gcry_kdf_*() functions, the order of
"ldadd" entries have to be tweaked in Makefile.util.def so that the
linker can discover these functions.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt/kdf: Fix 64-bit modulus on 32-bit platforms
Gary Lin [Wed, 15 Oct 2025 03:00:21 +0000 (11:00 +0800)] 
libgcrypt/kdf: Fix 64-bit modulus on 32-bit platforms

Use grub_divmod64() for the 64-bit modulus to prevent creation of
special division calls such as __umoddi3() and __aeabi_uldivmod() on
32-bit platforms.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt/kdf: Remove unsupported KDFs
Gary Lin [Wed, 15 Oct 2025 03:00:20 +0000 (11:00 +0800)] 
libgcrypt/kdf: Remove unsupported KDFs

Clean up _gcry_kdf_*() to remove unsupported KDFs.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt/kdf: Get rid of gpg_err_code_from_errno()
Gary Lin [Wed, 15 Oct 2025 03:00:19 +0000 (11:00 +0800)] 
libgcrypt/kdf: Get rid of gpg_err_code_from_errno()

gpg_err_code_from_errno() requires libgcrypt_wrap/mem.c which is not in
Makefile.utilgcry.def. This commit replaces gpg_err_code_from_errno()
with GPG_ERR_* to avoid the build errors.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agolibgcrypt/kdf: Implement hash_buffers() for BLAKE2b-512
Gary Lin [Wed, 15 Oct 2025 03:00:18 +0000 (11:00 +0800)] 
libgcrypt/kdf: Implement hash_buffers() for BLAKE2b-512

The hash_buffers() functions are disabled in GRUB by default but the
Argon2 implementation requires hash_buffers() for BLAKE2b-512.

This commit implements argon2_blake2b_512_hash_buffers() as the
replacement of _gcry_digest_spec_blake2b_512.hash_buffers().

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agocrypto: Update crypto.h for libgcrypt KDF functions
Gary Lin [Wed, 15 Oct 2025 03:00:17 +0000 (11:00 +0800)] 
crypto: Update crypto.h for libgcrypt KDF functions

This commit introduces the necessary changes to crypto.h in preparation
for implementing Argon2 support via the generic KDF functions, _gcry_kdf_*():
  - add new GPG error types required by kdf.c,
  - declare _gcry_digest_spec_blake2b_512 to enable BLAKE2b-512 digest calculations,
  - define the gcrypt KDF algorithm IDs for Argon2,
  - add the prototypes of _gcry_kdf_*() functions.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 weeks agoutil/import_gcry: Import kdf.c for Argon2
Gary Lin [Wed, 15 Oct 2025 03:00:16 +0000 (11:00 +0800)] 
util/import_gcry: Import kdf.c for Argon2

The import_gcry.py script now imports kdf.c from libgcrypt. To isolate
the Argon2 implementation, all unrelated functions have been removed.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agocommands/menuentry: Fix for out of bound access
Sudhakar Kuppusamy [Thu, 9 Oct 2025 09:19:39 +0000 (14:49 +0530)] 
commands/menuentry: Fix for out of bound access

A menu entry with an empty title leads to an out-of-bounds access at
"ch = src[len - 1]", i.e., "src" is empty and "len" is zero. So, fixing
this by checking the menu entry title length and throwing an error if
the length is zero.

Signed-off-by: Sridhar Markonda <sridharm@linux.ibm.com>
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agotests/tpm2_key_protector_test: Add a test for PCR Capping
Gary Lin [Fri, 3 Oct 2025 03:22:08 +0000 (11:22 +0800)] 
tests/tpm2_key_protector_test: Add a test for PCR Capping

A test is introduced to cap PCR 1 and track the PCR 1 value before and
after key unsealing.

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 agotpm2_key_protector: Support PCR capping
Gary Lin [Fri, 3 Oct 2025 03:22:07 +0000 (11:22 +0800)] 
tpm2_key_protector: Support PCR capping

To prevent a sealed key from being unsealed again, a common and
straightforward method is to "cap" the key by extending the associated
PCRs. When the PCRs associated with the sealed key are extended, TPM will
be unable to unseal the key, as the PCR values required for unsealing no
longer match, effectively rendering the key unusable until the next
system boot or a state where the PCRs are reset to their expected values.

To cap a specific set of PCRs, simply append the argument '-c pcr_list'
to the tpm2_key_protector command. Upon successfully unsealing the key,
the TPM2 key protector will then invoke tpm2_protector_cap_pcrs(). This
function extends the selected PCRs with an EV_SEPARATOR event,
effectively "capping" them. Consequently, the associated key cannot be
unsealed in any subsequent attempts until these PCRs are reset to their
original, pre-capped state, typically occurring upon the next system
boot.

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 agotss2: Implement grub_tcg2_cap_pcr() for emu
Gary Lin [Fri, 3 Oct 2025 03:22:06 +0000 (11:22 +0800)] 
tss2: Implement grub_tcg2_cap_pcr() for emu

Since there is no system firmware for grub-emu, the TPM2_PCR_Event
command becomes the only choice to implement grub_tcg2_cap_pcr().

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 agotss2: Implement grub_tcg2_cap_pcr() for ieee1275
Gary Lin [Fri, 3 Oct 2025 03:22:05 +0000 (11:22 +0800)] 
tss2: Implement grub_tcg2_cap_pcr() for ieee1275

This commit implements grub_tcg2_cap_pcr() for ieee1275 with the
firmware function, 2hash-ext-log, to extend the target PCR with an
EV_SEPARATOR event and record the event into the TPM event log.

To avoid duplicate code, ibmvtpm_2hash_ext_log() is moved to tcg2.c
and exported as a global function.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agotss2: Implement grub_tcg2_cap_pcr() for EFI
Gary Lin [Fri, 3 Oct 2025 03:22:04 +0000 (11:22 +0800)] 
tss2: Implement grub_tcg2_cap_pcr() for EFI

This commit implements grub_tcg2_cap_pcr() for EFI by using the UEFI
TCG2 protocol, HashLogExtendEvent, to extend the specified PCR with an
EV_SEPARATOR event and ensure the event will be recorded properly in the
TPM event log.

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 agotss2: Introduce grub_tcg2_cap_pcr()
Gary Lin [Fri, 3 Oct 2025 03:22:03 +0000 (11:22 +0800)] 
tss2: Introduce grub_tcg2_cap_pcr()

This commit introduces the definition of grub_tcg2_cap_pcr(), a new
function designed to enhance the security of sealed keys. Its primary
purpose is to "cap" a specific PCR by extending it with an EV_SEPARATOR
event. This action cryptographically alters the PCR value, making it
impossible to unseal any key that was previously sealed to the original
PCR state. Consequently, the sealed key remains protected against
unauthorized unsealing attempts until the associated PCRs are reset to
their initial configuration, typically occurring during a subsequent
system boot.

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 agotss2: Add TPM2_PCR_Event command
Gary Lin [Fri, 3 Oct 2025 03:22:02 +0000 (11:22 +0800)] 
tss2: Add TPM2_PCR_Event command

The TPM2_PCR_Event command is introduced to tss2 to allow the user to
extend a specific PCR. The related data structure and unmarshal function
are also introduced.

However, simply invoking TPM2_PCR_Event does not automatically record
the event into the TPM event log. The TPM event log is primarily
maintained by the system firmware (e.g., BIOS/UEFI). Therefore, for most
standard use cases, the recommended method for extending PCRs and
ensuring proper event logging is to utilize the system firmware
functions.

There are specific scenarios where direct use of TPM2_PCR_Event becomes
necessary. For instance, in environments lacking system firmware support
for PCR extension, such as the grub-emu, TPM2_PCR_Event serves as the
only available method to extend PCRs.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoloader/i386/linux: Transfer EDID information to kernel
Thomas Zimmermann [Thu, 2 Oct 2025 12:44:01 +0000 (14:44 +0200)] 
loader/i386/linux: Transfer EDID information to kernel

The Linux kernel's struct bootparams provides a field at offset 0x140
for storing an EDID header. Copy the video adapter's data to the field.

The edid_info field was added in 2003 (see "[FBDEV] EDID support from
OpenFirmware on PPC platoforms and from the BIOS on intel platforms."),
but only got useable in 2004 (see "[PATCH] Fix EDID_INFO in zero-page").
The boot protocol was at version 2.03 at that time.

The field was never used much, but with the recent addition of the efidrm
and vesadrm drivers to the kernel, it becomes much more useful. As with
the initial screen setup, these drivers can make use of the provided
EDID information for basic display output.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agofs/hfsplus: Allow reading files created by Mac OS 9
Dave Vasilevsky [Wed, 1 Oct 2025 21:03:48 +0000 (17:03 -0400)] 
fs/hfsplus: Allow reading files created by Mac OS 9

The "permissions" field of hfsplus files is only used by Mac OS X. This
causes GRUB to skip reading files created by Mac OS 9, since their
file mode is read as unknown. Instead, assume files with zero mode
are regular files.

From Technote 1150:

  The traditional Mac OS implementation of HFS Plus does not use the
  permissions field. Files created by traditional Mac OS have the
  entire field set to 0.

Signed-off-by: Dave Vasilevsky <dave@vasilevsky.ca>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agodocs: Fix build warnings in libgcrypt and blsuki doc
Sridhar Markonda [Wed, 17 Sep 2025 10:54:09 +0000 (16:24 +0530)] 
docs: Fix build warnings in libgcrypt and blsuki doc

Following warnings are thrown during libgrcypt and bluski doc build:

  grub.texi:4744: warning: node next pointer for `gcry_arcfour_module' is `gcry_blake2_module' but next is `gcry_aria_module' in menu
  grub.texi:4744: warning: node prev pointer for `gcry_arcfour_module' is `gcry_aria_module' but prev is `functional_test_module' in menu
  grub.texi:4751: warning: node prev pointer for `gcry_blake2_module' is `gcry_arcfour_module' but prev is `gcry_aria_module' in menu
  grub.texi:8532: warning: node next pointer for `trust' is `unset' but next is `uki' in menu
  grub.texi:8549: warning: node next pointer for `unset' is `uki' but next is `verify_detached' in menu
  grub.texi:8549: warning: node prev pointer for `unset' is `trust' but prev is `uki' in menu
  grub.texi:8557: warning: node next pointer for `uki' is `verify_detached' but next is `unset' in menu
  grub.texi:8557: warning: node prev pointer for `uki' is `unset' but prev is `trust' in menu
  grub.texi:8600: warning: node prev pointer for `verify_detached' is `uki' but prev is `unset' in menu

Fix order of gcry_aria_module and unset nodes.

Signed-off-by: Sridhar Markonda <sridharm@linux.ibm.com>
Reviewed-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agokern/command,commands/extcmd: Perform explicit NULL check in both the unregister...
Srish Srinivasan [Mon, 22 Sep 2025 06:02:46 +0000 (11:32 +0530)] 
kern/command,commands/extcmd: Perform explicit NULL check in both the unregister helpers

During command registration, grub_register_command_prio() returns
a 0 when there is a failure in memory allocation. In such a situation,
calls to grub_unregister_{command(), extcmd()} during command
unregistration will result in dereferencing a NULL pointer.

Perform explicit NULL check in both unregister helpers to prevent
undefined behaviour due to a NULL pointer dereference.

Signed-off-by: Srish Srinivasan <ssrish@linux.ibm.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 agocommands/efi/tpm: Call get_active_pcr_banks() only with TCG2 1.1 or newer
Luca Boccassi [Sat, 20 Sep 2025 01:12:32 +0000 (02:12 +0100)] 
commands/efi/tpm: Call get_active_pcr_banks() only with TCG2 1.1 or newer

The call was added in the 1.1 revision of the spec, 1.0 does
not have it, and there are some machines out there with a TPM2
and a UEFI firmware that only supports version 1.0, so the
call fails in those cases. Check the reported version before
calling get_active_pcr_banks().

See Table 4 in section 6.2 of the TCG EFI Protocol Specification:

  https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf

Fixes: f326c5c47 (commands/bli: Set LoaderTpm2ActivePcrBanks runtime variable)
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Reviewed-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agokern: Include function name on debug and error print functions
Leo Sandoval [Tue, 23 Sep 2025 23:33:32 +0000 (17:33 -0600)] 
kern: Include function name on debug and error print functions

With the following change, we see standard (grub_dprintf) and
error (grub_error) logs with the function name embedded (see below)
into the log which is particular useful when debugging:

  commands/efi/tpm.c:grub_tpm_measure:281:tpm: log_event, pcr = 8, size = 0xb,

Including one more field on the print log impacts the binary sizes
and in turn their respective distro packages. For Fedora rpm packages
the increase is 20k approximately.

Signed-off-by: Leo Sandoval <lsandova@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agokern: Make grub_error() more verbose
Peter Jones [Tue, 23 Sep 2025 23:33:31 +0000 (17:33 -0600)] 
kern: Make grub_error() more verbose

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agonet/tcp: Fix TCP port number reused on reboot
Michael Chang [Tue, 2 Sep 2025 06:58:50 +0000 (14:58 +0800)] 
net/tcp: Fix TCP port number reused on reboot

GRUB's TCP stack assigns source ports for outgoing connections starting
at 21550 and increments sequentially by 1 (e.g., 21550, 21551, ...).
While this generally works, it can lead to failures if the system
reboots rapidly and reuses the same source port too soon.

This issue was observed on powerpc-ieee1275 platforms using CAS (Client
Architecture Support) reboot. In such cases, loading the initrd over
HTTP may fail with connection timeouts. Packet captures show the failed
connections are flagged as "TCP Port Number Reused" by Wireshark.

The root cause is that GRUB reuses the same port shortly after reboot,
while the server may still be tracking the previous connection in
TIME_WAIT. This can result in the server rejecting the connection
attempt or responding with a stale ACK or RST, leading to handshake
failure.

This patch fixes the issue by introducing a time based source port
selection strategy. Instead of always starting from port 21550, GRUB now
computes an initial base port based on the current RTC time, divided
into 5 minute windows. The purpose of this time based strategy is to
ensure that GRUB avoids reusing the same source port within a 5 minute
window, thereby preventing collisions with stale server side connection
tracking that could interfere with a new TCP handshake.

A step size of 8 ensures that the same port will not be reused across
reboots unless GRUB opens more than 8 TCP connections per second on
average, something that is highly unlikely. In typical usage, a GRUB
boot cycle lasts about 15 seconds and may open fewer than 100
connections total, well below the reuse threshold. This makes the
approach robust against short reboot intervals while keeping the logic
simple and deterministic.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agodocs/grub: Document appended signature
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:25:05 +0000 (12:55 +0530)] 
docs/grub: Document appended signature

This explains how appended signatures can be used to form part of
a secure boot chain, and documents the commands and variables
introduced.

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>
3 weeks agodocs/grub: Document signing GRUB with an appended signature
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:25:04 +0000 (12:55 +0530)] 
docs/grub: Document signing GRUB with an appended signature

Signing GRUB for firmware that verifies an appended signature is a
bit fiddly. I don't want people to have to figure it out from scratch
so document it here.

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>
3 weeks agodocs/grub: Document signing GRUB under UEFI
Daniel Axtens [Mon, 6 Oct 2025 07:25:03 +0000 (12:55 +0530)] 
docs/grub: Document signing GRUB under UEFI

Before adding information about how GRUB is signed with an appended
signature scheme, it's worth adding some information about how it
can currently be signed for UEFI.

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>
3 weeks agoappended signatures: Verification tests
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:25:02 +0000 (12:55 +0530)] 
appended signatures: Verification tests

These tests are run through all_functional_test and test a range
of commands and behaviours.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoappended signatures: GRUB commands to manage the hashes
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:25:01 +0000 (12:55 +0530)] 
appended signatures: GRUB commands to manage the hashes

Introducing the following GRUB commands to manage certificate/binary
hashes.

  1. append_list_dbx:
      Show the list of distrusted certificates and binary/certificate
      hashes from the dbx list.
  2. append_add_db_hash:
      Add the trusted binary hash to the db list.
  3. append_add_dbx_hash:
      Add the distrusted certificate/binary hash to the dbx list.

Note that if signature verification (check_appended_signatures) is set to yes,
the append_add_db_hash and append_add_dbx_hash commands only accept the file
‘hash_file’ that is signed with an appended signature.

Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Tested-by: Sridhar Markonda <sridharm@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoappended signatures: GRUB commands to manage the certificates
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:25:00 +0000 (12:55 +0530)] 
appended signatures: GRUB commands to manage the certificates

Introducing the following GRUB commands to manage the certificates.

 1. append_list_db:
      Show the list of trusted certificates from the db list
 2. append_add_db_cert:
      Add the trusted certificate to the db list
 3. append_add_dbx_cert:
      Add the distrusted certificate to the dbx list
 4. append_verify:
      Verify the signed file using db list

Note that if signature verification (check_appended_signatures) is set to yes,
the append_add_db_cert and append_add_dbx_cert commands only accept the file
‘X509_certificate’ that is signed with an appended signature.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Tested-by: Sridhar Markonda <sridharm@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoappended signatures: Using db and dbx lists for signature verification
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:59 +0000 (12:54 +0530)] 
appended signatures: Using db and dbx lists for signature verification

Signature verification: verify the kernel against lists of hashes that are
either in dbx or db list. If it is not in the dbx list then the trusted keys
from the db list are used to verify the signature.

Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoappended signatures: Create db and dbx lists
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:58 +0000 (12:54 +0530)] 
appended signatures: Create db and dbx lists

If secure boot is enabled with static key management mode, the trusted
certificates will be extracted from the GRUB ELF Note and added to db list.

If secure boot is enabled with dynamic key management mode, the trusted
certificates and certificate/binary hash will be extracted from the PKS
and added to db list. The distrusted certificates, certificate/binary hash
are read from the PKS and added to dbx list. Both dbx and db lists usage is
added by a subsequent patch.

Note:
- If db does not exist in the PKS storage, then read the static keys as a db
  default keys from the GRUB ELF Note and add them into the db list.
- If the certificate or the certificate hash exists in the dbx list, then do not
  add that certificate/certificate hash to the db list.

Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoappended signatures: Introducing key management environment variable
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:57 +0000 (12:54 +0530)] 
appended signatures: Introducing key management environment variable

Introducing the appended signature key management environment variable. It is
automatically set to either "static" or "dynamic" based on the Platform KeyStore.

"static": Enforce static key management signature verification. This is the
          default. When the GRUB is locked down, user cannot change the value
          by setting the appendedsig_key_mgmt variable back to "dynamic".

"dynamic": Enforce dynamic key management signature verification. When the GRUB
           is locked down, user cannot change the value by setting the
           appendedsig_key_mgmt variable back to "static".

Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agopowerpc/ieee1275: Read the db and dbx secure boot variables
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:56 +0000 (12:54 +0530)] 
powerpc/ieee1275: Read the db and dbx secure boot variables

Enhancing the infrastructure to enable the Platform Keystore (PKS) feature,
which provides access to the SB_VERSION, db, and dbx secure boot variables
from PKS.

If PKS is enabled, it will read secure boot variables such as db and dbx
from PKS and extract EFI Signature List (ESL) from it. The ESLs would be
saved in the Platform Keystore buffer, and the appendedsig module would
read it later to extract the certificate's details from ESL.

In the following scenarios, static key management mode will be activated:
 1. When Secure Boot is enabled with static key management mode
 2. When SB_VERSION is unavailable but Secure Boot is enabled
 3. When PKS support is unavailable but Secure Boot is enabled

Note:

 SB_VERSION: Key Management Mode
 1 - Enable dynamic key management mode. Read the db and dbx variables from PKS,
     and use them for signature verification.
 0 - Enable static key management mode. Read keys from the GRUB ELF Note and
     use it for signature verification.

Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoappended signatures: Support verifying appended signatures
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:55 +0000 (12:54 +0530)] 
appended signatures: Support verifying appended signatures

Building on the parsers and the ability to embed X.509 certificates, as well
as the existing gcrypt functionality, add a module for verifying appended
signatures.

This includes a signature verifier that requires that the Linux kernel and
GRUB modules have appended signatures for verification.

Signature verification must be enabled by setting check_appended_signatures.
If secure boot is enabled with enforce mode when the appendedsig module is
loaded, signature verification will be enabled, and trusted keys will be
extracted from the GRUB ELF Note and stored in the db and locked automatically.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agopowerpc/ieee1275: Enter lockdown based on /ibm, secure-boot
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:54 +0000 (12:54 +0530)] 
powerpc/ieee1275: Enter lockdown based on /ibm, secure-boot

Read secure boot mode from 'ibm,secure-boot' property and if the secure boot
mode is set to 2 (enforce), enter lockdown. Else it is considered as disabled.
There are three secure boot modes. They are

0 - disabled
     No signature verification is performed. This is the default.
1 - audit
     Signature verification is performed and if signature verification fails,
     display the errors and allow the boot to continue.
2 - enforce
     Lockdown the GRUB. Signature verification is performed and if signature
     verification fails, display the errors and stop the boot.

Now, only support disabled and enforce.

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>
3 weeks agoappended signatures: Parse X.509 certificates
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:53 +0000 (12:54 +0530)] 
appended signatures: Parse X.509 certificates

This code allows us to parse:

 - X.509 certificates: at least enough to verify the signatures on the PKCS#7
   messages. We expect that the certificates embedded in GRUB will be leaf
   certificates, not CA certificates. The parser enforces this.

 - X.509 certificates support the Extended Key Usage extension and handle it by
   verifying that the certificate has a Code Signing usage.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> # EKU support
Reported-by: Michal Suchanek <msuchanek@suse.com> # key usage issue
Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoappended signatures: Parse PKCS#7 signed data
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:52 +0000 (12:54 +0530)] 
appended signatures: Parse PKCS#7 signed data

This code allows us to parse:

 - PKCS#7 signed data messages. Only a single signer info is supported, which
   is all that the Linux sign-file utility supports creating out-of-the-box.
   Only RSA, SHA-256 and SHA-512 are supported. Any certificate embedded in
   the PKCS#7 message will be ignored.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agoappended signatures: Parse ASN1 node
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:51 +0000 (12:54 +0530)] 
appended signatures: Parse ASN1 node

This code allows us to parse ASN1 node and allocating memory to store it.
It will work for anything where the size libtasn1 returns is right:
 - Integers
 - Octet strings
 - DER encoding of other structures

It will _not_ work for things where libtasn1 size requires adjustment:
 - Strings that require an extra NULL byte at the end
 - Bit strings because libtasn1 returns the length in bits, not bytes.

If the function returns a non-NULL value, the caller must free it.

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>
3 weeks agoappended signatures: Import GNUTLS's ASN.1 description files
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:50 +0000 (12:54 +0530)] 
appended signatures: Import GNUTLS's ASN.1 description files

In order to parse PKCS#7 messages and X.509 certificates with libtasn1, we need
some information about how they are encoded. We get these from GNUTLS, which has
the benefit that they support the features we need and are well tested.

The GNUTLS files are from:

- https://github.com/gnutls/gnutls/blob/master/lib/gnutls.asn
- https://github.com/gnutls/gnutls/blob/master/lib/pkix.asn

The GNUTLS license is LGPLv2.1+, which is GPLv3 compatible, allowing us to import
it without issue.

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>
3 weeks agogrub-install: Support embedding x509 certificates
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:49 +0000 (12:54 +0530)] 
grub-install: Support embedding x509 certificates

To support verification of appended signatures, we need a way to embed the
necessary public keys. Existing appended signature schemes in the Linux kernel
use X.509 certificates, so allow certificates to be embedded in the GRUB core
image in the same way as PGP keys.

Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
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>
3 weeks agopgp: Rename OBJ_TYPE_PUBKEY to OBJ_TYPE_GPG_PUBKEY
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:48 +0000 (12:54 +0530)] 
pgp: Rename OBJ_TYPE_PUBKEY to OBJ_TYPE_GPG_PUBKEY

Prior to the addition of the X.509 public key support for appended signature,
current PGP signature relied on the GPG public key. Changing the enum name
from "OBJ_TYPE_PUBKEY" to "OBJ_TYPE_GPG_PUBKEY" to differentiate between x509
certificate based appended signature and GPG certificate based PGP signature.

Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
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>
3 weeks agocrypto: Move storage for grub_crypto_pk_* to crypto.c
Daniel Axtens [Mon, 6 Oct 2025 07:24:47 +0000 (12:54 +0530)] 
crypto: Move storage for grub_crypto_pk_* to crypto.c

The way gcry_rsa and friends (the asymmetric ciphers) are loaded for the
pgp module is a bit quirky.

include/grub/crypto.h contains:
  extern struct gcry_pk_spec *grub_crypto_pk_rsa;

commands/pgp.c contains the actual storage:
  struct gcry_pk_spec *grub_crypto_pk_rsa;

And the module itself saves to the storage in pgp.c:
  GRUB_MOD_INIT(gcry_rsa)
  {
    grub_crypto_pk_rsa = &_gcry_pubkey_spec_rsa;
  }

This is annoying: gcry_rsa now has a dependency on pgp!

We want to be able to bring in gcry_rsa without bringing in PGP, so move the
storage to crypto.c.

Previously, gcry_rsa depended on pgp and mpi. Now it depends on crypto and mpi.
As pgp depends on crypto, this doesn't add any new module dependencies using
the PGP verfier.

[FWIW, the story is different for the symmetric ciphers. cryptodisk and friends
(zfs encryption etc) use grub_crypto_lookup_cipher_by_name() to get a cipher
handle. That depends on grub_ciphers being populated by people calling
grub_cipher_register. import_gcry.py ensures that the symmetric ciphers call it.]

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: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 weeks agopowerpc/ieee1275: Add support for signing GRUB with an appended signature
Sudhakar Kuppusamy [Mon, 6 Oct 2025 07:24:46 +0000 (12:54 +0530)] 
powerpc/ieee1275: Add support for signing GRUB with an appended signature

Add infrastructure to allow firmware to verify the integrity of GRUB
by use of a Linux-kernel-module-style appended signature. We initially
target powerpc-ieee1275, but the code should be extensible to other
platforms.

Usually these signatures are appended to a file without modifying the
ELF file itself. (This is what the 'sign-file' tool does, for example.)
The verifier loads the signed file from the file system and looks at the
end of the file for the appended signature. However, on powerpc-ieee1275
platforms, the bootloader is often stored directly in the PReP partition
as raw bytes without a file-system. This makes determining the location
of an appended signature more difficult.

To address this, we add a new ELF Note.

The name field of shall be the string "Appended-Signature", zero-padded
to 4 byte alignment. The type field shall be 0x41536967 (the ASCII values
for the string "ASig"). It must be the final section in the ELF binary.

The description shall contain the appended signature structure as defined
by the Linux kernel. The description will also be padded to be a multiple
of 4 bytes. The padding shall be added before the appended signature
structure (not at the end) so that the final bytes of a signed ELF file
are the appended signature magic.

A subsequent patch documents how to create a GRUB core.img validly signed
under this scheme.

Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
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>
8 weeks agolib/b64dec: Use grub_size_t instead of size_t for _gpgrt_b64dec_proc() function defin...
Anaëlle Cazuc [Tue, 2 Sep 2025 10:26:44 +0000 (12:26 +0200)] 
lib/b64dec: Use grub_size_t instead of size_t for _gpgrt_b64dec_proc() function definition

On some targets, size_t and grub_size_t may not be the same type
(unsigned long / unsigned int). This breaks the compilation because the
definition of _gpgrt_b64dec_proc() differs from gpgrt_b64dec_proc()
declaration. Fix it by using grub_size_t in the _gpgrt_b64dec_proc()
definition.

Signed-off-by: Anaëlle Cazuc <acazuc@acazuc.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
8 weeks agoutil/grub-mkimagexx: Fix riscv32 relocation offset
Anaëlle Cazuc [Tue, 2 Sep 2025 09:50:51 +0000 (11:50 +0200)] 
util/grub-mkimagexx: Fix riscv32 relocation offset

When using grub-mkrescue for a riscv32 target, an invalid implicit cast
on the offset calculation produces an error during the relocation process:

  grub-mkrescue: error: target XXX not reachable from pc=fc.

This patch adds an explicit grub_int64_t cast to compute the offset
as a 64-bit subtraction.

Signed-off-by: Anaëlle Cazuc <acazuc@acazuc.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
8 weeks agolibgcrypt: Allow GRUB to build with Clang
Andrew Hamilton [Sun, 31 Aug 2025 03:32:39 +0000 (22:32 -0500)] 
libgcrypt: Allow GRUB to build with Clang

Attempts to build GRUB with Clang were failing due to errors such as:

  error: redefinition of typedef 'gcry_md_hd_t' is a C11 feature

Correct this by adding a compiler pragma to disable the Clang
"typedef-redefinition" warnings. This required an update to
include/grub/crypto.h and the util/import_gcry.py script to add the
pragma to libgcrypt-grub's types.h due to u16 and similar types.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
8 weeks agotests: Add test ISO files to dist package
Andrew Hamilton [Mon, 1 Sep 2025 02:40:49 +0000 (21:40 -0500)] 
tests: Add test ISO files to dist package

Add test ISO files to dist package to allow ISO test to pass.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
8 weeks agotests: Test dates outside of 32-bit Unix range
Vladimir Serbinenko [Wed, 27 Aug 2025 22:32:14 +0000 (17:32 -0500)] 
tests: Test dates outside of 32-bit Unix range

Add tests outside the date range possible with 32-bit time calculation.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>