]> git.ipfire.org Git - thirdparty/grub.git/log
thirdparty/grub.git
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>
19 months agoosdep/bsd/hostdisk: Fix NetBSD compilation
Vladimir Serbinenko [Thu, 24 Aug 2023 19:48:20 +0000 (21:48 +0200)] 
osdep/bsd/hostdisk: Fix NetBSD compilation

Wrong function and variable name cause a stupid compilation error on
NetBSD and OpenBSD. Only NetBSD and OpenBSD use this file. No other
platform is affected.

Additionally, define RAW_FLOPPY_MAJOR constant if it is missing.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoosdep/generic/blocklist: Fix compilation
Vladimir Serbinenko [Thu, 24 Aug 2023 07:33:47 +0000 (09:33 +0200)] 
osdep/generic/blocklist: Fix compilation

After recent change in blocklist types we have a type mismatch. Fixing it
requires a wrapper or large changes. I feel like wrapper makes more sense.

Without this patch we end up with a compilation problem and without wrapping
callback data is not passed properly anymore.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agodisk/diskfilter: Remove unused variable
Vladimir Serbinenko [Thu, 24 Aug 2023 00:32:55 +0000 (02:32 +0200)] 
disk/diskfilter: Remove unused variable

Variable e is set but never used. We can just remove it now.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agobuild: Tolerate unused-but-set in generated lexer/bison files
Vladimir Serbinenko [Thu, 24 Aug 2023 00:32:26 +0000 (02:32 +0200)] 
build: Tolerate unused-but-set in generated lexer/bison files

We don't really control the small aspects of generated files and NetBSD
version has an unused variable that is then detected by gcc as warning
that is then promoted to error.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoloader/i386/bsdXX: Fix loading after unaligned module
Vladimir Serbinenko [Mon, 10 Jul 2023 15:17:35 +0000 (17:17 +0200)] 
loader/i386/bsdXX: Fix loading after unaligned module

Current code implicitly assumes that aligning chunk_size + *kern_end is
the same as aligning on curload which is not the case because
chunk_size starts at zero even if *kern_end is unaligned and ALIGN_PAGE
moved curload to an aligned position but not *kern_end + chunk_size.

This fixes booting of FreeBSD with zfs module.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agogrub-core/Makefile.am: Make path to extra_deps.lst relative to $(top_srcdir)/grub...
Mate Kukri [Fri, 8 Dec 2023 17:20:12 +0000 (17:20 +0000)] 
grub-core/Makefile.am: Make path to extra_deps.lst relative to $(top_srcdir)/grub-core

The commit 154dcb1ae (build: Allow explicit module dependencies) broke
out of tree builds by introducing the extra_deps.lst file into the
source tree but referencing it just by name in grub-core/Makefile.am.
Fix it by adding $(top_srcdir)/grub-core to the path.

Fixes: 154dcb1ae (build: Allow explicit module dependencies)
Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoutil/grub-install: Move platdir path canonicalization after files were copied to...
Mate Kukri [Fri, 8 Dec 2023 16:57:55 +0000 (16:57 +0000)] 
util/grub-install: Move platdir path canonicalization after files were copied to grubdir

The commit 3f9eace2d (util/grub-install: Delay copying files to
{grubdir,platdir} after install_device was validated) delaying
copying of files caused a regression when installing without an
existing directory structure.

This patch ensures that the platform directory actually exists by the
time the code tries to canonicalize its filename.

Fixes: 3f9eace2d (util/grub-install: Delay copying files to {grubdir,platdir} after install_device was validated)
Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoutil/grub-mkstandalone: Ensure deterministic tar file creation by sorting contents
Michael Chang [Wed, 6 Dec 2023 03:42:04 +0000 (11:42 +0800)] 
util/grub-mkstandalone: Ensure deterministic tar file creation by sorting contents

The add_tar_files() function currently iterates through a directory's
content using readdir(), which doesn't guarantee a specific order. This
lack of deterministic behavior impacts reproducibility in the build process.

This commit resolves the issue by introducing sorting functionality.
The list retrieved by readdir() is now sorted alphabetically before
incorporation into the tar archive, ensuring consistent and predictable
file ordering within the archive.

