]> git.ipfire.org Git - thirdparty/grub.git/log
thirdparty/grub.git
3 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>
3 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>
3 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>
3 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 months agotests/util/grub-shell-luks-tester: Find cryptodisk by UUID
Glenn Washburn [Thu, 6 Mar 2025 06:18:43 +0000 (00:18 -0600)] 
tests/util/grub-shell-luks-tester: Find cryptodisk by UUID

GRUB has the capability to search all the disks for a cryptodisk of a
given UUID. Use this instead of hardcoding which disk is the cryptodisk,
which can change when devices are added or removed, or potentially when
QEMU is upgraded. This can not be done for the detached header tests
because the header contains the UUID.

Also, capitalize comment lines for consistency.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 months agotests/util/grub-shell: Default qemuopts to envvar $GRUB_QEMU_OPTS
Glenn Washburn [Thu, 6 Mar 2025 06:48:13 +0000 (00:48 -0600)] 
tests/util/grub-shell: Default qemuopts to envvar $GRUB_QEMU_OPTS

Fix a regression where qemuopts was mistakenly defaulted to the empty
string. This prevents the sending of arbitrary QEMU options to tests,
which may be desirable for overriding the machine type. There was a
concern that allowing the tester to accept arbitrary options would add
headaches for another developer trying to diagnose why a test failed on
the testers machine because he could not be sure if any additional
options were passed to make the test fail. However, all the options are
recorded in the run.sh generated script, so this concern is unwarranted.

Fixes: 6d729ced70 (tests/util/grub-shell: Add $GRUB_QEMU_OPTS to run.sh to easily see unofficial QEMU arguments)
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk/lvm: Add informational messages in error cases of ignored features
Patrick Plenefisch [Sun, 8 Dec 2024 02:19:23 +0000 (21:19 -0500)] 
disk/lvm: Add informational messages in error cases of ignored features

Signed-off-by: Patrick Plenefisch <simonpatp@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk/lvm: Add support for cachevol LV
Patrick Plenefisch [Mon, 11 Nov 2024 18:18:39 +0000 (13:18 -0500)] 
disk/lvm: Add support for cachevol LV

Mark cachevol LV's as ignored features, which is true only if they are
configured as "writethrough". This patch does not let GRUB boot from
"writeback" cache-enabled LV's.

Signed-off-by: Patrick Plenefisch <simonpatp@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk/lvm: Add support for integrity LV
Patrick Plenefisch [Sat, 4 Jan 2025 20:02:54 +0000 (15:02 -0500)] 
disk/lvm: Add support for integrity LV

The LV matching must be done after processing the ignored feature
indirections, as integrity volumes & caches may have several levels
of indirection that the segments must be shifted through.

Signed-off-by: Patrick Plenefisch <simonpatp@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agolvm: Match all LVM segments before validation
Patrick Plenefisch [Sat, 4 Jan 2025 20:00:36 +0000 (15:00 -0500)] 
lvm: Match all LVM segments before validation

The PV matching must be completely finished before validating a volume,
otherwise referenced RAID stripes may not have PV data applied yet.

This change is required for integrity & cachevol support.

Signed-off-by: Patrick Plenefisch <simonpatp@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk/lvm: Remove unused cache_pool
Patrick Plenefisch [Wed, 14 Aug 2024 00:15:37 +0000 (20:15 -0400)] 
disk/lvm: Remove unused cache_pool

The cache_pool is never read or used, remove it.

Signed-off-by: Patrick Plenefisch <simonpatp@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk/lvm: Make cache_lv more generic as ignored_feature_lv
Patrick Plenefisch [Wed, 14 Aug 2024 00:40:02 +0000 (20:40 -0400)] 
disk/lvm: Make cache_lv more generic as ignored_feature_lv

This patch isn't necessary by itself, but when combined with subsequent
patches it enhances readability as ignored_features_lv is then used for
multiple types of extra LV's, not just cache LV's.

Signed-off-by: Patrick Plenefisch <simonpatp@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agocommands/ls: Add directory header for dir args
Glenn Washburn [Sun, 2 Mar 2025 05:15:37 +0000 (23:15 -0600)] 
commands/ls: Add directory header for dir args

Like the GNU ls, first print a line with the directory path before printing
files in the directory, which will not have a directory component, but only
if there is more than one argument.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agocommands/ls: Print full paths for file args
Glenn Washburn [Sun, 2 Mar 2025 05:15:36 +0000 (23:15 -0600)] 
commands/ls: Print full paths for file args

