]> git.ipfire.org Git - thirdparty/grub.git/log
thirdparty/grub.git
9 months agomodules: Load module sections at page-aligned addresses
Mate Kukri [Wed, 9 Oct 2024 08:16:39 +0000 (09:16 +0100)] 
modules: Load module sections at page-aligned addresses

Currently we load module sections at whatever alignment gcc+ld happened
to dump into the ELF section header which is often less then the page
size. Since NX protections are page based this alignment must be rounded
up to page size on platforms supporting NX protections. This patch
switches EFI platforms to load module sections at 4 KiB page-aligned
addresses. It then changes the allocation size computation and the
loader code in grub_dl_load_segments() to align the locations and sizes
up to these boundaries and fills any added padding with zeros. All of
this happens before relocations are applied, so the relocations factor
that in with no change.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agomodules: Don't allocate space for non-allocable sections
Peter Jones [Wed, 9 Oct 2024 08:16:38 +0000 (09:16 +0100)] 
modules: Don't allocate space for non-allocable sections

Currently when loading GRUB modules we allocate space for all sections
including those without SHF_ALLOC set. We then copy the sections that
/do/ have SHF_ALLOC set into the allocated memory leaving some of our
allocation untouched forever. Additionally, on platforms with GOT fixups
and trampolines we currently compute alignment round-ups for the
sections and sections with sh_size = 0. This patch removes the extra
space from the allocation computation and makes the allocation
computation loop skip empty sections as the loading loop does.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-By: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agomodules: Strip .llvm_addrsig sections and similar
Peter Jones [Wed, 9 Oct 2024 08:16:37 +0000 (09:16 +0100)] 
modules: Strip .llvm_addrsig sections and similar

Currently GRUB modules built with Clang or GCC have several sections
which we don't actually need or support. We already have a list of
sections to skip in genmod.sh and this patch adds the following
sections to that list (as well as a few newlines):
  - .note.gnu.property
  - .llvm*

Note that the glob there won't work without a new enough linker but the
failure is just reversion to the status quo. So, that's not a big problem.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-By: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agomodules: Make .module_license read-only
Peter Jones [Wed, 9 Oct 2024 08:16:36 +0000 (09:16 +0100)] 
modules: Make .module_license read-only

Currently .module_license is set writable, that is, the section has the
SHF_WRITE flag set, in the module's ELF headers. This probably never
actually matters but it can't possibly be correct. The patch sets that
data as "const" which causes that flag not to be set.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-By: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agoi386/memory: Rename PAGE_SIZE to GRUB_PAGE_SIZE and make it global
Daniel Kiper [Sun, 6 Oct 2024 14:14:46 +0000 (17:14 +0300)] 
i386/memory: Rename PAGE_SIZE to GRUB_PAGE_SIZE and make it global

This is an x86-specific thing and should be available globally.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agoi386/memory: Rename PAGE_SHIFT to GRUB_PAGE_SHIFT
Daniel Kiper [Sun, 6 Oct 2024 14:14:45 +0000 (17:14 +0300)] 
i386/memory: Rename PAGE_SHIFT to GRUB_PAGE_SHIFT

This fixes naming inconsistency that goes against coding style as well
as helps to avoid potential conflicts and confusion as this constant is
used in multiple places.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agoi386/msr: Extract and improve MSR support detection code
Daniel Kiper [Sun, 6 Oct 2024 14:14:44 +0000 (17:14 +0300)] 
i386/msr: Extract and improve MSR support detection code

Currently rdmsr and wrmsr commands have own MSR support detection code.
This code is the same. So, it is duplicated. Additionally, this code
cannot be reused by others. Hence, extract this code to a function and
make it public. By the way, improve a code a bit.

Additionally, use GRUB_ERR_BAD_DEVICE instead of GRUB_ERR_BUG to signal
an error because errors encountered by this new routine are not bugs.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agoi386/msr: Rename grub_msr_read() and grub_msr_write()
Daniel Kiper [Sun, 6 Oct 2024 14:14:43 +0000 (17:14 +0300)] 
i386/msr: Rename grub_msr_read() and grub_msr_write()

Use more obvious names which match corresponding instructions:
  * grub_msr_read()  => grub_rdmsr(),
  * grub_msr_write() => grub_wrmsr().

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agoi386/msr: Merge rdmsr.h and wrmsr.h into msr.h
Daniel Kiper [Sun, 6 Oct 2024 14:14:42 +0000 (17:14 +0300)] 
i386/msr: Merge rdmsr.h and wrmsr.h into msr.h

It does not make sense to have separate headers for individual static
functions. So, make one common place to store them.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agocommands/tpm: Skip loopback image measurement
Michael Chang [Thu, 3 Oct 2024 07:23:22 +0000 (15:23 +0800)] 
commands/tpm: Skip loopback image measurement

The loopback image is configured to function as a disk by being mapped
as a block device. Instead of measuring the entire block device we
should focus on tracking the individual files accessed from it. For
example, we do not directly measure block devices like hd0 disk but the
files opened from it.

This method is important to avoid running out of memory since loopback
images can be very large. Trying to read and measure the whole image at
once could cause out of memory errors and disrupt the boot process.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agonet/drivers/efi/efinet: Skip virtual VLAN devices during card enumeration
Michael Chang [Thu, 3 Oct 2024 07:23:15 +0000 (15:23 +0800)] 
net/drivers/efi/efinet: Skip virtual VLAN devices during card enumeration

Similarly to the issue described in commit c52ae4057 (efinet: skip
virtual IPv4 and IPv6 devices during card enumeration) the UEFI PXE
driver creates additional VLAN child devices when a VLAN ID is
configured on a network interface associated with a physical NIC. These
virtual VLAN devices must be skipped during card enumeration to ensure
that the subsequent SNP exclusive open operation targets the correct
physical card instances. Otherwise packet transfer would fail.

A device path example with VLAN nodes:

  /MAC(123456789ABC,0x1)/Vlan(20)/IPv4(0.0.0.0,0x0,DHCP,0.0.0.0,0.0.0.0,0.0.0.0)

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agoefi/console: Properly clear leftover artifacts from the screen
Michael Chang [Thu, 3 Oct 2024 07:23:08 +0000 (15:23 +0800)] 
efi/console: Properly clear leftover artifacts from the screen

A regression in GRUB 2.12 causes the GRUB screen to become cluttered
with artifacts from the previous screen whether it's the UEFI post UI,
UEFI shell or any graphical UI running before GRUB. This issue occurs
in situations like booting GRUB from the UEFI shell and going straight
to the rescue or command shell causing visual discomfort.