On the occasion fix tfp memory leak.

Signed-off-by: Michael Chang <mchang@suse.com>
Signed-off-by: Bernhard Wiedemann <bwiedemann@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
19 months agoutil/grub-mkstandalone: Ensure stable timestamps for generated images
Michael Chang [Wed, 6 Dec 2023 03:42:03 +0000 (11:42 +0800)] 
util/grub-mkstandalone: Ensure stable timestamps for generated images

This change mirrors a previous fix [1] but is specific to images
generated by grub-mkstandalone.

The former fix, commit 85a7be241 (util/mkimage: Use stable timestamp
when generating binaries.), focused on utilizing a stable timestamp
during binary generation in the util/mkimage context. This commit
extends that approach to the images produced by grub-mkstandalone,
ensuring consistency and stability in timestamps across all generated
binaries.

[1] 85a7be241 util/mkimage: Use stable timestamp when generating binaries.

Signed-off-by: Michael Chang <mchang@suse.com>
Signed-off-by: Bernhard Wiedemann <bwiedemann@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
20 months agonet/http: Fix gcc-13 errors relating to type signedness
Mate Kukri [Wed, 29 Nov 2023 19:58:25 +0000 (19:58 +0000)] 
net/http: Fix gcc-13 errors relating to type signedness

Replace definition of HTTP_PORT with a pre-processor macro that converts
the constant to the correct grub_uint16_t type.

Change "port" local variable definition in http_establish() to have the
same type.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com
20 months agotemplates: Reinstate unused version comparison functions with warning
Julian Andres Klode [Wed, 29 Nov 2023 12:42:55 +0000 (13:42 +0100)] 
templates: Reinstate unused version comparison functions with warning

Revert the commit a79c567f6 (templates: Remove unused version comparison
functions) and add a warning to the functions that they are deprecated.

Removing the functions directly caused a lot of upgrade issues
with custom user scripts that called the functions. In Debian and
Ubuntu, grub-mkconfig is invoked as a post-installation script
and would fail, causing upgrades to fail halfway through and
putting the package manager into an inconsistent state.

FWIW, we get one bug per 2 weeks basically, for an interim Ubuntu
release which generally does not receive much usage, that is a high
number.

The proposal is to pick this for 2.12 and directly after the release
remove it again. Then users will have time to fix their scripts without
systems breaking immediately.

This reverts commit a79c567f6 (templates: Remove unused version
comparison functions).

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>
20 months agoutil/grub-install: Delay copying files to {grubdir,platdir} after install_device...
Mate Kukri [Fri, 24 Nov 2023 08:32:57 +0000 (08:32 +0000)] 
util/grub-install: Delay copying files to {grubdir,platdir} after install_device was validated

Previously grub-install copied modules to grubdir before doing any
validation on the install_device.

When grub-install was called with an invalid install_device, modules
were already copied to /boot before it found out and was forced to rely
on atexit() rollback.

This patch delays copying the modules after at least some install_device
validation was done, and thus reduces reliance on successful rollback.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
20 months agoefi: Set shim_lock_enabled even if validation is disabled
Julian Andres Klode [Tue, 21 Nov 2023 17:09:59 +0000 (18:09 +0100)] 
efi: Set shim_lock_enabled even if validation is disabled

If validation has been disabled via MokSbState, secure boot on the
firmware is still enabled, and the kernel fails to boot.

This is a bit hacky, because shim_lock is not *fully* enabled, but
it triggers the right code paths.

Ultimately, all this will be resolved by shim gaining it's own image
loading and starting protocol, so this is more a temporary workaround.

Fixes: 6425c12cd (efi: Fallback to legacy mode if shim is loaded on x86 archs)
Cc: Peter Jones <pjones@redhat.com>
Cc: Michael Chang <mchang@suse.com>
Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
20 months agodocs: Improve bli module documentation
Oliver Steffen [Thu, 16 Nov 2023 15:37:40 +0000 (16:37 +0100)] 
docs: Improve bli module documentation