For arguments that are paths to files, print the full path of the file.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agocommands/ls: Output path for single file arguments given with path
Glenn Washburn [Sun, 2 Mar 2025 05:15:35 +0000 (23:15 -0600)] 
commands/ls: Output path for single file arguments given with path

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agocommands/ls: Show modification time for file paths
Glenn Washburn [Sun, 2 Mar 2025 05:15:34 +0000 (23:15 -0600)] 
commands/ls: Show modification time for file paths

The modification time for paths to files was not being printed because
the grub_dirhook_info, which contains the mtime, was initialized to NULL.
Instead of calling print_file() directly, use fs->fs_dir() to call
print_file() with a properly filled in grub_dirhook_info. This has the
added benefit of reducing code complexity.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agocommands/ls: Merge print_files_long() and print_files() into print_file()
Glenn Washburn [Sun, 2 Mar 2025 05:15:33 +0000 (23:15 -0600)] 
commands/ls: Merge print_files_long() and print_files() into print_file()

Simplify the code by removing logic around which file printer to call.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agocommands/ls: Return proper GRUB_ERR_* for functions returning type grub_err_t
Glenn Washburn [Sun, 2 Mar 2025 05:15:32 +0000 (23:15 -0600)] 
commands/ls: Return proper GRUB_ERR_* for functions returning type grub_err_t

Also, remove unused code.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agocommands/acpi: Use options enum to index command options
Glenn Washburn [Sat, 1 Mar 2025 08:15:07 +0000 (02:15 -0600)] 
commands/acpi: Use options enum to index command options

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodocs: Capture additional commands restricted by lockdown
Andrew Hamilton [Fri, 28 Feb 2025 21:55:24 +0000 (15:55 -0600)] 
docs: Capture additional commands restricted by lockdown

Update documentation to capture that all memrw commands, the minicmd
dump command, and raw memory dumping via hexdump are restricted when
lockdown is enabled. This aligns to recent GRUB code updates.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodocs: Document restricted filesystems in lockdown
Andrew Hamilton [Fri, 28 Feb 2025 21:55:23 +0000 (15:55 -0600)] 
docs: Document restricted filesystems in lockdown

Document which filesystems are not allowed when lockdown
is enabled to align to recent GRUB changes.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoloader/i386/bsd: Fix type passed for the kernel
Vladimir Serbinenko [Tue, 4 Mar 2025 18:46:30 +0000 (21:46 +0300)] 
loader/i386/bsd: Fix type passed for the kernel

FreeBSD loader always passes "elf kernel". We currently pass "elf64 kernel"
when loading 64-bit kernel. The -CURRENT, HEAD, kernel accepts only
"elf kernel". Older kernel accepts either.

Tested with FreeBSD and DragonFlyBSD.

Reference: https://cgit.freebsd.org/src/commit/?id=b72ae900d4348118829fe04abdc11b620930c30f

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agokern/partition: Unbreak support for nested partitions
Vladimir Serbinenko [Sun, 2 Mar 2025 21:02:21 +0000 (00:02 +0300)] 
kern/partition: Unbreak support for nested partitions

When using syntax "hd0,gtp3,dfly1" then ptr points to trailing part, ",dfly1".
So, it's improper to consider it as an invalid partition.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agolib/tss2/tss2_structs.h: Fix clang build - remove duplicate typedef
Andrew Hamilton [Sun, 2 Mar 2025 16:54:04 +0000 (10:54 -0600)] 
lib/tss2/tss2_structs.h: Fix clang build - remove duplicate typedef

grub-core/lib/tss2/tss2_structs.h contains a duplicate typedef as follows:
  typedef TPMS_SCHEME_HASH_t TPMS_SCHEME_KDF2_t;

This causes a build failure when compiling with clang. Remove the
duplicate typedef which allows successfully building GRUB with clang.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoinclude/grub/mm.h: Remove duplicate inclusion of grub/err.h
Yuri Zaporozhets [Mon, 23 Dec 2024 20:47:18 +0000 (21:47 +0100)] 
include/grub/mm.h: Remove duplicate inclusion of grub/err.h

The header is included twice. Fix that.

Signed-off-by: Yuri Zaporozhets <yuriz@qrv-systems.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoscript/execute: Don't let trailing blank lines determine the return code
James Le Cuirot [Mon, 30 Dec 2024 10:52:23 +0000 (10:52 +0000)] 
script/execute: Don't let trailing blank lines determine the return code

The grub_script_execute_sourcecode() parses and executes code one line
at a time, updating the return code each time because only the last line
determines the final status. However, trailing new lines were also
executed, masking any failure on the previous line. Fix this by only
trying to execute the command when there is actually one present.

This has presumably never been noticed because this code is not used by
regular functions, only in special cases like eval and menu entries. The
latter generally don't return at all, having booted an OS. When failing
to boot, upstream GRUB triggers the fallback mechanism regardless of the
return code.