The regression was introduced by commit 2d7c3abd8 (efi/console: Do not
set text-mode until it is actually needed). To address the screen
flickering issue this commit suppresses the text-mode setting until the
first output is requested. Before text-mode is set any attempt to clear
the screen has no effect. This inactive period renders the clear screen
ineffective in early boot stages, potentially leaving leftover artifacts
that will clutter the GRUB console display, as there is no guarantee
there will always be a clear screen after the first output.

The issue is fixed by ensuring grub_console_cls() to work through lazy
mode-setting, while also avoiding screen clearing for the hidden menu
which the flicker-free patch aims to improve.

Fixes: 2d7c3abd8 (efi/console: Do not set text-mode until we actually need it)
Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9 months agokern/riscv/efi/init: Use time register in grub_efi_get_time_ms()
Heinrich Schuchardt [Mon, 12 Aug 2024 14:13:18 +0000 (16:13 +0200)] 
kern/riscv/efi/init: Use time register in grub_efi_get_time_ms()

The cycle register is not guaranteed to count at constant frequency.
If it is counting at all depends on the state the performance monitoring
unit. Use the time register to measure time.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agoloader/efi/linux: Reset freed pointer
Frediano Ziglio [Tue, 3 Sep 2024 15:15:47 +0000 (16:15 +0100)] 
loader/efi/linux: Reset freed pointer

Avoid dangling pointer. Code should not be reached but better safe than sorry.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agoloader/efi/linux: Reuse len variable
Frediano Ziglio [Tue, 3 Sep 2024 15:15:46 +0000 (16:15 +0100)] 
loader/efi/linux: Reuse len variable

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agolib/x86_64/relocator_asm: Use .quad instead of .long
Frediano Ziglio [Tue, 3 Sep 2024 08:00:30 +0000 (09:00 +0100)] 
lib/x86_64/relocator_asm: Use .quad instead of .long

They are single 64-bit values. Used in other assembly files too.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agolib/x86_64/relocator_asm: Fix comment in code
Frediano Ziglio [Tue, 3 Sep 2024 08:00:29 +0000 (09:00 +0100)] 
lib/x86_64/relocator_asm: Fix comment in code

The instruction uses a 64-bit immediate.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agoloader/efi/linux: Update comment
Frediano Ziglio [Tue, 3 Sep 2024 08:00:27 +0000 (09:00 +0100)] 
loader/efi/linux: Update comment

The function called is grub_utf8_to_utf16().

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agoutil/grub-mkimagexx: Explicitly move modules to __bss_start for MIPS targets
Vladimir Serbinenko [Tue, 3 Sep 2024 17:58:52 +0000 (20:58 +0300)] 
util/grub-mkimagexx: Explicitly move modules to __bss_start for MIPS targets

Assembly code looks for modules at __bss_start. Make this position explicit
rather than matching BSS alignment and module alignment.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agoinclude/grub/offsets.h: Set mod_align to 4 on MIPS
Vladimir Serbinenko [Tue, 3 Sep 2024 17:58:51 +0000 (20:58 +0300)] 
include/grub/offsets.h: Set mod_align to 4 on MIPS

Module structure has natural alignment of 4. Respect it explicitly
rather than relying on the fact that _end is usually aligned.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agogentpl: Put boot/mips/startup_raw.S into beginning of the image
Vladimir Serbinenko [Tue, 3 Sep 2024 17:58:50 +0000 (20:58 +0300)] 
gentpl: Put boot/mips/startup_raw.S into beginning of the image

Otherwise it breaks the decompressors for MIPS targets.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agoconfigure: Add -mno-gpopt option for mips and mipsel targets
Vladimir Serbinenko [Tue, 3 Sep 2024 17:58:49 +0000 (20:58 +0300)] 
configure: Add -mno-gpopt option for mips and mipsel targets

Without it compiler generates GPREL16 references which do not work
with our memory layout.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agolib/xzembed/xz_dec_bcj: Silence warning when no BCJ is available
Vladimir Serbinenko [Tue, 3 Sep 2024 17:58:48 +0000 (20:58 +0300)] 
lib/xzembed/xz_dec_bcj: Silence warning when no BCJ is available

BCJ is not available for all platforms hence arguments may end up unused.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agofs/erofs: Replace 64-bit modulo with bitwise operations
Vladimir Serbinenko [Tue, 3 Sep 2024 17:58:47 +0000 (20:58 +0300)] 
fs/erofs: Replace 64-bit modulo with bitwise operations

Otherwise depending on compiler we end up with umoddi3 reference and
failed module dependency resolution.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agoconfigure: Look for .otf fonts
Vladimir Serbinenko [Tue, 3 Sep 2024 17:58:46 +0000 (20:58 +0300)] 
configure: Look for .otf fonts

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agoloader/efi/chainloader: Do not print device path of chainloaded file
Mate Kukri [Thu, 15 Aug 2024 09:52:56 +0000 (10:52 +0100)] 
loader/efi/chainloader: Do not print device path of chainloaded file

Users have no reason to see this and it can break graphical boot.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agodocs: Document all GRUB modules
Andrew Hamilton [Sun, 4 Aug 2024 16:32:51 +0000 (11:32 -0500)] 
docs: Document all GRUB modules

Add documentation for all GRUB modules contained in the source code tree.
When possible, cross-references to additional detail on commands was added
from their corresponding module documentation. In addition, documentation
for the file command was added.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11 months agocommands/bli: Fix crash in get_part_uuid()
Michael Chang [Wed, 17 Jul 2024 06:46:46 +0000 (14:46 +0800)] 
commands/bli: Fix crash in get_part_uuid()

The get_part_uuid() function made an assumption that the target GRUB
device is a partition device and accessed device->disk->partition
without checking for NULL. There are four situations where this
assumption is problematic:

1. The device is a net device instead of a disk.
2. The device is an abstraction device, like LVM, RAID, or CRYPTO, which
   is mostly logical "disk" ((lvmid/<UUID>) and so on).
3. Firmware RAID may present the ESP to GRUB as an EFI disk (hd0) device
   if it is contained within a Linux software RAID.
4. When booting from a CD-ROM, the ESP is a VFAT image indexed by the El
   Torito boot catalog. The boot device is set to (cd0), corresponding
   to the CD-ROM image mounted as an ISO 9660 filesystem.

As a result, get_part_uuid() could lead to a NULL pointer dereference
and trigger a synchronous exception during boot if the ESP falls into
one of these categories. This patch fixes the problem by adding the
necessary checks to handle cases where the ESP is not a partition device.

Additionally, to avoid disrupting the boot process, this patch relaxes
the severity of the errors in this context to non-critical. Errors will
be logged, but they will not prevent the boot process from continuing.