Improve the documentation of the bli module and explain in more detail what
it does. Make clear that GPT formatted drives are expected and other
partition formats are ignored. Also reorder and reword this section a bit.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
20 months agobli: Add explicit dependency on the part_gpt module
Oliver Steffen [Thu, 16 Nov 2023 15:37:39 +0000 (16:37 +0100)] 
bli: Add explicit dependency on the part_gpt module

The bli module has a "hidden" dependency on the part_gpt module, which
is not picked up automatically by the build system. One purpose of the
bli module is to communicate the GPT UUID of the partition GRUB was
launched from to Linux user-space (systemd-gpt-auto-generator).
Without the part_gpt module, bli is not able to obtain the UUID. Since
bli does its work in the module initialization function, the order in
which the modules are loaded is also important: part_gpt needs to be
loaded before the bli module.

To solve this, track this dependency explicitly.

Note that the Boot Loader Interface specification, which bli aims to
implement, requires GPT formatted drives. The bli module ignores all
other partition formats.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
20 months agobuild: Allow explicit module dependencies
Oliver Steffen [Thu, 16 Nov 2023 15:37:38 +0000 (16:37 +0100)] 
build: Allow explicit module dependencies

The build system deduces inter-module dependencies from the symbols
required and exported by the modules. This works well, except for some
rare cases where the dependency is indirect or hidden. A module might
not make use of any function of some other module, but still expect its
functionality to be available to GRUB.

To solve this, introduce a new file, currently empty, called extra_deps.lst
to track these cases manually. This file gets processed in the same way
as the automatically generated syminfo.lst, making it possible to inject
data into the dependency resolver.

Since *.lst files are set to be ignored by git, add an exception for
extra_deps.lst.

Additionally, introduce a new keyword for the syminfo.lst syntax:
"depends" allows specifying a module dependency directly:

  depends <module> <depdendency>...

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
20 months agokern/ieee1275/init/ppc64: Display upper_mem_limit when debugging
Stefan Berger [Thu, 30 Nov 2023 14:17:24 +0000 (09:17 -0500)] 
kern/ieee1275/init/ppc64: Display upper_mem_limit when debugging

Display upper_mem_limit and its rounded-down value in MiB.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
20 months agokern/ieee1275/init/ppc64: Fix a comment
Stefan Berger [Thu, 30 Nov 2023 14:17:23 +0000 (09:17 -0500)] 
kern/ieee1275/init/ppc64: Fix a comment

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
20 months agokern/ieee1275/ieee1275: Display successful memory claims when debugging
Stefan Berger [Thu, 30 Nov 2023 14:17:22 +0000 (09:17 -0500)] 
kern/ieee1275/ieee1275: Display successful memory claims when debugging

Display successful memory claims with exact address and rounded-down
MiB location and rounded-up size in MiB.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
20 months agoloader/powerpc/ieee1275: Use new allocation function for kernel and initrd
Stefan Berger [Thu, 30 Nov 2023 14:17:21 +0000 (09:17 -0500)] 
loader/powerpc/ieee1275: Use new allocation function for kernel and initrd

On PowerVM and KVM on Power use the new memory allocation function that
honors restrictions on which memory GRUB can actually use. In the request
structure indicate the request for a single memory block along with
address alignment restrictions. Request direct usage of the memory block
by setting init_region to false (prevent it from being added to GRUB's
heap). Initialize the found addr to -1, so that -1 will be returned
to the loader in case no memory could be allocated.

Report an out-of-memory error in case the initrd could not be loaded.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
20 months agokern/ieee1275/cmain/ppc64: Introduce flags to identify KVM and PowerVM
Stefan Berger [Thu, 30 Nov 2023 14:17:20 +0000 (09:17 -0500)] 
kern/ieee1275/cmain/ppc64: Introduce flags to identify KVM and PowerVM

Introduce flags to identify PowerVM and KVM on Power and set them where
each type of host has been detected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
20 months agokern/ieee1275/init/ppc64: Rename regions_claim() to grub_regions_claim()
Stefan Berger [Thu, 30 Nov 2023 14:17:19 +0000 (09:17 -0500)] 
kern/ieee1275/init/ppc64: Rename regions_claim() to grub_regions_claim()