We noticed the problem while using Red Hat's patches, which change this
behaviour to take account of the return code. In that case, a failure
takes you back to the menu rather than triggering a fallback.

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agogitignore: Ignore generated files from libtasn
Glenn Washburn [Fri, 10 Jan 2025 20:19:41 +0000 (14:19 -0600)] 
gitignore: Ignore generated files from libtasn

The commit 504058e8 (libtasn1: Compile into asn1 module) generates files
into the grub-core/lib/libtasn1-grub directory and commit 99cda678
(asn1_test: Test module for libtasn1) generates files into the
grub-core/tests/asn1/tests directory. Ignore these directories as they
are not under revision control.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoutil/grub.d/30_os-prober.in: Conditionally show or hide chain and efi menu entries
Pascal Hambourg [Mon, 24 Feb 2025 17:10:45 +0000 (18:10 +0100)] 
util/grub.d/30_os-prober.in: Conditionally show or hide chain and efi menu entries

On systems which support multiple boot platforms such as BIOS and
EFI, it makes no sense to show menu entries which are not supported
by the current boot platform. Menu entries generated from os-prober
"chain" boot type use boot sector chainloading which is supported
on PC BIOS platform only.

Show "chain" menu entries only if boot platform is PC BIOS.
Show "efi" menu entries only if boot platform is EFI.

This is aimed to allow os-prober to report both EFI and PC BIOS
boot loaders regardless of the current boot mode on x86 systems
which support both EFI and legacy BIOS boot, in order to generate
a config file which can be used with either BIOS or EFI boot.

Signed-off-by: Pascal Hambourg <pascal@plouf.fr.eu.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoutil/grub.d/30_os-prober.in: Fix GRUB_OS_PROBER_SKIP_LIST for non-EFI
Pascal Hambourg [Fri, 21 Feb 2025 11:20:28 +0000 (12:20 +0100)] 
util/grub.d/30_os-prober.in: Fix GRUB_OS_PROBER_SKIP_LIST for non-EFI

GRUB documentation states:

  GRUB_OS_PROBER_SKIP_LIST
    List of space-separated FS UUIDs of filesystems to be ignored from
    os-prober output. For efi chainloaders it’s <UUID>@<EFI FILE>

But the actual behaviour does not match this description.

  GRUB_OS_PROBER_SKIP_LIST="<UUID>"

does nothing. In order to skip non-EFI bootloaders, you must set

  GRUB_OS_PROBER_SKIP_LIST="<UUID>@<DEVICE>"

which is both absurd, <UUID> and <DEVICE> are redundant, and wrong,
<DEVICE> such as /dev/sd* may not be persistent across boots.

Also, any non-word character is accepted as a separator, including "-"
and "@" which may be present in UUIDs. This can cause false positives
because of partial UUID match.