Fixes: e0fa7dc84 (bli: Add a module for the Boot Loader Interface)
Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-By: Oliver Steffen <osteffen@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agoutil/grub-mkrescue: Check existence of option arguments
Thomas Schmitt [Mon, 17 Jun 2024 19:03:00 +0000 (21:03 +0200)] 
util/grub-mkrescue: Check existence of option arguments

As reported by Victoriia Egorova in bug 65880, grub-mkrescue does not
verify that the expected argument of an option like -d or -k does really
exist in argv. So, check the loop counter before incrementing it inside
the loop which copies argv to argp_argv. Issue an error message similar
to what older versions of grub-mkrescue did with a missing argument,
e.g. 2.02.

Fixes: https://savannah.gnu.org/bugs/index.php?65880
Signed-off-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agoloader/efi/fdt: Add fdtdump command to access device tree
Tobias Heider [Mon, 17 Jun 2024 15:10:26 +0000 (17:10 +0200)] 
loader/efi/fdt: Add fdtdump command to access device tree

The fdtdump command allows dumping arbitrary device tree properties
and saving them to a variable similar to the smbios command.

This is useful in scripts where further actions such as selecting
a kernel or loading another device tree depend on the compatible
or model values of the device tree provided by the firmware.

For now only the root level properties of the dtb are exposed.

Signed-off-by: Tobias Heider <tobias.heider@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agoosdep/devmapper/getroot: Unmark 2 strings for translation
Vladimir Serbinenko [Mon, 17 Jun 2024 12:59:56 +0000 (15:59 +0300)] 
osdep/devmapper/getroot: Unmark 2 strings for translation

First they're use macros so they can't be translated as-is.
Second there is no point in translating them as they're too technical.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agoloader/emu/linux: Fix determination of program name
Vladimir Serbinenko [Mon, 17 Jun 2024 12:56:31 +0000 (15:56 +0300)] 
loader/emu/linux: Fix determination of program name

Current code works only if package matches binary name transformation rules.
It's often true but is not guaranteed.

Fixes: https://savannah.gnu.org/bugs/?64410
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agodisk/cryptodisk: Fix translatable message
Vladimir Serbinenko [Mon, 17 Jun 2024 12:56:30 +0000 (15:56 +0300)] 
disk/cryptodisk: Fix translatable message

Fixes: https://savannah.gnu.org/bugs/?64408
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agotests: Add test for ZFS zstd
Vladimir Serbinenko [Mon, 17 Jun 2024 11:44:09 +0000 (14:44 +0300)] 
tests: Add test for ZFS zstd

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agofs/zfs/zfs: Add support for zstd compression
Vladimir Serbinenko [Mon, 17 Jun 2024 11:44:08 +0000 (14:44 +0300)] 
fs/zfs/zfs: Add support for zstd compression

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agokern/efi/mm: Detect calls to grub_efi_drop_alloc() with wrong page counts
Mate Kukri [Wed, 12 Jun 2024 15:14:21 +0000 (16:14 +0100)] 
kern/efi/mm: Detect calls to grub_efi_drop_alloc() with wrong page counts

Silently keeping entries in the list if the address matches, but the
page count doesn't is a bad idea, and can lead to double frees.

grub_efi_free_pages() have already freed parts of this block by this
point, and thus keeping the whole block in the list and freeing it again
at exit can lead to double frees.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agokern/efi/mm: Change grub_efi_allocate_pages_real() to call semantically correct free...
Mate Kukri [Wed, 12 Jun 2024 15:10:50 +0000 (16:10 +0100)] 
kern/efi/mm: Change grub_efi_allocate_pages_real() to call semantically correct free function

If the firmware happens to return 0 as an address of allocated pages,
grub_efi_allocate_pages_real() tries to allocate a new set of pages,
and then free the ones at address 0.

However at that point grub_efi_store_alloc() wasn't yet called, so
freeing the pages at 0 using grub_efi_free_pages() which calls
grub_efi_drop_alloc() isn't necessary, so let's call b->free_pages()
instead.

The call to grub_efi_drop_alloc() doesn't seem particularly harmful,
because it seems to do nothing if the allocation it is asked to drop
isn't on the list, but the call to it is obviously unnecessary here.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agokern/efi/mm: Change grub_efi_mm_add_regions() to keep track of map allocation size
Mate Kukri [Wed, 12 Jun 2024 15:10:49 +0000 (16:10 +0100)] 
kern/efi/mm: Change grub_efi_mm_add_regions() to keep track of map allocation size

If the map was too big for the initial allocation, it was freed and replaced
with a bigger one, but the free call still used the hard-coded size.

Seems like this wasn't hit for a long time, because most firmware maps
fit into 12K.

This bug was triggered on Project Mu firmware with a big memory map, and
results in the heap getting trashed and the firmware ASSERTING on
corrupted heap guard values when GRUB exits.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agotests/util/grub-fs-tester: Fix EROFS label tests in grub-fs-tester
Yifan Zhao [Wed, 12 Jun 2024 07:28:41 +0000 (15:28 +0800)] 
tests/util/grub-fs-tester: Fix EROFS label tests in grub-fs-tester

mkfs.erofs with version < 1.6 does not support the -L option.
Let's detect the version of mkfs.erofs and skip the label tests
if it is not supported.

Suggested-by: Glenn Washburn <development@efficientek.com>
Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agotests: Switch to requiring exfatprogs from exfat-utils
Glenn Washburn [Sun, 9 Jun 2024 04:42:43 +0000 (23:42 -0500)] 
tests: Switch to requiring exfatprogs from exfat-utils

The current Debian stable, now 12, has dropped the exfat-utils package
that the exfat filesystem test requires to run. There is an exfatprogs
package that replaces exfat-utils, though it is not a drop-in replacement
because mkfs.exfat has differing command line option names. Note, that
we're not yet switching to using the exfat kernel module because this
allows the testings on kernels that do not have the module.

Update mkfs.exfat usage to adhere to the different exfatprogs usage. Also,
the exfatprogs mkfs.exfat, following the exfat specification more closely,
only allows a maximum of 22 bytes of UTF-16 characters in the volume label
compared to 30 bytes from exfat-utils. So the exfat label test is updated
accordingly.

Update documentation to note that exfatprogs is now needed and also
exfat-fuse, which is needed do the fuse mount.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agotests/util/grub-shell-luks-tester: Fix detached header test getting wrong header...
Glenn Washburn [Sun, 9 Jun 2024 04:22:05 +0000 (23:22 -0500)] 
tests/util/grub-shell-luks-tester: Fix detached header test getting wrong header path