Rename regions_claim() to grub_regions_claim() to make it available for
memory allocation. The ieee1275 loader will use this function on PowerVM
and KVM on Power and thus avoid usage of memory that it is not allowed
to use.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
20 months agokern/ieee1275/init/ppc64: Add support for alignment requirements
Stefan Berger [Thu, 30 Nov 2023 14:17:18 +0000 (09:17 -0500)] 
kern/ieee1275/init/ppc64: Add support for alignment requirements

Add support for memory alignment requirements and adjust a candidate
address to it before checking whether the block is large enough. This
must be done in this order since the alignment adjustment can make
a block smaller than what was requested.

None of the current callers has memory alignment requirements but the
ieee1275 loader for kernel and initrd will use it to convey them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
20 months agokern/ieee1275/init/ppc64: Return allocated address using context
Stefan Berger [Thu, 30 Nov 2023 14:17:17 +0000 (09:17 -0500)] 
kern/ieee1275/init/ppc64: Return allocated address using context

Return the allocated address of the memory block in the request structure
if a memory allocation was actually done. Leave the address untouched
otherwise. This enables a caller who wants to use the allocated memory
directly, rather than adding the memory to the heap, to see where memory
was allocated. None of the current callers need this but the converted
ieee1275 loader will make use of it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
20 months agokern/ieee1275/init/ppc64: Decide by request whether to initialize region
Stefan Berger [Thu, 30 Nov 2023 14:17:16 +0000 (09:17 -0500)] 
kern/ieee1275/init/ppc64: Decide by request whether to initialize region

Let the regions_claim() request structure's init_region determine whether
to call grub_mm_init_region() on it. This allows for adding memory to
GRUB's memory heap if init_region is set to true, or direct usage of the
memory otherwise. Set all current callers' init_region to true since they
want to add memory regions to GRUB's heap.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
20 months agokern/ieee1275/init/ppc64: Introduce a request for regions_claim()
Stefan Berger [Thu, 30 Nov 2023 14:17:15 +0000 (09:17 -0500)] 
kern/ieee1275/init/ppc64: Introduce a request for regions_claim()

The regions_claim() function limits the allocation of memory regions
by excluding certain memory areas from being used by GRUB. This for
example includes a gap between 640MB and 768MB as well as an upper
limit beyond which no memory may be used when an fadump is present.
However, the ieee1275 loader for kernel and initrd currently does not
use regions_claim() for memory allocation on PowerVM and KVM on Power
and therefore may allocate memory in those areas that it should not use.

To make the regions_claim() function more flexible and ultimately usable
for the ieee1275 loader, introduce a request structure to pass various
parameters to the regions_claim() function that describe the properties
of requested memory chunks. In a first step, move the total and flags
variables into this structure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
20 months agofs/xfs: Add large extent counters incompat feature support
Anthony Iliopoulos [Thu, 26 Oct 2023 09:53:39 +0000 (11:53 +0200)] 
fs/xfs: Add large extent counters incompat feature support

XFS introduced 64-bit extent counters for inodes via a series of
upstream commits and the feature was marked as stable in v6.5 via
commit 61d7e8274cd8 (xfs: drop EXPERIMENTAL tag for large extent
counts).

Further, xfsprogs release v6.5.0 switched this feature on by default
in mkfs.xfs via commit e5b18d7d1d96 (mkfs: enable large extent counts
by default).

Filesystems formatted with large extent count support, nrext64=1, are
thus currently not recognizable by GRUB, since this is an incompat
feature. Add the required support so that those filesystems and inodes
with large extent counters can be read by GRUB.

Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
Reviewed-by: Andrey Albershteyn <aalbersh@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Marta Lewandowska <mlewando@redhat.com>
Tested-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
21 months agogpt: Add compile time asserts for guid and gpt_partentry sizes
Vladimir Serbinenko [Sun, 13 Aug 2023 07:18:53 +0000 (09:18 +0200)] 
gpt: Add compile time asserts for guid and gpt_partentry sizes

With new alignment specification it's easy to screw up. Fortunately if it
happens the size will be bigger than intended. Compile time assert will catch
this.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agotypes: Split aligned and packed guids
Vladimir Serbinenko [Sun, 13 Aug 2023 07:18:23 +0000 (09:18 +0200)] 
types: Split aligned and packed guids