This patch fixes these flaws while retaining some backward compatibility
with previous behaviour which may be expected by existing setups:
  - also accept <UUID>@/dev/* (with warning) for non-EFI bootloaders,
  - also accept comma and semicolon as separator.

Fixes: 55e706c9 (Add GRUB_OS_PROBER_SKIP_LIST to selectively skipping systems)
Signed-off-by: Pascal Hambourg <pascal@plouf.fr.eu.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodocs: Do not reference non-existent --dumb option
Glenn Washburn [Sat, 4 Jan 2025 07:50:32 +0000 (01:50 -0600)] 
docs: Do not reference non-existent --dumb option

This appears to be a relic from GRUB legacy that used a --dumb option for
its terminal command. The proper way to do this in GRUB2 is to set the
terminal to "dumb" via the terminfo command.

Fixes: https://savannah.gnu.org/bugs/?66302
Reported-by: Jernej Jakob <jernej.jakob+savgnu@gmail.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodocs: Replace @lbracechar{} and @rbracechar{} with @{ and @}
Glenn Washburn [Sat, 4 Jan 2025 07:41:15 +0000 (01:41 -0600)] 
docs: Replace @lbracechar{} and @rbracechar{} with @{ and @}

Support for @lbracechar{} and @rbracechar{} was added in GNU Texinfo 5.0
but many older systems may have versions lower than this. Use @{ and @}
to support a wider range of GNU Texinfo versions.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs/xfs: Fix grub_xfs_iterate_dir() return value in case of failure
Egor Ignatov [Thu, 23 Jan 2025 17:44:14 +0000 (20:44 +0300)] 
fs/xfs: Fix grub_xfs_iterate_dir() return value in case of failure

Commit ef7850c757 (fs/xfs: Fix issues found while fuzzing the XFS
filesystem) introduced multiple boundary checks in grub_xfs_iterate_dir()
but handled the error incorrectly returning error code instead of 0.
Fix it. Also change the error message so that it doesn't match the
message in grub_xfs_read_inode().

Fixes: ef7850c757 (fs/xfs: Fix issues found while fuzzing the XFS filesystem)
Signed-off-by: Egor Ignatov <egori@altlinux.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs/xfs: Add new superblock features added in Linux 6.12/6.13
Darrick J. Wong [Mon, 3 Feb 2025 23:41:22 +0000 (15:41 -0800)] 
fs/xfs: Add new superblock features added in Linux 6.12/6.13

The Linux port of XFS added a few new features in 2024. The existing
GRUB driver doesn't attempt to read or write any of the new metadata,
so, all three can be added to the incompat allowlist.

On the occasion align XFS_SB_FEAT_INCOMPAT_NREXT64 value.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs/ext2: Rework out-of-bounds read for inline and external extents
Michael Chang [Fri, 21 Feb 2025 01:06:12 +0000 (09:06 +0800)] 
fs/ext2: Rework out-of-bounds read for inline and external extents

Previously, the number of extent entries was not properly capped based
on the actual available space. This could lead to insufficient reads for
external extents since the computation was based solely on the inline
extent layout.

In this patch, when processing the extent header we determine whether
the header is stored inline, i.e. at inode->blocks.dir_blocks, or in an
external extent block. We then clamp the number of entries accordingly
(using max_inline_ext for inline extents and max_external_ext for
external extent blocks).

This change ensures that only the valid number of extent entries is
processed preventing out-of-bound reads and potential filesystem
corruption.

Fixes: 7e2f750f0a (fs/ext2: Fix out-of-bounds read for inline extents)
Signed-off-by: Michael Chang <mchang@suse.com>
Tested-by: Christian Hesse <mail@eworm.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk/ahci: Remove conditional operator for endtime
Leo Sandoval [Wed, 22 Jan 2025 20:10:24 +0000 (14:10 -0600)] 
disk/ahci: Remove conditional operator for endtime

The conditional makes no sense when the two possible expressions have
the same value, so, remove it (perhaps the compiler does it for us but
better to remove it). This change makes spinup argument unused. So, drop
it as well.

Signed-off-by: Leo Sandoval <lsandova@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoterm/ns8250-spcr: Return if redirection is disabled
Benjamin Herrenschmidt [Tue, 21 Jan 2025 17:01:26 +0000 (11:01 -0600)] 
term/ns8250-spcr: Return if redirection is disabled

The Microsoft spec for SPCR says "The base address of the Serial Port
register set described using the ACPI Generic Address Structure, or
0 if console redirection is disabled". So, return early if redirection
is disabled (base address = 0). If this check is not done we may get
invalid ports on machines with redirection disabled and boot may hang
when reading the grub.cfg file.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Leo Sandoval <lsandova@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agocommands/file: Fix NULL dereference in the knetbsd tests
Lukas Fink [Sun, 5 Jan 2025 08:24:11 +0000 (02:24 -0600)] 
commands/file: Fix NULL dereference in the knetbsd tests

The pointer returned by grub_elf_file() is not checked to verify it is
not NULL before use. A NULL pointer may be returned when the given file
does not have a valid ELF header.

Fixes: https://savannah.gnu.org/bugs/?61960
Signed-off-by: Glenn Washburn <development@efficientek.com>
Signed-off-by: Lukas Fink <lukas.fink1@gmail.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agogdb_helper: Typo hueristic
Heinrich Schuchardt [Thu, 16 Jan 2025 12:25:14 +0000 (13:25 +0100)] 
gdb_helper: Typo hueristic

%s/hueristic/heuristic/

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agokern/efi/mm: Reset grub_mm_add_region_fn after ExitBootServices() call
Ruihan Li [Mon, 16 Dec 2024 04:26:58 +0000 (12:26 +0800)] 
kern/efi/mm: Reset grub_mm_add_region_fn after ExitBootServices() call

The EFI Boot Services can be used after ExitBootServices() call because
the GRUB code still may allocate memory.

An example call stack is:

  grub_multiboot_boot
    grub_multiboot2_make_mbi
      grub_efi_finish_boot_services
        b->exit_boot_services
    normal_boot
      grub_relocator32_boot
        grub_relocator_alloc_chunk_align_safe
          grub_relocator_alloc_chunk_align
            grub_malloc
              grub_memalign
                grub_mm_add_region_fn
                [= grub_efi_mm_add_regions]
                  grub_efi_allocate_any_pages
                    grub_efi_allocate_pages_real
                      b->allocate_pages

This can lead to confusing errors. After ExitBootServices() call
b->allocate_pages may point to the NULL address resulting in something like:

  !!!! X64 Exception Type - 01(#DB - Debug)  CPU Apic ID - 00000000 !!!!
  RIP  - 000000000000201F, CS  - 0000000000000038, RFLAGS - 0000000000200002
  RAX  - 000000007F9EE010, RCX - 0000000000000001, RDX - 0000000000000002
  RBX  - 0000000000000006, RSP - 00000000001CFBEC, RBP - 0000000000000000
  RSI  - 0000000000000000, RDI - 00000000FFFFFFFF
  R8   - 0000000000000006, R9  - 000000007FEDFFB8, R10 - 0000000000000000
  R11  - 0000000000000475, R12 - 0000000000000001, R13 - 0000000000000002
  R14  - 00000000FFFFFFFF, R15 - 000000007E432C08
  DS   - 0000000000000030, ES  - 0000000000000030, FS  - 0000000000000030
  GS   - 0000000000000030, SS  - 0000000000000030
  CR0  - 0000000080010033, CR2 - 0000000000000000, CR3 - 000000007FC01000
  CR4  - 0000000000000668, CR8 - 0000000000000000
  DR0  - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
  DR3  - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
  GDTR - 000000007F9DE000 0000000000000047, LDTR - 0000000000000000
  IDTR - 000000007F470018 0000000000000FFF,   TR - 0000000000000000
  FXSAVE_STATE - 00000000001CF840

Ideally we would like to avoid all memory allocations after exiting EFI
Boot Services altogether but that requires significant code changes. This
patch adds a simple workaround that resets grub_mm_add_region_fn to NULL
after ExitBootServices() call, so:

  - Memory allocations have a better chance of succeeding because grub_memalign()
    will try to reclaim the disk cache if it sees a NULL in grub_mm_add_region_fn.

  - At worst it will fail to allocate memory but it will explicitly tell users
    that it's out of memory, which is still much better than the current
    situation where it fails in a fairly random way and triggers a CPU fault.

Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoi386/tsc: The GRUB menu gets stuck due to unserialized rdtsc
Duan Yayong [Mon, 9 Dec 2024 06:48:32 +0000 (14:48 +0800)] 
i386/tsc: The GRUB menu gets stuck due to unserialized rdtsc

This patch is used to fix GRUB menu gets stuck in server AC
poweron/poweroff stress test of x86_64, which is reproduced with
1/200 ratio. The root cause analysis as below:

Q: What's the code logic?

A: The grub_tsc_init() function will init tsc by setting grub_tsc_rate,
   which call stack is:

     grub_tsc_init() -> grub_tsc_calibrate_from_pmtimer() -> grub_divmod64()

   Among, grub_divmod64() function needs tsc_diff as the second parameter.
   In grub_pmtimer_wait_count_tsc(), we will call grub_get_tsc() function
   to get time stamp counter value to assign to start_tsc variable, and
   get into while (1) loop space to get end_tsc variable value with same
   function, after 3580 ticks, return "end_tsc - start_tsc". Actually,
   rdtsc instruction will be called in grub_get_tsc, but rdtsc instruction
   is not reliable (for the reason see the next question), which will cause
   tsc_diff to be a very big number larger than (1UL << 32) or a negative
   number, so that grub_tsc_rate will be zero. When run_menu() function is
   startup, and calls grub_tsc_get_time_ms() function to get current time
   to check if timeout time reach, at this time, grub_tsc_get_time_ms()
   function will return zero due to zero grub_tsc_rate variable, then GRUB
   menu gets stuck...

Q: What's the difference between rdtsc and rdtscp instructions in x86_64
   architecture? Here is more explanations from Intel® 64 and IA-32
   Architectures Software Developer’s Manual Volume 2B (December 2024):
   https://cdrdv2.intel.com/v1/dl/getContent/671241

A: In page 4-558 -> RDTSC—Read Time-Stamp Counter:
   The RDTSC instruction is not a serializing instruction. It does not
   necessarily wait until all previous instructions have been executed
   before reading the counter. Similarly, subsequent instructions may
   begin execution before the read operation is performed. The following
   items may guide software seeking to order executions of RDTSC:
     - If software requires RDTSC to be executed only after all previous
       instructions have executed and all previous loads are globally
       visible, it can execute LFENCE immediately before RDTSC.
     - If software requires RDTSC to be executed only after all previous
       instructions have executed and all previous loads and stores are
       globally visible, it can execute the sequence MFENCE;LFENCE
       immediately before RDTSC.
     - If software requires RDTSC to be executed prior to execution of any
       subsequent instruction (including any memory accesses), it can execute
       the sequence LFENCE immediately after RDTSC.

A: In page 4-560 -> RDTSCP—Read Time-Stamp Counter and Processor ID:
   The RDTSCP instruction is not a serializing instruction, but it does wait
   until all previous instructions have executed and all previous loads are
   globally visible. But it does not wait for previous stores to be globally
   visible, and subsequent instructions may begin execution before the read
   operation is performed. The following items may guide software seeking to
   order executions of RDTSCP:
     - If software requires RDTSCP to be executed only after all previous
       stores are globally visible, it can execute MFENCE immediately before
       RDTSCP.
     - If software requires RDTSCP to be executed prior to execution of any
       subsequent instruction (including any memory accesses), it can execute
       LFENCE immediately after RDTSCP.

Q: Why there is a cpuid serializing instruction before rdtsc instruction,
   but "grub_get_tsc" still cannot work as expect?

A: From Intel® 64 and IA-32 Architectures Software Developer's Manual
   Volume 2A: Instruction Set Reference, A-L (December 2024):
   https://cdrdv2.intel.com/v1/dl/getContent/671199

   In page 3-222 -> CPUID—CPU Identification:
   CPUID can be executed at any privilege level to serialize instruction execution.
   Serializing instruction execution guarantees that any modifications to flags,
   registers, and memory for previous instructions are completed before
   the next instruction is fetched and executed.

   So we only kept the instruction rdtsc and its previous instruction in order
   currently. But it is still out-of-order possibility between rdtsc instruction
   and its subsequent instruction.

Q: Why do we do this fix?

A: In the one hand, add cpuid instruction after rdtsc instruction to make sure
   rdtsc instruction to be executed prior to execution of any subsequent instruction,
   about serializing execution that all previous instructions have been executed
   before rdtsc, there is a cpuid usage in original code. In the other hand, using
   cpuid instruction rather than lfence can make sure a forward compatibility for
   previous HW.

   Base this fix, we did 1500 cycles power on/off stress test, and did not reproduce
   this issue again.

Fixes: https://savannah.gnu.org/bugs/?66257
Signed-off-by: Duan Yayong <duanyayong@bytedance.com>
Signed-off-by: Li Yongqiang <liyongqiang@huaqin.com>
Signed-off-by: Sun Ming <simon.sun@huaqin.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agokern/i386/tsc_pmtimer: The GRUB menu gets stuck due to failed calibration
Duan Yayong [Thu, 28 Nov 2024 03:48:26 +0000 (11:48 +0800)] 
kern/i386/tsc_pmtimer: The GRUB menu gets stuck due to failed calibration

The grub_divmod64() may return 0 but grub_tsc_calibrate_from_pmtimer()
still returns 1 saying calibration succeeded. Of course it is not true.
So, return 0 when grub_divmod64() returns 0. This way other calibration
functions can be called subsequently.

Signed-off-by: Duan Yayong <duanyayong@bytedance.com>
Signed-off-by: Li Yongqiang <liyongqiang@huaqin.com>
Signed-off-by: Sun Ming <simon.sun@huaqin.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoloader/i386/linux: Fix cleanup if kernel doesn't support 64-bit addressing
Sergii Dmytruk [Fri, 1 Nov 2024 22:54:40 +0000 (00:54 +0200)] 
loader/i386/linux: Fix cleanup if kernel doesn't support 64-bit addressing

Simply returning from grub_cmd_linux() doesn't free "file" resource nor
calls grub_dl_ref(my_mod). Jump to "fail" label for proper cleanup like
other error checks do.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoloader/i386/bsd: Use safe math to avoid underflow
Alec Brown [Wed, 5 Feb 2025 22:04:08 +0000 (22:04 +0000)] 
loader/i386/bsd: Use safe math to avoid underflow

The operation kern_end - kern_start may underflow when we input it into
grub_relocator_alloc_chunk_addr() call. To avoid this we can use safe
math for this subtraction.

Fixes: CID 73845
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoloader/i386/linux: Cast left shift to grub_uint32_t
Alec Brown [Fri, 7 Feb 2025 01:47:57 +0000 (01:47 +0000)] 
loader/i386/linux: Cast left shift to grub_uint32_t

The Coverity complains that we might overflow into a negative value when
setting linux_params.kernel_alignment to (1 << align). We can remedy
this by casting it to grub_uint32_t.

Fixes: CID 473876
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agokern/misc: Add sanity check after grub_strtoul() call
Lidong Chen [Thu, 6 Feb 2025 18:16:57 +0000 (18:16 +0000)] 
kern/misc: Add sanity check after grub_strtoul() call

When the format string, fmt0, includes a positional argument
grub_strtoul() or grub_strtoull() is called to extract the argument
position. However, the returned argument position isn't fully validated.
If the format is something like "%0$x" then these functions return
0 which leads to an underflow in the calculation of the args index, curn.
The fix is to add a check to ensure the extracted argument position is
greater than 0 before computing curn. Additionally, replace one
grub_strtoull() with grub_strtoul() and change curn type to make code
more correct.

Fixes: CID 473841
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agokern/partition: Add sanity check after grub_strtoul() call
Lidong Chen [Thu, 6 Feb 2025 18:16:56 +0000 (18:16 +0000)] 
kern/partition: Add sanity check after grub_strtoul() call

The current code incorrectly assumes that both the input and the values
returned by grub_strtoul() are always valid which can lead to potential
errors. This fix ensures proper validation to prevent any unintended issues.

Fixes: CID 473843
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agonormal/menu: Use safe math to avoid an integer overflow
Alec Brown [Tue, 4 Feb 2025 15:11:11 +0000 (15:11 +0000)] 
normal/menu: Use safe math to avoid an integer overflow

The Coverity indicates that the variable current_entry might overflow.
To prevent this use safe math when adding GRUB_MENU_PAGE_SIZE to current_entry.

On the occasion fix limiting condition which was broken.

Fixes: CID 473853
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agobus/usb/ehci: Define GRUB_EHCI_TOGGLE as grub_uint32_t
Alec Brown [Tue, 4 Feb 2025 15:11:10 +0000 (15:11 +0000)] 
bus/usb/ehci: Define GRUB_EHCI_TOGGLE as grub_uint32_t

The Coverity indicates that GRUB_EHCI_TOGGLE is an int that contains
a negative value and we are using it for the variable token which is
grub_uint32_t. To remedy this we can cast the definition to grub_uint32_t.

Fixes: CID 473851
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agomisc: Ensure consistent overflow error messages
Lidong Chen [Tue, 21 Jan 2025 19:02:39 +0000 (19:02 +0000)] 
misc: Ensure consistent overflow error messages

Update the overflow error messages to make them consistent
across the GRUB code.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agoosdep/unix/getroot: Fix potential underflow
Lidong Chen [Wed, 29 Jan 2025 06:48:38 +0000 (06:48 +0000)] 
osdep/unix/getroot: Fix potential underflow

The entry_len is initialized in grub_find_root_devices_from_mountinfo()
to 0 before the while loop iterates through /proc/self/mountinfo. If the
file is empty or contains only invalid entries entry_len remains
0 causing entry_len - 1 in the subsequent for loop initialization
to underflow. To prevent this add a check to ensure entry_len > 0 before
entering the for loop.

Fixes: CID 473877
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
5 months agoscript/execute: Fix potential underflow and NULL dereference
Lidong Chen [Wed, 29 Jan 2025 06:48:37 +0000 (06:48 +0000)] 
script/execute: Fix potential underflow and NULL dereference

The result is initialized to 0 in grub_script_arglist_to_argv().
If the for loop condition is not met both result.args and result.argc
remain 0 causing result.argc - 1 to underflow and/or result.args NULL
dereference. Fix the issues by adding relevant checks.

Fixes: CID 473880
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs/sfs: Check if allocated memory is NULL
Alec Brown [Tue, 28 Jan 2025 05:15:50 +0000 (05:15 +0000)] 
fs/sfs: Check if allocated memory is NULL

When using grub_zalloc(), if we are out of memory, this function can fail.
After allocating memory, we should check if grub_zalloc() returns NULL.
If so, we should handle this error.

Fixes: CID 473856
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agonet: Check if returned pointer for allocated memory is NULL
Alec Brown [Wed, 22 Jan 2025 18:04:44 +0000 (18:04 +0000)] 
net: Check if returned pointer for allocated memory is NULL

When using grub_malloc(), the function can fail if we are out of memory.
After allocating memory we should check if this function returned NULL
and handle this error if it did.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agonet: Prevent overflows when allocating memory for arrays
Lidong Chen [Wed, 22 Jan 2025 18:04:43 +0000 (18:04 +0000)] 
net: Prevent overflows when allocating memory for arrays

Use grub_calloc() when allocating memory for arrays to ensure proper
overflow checks are in place.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agonet: Use safe math macros to prevent overflows
Lidong Chen [Wed, 22 Jan 2025 18:04:42 +0000 (18:04 +0000)] 
net: Use safe math macros to prevent overflows

Replace direct arithmetic operations with macros from include/grub/safemath.h
to prevent potential overflow issues when calculating the memory sizes.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs/zfs: Add missing NULL check after grub_strdup() call
Lidong Chen [Wed, 22 Jan 2025 07:17:04 +0000 (07:17 +0000)] 
fs/zfs: Add missing NULL check after grub_strdup() call

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs/zfs: Check if returned pointer for allocated memory is NULL
Lidong Chen [Wed, 22 Jan 2025 07:17:01 +0000 (07:17 +0000)] 
fs/zfs: Check if returned pointer for allocated memory is NULL

When using grub_malloc() or grub_zalloc(), these functions can fail if
we are out of memory. After allocating memory we should check if these
functions returned NULL and handle this error if they did.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs/zfs: Prevent overflows when allocating memory for arrays
Lidong Chen [Wed, 22 Jan 2025 07:17:03 +0000 (07:17 +0000)] 
fs/zfs: Prevent overflows when allocating memory for arrays

Use grub_calloc() when allocating memory for arrays to ensure proper
overflow checks are in place.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs/zfs: Use safe math macros to prevent overflows
Lidong Chen [Wed, 22 Jan 2025 07:17:02 +0000 (07:17 +0000)] 
fs/zfs: Use safe math macros to prevent overflows

Replace direct arithmetic operations with macros from include/grub/safemath.h
to prevent potential overflow issues when calculating the memory sizes.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs: Prevent overflows when assigning returned values from read_number()
Lidong Chen [Tue, 21 Jan 2025 19:02:38 +0000 (19:02 +0000)] 
fs: Prevent overflows when assigning returned values from read_number()

The direct assignment of the unsigned long long value returned by
read_number() can potentially lead to an overflow on a 32-bit systems.
The fix replaces the direct assignments with calls to grub_cast()
which detects the overflows and safely assigns the values if no
overflow is detected.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs: Prevent overflows when allocating memory for arrays
Lidong Chen [Tue, 21 Jan 2025 19:02:37 +0000 (19:02 +0000)] 
fs: Prevent overflows when allocating memory for arrays

Use grub_calloc() when allocating memory for arrays to ensure proper
overflow checks are in place.

The HFS+ and squash4 security vulnerabilities were reported by
Jonathan Bar Or <jonathanbaror@gmail.com>.

Fixes: CVE-2025-0678
Fixes: CVE-2025-1125
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs: Use safe math macros to prevent overflows
Lidong Chen [Tue, 21 Jan 2025 19:02:36 +0000 (19:02 +0000)] 
fs: Use safe math macros to prevent overflows

Replace direct arithmetic operations with macros from include/grub/safemath.h
to prevent potential overflow issues when calculating the memory sizes.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk/ieee1275/ofdisk: Call grub_ieee1275_close() when grub_malloc() fails
Alec Brown [Wed, 22 Jan 2025 02:55:12 +0000 (02:55 +0000)] 
disk/ieee1275/ofdisk: Call grub_ieee1275_close() when grub_malloc() fails

In the dev_iterate() function a handle is opened but isn't closed when
grub_malloc() returns NULL. We should fix this by closing it on error.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk: Check if returned pointer for allocated memory is NULL
Alec Brown [Wed, 22 Jan 2025 02:55:11 +0000 (02:55 +0000)] 
disk: Check if returned pointer for allocated memory is NULL

When using grub_malloc(), grub_zalloc() or grub_calloc(), these functions can
fail if we are out of memory. After allocating memory we should check if these
functions returned NULL and handle this error if they did.

On the occasion make a NULL check in ATA code more obvious.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk: Prevent overflows when allocating memory for arrays
Alec Brown [Wed, 22 Jan 2025 02:55:10 +0000 (02:55 +0000)] 
disk: Prevent overflows when allocating memory for arrays

Use grub_calloc() when allocating memory for arrays to ensure proper
overflow checks are in place.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agodisk: Use safe math macros to prevent overflows
Alec Brown [Wed, 22 Jan 2025 02:55:09 +0000 (02:55 +0000)] 
disk: Use safe math macros to prevent overflows

Replace direct arithmetic operations with macros from include/grub/safemath.h
to prevent potential overflow issues when calculating the memory sizes.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 months agofs: Disable many filesystems under lockdown
Daniel Axtens [Sat, 23 Mar 2024 05:20:45 +0000 (16:20 +1100)] 
fs: Disable many filesystems under lockdown

The idea is to permit the following: btrfs, cpio, exfat, ext, f2fs, fat,
hfsplus, iso9660, squash4, tar, xfs and zfs.

The JFS, ReiserFS, romfs, UDF and UFS security vulnerabilities were
reported by Jonathan Bar Or <jonathanbaror@gmail.com>.

Fixes: CVE-2025-0677
Fixes: CVE-2025-0684
Fixes: CVE-2025-0685
Fixes: CVE-2025-0686
Fixes: CVE-2025-0689
Suggested-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>