When $detached_header was set 1, $luksdiskfile was set to the LUKS header
file path with "${detached_header:-$luksfile}" appended, which evaluates
to "1". Fix this by using two statements to set $luksdiskfile. The first
sets it to the header file if $detached_header is set, otherwise leave it
unset. The second statement sets it to itself if it is already set,
otherwise it is set to $luksfile.

Fixes: a7b540e6e (tests: Add cryptomount functional test)
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agotests/util/grub-shell: Add flexibility in QEMU firmware handling
Glenn Washburn [Sun, 9 Jun 2024 02:42:35 +0000 (21:42 -0500)] 
tests/util/grub-shell: Add flexibility in QEMU firmware handling

First look for firmware files in the source directory and then, if not
found, look for them in locations where Debian installs them. Prefer to
use the unified firmware file and, if not found, use the pflash firmware
files split in to code and variables. By looking for files in the source
directory first, system firmware files can be overridden and it can be
ensured that the tests can be run regardless of the distro or where the
system firmware files are stored. If no firmware files are found, print
an error message and exit with error.

If a firmware VARS file is found, use it with snapshot mode enabled, which
makes the VARS writable to the virtual machine, but does not write back
the changes to the file. This allows using the readonly system VARS file
without copying it or using it in readonly mode, which causes the ARM
machine to fail. This also gives tests effectively their own ephemeral VARS
file that can be written to without causing side-effects for other tests.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agotests/util/grub-shell: Use pflash instead of -bios to load UEFI firmware
Glenn Washburn [Sun, 9 Jun 2024 02:42:34 +0000 (21:42 -0500)] 
tests/util/grub-shell: Use pflash instead of -bios to load UEFI firmware

According to the OVMF whitepaper [1]:

  IMPORTANT: Never pass OVMF.fd to qemu with the -bios option. That option
  maps the firmware image as ROM into the guest's address space, and forces
  OVMF to emulate non-volatile variables with a fallback driver that is
  bound to have insufficient and confusing semantics.

Use the pflash interface instead. Currently the unified firmware file is
used, which contains both firmware code and variable sections. By enabling
snapshot on the pflash device, the firmware can be loaded in such a way
that variables can be written to without writing to the backing file.

Since pflash does no searching for firmware paths that are not absolute,
unlike the -bios option, also make firmware paths absolute. Additionally,
update the previous firmware paths or file names that did not correspond to
ones installed by Debian.

Use the q35 machine, instead of the default i440fx, for i386-efi because
the default machine type does not emulate a flash device, which is now
needed to load the firmware.

[1] http://www.linux-kvm.org/downloads/lersek/ovmf-whitepaper-c770f8c.txt

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agotests/util/grub-shell: Print gdbinfo if on EFI platform
Glenn Washburn [Sun, 9 Jun 2024 02:22:31 +0000 (21:22 -0500)] 
tests/util/grub-shell: Print gdbinfo if on EFI platform

Allow using GDB to debug a failing QEMU test. This output does not cause
issues for tests because it happens before the trim line, and so will be
ignored.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agoconfigure: Add Debian/Ubuntu DejaVu font path
Glenn Washburn [Sat, 8 Jun 2024 22:44:15 +0000 (17:44 -0500)] 
configure: Add Debian/Ubuntu DejaVu font path

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agoterm/ns8250-spcr: Add one more 16550 debug type
Udo Steinberg [Fri, 7 Jun 2024 21:44:43 +0000 (23:44 +0200)] 
term/ns8250-spcr: Add one more 16550 debug type

Type 0x01 was introduced with the ACPI DBGP table and type 0x12 was introduced
with the ACPI DBG2 table. Type 0x12 is used by the ACPI SPCR table on recent
AWS bare-metal instances (c6i/c7i). Also give each debug type a proper name.

Signed-off-by: Udo Steinberg <udo@hypervisor.org>
Reviewed-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agoloader/i386/multiboot_mbi: Fix handling of errors in broken aout-kludge
Vladimir Serbinenko [Fri, 17 May 2024 07:53:27 +0000 (10:53 +0300)] 
loader/i386/multiboot_mbi: Fix handling of errors in broken aout-kludge

Current code in some codepaths neither discards nor reports errors.
Properly surface the error.

While on it split 2 cases of unrelated variables both named err.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 months agonet/drivers/ieee1275/ofnet: Remove 200 ms timeout in get_card_packet() to reduce...
Michael Chang [Mon, 6 May 2024 02:34:22 +0000 (10:34 +0800)] 
net/drivers/ieee1275/ofnet: Remove 200 ms timeout in get_card_packet() to reduce input latency

When GRUB image is netbooted on ppc64le, the keyboard input exhibits
significant latency, reports even say that characters are processed
about once per second. This issue makes interactively trying to debug
a ppc64le config very difficult.

It seems that the latency is largely caused by a 200 ms timeout in the
idle event loop, during which the network card interface is consistently
polled for incoming packets. Often, no packets arrive during this
period, so the timeout nearly always expires, which blocks the response
to key inputs.

Furthermore, this 200 ms timeout might not need to be enforced at this
basic layer, considering that GRUB performs synchronous reads and its
timeout management is actually handled by higher layers, not directly in
the card instance. Additionally, the idle polling, which reacts to
unsolicited packets like ICMP and SLAAC, would be fine at a less frequent
polling interval, rather than needing a timeout for receiving a response.

For these reasons, we believe the timeout in get_card_packet() should be
effectively removed. According to test results, the delay has disappeared,
and it is now much easier to use interactively.

Signed-Off-by: Michael Chang <mchang@suse.com>
Tested-by: Tony Jones <tonyj@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agocommands/efi/tpm: Re-enable measurements on confidential computing platforms
Hector Cao [Mon, 3 Jun 2024 21:36:25 +0000 (23:36 +0200)] 
commands/efi/tpm: Re-enable measurements on confidential computing platforms

The measurements for confidential computing has been introduced in the
commit 4c76565b6 (efi/tpm: Add EFI_CC_MEASUREMENT_PROTOCOL support).
Recently the patch 30708dfe3 (tpm: Disable the tpm verifier if the TPM
device is not present) has been introduced to optimize the memory usage
when a TPM device is not available on platforms. This fix prevents the
tpm module to be loaded on confidential computing platforms, e.g. Intel
machines with TDX enabled, where the TPM device is not available.

In this patch, we propose to load the tpm module for this use case by
generalizing the tpm feature detection in order to cover CC platforms.
Basically, we do it by detecting the availability of the
EFI_CC_MEASUREMENT_PROTOCOL EFI protocol.