On ia64 alignment requirements are strict. When we pass a pointer to
UUID it needs to be at least 4-byte aligned or EFI will crash.
On the other hand in device path there is no padding for UUID, so we
need 2 types in one formor another. Make 4-byte aligned and unaligned types

The code is structured in a way to accept unaligned inputs
in most cases and supply 4-byte aligned outputs.

Efiemu case is a bit ugly because there inputs and outputs are
reversed and so we need careful casts to account for this
inversion.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agogpt_partition: Mark grub_gpt_partentry as having natural alignment
Vladimir Serbinenko [Tue, 31 Oct 2023 17:24:09 +0000 (18:24 +0100)] 
gpt_partition: Mark grub_gpt_partentry as having natural alignment

gpt_partition contains grub_guid. We need to decide whether the whole
structure is unaligned and then we need to use packed_guid. But we never
have unaligned part entries as we read them in an aligned buffer from disk.
Hence just make it all aligned.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
21 months agoefi: Deduplicate configuration table search function
Vladimir Serbinenko [Sun, 13 Aug 2023 07:15:02 +0000 (09:15 +0200)] 
efi: Deduplicate configuration table search function

We do table search in many places doing exactly the same algorithm.
The only minor variance in users is which table is used if several entries
are present. As specification mandates uniqueness and even if it ever isn't,
first entry is good enough, unify this code and always use the first entry.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agolsefi: Add missing static qualifier
Vladimir Serbinenko [Sun, 13 Aug 2023 07:15:54 +0000 (09:15 +0200)] 
lsefi: Add missing static qualifier

known_protocols isn't used anywhere else and even misses grub_ prefix, so
let's make it local (static).

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agotypes: Fix typo
Vladimir Serbinenko [Sun, 13 Aug 2023 07:19:02 +0000 (09:19 +0200)] 
types: Fix typo

Just a small grammar mistake.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agoutil/grub-mount: Check file path sanity
Qiumiao Zhang [Wed, 25 Oct 2023 03:54:57 +0000 (11:54 +0800)] 
util/grub-mount: Check file path sanity

The function argp_parser() in util/grub-mount.c lacks a check on the
sanity of the file path when parsing parameters. This results in
a segmentation fault if a partition is mounted to a non-existent path.

Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agoconfigure: Make the DJVU_FONT_SOURCE configurable with --with-dejavufont=FILE
Richard Marko [Thu, 19 Oct 2023 13:22:52 +0000 (15:22 +0200)] 
configure: Make the DJVU_FONT_SOURCE configurable with --with-dejavufont=FILE

Font might be located in different location, the default font might
not be available on all systems or other font might be preferred.

Signed-off-by: Richard Marko <srk@48.io>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agoconfigure: Make the Unifont FONT_SOURCE configurable with --with-unifont=FILE
Mads Kiilerich [Thu, 19 Oct 2023 13:22:51 +0000 (15:22 +0200)] 
configure: Make the Unifont FONT_SOURCE configurable with --with-unifont=FILE

Font might be located in different location, the default font might
not be available on all systems or other font might be preferred.

Signed-off-by: Mads Kiilerich <mads@kiilerich.com>
Signed-off-by: Richard Marko <srk@48.io>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agofs/xfs: Fix XFS directory extent parsing
Jon DeVree [Wed, 18 Oct 2023 03:03:47 +0000 (23:03 -0400)] 
fs/xfs: Fix XFS directory extent parsing

The XFS directory entry parsing code has never been completely correct
for extent based directories. The parser correctly handles the case
where the directory is contained in a single extent, but then mistakenly
assumes the data blocks for the multiple extent case are each identical
to the single extent case. The difference in the format of the data
blocks between the two cases is tiny enough that its gone unnoticed for
a very long time.

A recent change introduced some additional bounds checking into the XFS
parser. Like GRUB's existing parser, it is correct for the single extent
case but incorrect for the multiple extent case. When parsing a directory
with multiple extents, this new bounds checking is sometimes (but not
always) tripped and triggers an "invalid XFS directory entry" error. This
probably would have continued to go unnoticed but the /boot/grub/<arch>
directory is large enough that it often has multiple extents.

The difference between the two cases is that when there are multiple
extents, the data blocks do not contain a trailer nor do they contain
any leaf information. That information is stored in a separate set of
extents dedicated to just the leaf information. These extents come after
the directory entry extents and are not included in the inode size. So
the existing parser already ignores the leaf extents.

The only reason to read the trailer/leaf information at all is so that
the parser can avoid misinterpreting that data as directory entries. So
this updates the parser as follows:

For the single extent case the parser doesn't change much:
1. Read the size of the leaf information from the trailer
2. Set the end pointer for the parser to the start of the leaf
   information. (The previous bounds checking set the end pointer to the
   start of the trailer, so this is actually a small improvement.)
3. Set the entries variable to the expected number of directory entries.

For the multiple extent case:
1. Set the end pointer to the end of the block.
2. Do not set up the entries variable. Figuring out how many entries are
   in each individual block is complex and does not seem worth it when
   it appears to be safe to just iterate over the entire block.

The bounds check itself was also dependent upon the faulty XFS parser
because it accidentally used "filename + length - 1". Presumably this
was able to pass the fuzzer because in the old parser there was always
8 bytes of slack space between the tail pointer and the actual end of
the block. Since this is no longer the case the bounds check needs to be
updated to "filename + length + 1" in order to prevent a regression in
the handling of corrupt fliesystems.

Notes:
* When there is only one extent there will only ever be one block. If
  more than one block is required then XFS will always switch to holding
  leaf information in a separate extent.
* B-tree based directories seems to be parsed properly by the same code
  that handles multiple extents. This is unlikely to ever occur within
  /boot though because its only used when there are an extremely large
  number of directory entries.

Fixes: ef7850c75 (fs/xfs: Fix issues found while fuzzing the XFS filesystem)
Fixes: b2499b29c (Adds support for the XFS filesystem.)
Fixes: https://savannah.gnu.org/bugs/?64376
Signed-off-by: Jon DeVree <nuxi@vault24.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Tested-by: Marta Lewandowska <mlewando@redhat.com>
21 months agofs/xfs: Incorrect short form directory data boundary check
Lidong Chen [Thu, 28 Sep 2023 22:33:44 +0000 (22:33 +0000)] 
fs/xfs: Incorrect short form directory data boundary check

After parsing of the current entry, the entry pointer is advanced
to the next entry at the end of the "for" loop. In case where the
last entry is at the end of the data boundary, the advanced entry
pointer can point off the data boundary. The subsequent boundary
check for the advanced entry pointer can cause a failure.

The fix is to include the boundary check into the "for" loop
condition.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Tested-by: Marta Lewandowska <mlewando@redhat.com>
21 months agoRevert "zfsinfo: Correct a check for error allocating memory"
Vladimir 'phcoder' Serbinenko [Fri, 6 Oct 2023 18:23:53 +0000 (20:23 +0200)] 
Revert "zfsinfo: Correct a check for error allocating memory"

Original commit is wrong because grub_file_get_device_name() may return NULL
if we use implicit $root. Additionally, the grub_errno is guaranteed to be
GRUB_ERR_NONE at the beginning of a command. So, everything should work as
expected and Coverity report, CID 73668, WRT to this code should be treated
as false positive.

This reverts commit 7aab03418 (zfsinfo: Correct a check for error allocating memory).

Fixes: 7aab03418 (zfsinfo: Correct a check for error allocating memory)
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agodisk/i386/pc/biosdisk: Read up to 63 sectors in LBA mode
ValdikSS [Tue, 10 Oct 2023 18:28:44 +0000 (21:28 +0300)] 
disk/i386/pc/biosdisk: Read up to 63 sectors in LBA mode

Current code imposes limitations on the amount of sectors read in
a single call according to CHS layout of the disk even in LBA
read mode. There's no need to obey CHS layout restrictions for
LBA reads on LBA disks. It only slows down booting process.

See: https://lore.kernel.org/grub-devel/d42a11fa-2a59-b5e7-08b1-d2c60444bb99@valdikss.org.ru/