Fixes: https://savannah.gnu.org/bugs/?65821
Fixes: 30708dfe3 (tpm: Disable the tpm verifier if the TPM device is not present)
Signed-off-by: Hector Cao <hector.cao@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
14 months agoutil/grub-mkpasswd-pbkdf2: Simplify the main function implementation
Tianjia Zhang [Mon, 27 May 2024 12:42:04 +0000 (20:42 +0800)] 
util/grub-mkpasswd-pbkdf2: Simplify the main function implementation

Allocate memory if needed, while saving the corresponding release
operation, reducing the amount of code and code complexity.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agokern/ieee1275/init: Add IEEE 1275 Radix support for KVM on Power
Avnish Chouhan [Thu, 23 May 2024 13:13:14 +0000 (18:43 +0530)] 
kern/ieee1275/init: Add IEEE 1275 Radix support for KVM on Power

This patch adds support for Radix, Xive and Radix_gtse in Options
vector5 which is required for KVM LPARs. KVM LPARs ONLY support
Radix and not the Hash. Not enabling Radix on any PowerVM KVM LPARs
will result in boot failure.

Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agofs/zfs/zfs: Mark vdev_zaps_v2 and head_errlog as supported
Vladimir Serbinenko [Thu, 16 May 2024 19:27:41 +0000 (22:27 +0300)] 
fs/zfs/zfs: Mark vdev_zaps_v2 and head_errlog as supported

We don't need any actual adjustments as we don't use the affected structures.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agotypes: Add missing casts in compile-time byteswaps
Vladimir Serbinenko [Thu, 16 May 2024 19:22:58 +0000 (22:22 +0300)] 
types: Add missing casts in compile-time byteswaps

Without them, e.g., 0x80LL on 64-bit target is 32-bit byte-swapped to
0xffffffff80000000 instead of correct 0x80000000.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agofont: Add Fedora-specific font paths
Vladimir Serbinenko [Thu, 16 May 2024 19:03:29 +0000 (22:03 +0300)] 
font: Add Fedora-specific font paths

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agofs/bfs: Fix improper grub_free() on non-existing files
Vladimir Serbinenko [Thu, 16 May 2024 18:37:49 +0000 (21:37 +0300)] 
fs/bfs: Fix improper grub_free() on non-existing files

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agoio/gzio: Properly init a table
Daniel Axtens [Sun, 12 May 2024 14:32:09 +0000 (00:32 +1000)] 
io/gzio: Properly init a table

ARRAY_SIZE() is the count of elements, but the element size is 4 bytes, so
this was only initing the first 1/4th of the table. Detected with valgrind.

This should only matter in error paths, and I've not been able to identify
any actual misbehaviour that results from reading in-bounds but uninited data.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agoio/gzio: Abort early when get_byte() reads nothing
Daniel Axtens [Sun, 12 May 2024 14:32:08 +0000 (00:32 +1000)] 
io/gzio: Abort early when get_byte() reads nothing

This isn't intended to be a functional change, but it makes a lot of failures a lot
faster, which is extremely helpful for fuzzing.

Without this change, we keep trying and trying to read more bytes into our buffer,
never being able to (read always returns 0) and so we just return old buffer contents
over and over until the decompression process fails some other way.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agocli_lock: Add build option to block command line interface
Alec Brown [Wed, 24 Jan 2024 06:26:37 +0000 (06:26 +0000)] 
cli_lock: Add build option to block command line interface

Add functionality to disable command line interface access and editing of GRUB
menu entries if GRUB image is built with --disable-cli.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agofs/erofs: Add tests for EROFS in grub-fs-tester
Yifan Zhao [Mon, 20 May 2024 17:20:59 +0000 (01:20 +0800)] 
fs/erofs: Add tests for EROFS in grub-fs-tester

This patch introduces three EROFS tests which cover compact, extended
and chunk-based inodes respectively.

Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
Reviewed-by: Glenn Washburn <development@efficientek.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agofs/erofs: Add support for the EROFS
Yifan Zhao [Mon, 20 May 2024 17:20:58 +0000 (01:20 +0800)] 
fs/erofs: Add support for the EROFS

The EROFS [1] is a lightweight read-only filesystem designed for performance
which has already been shipped in most Linux distributions as well as widely
used in several scenarios, such as Android system partitions, container
images and rootfs for embedded devices.

This patch brings in the EROFS uncompressed support. Now, it's possible to
boot directly through GRUB with an EROFS rootfs.

Support for the EROFS compressed files will be added later.

[1] https://erofs.docs.kernel.org

Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
Tested-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agosafemath: Add ALIGN_UP_OVF() which checks for an overflow
Gao Xiang [Mon, 20 May 2024 17:20:57 +0000 (01:20 +0800)] 
safemath: Add ALIGN_UP_OVF() which checks for an overflow

The following EROFS patch will use this helper to handle
ALIGN_UP() overflow.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agodocs: Fix spelling mistakes
Jonathan Davies [Mon, 20 May 2024 07:58:24 +0000 (08:58 +0100)] 
docs: Fix spelling mistakes

Signed-off-by: Jonathan Davies <jonathan.davies@nutanix.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agoutil/grub.d/00_header.in: Quote background image pathname in output
Pascal Hambourg [Sun, 19 May 2024 15:50:10 +0000 (17:50 +0200)] 
util/grub.d/00_header.in: Quote background image pathname in output

This is required if the pathname contains spaces or GRUB shell
metacharacters else the generated config file check will fail.

Signed-off-by: Pascal Hambourg <pascal@plouf.fr.eu.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agodisk/lvm: GRUB fails to detect LVM volumes due to an incorrect computation of mda_end
Rogier [Mon, 6 May 2024 20:18:45 +0000 (15:18 -0500)] 
disk/lvm: GRUB fails to detect LVM volumes due to an incorrect computation of mda_end

When handling a regular LVM volume, GRUB can fail with the message:

  error: disk `lvmid/******-****-****-****-****-****-****/******-****-****-****-****-****-******' not found.

If the condition which triggers this exists, grub-probe will report the
error mentioned above. Similarly, the GRUB boot code will fail to detect
LVM volumes, resulting in a failure to boot off of LVM disks/partitions.
The condition can be created on any LVM VG by an LVM configuration change,
so any system with /boot on LVM can become unbootable at "any" time (after
any LVM configuration change).

The problem is caused by an incorrect computation of mda_end in disk/lvm.c,
when the metadata area wraps around. Apparently, this can start happening at
around 220 metadata changes to the VG.

Fixes: 879c4a834 (lvm: Fix two more potential data-dependent alloc overflows)
Fixes: https://savannah.gnu.org/bugs/?61620
Signed-off-by: Rogier <rogier777@gmail.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-By: Michael Chang <mchang@suse.com>
14 months agodisk/cryptodisk: Allow user to retry failed passphrase
Forest [Tue, 7 May 2024 00:07:30 +0000 (17:07 -0700)] 
disk/cryptodisk: Allow user to retry failed passphrase

Give the user a chance to re-enter their cryptodisk passphrase after a typo,
rather than immediately failing (and likely dumping them into a GRUB shell).

By default, we allow 3 tries before giving up. A value in the
cryptodisk_passphrase_tries environment variable will override this default.

The user can give up early by entering an empty passphrase, just as they
could before this patch.

Signed-off-by: Forest <forestix@nom.one>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agodisk/mdraid1x_linux: Prevent infinite recursion
Lidong Chen [Mon, 29 Apr 2024 16:38:03 +0000 (16:38 +0000)] 
disk/mdraid1x_linux: Prevent infinite recursion

The test corpus for version-1 RAID generated an infinite recursion
in grub_partition_iterate() while attempting to read the superblock.
The reason for the issue was that the data region overlapped with
the superblock.

The infinite call loop looks like this:
  grub_partition_iterate() -> partmap->iterate() ->
    -> grub_disk_read() -> grub_disk_read_small() ->
    -> grub_disk_read_small_real() -> grub_diskfilter_read() ->
    -> read_lv() -> read_segment() -> grub_diskfilter_read_node() ->
    -> grub_disk_read() -> grub_disk_read_small() -> ...

The fix adds checks for both the superblock region and the data
region when parsing the superblock metadata in grub_mdraid_detect().

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agoefi: Fix stack protector issues
Ard Biesheuvel [Sat, 27 Apr 2024 13:07:58 +0000 (08:07 -0500)] 
efi: Fix stack protector issues

The "ground truth" stack protector cookie value is kept in a global
variable, and loaded in every function prologue and epilogue to store
it into resp. compare it with the stack slot holding the cookie.

If the comparison fails, the program aborts, and this might occur
spuriously when the global variable changes values between the entry and
exit of a function. This implies that assigning the global variable at
boot should not involve any instrumented function calls, unless special
care is taken to ensure that the live call stack is synchronized, which
is non-trivial.

So avoid any function calls, including grub_memcpy(), which is
unnecessary given that the stack cookie is always a suitably aligned
variable of the native word size.

While at it, leave the last byte 0x0 to avoid inadvertent unbounded
strings on the stack.

Note that the use of __attribute__((optimize)) is described as
unsuitable for production use in the GCC documentation, so let's drop
this as well now that it is no longer needed.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14 months agobuild: Track explicit module dependencies in Makefile.core.def
Oliver Steffen [Thu, 22 Feb 2024 13:32:31 +0000 (14:32 +0100)] 
build: Track explicit module dependencies in Makefile.core.def

Add a new keyword, "depends", to the module definition syntax
used in Makefile.core.def. This allows specifying explicit module
dependencies together with the module definition.

Do not track the "extra_deps.lst" file in the repository anymore,
it is now auto-generated.

Make use of this new keyword in the bli module definition.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
15 months agowindows: Add _stack_chk_guard/_stack_chk_fail symbols for Windows 64-bit target
Daniel Kiper [Tue, 9 Apr 2024 17:56:02 +0000 (19:56 +0200)] 
windows: Add _stack_chk_guard/_stack_chk_fail symbols for Windows 64-bit target

Otherwise the GRUB cannot start due to missing symbols when stack
protector is enabled on EFI platforms.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
15 months agoutil/bash-completion: Fix for bash-completion 2.12
Gary Lin [Mon, 25 Mar 2024 02:11:34 +0000 (10:11 +0800)] 
util/bash-completion: Fix for bash-completion 2.12

_split_longopt() was the bash-completion private API and removed since
bash-completion 2.12. This commit initializes the bash-completion
general variables with _init_completion() to avoid the potential
"command not found" error.

Although bash-completion 2.12 introduces _comp_initialize() to deprecate
_init_completion(), _init_completion() is still chosen for the better
backward compatibility.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
15 months agoutil/grub-fstest: Add a new command zfs-bootfs
Vladimir 'phcoder' Serbinenko [Fri, 15 Mar 2024 19:59:04 +0000 (22:59 +0300)] 
util/grub-fstest: Add a new command zfs-bootfs

It is useful to check zfs-bootfs command.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
15 months agoefi: Enable CMOS on x86 EFI platforms
Vladimir 'phcoder' Serbinenko [Fri, 15 Mar 2024 19:35:07 +0000 (22:35 +0300)] 
efi: Enable CMOS on x86 EFI platforms

The CMOS actually exists on most EFI platforms and in some cases is used to
store useful data that makes it justifiable for GRUB to read/write it.

As for date and time keep using EFI API and not CMOS one.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
15 months agoacpi: Mark MADT entries as packed
Vladimir 'phcoder' Serbinenko [Fri, 15 Mar 2024 19:02:07 +0000 (22:02 +0300)] 
acpi: Mark MADT entries as packed

No alignment is guaranteed and in fact on my IA-64 SAPIC is aligned
to 4 bytes instead of 8 and causes a trap. It affects only rarely used
lsacpi command and so went unnoticed.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
15 months agogfxmenu/view: Resolve false grub_errno disrupting boot process
Michael Chang [Mon, 19 Feb 2024 03:29:11 +0000 (11:29 +0800)] 
gfxmenu/view: Resolve false grub_errno disrupting boot process

When enabling gfxmenu and choosing to boot the Xen hypervisor from its
menu, an error occurred:

  error: ../../grub-core/video/bitmap_scale.c:42:null src bitmap in grub_video_create_scaled.

The error is returned by grub_video_bitmap_create_scaled() when the
source pixmap is not there. The init_background() uses it to scale up
the background image so it can fully fit into the screen resolution.

However not all backgrounds are set by a image, i.e. the "desktop-image"
property of the theme file. Instead a color code may be used, for
example OpenSUSE's green background uses "desktop-color" property:

  desktop-color: "#0D202F"

So it is absolutely fine to call init_background() without a raw pixmap
if color code is used. A missing check has to be added to ensure the
grub_errno will not be erroneously set and gets in the way of ensuing
boot process.

The reason it happens sporadically is due to grub_errno is reset to
GRUB_ERR_NONE in other places if a function's error return can be
ignored. In particular this hunk in grub_gfxmenu_create_box() does the
majority of the reset of grub_errno returned by init_background(), but
the path may not be always chosen.

  grub_video_bitmap_load (&box->raw_pixmaps[i], path);
  grub_free (path);

  /* Ignore missing pixmaps.  */
  grub_errno = GRUB_ERR_NONE;

In any case, we cannot account on such random behavior and should only
return grub_errno if it is justified.

On the occasion move the grub_video_bitmap struct definition to the
beginning of the function.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
15 months agofs/xfs: Handle non-continuous data blocks in directory extents
Jon DeVree [Sun, 11 Feb 2024 15:34:58 +0000 (10:34 -0500)] 
fs/xfs: Handle non-continuous data blocks in directory extents

The directory extent list does not have to be a continuous list of data
blocks. When GRUB tries to read a non-existant member of the list,
grub_xfs_read_file() will return a block of zero'ed memory. Checking for
a zero'ed magic number is sufficient to skip this non-existant data block.

Prior to commit 07318ee7e (fs/xfs: Fix XFS directory extent parsing)
this was handled as a subtle side effect of reading the (non-existant)
tail data structure. Since the block was zero'ed the computation of the
number of directory entries in the block would return 0 as well.

Fixes: 07318ee7e (fs/xfs: Fix XFS directory extent parsing)
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2254370
Signed-off-by: Jon DeVree <nuxi@vault24.org>
Reviewed-By: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
17 months agoRevert "templates: Reinstate unused version comparison functions with warning"
Julian Andres Klode [Tue, 30 Jan 2024 12:59:43 +0000 (13:59 +0100)] 
Revert "templates: Reinstate unused version comparison functions with warning"

We reinstated these functions before the 2.12 release with a warning
such that users upgrading to 2.12 who had custom scripts using them
would not get broken in the upgrade and agreed to remove them after
the 2.12 release. This removes them accordingly.

This reverts commit e7a831963 (templates: Reinstate unused version
comparison functions with warning).

Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
17 months agoutil/bash-completion: Load scripts on demand
Gary Lin [Tue, 30 Jan 2024 06:41:10 +0000 (14:41 +0800)] 
util/bash-completion: Load scripts on demand

There are two system directories for bash-completion scripts. One is
/usr/share/bash-completion/completions/ and the other is
/etc/bash_completion.d/. The "etc" scripts are loaded in advance and
for backward compatibility while the "usr" scripts are loaded on demand.
To load scripts on demand it requires a corresponding script for every
command. So, the main bash-completion script is split into several
subscripts for different "grub-*" commands. To share the code the real
completion functions are still implemented in "grub" and each
subscript sources "grub" and invokes the corresponding function.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
18 months agoutil/grub.d/10_hurd.in: Find proper ld.so on 64-bit systems
Samuel Thibault [Tue, 23 Jan 2024 20:47:56 +0000 (21:47 +0100)] 
util/grub.d/10_hurd.in: Find proper ld.so on 64-bit systems

The 64-bit ABI defines ld.so to be /lib/ld-x86-64.so.1.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
18 months agoosdep/hurd/getroot: Fix 64-bit build
Samuel Thibault [Tue, 23 Jan 2024 20:47:36 +0000 (21:47 +0100)] 
osdep/hurd/getroot: Fix 64-bit build

The file_get_fs_options() takes a mach_msg_type_number_t, 32-bit,
not a size_t, 64-bit on 64-bit platforms.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
18 months agoloader/i386/multiboot_mbi: Clean up redundant code
Alec Brown [Sat, 20 Jan 2024 02:52:51 +0000 (02:52 +0000)] 
loader/i386/multiboot_mbi: Clean up redundant code

In grub-core/loader/i386/multiboot_mbi.c, Coverity spotted redundant code where
the variable err was being set to GRUB_ERR_NONE and then being overwritten
later without being used. Since this is unnecessary, we can remove the code
that sets err to GRUB_ERR_NONE.

Fixes: CID 428877
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
18 months agoosdep/unix/getroot: Clean up redundant code
Alec Brown [Sat, 20 Jan 2024 02:52:50 +0000 (02:52 +0000)] 
osdep/unix/getroot: Clean up redundant code

In grub-core/osdep/unix/getroot.c, Coverity spotted redundant code where the
double pointer os_dev was being set to 0 and then being overwritten later
without being used. Since this is unnecessary, we can remove the code that
sets os_dev to 0.

Fixes: CID 428875
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
18 months agofs/jfs: Clean up redundant code
Alec Brown [Sat, 20 Jan 2024 02:52:49 +0000 (02:52 +0000)] 
fs/jfs: Clean up redundant code

In grub-core/fs/jfs.c, Coverity spotted redundant code where the pointer diro
was being set to 0 and then being overwritten later without being used. Since
this is unnecessary, we can remove the code that sets diro to 0.

Fixes: CID 428876
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
18 months agotests: Switch password quality check off for luks2 test
Gary Lin [Fri, 29 Dec 2023 09:08:20 +0000 (17:08 +0800)] 
tests: Switch password quality check off for luks2 test

When adding/changing the password for the luks2 partition, cryptsetup
may reject the command due to the weak password. Since this is only for
testing, add "--force-password" to switch password quality check off to
avoid the unexpected failure.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agobuild: Include grub-core/extra_deps.lst in dist
Oskari Pirhonen [Thu, 21 Dec 2023 07:17:35 +0000 (01:17 -0600)] 
build: Include grub-core/extra_deps.lst in dist

Fixes build failure due to the extra_deps.lst file not existing in the
tarball. Found while trying to package GRUB 2.12 for Gentoo.

  make[3]: *** No rule to make target '/var/tmp/portage/sys-boot/grub-2.12/work/grub-2.12/grub-core/extra_deps.lst', needed by 'syminfo.lst'.  Stop.

Fixes: 89fbe0cac (grub-core/Makefile.am: Make path to extra_deps.lst relative to $(top_srcdir)/grub-core)
Fixes: 154dcb1ae (build: Allow explicit module dependencies)
Signed-off-by: Oskari Pirhonen <xxc3ncoredxx@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoBump version to 2.13
Daniel Kiper [Wed, 20 Dec 2023 16:25:46 +0000 (17:25 +0100)] 
Bump version to 2.13

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoRelease 2.12 grub-2.12
Daniel Kiper [Wed, 20 Dec 2023 15:54:46 +0000 (16:54 +0100)] 
Release 2.12

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoefi: Add support for reproducible builds
Glenn Washburn [Tue, 19 Dec 2023 06:00:01 +0000 (00:00 -0600)] 
efi: Add support for reproducible builds

Having randomly generated bytes in the binary output breaks reproducible
builds. Since build timestamps are usually the source of irreproducibility
there is a standard which defines an environment variable SOURCE_DATE_EPOCH
to be used when set for build timestamps. According to the standard [1], the
value of SOURCE_DATE_EPOCH is a base-10 integer of the number of seconds
since the UNIX epoch. Currently, this is a 10 digit number that fits into
32-bits, but will not shortly after the year 2100. So to be future-proof
only use the least significant 32-bits. On 64-bit architectures, where the
canary is also 64-bits, there is an extra 32-bits that can be filled to
provide more entropy. The first byte is NUL to filter out string buffer
overflow attacks and the remaining 24-bits are set to static random bytes.

[1] https://reproducible-builds.org/specs/source-date-epoch

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoefi: Generate stack protector canary at build time if urandom is available
Glenn Washburn [Tue, 19 Dec 2023 06:00:00 +0000 (00:00 -0600)] 
efi: Generate stack protector canary at build time if urandom is available

Generating the canary at build time allows the canary to be different for
every build which could limit the effectiveness of certain exploits.
Fallback to the statically generated random bytes if /dev/urandom is not
readable, e.g. Windows.

On 32-bit architectures, which use a 32-bit canary, reduce the canary to
4 bytes with one byte being NUL to filter out string buffer overflow attacks.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoefi: Initialize canary to non-zero value
Glenn Washburn [Tue, 19 Dec 2023 05:59:59 +0000 (23:59 -0600)] 
efi: Initialize canary to non-zero value

The canary, __stack_chk_guard, is in the BSS and so will get initialized to
zero if it is not explicitly initialized. If the UEFI firmware does not
support the RNG protocol, then the canary will not be randomized and will
be zero. This seems like a possibly easier value to write by an attacker.
Initialize canary to static random bytes, so that it is still random when
there is no RNG protocol. Set at least one byte to NUL to protect against
string buffer overflow attacks [1]. Code that writes NUL terminated strings
will terminate when a NUL is encountered in the input byte stream. So the
attacker will not be able to forge the canary by including it in the input
stream without terminating the string operation and thus limiting the
stack corruption.

[1] https://www.sans.org/blog/stack-canaries-gingerly-sidestepping-the-cage/

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agogfxmenu/gui_image: Fix double free of bitmap
Alec Brown [Wed, 13 Dec 2023 22:25:13 +0000 (22:25 +0000)] 
gfxmenu/gui_image: Fix double free of bitmap

In grub-core/gfxmenu/gui_image.c, Coverity detected a double free in the
function load_image(). The function checks if self->bitmap and self->raw_bitmap
aren't NULL and then frees them. In the case self->bitmap and self->raw_bitmap
are the same, only self->raw_bitmap is freed which would also free the memory
used by self->bitmap. However, in this case self->bitmap isn't being set to NULL
which could lead to a double free later in the code. After self->raw_bitmap is
freed, it gets set to the variable bitmap. If this variable is NULL, the code
could have a path that would free self->bitmap a second time in the function
rescale_image().

Fixes: CID 292472
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agocommands/acpi: Fix calculation of ACPI tables addresses when processing RSDT and...
Qiumiao Zhang [Mon, 11 Dec 2023 09:20:25 +0000 (17:20 +0800)] 
commands/acpi: Fix calculation of ACPI tables addresses when processing RSDT and XSDT

According to the ACPI specification the XSDT Entry field contains an array
of 64-bit physical addresses which points to other DESCRIPTION_HEADERs. However,
the entry_ptr iterator is defined as a 32-bit pointer. It means each 64-bit
entry in the XSDT table is treated as two separate 32-bit entries then. Fix the
issue by using correct addresses sizes when processing RSDT and XSDT tables.

Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agolibnvpair: Support prefixed nvlist symbol names as found on NetBSD
Vladimir Serbinenko [Thu, 24 Aug 2023 22:01:25 +0000 (00:01 +0200)] 
libnvpair: Support prefixed nvlist symbol names as found on NetBSD

NetBSD uses slightly different function names for the same functions.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agobootstrap: Don't check gettext version
Vladimir Serbinenko [Thu, 24 Aug 2023 19:47:50 +0000 (21:47 +0200)] 
bootstrap: Don't check gettext version

NetBSD gettext is older than the check but we don't actually need 0.18.3,
older one works fine. This is needed to make bootstrap work on NetBSD.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agokern/mm: Use %x and cast for displaying sizeof()
Vladimir Serbinenko [Fri, 25 Aug 2023 11:37:43 +0000 (13:37 +0200)] 
kern/mm: Use %x and cast for displaying sizeof()

There is some variance in how compiler treats sizeof() especially
on 32-bit platforms where it can be naturally either int or long.
Explicit cast solves the issue.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoconfigure: Add RPATH for freetype on NetBSD
Vladimir Serbinenko [Thu, 24 Aug 2023 23:54:09 +0000 (01:54 +0200)] 
configure: Add RPATH for freetype on NetBSD

Without this build-time mkfont fails dynamic linking. This is not ideal
but improves the situation until a better solution is available.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoconfigure: Add *BSD font paths
Vladimir Serbinenko [Thu, 24 Aug 2023 22:00:52 +0000 (00:00 +0200)] 
configure: Add *BSD font paths

*BSD puts fonts in other places. Add them to the list.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoautogen: Accept python3.10 as a python alternative
Vladimir Serbinenko [Thu, 24 Aug 2023 21:25:48 +0000 (23:25 +0200)] 
autogen: Accept python3.10 as a python alternative

NetBSD doesn't provide python or python3.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agobuild: Rename HAVE_LIBZFS to USE_LIBZFS
Vladimir Serbinenko [Thu, 24 Aug 2023 21:24:30 +0000 (23:24 +0200)] 
build: Rename HAVE_LIBZFS to USE_LIBZFS

The HAVE_LIBZFS is defined by libzfs test and hence conflicts with
manual definition. On NetBSD it ends up detecting zfs but not detecting
nvpair and creates confusion. Split them.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agognulib: Tolerate always_inline attribute being ignored
Vladimir Serbinenko [Thu, 24 Aug 2023 20:45:53 +0000 (22:45 +0200)] 
gnulib: Tolerate always_inline attribute being ignored

It's not critical, -Werror on it is inappropriate. We don't want to
modify gnulib too much. This warning is pretty much irrelevant.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoutil/editenv: Don't use %m formatter
Vladimir Serbinenko [Thu, 24 Aug 2023 20:32:45 +0000 (22:32 +0200)] 
util/editenv: Don't use %m formatter

It's not available on NetBSD outside of syslog. Using strerror() is more
reliable as we retrieve errno immediately rather than down the stack.

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