Signed-off-by: ValdikSS <iam@valdikss.org.ru>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agokern/i386/pc/init: Flush cache only on VIA C3 and earlier
ValdikSS [Fri, 6 Oct 2023 17:13:51 +0000 (20:13 +0300)] 
kern/i386/pc/init: Flush cache only on VIA C3 and earlier

The code flushes the cache on VIA processors unconditionally which
is excessive. Check for cpuid family and execute wbinvd only on C3
and earlier.

Fixes: https://savannah.gnu.org/bugs/?45149
Fixes: 25492a0f0 (Add wbinvd around bios call.)
Signed-off-by: ValdikSS <iam@valdikss.org.ru>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agofs/btrfs: Zero file data not backed by extents
Fabian Vogt [Thu, 5 Oct 2023 13:57:44 +0000 (15:57 +0200)] 
fs/btrfs: Zero file data not backed by extents

Implicit holes in file data need to be zeroed explicitly, instead of
just leaving the data in the buffer uninitialized.

This led to kernels randomly failing to boot in "fun" ways when loaded
from btrfs with the no_holes feature enabled, because large blocks of
zeros in the kernel file contained random data instead.

Signed-off-by: Fabian Vogt <fvogt@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
21 months agokern/ieee1275/init: Restrict high memory in presence of fadump on ppc64
Stefan Berger [Wed, 4 Oct 2023 15:32:35 +0000 (11:32 -0400)] 
kern/ieee1275/init: Restrict high memory in presence of fadump on ppc64

When a kernel dump is present then restrict the high memory regions to
avoid allocating memory where the kernel dump resides. Use the
ibm,kernel-dump node under /rtas to determine whether a kernel dump
exists and up to which limit GRUB can use available memory. Set the
upper_mem_limit to the size of the kernel dump section of type
REAL_MODE_REGION and therefore only allow GRUB's memory usage for high
addresses from RMO_ADDR_MAX to upper_mem_limit. This means that GRUB can
use high memory in the range of RMO_ADDR_MAX (768MB) to upper_mem_limit
and the kernel-dump memory regions above upper_mem_limit remain
untouched. This change has no effect on memory allocations below
linux_rmo_save (typically at 640MB).

Also, fall back to allocating below rmo_linux_save in case the chunk of
memory there would be larger than the chunk of memory above RMO_ADDR_MAX.
This can for example occur if a free memory area is found starting at 300MB
extending up to 1GB but a kernel dump is located at 768MB and therefore
does not allow the allocation of the high memory area but requiring to use
the chunk starting at 300MB to avoid an unnecessary out-of-memory condition.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agotests/util/grub-shell: Enable RNG device to better test stack smashing
Glenn Washburn [Fri, 1 Sep 2023 04:50:56 +0000 (23:50 -0500)] 
tests/util/grub-shell: Enable RNG device to better test stack smashing

In certain firmwares, e.g. OVMF, the RNG protocol is not enabled unless
there is an RNG device. When not enabled, GRUB fails to initialize the
stack guard with random bytes. For testing, this is not a big issue, but
there have been bugs found in the initialization. So turn this on for EFI
platforms to catch any regressions.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21 months agokern/efi/init: Disable stack smashing protection on grub_efi_init()
Glenn Washburn [Tue, 18 Jul 2023 05:47:14 +0000 (00:47 -0500)] 
kern/efi/init: Disable stack smashing protection on grub_efi_init()

GCC is electing to instrument grub_efi_init() to give it stack smashing
protection when configuring with --enable-stack-protector on the x86_64-efi
target. In the function prologue, the canary at the top of the stack frame
is set to the value of the stack guard. And in the epilogue, the canary is
checked to verify if it is equal to the guard and if not to call the stack
check fail function. The issue is that grub_efi_init() sets up the guard
by initializing it with random bytes, if the firmware supports the RNG
protocol. So in its prologue the canary will be set with the value of the
uninitialized guard, likely NUL bytes. Then the guard is initialized, and
finally the epilogue checks the canary against the guard, which will almost
certainly be different. This causes the code path for a smashed stack to be
taken, causing the machine to print out a message that stack smashing was
detected, wait 5 seconds, and then reboot. Disable grub_efi_init()
instrumentation so there is no stack smashing false positive generated.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>