]> git.ipfire.org Git - thirdparty/grub.git/log
thirdparty/grub.git
2 years agoterm/ns8250: Use ACPI SPCR table when available to configure serial
Benjamin Herrenschmidt [Fri, 23 Dec 2022 01:47:57 +0000 (12:47 +1100)] 
term/ns8250: Use ACPI SPCR table when available to configure serial

"serial auto" is now equivalent to just "serial" and will use the
SPCR to discover the port if present, otherwise defaults to "com0"
as before.

This allows to support MMIO ports specified by ACPI which is needed
on AWS EC2 "metal" instances, and will enable GRUB to pickup the
port configuration specified by ACPI in other cases.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoterm/ns8250: Add configuration parameter when adding ports
Benjamin Herrenschmidt [Fri, 23 Dec 2022 01:47:56 +0000 (12:47 +1100)] 
term/ns8250: Add configuration parameter when adding ports

This will allow ports to be added with a pre-set configuration.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoterm/ns8250: Move base clock definition to a header
Benjamin Herrenschmidt [Fri, 23 Dec 2022 01:47:55 +0000 (12:47 +1100)] 
term/ns8250: Move base clock definition to a header

And while at it, unify it as clock frequency in Hz, to match the value in
grub_serial_config struct and do the division by 16 in one common place.

This will simplify adding SPCR support.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoterm/ns8250: Add base support for MMIO UARTs
Benjamin Herrenschmidt [Fri, 23 Dec 2022 01:47:54 +0000 (12:47 +1100)] 
term/ns8250: Add base support for MMIO UARTs

This adds the ability for the driver to access UARTs via MMIO instead
of PIO selectively at runtime, and exposes a new function to add an
MMIO port.

In an ideal world, MMIO accessors would be generic and have architecture
specific memory barriers. However, existing drivers don't have them and
most of those "bare metal" drivers tend to be for x86 which doesn't need
them. If necessary, those can be added later.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoacpi: Add SPCR and generic address definitions
Benjamin Herrenschmidt [Fri, 23 Dec 2022 01:47:53 +0000 (12:47 +1100)] 
acpi: Add SPCR and generic address definitions

This adds the definition of the two ACPI tables according to the spec.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agokern/acpi: Export a generic grub_acpi_find_table()
Benjamin Herrenschmidt [Fri, 23 Dec 2022 01:47:52 +0000 (12:47 +1100)] 
kern/acpi: Export a generic grub_acpi_find_table()

And convert grub_acpi_find_fadt() to use it.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agokern/fs: Fix possible integer overflow in i386-pc mode with large partitions
Maxim Fomin [Wed, 28 Dec 2022 17:40:06 +0000 (17:40 +0000)] 
kern/fs: Fix possible integer overflow in i386-pc mode with large partitions

The i386-pc mode supports MBR partition scheme where maximum partition
size is 2 TiB. In case of large partitions left shift expression with
unsigned long int "length" object may cause integer overflow making
calculated partition size less than true value. This issue is fixed by
increasing the size of "length" integer type.

Signed-off-by: Maxim Fomin <maxim@fomin.one>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agocommands/cmp: Only return success when both files have the same contents
Glenn Washburn [Thu, 15 Dec 2022 18:13:30 +0000 (12:13 -0600)] 
commands/cmp: Only return success when both files have the same contents

This allows the cmp command to be used in GRUB scripts to conditionally
run commands based on whether two files are the same.

The command is now quiet by default and the -v switch can be given to enable
verbose mode, the previous behavior.

Update documentation accordingly.

Suggested-by: Li Gen <ligenlive@gmail.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodocs: Remove text about cryptodisk UUIDs no being able to use dashes
Glenn Washburn [Thu, 15 Dec 2022 18:04:39 +0000 (12:04 -0600)] 
docs: Remove text about cryptodisk UUIDs no being able to use dashes

This was fixed here: 3cf2e848bc (disk/cryptodisk: Allows UUIDs to be compared
in a dash-insensitive manner).

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotests/util/grub-shell: Add GRUB output logfile with grub-shell --debug
Glenn Washburn [Thu, 15 Dec 2022 16:45:46 +0000 (10:45 -0600)] 
tests/util/grub-shell: Add GRUB output logfile with grub-shell --debug

This allows seeing full QEMU output of grub-shell, which can be invaluable
when debugging failing tests.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotemplates/linux_xen: Fix detecting XSM policy
Marek Marczykowski-Górecki [Tue, 13 Dec 2022 04:12:35 +0000 (05:12 +0100)] 
templates/linux_xen: Fix detecting XSM policy

The xenpolicy variable was left set from previous function call. This
resulted in all-but-first menu entries including XSM policy, even if it
did not exist.

Fix this by initializing the xenpolicy variable.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Reject fonts with negative max_char_width or max_char_height
Zhang Boyang [Mon, 5 Dec 2022 11:29:38 +0000 (19:29 +0800)] 
font: Reject fonts with negative max_char_width or max_char_height

If max_char_width or max_char_height are negative wrong values can be propagated
by grub_font_get_max_char_width() or grub_font_get_max_char_height(). Prevent
this from happening.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Assign null_font to unknown_glyph
Zhang Boyang [Mon, 5 Dec 2022 11:29:37 +0000 (19:29 +0800)] 
font: Assign null_font to unknown_glyph

Like glyphs in ascii_font_glyph[], assign null_font to
unknown_glyph->font in order to prevent grub_font_get_*() from
dereferencing NULL pointer.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Check return value of grub_malloc() in ascii_glyph_lookup()
Zhang Boyang [Mon, 5 Dec 2022 11:29:36 +0000 (19:29 +0800)] 
font: Check return value of grub_malloc() in ascii_glyph_lookup()

There is a problem in ascii_glyph_lookup(). It doesn't check the return
value of grub_malloc(). If memory can't be allocated, then NULL pointer
will be written to.

This patch fixes the problem by fallbacking to unknown_glyph when
grub_malloc() returns NULL.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodisk/plainmount: Support plain encryption mode
Maxim Fomin [Wed, 28 Dec 2022 17:20:00 +0000 (17:20 +0000)] 
disk/plainmount: Support plain encryption mode

This patch adds support for plain encryption mode, plain dm-crypt, via
new module/command named "plainmount".

Signed-off-by: Maxim Fomin <maxim@fomin.one>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Glenn Washburn <development@efficientek.com>
2 years agoutil/grub-mkrescue: Search by file UUID rather than partition UUID for EFI boot
Pete Batard [Fri, 25 Nov 2022 17:22:17 +0000 (17:22 +0000)] 
util/grub-mkrescue: Search by file UUID rather than partition UUID for EFI boot

The final piece needed to add UEFI file system transposition support is to
ensure the boot media can be located regardless of how the boot partition
was instantiated. Especially, we do not want to be reliant on brittle
partition UUIDs, as these only work if a boot media is duplicated at the
block level and not at the file system level.

To accomplish this for EFI boot, we now create a UUID file in a .disk/
directory, that can then be searched for.

Note: The switch from make_image_fwdisk_abs() to make_image_abs() is
needed in order to use the search functionality.

Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/grub-mkrescue: Preserve a copy of the EFI bootloaders on the ISO 9660 file system
Pete Batard [Fri, 25 Nov 2022 17:22:16 +0000 (17:22 +0000)] 
util/grub-mkrescue: Preserve a copy of the EFI bootloaders on the ISO 9660 file system

To enable file system transposition support for UEFI, we also must ensure that
there exists a copy of the EFI bootloaders, that are currently embedded in the
efi.img for xorriso, at their expected UEFI location on the ISO 9660 file system.

This is accomplished by removing the use of a temporary directory to create the
efi/ content, to instead place it at the root of the ISO 9660 content.

Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/grub-mkrescue: Add support for FAT and NTFS on EFI boot
Pete Batard [Fri, 25 Nov 2022 17:22:15 +0000 (17:22 +0000)] 
util/grub-mkrescue: Add support for FAT and NTFS on EFI boot

In order to add file system transposition support for UEFI, i.e. the ability
to copy the content of an grub-mkrescue ISO 9660 image onto user-formatted
media, and have that boot on UEFI systems, the first thing we need to do is
add support for the file systems that are natively handled by UEFI. This
mandatorily includes FAT, but we also include NTFS as the latter is also
commonly supported on modern x64 platforms.

Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/bash-completion: Disable SC2120 shellcheck warning
t.feng [Tue, 6 Dec 2022 13:49:31 +0000 (21:49 +0800)] 
util/bash-completion: Disable SC2120 shellcheck warning

SC2120 (warning): function references arguments, but none are ever passed.

In grub-completion.bash.in line 63:
__grub_get_options_from_help () {
^-- SC2120 (warning)
     local prog

     if [ $# -ge 1 ]; then
         prog="$1"

The arg of __grub_get_options_from_help() is optional. So, the current
code meets the exception and does not need to be modified. Ignoring the
warning then.

More: https://github.com/koalaman/shellcheck/wiki/SC2120

Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/bash-completion: Fix SC2155 shellcheck warning
t.feng [Tue, 6 Dec 2022 13:49:30 +0000 (21:49 +0800)] 
util/bash-completion: Fix SC2155 shellcheck warning

SC2155 (warning): Declare and assign separately to avoid masking return values.

The exit status of the command is overridden by the exit status of the
creation of the local variable.

In grub-completion.bash.in line 115:
    local config_file=$(__grub_dir)/grub.cfg
          ^---------^ SC2155 (warning)

In grub-completion.bash.in line 126:
    local grub_dir=$(__grub_dir)
          ^------^ SC2155 (warning)

More: https://github.com/koalaman/shellcheck/wiki/SC2155

Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/bash-completion: Fix SC2207 shellcheck warning
t.feng [Tue, 6 Dec 2022 13:49:29 +0000 (21:49 +0800)] 
util/bash-completion: Fix SC2207 shellcheck warning

SC2207 (warning): Prefer mapfile or read -a to split
command output (or quote to avoid splitting).

In grub-completion.bash.in line 56:
        COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur"))
                   ^-- SC2207 (warning)

In grub-completion.bash.in line 119:
        COMPREPLY=( $(compgen \
                    ^-- SC2207 (warning)

In grub-completion.bash.in line 128:
    COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
                ^-- SC2207 (warning)

COMPREPLY=($(command)) are doing unquoted command expansion in an array.
This will invoke the shell's sloppy word splitting and glob expansion.

If we want to split the output into lines or words, use read -r and
loops will be better. This prevents the shell from doing unwanted
splitting and glob expansion, and therefore avoiding problems with
output containing spaces or special characters.

More: https://github.com/koalaman/shellcheck/wiki/SC2207

Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/bash-completion: Fix SC2070 shellcheck error
t.feng [Tue, 6 Dec 2022 13:49:28 +0000 (21:49 +0800)] 
util/bash-completion: Fix SC2070 shellcheck error

SC2070 (error): -n doesn't work with unquoted arguments.
Quote or use [[ ]].
In grub-completion.bash.in line 130:
             [ -n $tmp ] && {
                  ^--^ SC2070 (error)

More: https://github.com/koalaman/shellcheck/wiki/SC2070

Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agokern/file: Fix error handling in grub_file_open()
Steve McIntyre [Tue, 6 Dec 2022 01:45:11 +0000 (01:45 +0000)] 
kern/file: Fix error handling in grub_file_open()

grub_file_open() calls grub_file_get_device_name(), but doesn't check
the return. Instead, it checks if grub_errno is set.

However, nothing initialises grub_errno here when grub_file_open()
starts. This means that trying to open one file that doesn't exist and
then trying to open another file that does will (incorrectly) also
fail to open that second file.

Let's fix that.

Signed-off-by: Steve McIntyre <steve@einval.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoloader/i386/linux: Fix initrd maximum address overflow
Jeremy Szu [Sun, 4 Dec 2022 12:25:09 +0000 (20:25 +0800)] 
loader/i386/linux: Fix initrd maximum address overflow

The current i386 initrd is limited under 1 GiB memory and it works with
most compressed initrds (also initrd_addr_max case reported by kernel).

addr = (addr_max - aligned_size) & ~0xFFF;

Above line is used to calculate the reasonable address to store the initrd.

However, if initrd size is greater than 1 GiB or initrd_addr_max, then it
will get overflow, especially on x86_64 arch.

Therefore, add a check point to prevent it overflows as well as having
a debug log for complex story of initrd addresses.

Signed-off-by: Jeremy Szu <jeremy.szu@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotemplates: Enable fwsetup on EFI platforms only
Dimitri John Ledkov [Tue, 29 Nov 2022 22:13:27 +0000 (22:13 +0000)] 
templates: Enable fwsetup on EFI platforms only

Only perform call to fwsetup if one is on EFI platform. On all other
platforms fwsetup command does not exists, and thus returns 0 and
a useless uefi-firmware menu entry gets generated.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/xfs: Fix memory leaks in XFS module
t.feng [Tue, 29 Nov 2022 09:14:15 +0000 (17:14 +0800)] 
fs/xfs: Fix memory leaks in XFS module

Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/squash4: Fix memory leaks in grub_squash_iterate_dir()
t.feng [Tue, 29 Nov 2022 09:14:14 +0000 (17:14 +0800)] 
fs/squash4: Fix memory leaks in grub_squash_iterate_dir()

Fixes: 20dd511c8 (Handle "." and ".." on squashfs)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/iso9660: Fix memory leaks in grub_iso9660_susp_iterate()
t.feng [Tue, 29 Nov 2022 09:14:13 +0000 (17:14 +0800)] 
fs/iso9660: Fix memory leaks in grub_iso9660_susp_iterate()

Fixes: 99373ce47 (* grub-core/fs/iso9660.c: Remove nested functions)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/hfsplus: Fix memory leak in grub_hfsplus_btree_search()
t.feng [Tue, 29 Nov 2022 09:14:12 +0000 (17:14 +0800)] 
fs/hfsplus: Fix memory leak in grub_hfsplus_btree_search()

Fixes: 58ea11d5b (fs/hfsplus: Don't fetch a key beyond the end of the node)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/bfs: Fix memory leak in read_bfs_file()
t.feng [Tue, 29 Nov 2022 09:14:11 +0000 (17:14 +0800)] 
fs/bfs: Fix memory leak in read_bfs_file()

The l1_entries and l2_entries were not freed at the end of file read.

Fixes: 5825b3794 (BFS implementation based on the specification)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/ntfs: Fix memory leaks in grub_ntfs_read_symlink()
t.feng [Tue, 29 Nov 2022 09:14:10 +0000 (17:14 +0800)] 
fs/ntfs: Fix memory leaks in grub_ntfs_read_symlink()

Fixes: 5773fb641 (Support NTFS reparse points)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/minix: Fix memory leaks in grub_minix_lookup_symlink()
t.feng [Tue, 29 Nov 2022 09:14:09 +0000 (17:14 +0800)] 
fs/minix: Fix memory leaks in grub_minix_lookup_symlink()

Fixes: a07e6ad01 (* grub-core/fs/minix.c: Remove variable length arrays)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/btrfs: Fix memory leak in find_path()
t.feng [Tue, 29 Nov 2022 09:14:08 +0000 (17:14 +0800)] 
fs/btrfs: Fix memory leak in find_path()

Fixes: 82591fa6e (Make / in btrfs refer to real root)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/affs: Fix memory leaks in grub_affs_create_node()
t.feng [Tue, 29 Nov 2022 09:14:07 +0000 (17:14 +0800)] 
fs/affs: Fix memory leaks in grub_affs_create_node()

The hashtable is not freed if GRUB_AFFS_FILETYPE_HARDLINK and
grub_disk_read() failed. If grub_affs_create_node() returns non-zero
the hashtable should be freed too.

By the way, the hashtable argument is unused in grub_affs_create_node().
So, we can remove the argument and free it in grub_affs_iterate_dir().
It allocates the memory and it should be responsible for releasing it.

This is why commit ebf32bc4e9 (fs/affs: Fix resource leaks) missed
this memory leak.

Fixes: ebf32bc4e9 (fs/affs: Fix resource leaks)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agonormal/cmdline: Fix two related integer underflows
Ryan Cohen [Sat, 26 Nov 2022 22:22:52 +0000 (17:22 -0500)] 
normal/cmdline: Fix two related integer underflows

An unchecked decrement operation in cl_print() would cause a few
integers to underflow. Where an output terminal's state is stored in
cl_term, the values cl_term->ystart and cl_term->pos.y both underflow.

This can be replicated with the following steps:

1. Get to the GRUB command line
2. Hold down the "d" key (or any key that enters a visible character)
   until it fills the entire row
3. Press "HOME" and then press "CTRL-k". This will clear every
   character entered in step 2
4. Continuously press "CTRL-y" until the terminal scrolls the original
   prompt ("grub> ") passed the terminal's top row. Now, no prompt
   should be visible. This step causes cl_term->ystart to underflow
5. Press "HOME" and then "d" (or any visible character). This can have
   different visual effects for different systems, but it will always
   cause cl_term->pos.y to underflow

On BIOS systems, these underflows cause the output terminal to
completely stop displaying anything. Characters can still be
entered and commands can be run, but nothing will display on the
terminal. From here, you can only get the display working by running
a command to switch the current output terminal to a different type:

terminal_output <OTHER_TERMINAL>

On UEFI systems, these replication steps do not break the output
terminal. Until you press "ENTER", the cursor stops responding to input,
but you can press "ENTER" after step 5 and the command line will
work properly again. This patch is mostly important for BIOS systems
where the output terminal is rendered unusable after the underflows
occur.

This patch adds two checks, one for each variable. It ensures that
cl_term->ystart does not decrement passed 0. It also ensures that
cl_term->pos.y does not get set passed the terminal's bottom row.

When the previously listed replication steps are followed with this
patch, the terminal's cursor will be set to the top row and the command
line is still usable, even on BIOS systems.

Signed-off-by: Ryan Cohen <rcohenprogramming@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoterm/i386/pc/vga_text: Prevent out-of-bounds writes to VGA text buffer
Ryan Cohen [Sat, 26 Nov 2022 22:22:51 +0000 (17:22 -0500)] 
term/i386/pc/vga_text: Prevent out-of-bounds writes to VGA text buffer

Coordinates passed to screen_write_char() did not have any checks to
ensure they are not out-of-bounds. This adds an if statement to prevent
out-of-bounds writes to the VGA text buffer.

Signed-off-by: Ryan Cohen <rcohenprogramming@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoloader/linux: Ensure the newc pathname is NULL-terminated
Gary Lin [Fri, 25 Nov 2022 07:37:35 +0000 (15:37 +0800)] 
loader/linux: Ensure the newc pathname is NULL-terminated

Per "man 5 cpio", the namesize in the cpio header includes the trailing
NUL byte of the pathname and the pathname is followed by NUL bytes, but
the current implementation ignores the trailing NUL byte when making
the newc header. Although make_header() tries to pad the pathname string,
the padding won't happen when strlen(name) + sizeof(struct newc_head)
is a multiple of 4, and the non-NULL-terminated pathname may lead to
unexpected results.

Assume that a file is created with 'echo -n aaaa > /boot/test12' and
loaded by grub2:

    linux /boot/vmlinuz
    initrd newc:test12:/boot/test12 /boot/initrd

The initrd command eventually invoked grub_initrd_load() and sent
't''e''s''t''1''2' to make_header() to generate the header:

00000070  30 37 30 37 30 31 33 30  31 43 41 30 44 45 30 30  |070701301CA0DE00|
00000080  30 30 38 31 41 34 30 30  30 30 30 33 45 38 30 30  |0081A4000003E800|
00000090  30 30 30 30 36 34 30 30  30 30 30 30 30 31 36 33  |0000640000000163|
000000a0  37 36 45 34 35 32 30 30  30 30 30 30 30 34 30 30  |76E4520000000400|
000000b0  30 30 30 30 30 38 30 30  30 30 30 30 31 33 30 30  |0000080000001300|
000000c0  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
000000d0  30 30 30 30 30 36 30 30  30 30 30 30 30 30 74 65  |00000600000000te|
                                                                  ^namesize
000000e0  73 74 31 32 61 61 61 61  30 37 30 37 30 31 30 30  |st12aaaa07070100|
                   ^^ end of the pathname

Since strlen("test12") + sizeof(struct newc_head) is 116 = 29 * 4,
make_header() didn't pad the pathname, and the file content followed
"test12" immediately. This violates the cpio format and may trigger such
error during linux boot:

    Initramfs unpacking failed: ZSTD-compressed data is trunc

To avoid the potential problems, this commit counts the trailing NUL byte
in when calling make_header() and adjusts the initrd size accordingly.

Now the header becomes

00000070  30 37 30 37 30 31 33 30  31 43 41 30 44 45 30 30  |070701301CA0DE00|
00000080  30 30 38 31 41 34 30 30  30 30 30 33 45 38 30 30  |0081A4000003E800|
00000090  30 30 30 30 36 34 30 30  30 30 30 30 30 31 36 33  |0000640000000163|
000000a0  37 36 45 34 35 32 30 30  30 30 30 30 30 34 30 30  |76E4520000000400|
000000b0  30 30 30 30 30 38 30 30  30 30 30 30 31 33 30 30  |0000080000001300|
000000c0  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
000000d0  30 30 30 30 30 37 30 30  30 30 30 30 30 30 74 65  |00000700000000te|
                                                                  ^namesize
000000e0  73 74 31 32 00 00 00 00  61 61 61 61 30 37 30 37  |st12....aaaa0707|
                      ^^ end of the pathname

Besides the trailing NUL byte, make_header() pads 3 more NUL bytes, and
the user can safely read the pathname without a further check.

To conform to the cpio format, the headers for "TRAILER!!!" are also
adjusted to include the trailing NUL byte, not ignore it.

Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/udf: Validate length of AED in grub_udf_read_block()
Jagannathan Raman [Thu, 17 Nov 2022 00:17:52 +0000 (00:17 +0000)] 
fs/udf: Validate length of AED in grub_udf_read_block()

Validate the length of Allocation Extent Descriptor in grub_udf_read_block(),
based on the details in UDF spec. v2.01 section 2.3.11.

Fixes: CID 314037
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/grub-install: Ensure a functional /dev/nvram
Ismael Luceno [Mon, 5 Sep 2022 12:39:46 +0000 (14:39 +0200)] 
util/grub-install: Ensure a functional /dev/nvram

This enables an early failure; for i386-ieee1275 and powerpc-ieee1275 on
Linux, without /dev/nvram the system may be left in an unbootable state.

Signed-off-by: Ismael Luceno <iluceno@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotemplates: Set defaults using var substitution
Ismael Luceno [Wed, 24 Aug 2022 13:36:07 +0000 (15:36 +0200)] 
templates: Set defaults using var substitution

Signed-off-by: Ismael Luceno <iluceno@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotests: Put all generated files into working dir and use better file names
Glenn Washburn [Mon, 22 Aug 2022 23:19:02 +0000 (18:19 -0500)] 
tests: Put all generated files into working dir and use better file names

When running tests there are many invocations of grub-shell, and because
the output files are all random names in the same tmp directory, it
becomes more work to figure out which files went with which grub-shell
invocations. So all generated files from one invocation of grub-shell
are put into a randomly named directory, so as not to collide with other
grub-shell invocations. And now that the generated files can be put in
a location where they will not get stepped on, and they can be named
sensible names.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agonormal/charset: Fix an integer overflow in grub_unicode_aglomerate_comb()
Zhang Boyang [Fri, 28 Oct 2022 13:31:39 +0000 (21:31 +0800)] 
normal/charset: Fix an integer overflow in grub_unicode_aglomerate_comb()

The out->ncomb is a bit-field of 8 bits. So, the max possible value is 255.
However, code in grub_unicode_aglomerate_comb() doesn't check for an
overflow when incrementing out->ncomb. If out->ncomb is already 255,
after incrementing it will get 0 instead of 256, and cause illegal
memory access in subsequent processing.

This patch introduces GRUB_UNICODE_NCOMB_MAX to represent the max
acceptable value of ncomb. The code now checks for this limit and
ignores additional combining characters when limit is reached.

Reported-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Assign null_font to glyphs in ascii_font_glyph[]
Zhang Boyang [Fri, 28 Oct 2022 09:29:16 +0000 (17:29 +0800)] 
font: Assign null_font to glyphs in ascii_font_glyph[]

The calculations in blit_comb() need information from glyph's font, e.g.
grub_font_get_xheight(main_glyph->font). However, main_glyph->font is
NULL if main_glyph comes from ascii_font_glyph[]. Therefore
grub_font_get_*() crashes because of NULL pointer.

There is already a solution, the null_font. So, assign it to those glyphs
in ascii_font_glyph[].

Reported-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Harden grub_font_blit_glyph() and grub_font_blit_glyph_mirror()
Zhang Boyang [Sun, 23 Oct 2022 23:15:41 +0000 (07:15 +0800)] 
font: Harden grub_font_blit_glyph() and grub_font_blit_glyph_mirror()

As a mitigation and hardening measure add sanity checks to
grub_font_blit_glyph() and grub_font_blit_glyph_mirror(). This patch
makes these two functions do nothing if target blitting area isn't fully
contained in target bitmap. Therefore, if complex calculations in caller
overflows and malicious coordinates are given, we are still safe because
any coordinates which result in out-of-bound-write are rejected. However,
this patch only checks for invalid coordinates, and doesn't provide any
protection against invalid source glyph or destination glyph, e.g.
mismatch between glyph size and buffer size.

This hardening measure is designed to mitigate possible overflows in
blit_comb(). If overflow occurs, it may return invalid bounding box
during dry run and call grub_font_blit_glyph() with malicious
coordinates during actual blitting. However, we are still safe because
the scratch glyph itself is valid, although its size makes no sense, and
any invalid coordinates are rejected.

It would be better to call grub_fatal() if illegal parameter is detected.
However, doing this may end up in a dangerous recursion because grub_fatal()
would print messages to the screen and we are in the progress of drawing
characters on the screen.

Reported-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Fix an integer underflow in blit_comb()
Zhang Boyang [Mon, 24 Oct 2022 00:05:35 +0000 (08:05 +0800)] 
font: Fix an integer underflow in blit_comb()

The expression (ctx.bounds.height - combining_glyphs[i]->height) / 2 may
evaluate to a very big invalid value even if both ctx.bounds.height and
combining_glyphs[i]->height are small integers. For example, if
ctx.bounds.height is 10 and combining_glyphs[i]->height is 12, this
expression evaluates to 2147483647 (expected -1). This is because
coordinates are allowed to be negative but ctx.bounds.height is an
unsigned int. So, the subtraction operates on unsigned ints and
underflows to a very big value. The division makes things even worse.
The quotient is still an invalid value even if converted back to int.

This patch fixes the problem by casting ctx.bounds.height to int. As
a result the subtraction will operate on int and grub_uint16_t which
will be promoted to an int. So, the underflow will no longer happen. Other
uses of ctx.bounds.height (and ctx.bounds.width) are also casted to int,
to ensure coordinates are always calculated on signed integers.

Fixes: CVE-2022-3775
Reported-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofbutil: Fix integer overflow
Zhang Boyang [Mon, 5 Sep 2022 19:03:21 +0000 (03:03 +0800)] 
fbutil: Fix integer overflow

Expressions like u64 = u32 * u32 are unsafe because their products are
truncated to u32 even if left hand side is u64. This patch fixes all
problems like that one in fbutil.

To get right result not only left hand side have to be u64 but it's also
necessary to cast at least one of the operands of all leaf operators of
right hand side to u64, e.g. u64 = u32 * u32 + u32 * u32 should be
u64 = (u64)u32 * u32 + (u64)u32 * u32.

For 1-bit bitmaps grub_uint64_t have to be used. It's safe because any
combination of values in (grub_uint64_t)u32 * u32 + u32 expression will
not overflow grub_uint64_t.

Other expressions like ptr + u32 * u32 + u32 * u32 are also vulnerable.
They should be ptr + (grub_addr_t)u32 * u32 + (grub_addr_t)u32 * u32.

This patch also adds a comment to grub_video_fb_get_video_ptr() which
says it's arguments must be valid and no sanity check is performed
(like its siblings in grub-core/video/fb/fbutil.c).

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agokern/efi/sb: Enforce verification of font files
Zhang Boyang [Sun, 14 Aug 2022 07:51:54 +0000 (15:51 +0800)] 
kern/efi/sb: Enforce verification of font files

As a mitigation and hardening measure enforce verification of font
files. Then only trusted font files can be load. This will reduce the
attack surface at cost of losing the ability of end-users to customize
fonts if e.g. UEFI Secure Boot is enabled. Vendors can always customize
fonts because they have ability to pack fonts into their GRUB bundles.

This goal is achieved by:

  * Removing GRUB_FILE_TYPE_FONT from shim lock verifier's
    skip-verification list.

  * Adding GRUB_FILE_TYPE_FONT to lockdown verifier's defer-auth list,
    so font files must be verified by a verifier before they can be loaded.

Suggested-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Fix integer underflow in binary search of char index
Zhang Boyang [Sun, 14 Aug 2022 10:09:38 +0000 (18:09 +0800)] 
font: Fix integer underflow in binary search of char index

If search target is less than all entries in font->index then "hi"
variable is set to -1, which translates to SIZE_MAX and leads to errors.

This patch fixes the problem by replacing the entire binary search code
with the libstdc++'s std::lower_bound() implementation.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Fix integer overflow in BMP index
Zhang Boyang [Sun, 14 Aug 2022 18:04:58 +0000 (02:04 +0800)] 
font: Fix integer overflow in BMP index

The BMP index (font->bmp_idx) is designed as a reverse lookup table of
char entries (font->char_index), in order to speed up lookups for BMP
chars (i.e. code < 0x10000). The values in BMP index are the subscripts
of the corresponding char entries, stored in grub_uint16_t, while 0xffff
means not found.

This patch fixes the problem of large subscript truncated to grub_uint16_t,
leading BMP index to return wrong char entry or report false miss. The
code now checks for bounds and uses BMP index as a hint, and fallbacks
to binary-search if necessary.

On the occasion add a comment about BMP index is initialized to 0xffff.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Fix integer overflow in ensure_comb_space()
Zhang Boyang [Thu, 4 Aug 2022 18:27:05 +0000 (02:27 +0800)] 
font: Fix integer overflow in ensure_comb_space()

In fact it can't overflow at all because glyph_id->ncomb is only 8-bit
wide. But let's keep safe if somebody changes the width of glyph_id->ncomb
in the future. This patch also fixes the inconsistency between
render_max_comb_glyphs and render_combining_glyphs when grub_malloc()
returns NULL.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Remove grub_font_dup_glyph()
Zhang Boyang [Thu, 4 Aug 2022 18:13:29 +0000 (02:13 +0800)] 
font: Remove grub_font_dup_glyph()

Remove grub_font_dup_glyph() since nobody is using it since 2013, and
I'm too lazy to fix the integer overflow problem in it.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Fix several integer overflows in grub_font_construct_glyph()
Zhang Boyang [Thu, 4 Aug 2022 17:58:27 +0000 (01:58 +0800)] 
font: Fix several integer overflows in grub_font_construct_glyph()

This patch fixes several integer overflows in grub_font_construct_glyph().
Glyphs of invalid size, zero or leading to an overflow, are rejected.
The inconsistency between "glyph" and "max_glyph_size" when grub_malloc()
returns NULL is fixed too.

Fixes: CVE-2022-2601
Reported-by: Zhang Boyang <zhangboyang.id@gmail.com>
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Fix size overflow in grub_font_get_glyph_internal()
Zhang Boyang [Thu, 4 Aug 2022 16:51:20 +0000 (00:51 +0800)] 
font: Fix size overflow in grub_font_get_glyph_internal()

The length of memory allocation and file read may overflow. This patch
fixes the problem by using safemath macros.

There is a lot of code repetition like "(x * y + 7) / 8". It is unsafe
if overflow happens. This patch introduces grub_video_bitmap_calc_1bpp_bufsz().
It is safe replacement for such code. It has safemath-like prototype.

This patch also introduces grub_cast(value, pointer), it casts value to
typeof(*pointer) then store the value to *pointer. It returns true when
overflow occurs or false if there is no overflow. The semantics of arguments
and return value are designed to be consistent with other safemath macros.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofont: Reject glyphs exceeds font->max_glyph_width or font->max_glyph_height
Zhang Boyang [Wed, 3 Aug 2022 11:45:33 +0000 (19:45 +0800)] 
font: Reject glyphs exceeds font->max_glyph_width or font->max_glyph_height

Check glyph's width and height against limits specified in font's
metadata. Reject the glyph (and font) if such limits are exceeded.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoloader/multiboot_elfxx: Fix memory leak
t.feng [Thu, 10 Nov 2022 07:01:15 +0000 (15:01 +0800)] 
loader/multiboot_elfxx: Fix memory leak

The commit eb33e61b3 (multiboot: fix memory leak) did not fix all
issues. Fix all of them right now.

Fixes: eb33e61b3 (multiboot: fix memory leak)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodocs: Correct GRUB_DISABLE_LINUX_PARTUUID documentation
Damian Szuberski [Mon, 14 Nov 2022 19:00:56 +0000 (20:00 +0100)] 
docs: Correct GRUB_DISABLE_LINUX_PARTUUID documentation

Signed-off-by: szubersk <szuberskidamian@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoosdep/unix/getroot: Pass -P to zpool status
Arsen Arsenović [Mon, 7 Nov 2022 23:22:36 +0000 (00:22 +0100)] 
osdep/unix/getroot: Pass -P to zpool status

zpool status by default prints basenames of VDEVs, which means that GRUB
would have to go around guessing to see whether a VDEV exists. Instead,
it'd be more robust to simply tell zpool to give us full paths to VDEVs
via -P.

Signed-off-by: Arsen Arsenović <arsen@aarsen.me>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agonormal/help: Add paging instructions to normal and help prompts
Robbie Harwood [Fri, 4 Nov 2022 17:05:37 +0000 (13:05 -0400)] 
normal/help: Add paging instructions to normal and help prompts

This is not an ideal solution, as interactive users must always run
a command in order to get the behavior they want, but it avoids
problematic interactions between prompting and sourcing files.

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agocommands/tpm: Don't propagate measurement failures to the verifiers layer
Robbie Harwood [Fri, 4 Nov 2022 16:13:36 +0000 (12:13 -0400)] 
commands/tpm: Don't propagate measurement failures to the verifiers layer

Currently if an EFI firmware fails to do a TPM measurement for a file,
the error will be propagated to the verifiers framework which will
prevent it to be opened. This mean that buggy firmwares will lead to
the system not booting because files won't be allowed to be loaded. But
a failure to do a TPM measurement isn't expected to be a fatal error
that causes the system to be unbootable.

To avoid this, don't return errors from .write and .verify_string
callbacks and just print a debug message in the case of a TPM
measurement failure. Add an environment variable, tpm_fail_fatal, to
restore the previous behavior.

Also-authored-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agokern/env: Add function for retrieving variables as booleans
Robbie Harwood [Fri, 4 Nov 2022 16:13:35 +0000 (12:13 -0400)] 
kern/env: Add function for retrieving variables as booleans

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotypes: Make bool generally available
Robbie Harwood [Fri, 4 Nov 2022 16:13:34 +0000 (12:13 -0400)] 
types: Make bool generally available

Add an include on stdbool.h, making the bool type generally available
within the GRUB without needing to add a file-specific include every
time it would be used.

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoloader: Add support for grub-emu to kexec Linux menu entries
Raymund Will [Mon, 24 Oct 2022 18:33:50 +0000 (14:33 -0400)] 
loader: Add support for grub-emu to kexec Linux menu entries

The GRUB emulator is used as a debugging utility but it could also be
used as a user-space bootloader if there is support to boot an operating
system.

The Linux kernel is already able to (re)boot another kernel via the
kexec boot mechanism. So the grub-emu tool could rely on this feature
and have linux and initrd commands that are used to pass a kernel,
initramfs image and command line parameters to kexec for booting
a selected menu entry.

By default the systemctl kexec option is used so systemd can shutdown
all of the running services before doing a reboot using kexec. But if
this is not present, it can fall back to executing the kexec user-space
tool directly. The ability to force a kexec-reboot when systemctl kexec
fails must only be used in controlled environments to avoid possible
filesystem corruption and data loss.

Signed-off-by: Raymund Will <rw@suse.com>
Signed-off-by: John Jolly <jjolly@suse.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotemplates: Introduce GRUB_TOP_LEVEL_* vars
Denton Liu [Mon, 24 Oct 2022 10:46:42 +0000 (03:46 -0700)] 
templates: Introduce GRUB_TOP_LEVEL_* vars

A user may wish to use an image that is not sorted as the "latest"
version as the top-level entry. For example, in Arch Linux, if a user
has the LTS and regular kernels installed, "/boot/vmlinuz-linux-lts"
gets sorted as the "latest" compared to "/boot/vmlinuz-linux", meaning
the LTS kernel becomes the top-level entry. However, a user may wish to
use the regular kernel as the top-level default with the LTS only
existing as a backup.

This need can be seen in Arch Linux's AUR with two user-submitted
packages[0][1] providing an update hook which patches /etc/grub.d/10_linux
to move the desired kernel to the top-level. This patch serves to solve
this in a more generic way.

Introduce the GRUB_TOP_LEVEL, GRUB_TOP_LEVEL_XEN and GRUB_TOP_LEVEL_OS_PROBER
variables to allow users to specify the top-level entry.

Create grub_move_to_front() as a helper function which moves entries to
the front of a list. This function does the heavy lifting of moving
the menu entry to the front in each script.

In 10_netbsd, since there isn't an explicit list variable, extract the
items that are being iterated through into a list so that we can
optionally apply grub_move_to_front() to the list before the loop.

[0]: https://aur.archlinux.org/packages/grub-linux-default-hook
[1]: https://aur.archlinux.org/packages/grub-linux-rt-default-hook

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Reviewed-by: Oskari Pirhonen <xxc3ncoredxx@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agovideo/readers: Add artificial limit to image dimensions
Alec Brown [Thu, 27 Oct 2022 00:16:44 +0000 (20:16 -0400)] 
video/readers: Add artificial limit to image dimensions

In grub-core/video/readers/jpeg.c, the height and width of a JPEG image don't
have an upper limit for how big the JPEG image can be. In Coverity, this is
getting flagged as an untrusted loop bound. This issue can also seen in PNG and
TGA format images as well but Coverity isn't flagging it. To prevent this, the
constant IMAGE_HW_MAX_PX is being added to include/grub/bitmap.h, which has
a value of 16384, to act as an artificial limit and restrict the height and
width of images. This value was picked as it is double the current max
resolution size, which is 8K.

Fixes: CID 292450
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodisk/diskfilter: Don't make a RAID array with more than 1024 disks
Daniel Axtens [Wed, 19 Oct 2022 09:23:22 +0000 (20:23 +1100)] 
disk/diskfilter: Don't make a RAID array with more than 1024 disks

This is "belt and braces" with commit 12e20a6a695f (disk/diskfilter:
Check calloc() result for NULL): we end up trying to use too much memory
in situations like corrupted Linux software RAID setups purporting to
use a huge number of disks. Simply refuse to permit such configurations.

1024 is a bit arbitrary, yes, and I feel a bit like I'm tempting fate
here, but I think 1024 disks in an array (that GRUB has to read to boot!)
should be enough for anyone.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoarm64/efi/linux: Ignore FDT unless we need to modify it
Ard Biesheuvel [Tue, 18 Oct 2022 19:05:07 +0000 (21:05 +0200)] 
arm64/efi/linux: Ignore FDT unless we need to modify it

Now that we implemented support for the LoadFile2 protocol for initrd
loading, there is no longer a need to pass the initrd parameters via
the device tree. This means that when the LoadFile2 protocol is being
used, there is no reason to update the device tree in the first place,
and so we can ignore it entirely.

The only remaining reason to deal with the devicetree is if we are
using the "devicetree" command to load one from disk, so tweak the
logic in grub_fdt_install() to take that into account.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoarm64/efi/linux: Implement LoadFile2 initrd loading protocol for Linux
Ard Biesheuvel [Tue, 18 Oct 2022 19:05:06 +0000 (21:05 +0200)] 
arm64/efi/linux: Implement LoadFile2 initrd loading protocol for Linux

Recent Linux kernels will invoke the LoadFile2 protocol installed on
a well-known vendor media path to load the initrd if it is exposed by
the firmware. Using this method is preferred for two reasons:
  - the Linux kernel is in charge of allocating the memory, and so it can
    implement any placement policy it wants (given that these tend to
    change between kernel versions),
  - it is no longer necessary to modify the device tree provided by the
    firmware.

So let's install this protocol when handling the "initrd" command if
such a recent kernel was detected (based on the PE/COFF image version),
and defer loading the initrd contents until the point where the kernel
invokes the LoadFile2 protocol.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoefi/efinet: Don't close connections at fini_hw() time
Ard Biesheuvel [Tue, 18 Oct 2022 19:05:05 +0000 (21:05 +0200)] 
efi/efinet: Don't close connections at fini_hw() time

When GRUB runs on top of EFI firmware, it only has access to block and
network device abstractions exposed by the firmware, and it is up to the
firmware to quiesce the underlying hardware when exiting boot services
and handing over to the OS.

This is especially important for network devices, to prevent incoming
packets from being DMA'd straight into memory after the OS has taken
over but before it has managed to reconfigure the network hardware.

GRUB handles this by means of the grub_net_fini_hw() preboot hook, which
is executed before calling into the booted image. This means that all
network devices disappear or become inoperable before the EFI stub
executes on EFI targeted builds. This is problematic as it prevents the
EFI stub from calling back into GRUB provided protocols such as
LoadFile2 for the initrd, which we will provide in a subsequent patch.

So add a flag that indicates to the network core that EFI network
devices should not be closed when grub_net_fini_hw() is called.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoloader/arm64/linux: Account for COFF headers appearing at unexpected offsets
Ard Biesheuvel [Tue, 18 Oct 2022 19:05:04 +0000 (21:05 +0200)] 
loader/arm64/linux: Account for COFF headers appearing at unexpected offsets

The way we load the Linux and PE/COFF image headers depends on a fixed
placement of the COFF header at offset 0x40 into the file. This is
a reasonable default, given that this is where Linux emits it today.
However, in order to comply with the PE/COFF spec, which allows this
header to appear anywhere in the file, let's ensure that we read the
header from where it actually appears in the file if it is not located
at offset 0x40.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoarm/linux: Unify ARM/arm64 vs Xen PE/COFF header handling
Ard Biesheuvel [Tue, 18 Oct 2022 19:05:03 +0000 (21:05 +0200)] 
arm/linux: Unify ARM/arm64 vs Xen PE/COFF header handling

Xen has its own version of the image header, to account for the
additional PE/COFF header fields. Since we are adding references to
those in the shared EFI loader code, update the common definitions
and drop the Xen specific one which no longer has a purpose.

Since in both cases, the call to grub_arch_efi_linux_check_image() is
preceded by a load of the image header, let's move the load into that
function, and rename it to grub_arch_efi_linux_load_image_header().

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoefi: Move MS-DOS stub out of generic PE header definition
Ard Biesheuvel [Tue, 18 Oct 2022 19:05:02 +0000 (21:05 +0200)] 
efi: Move MS-DOS stub out of generic PE header definition

The PE/COFF spec permits the COFF signature and file header to appear
anywhere in the file, and the actual offset is recorded in 4 byte
little endian field at offset 0x3c of the image.

When GRUB is emitted as a PE/COFF binary, we reuse the 128 byte MS-DOS
stub (even for non-x86 architectures), putting the COFF signature and
file header at offset 0x80. However, other PE/COFF images may use
different values, and non-x86 Linux kernels use an offset of 0x40
instead.

So let's get rid of the grub_pe32_header struct from pe32.h, given that
it does not represent anything defined by the PE/COFF spec. Instead,
introduce a minimal struct grub_msdos_image_header type based on the
PE/COFF spec's description of the image header, and use the offset
recorded at file position 0x3c to discover the actual location of the PE
signature and the COFF image header.

The remaining fields are moved into a struct grub_pe_image_header,
which we will use later to access COFF header fields of arbitrary
images (and which may therefore appear at different offsets)

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agokern/buffer: Handle NULL input pointer in grub_buffer_free()
Jagannathan Raman [Mon, 17 Oct 2022 14:04:39 +0000 (14:04 +0000)] 
kern/buffer: Handle NULL input pointer in grub_buffer_free()

The grub_buffer_free() should handle NULL input pointer, similar to
grub_free(). If the pointer is not referencing any memory location,
grub_buffer_free() need not perform any function.

Fixes: CID 396931
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/zfs/zfs: Update dangling dn_new pointer in dnode_get_path()
Jagannathan Raman [Mon, 17 Oct 2022 14:04:38 +0000 (14:04 +0000)] 
fs/zfs/zfs: Update dangling dn_new pointer in dnode_get_path()

The dnode_get_path() traverses dnode structures to locate the dnode leaf
of a given path. When the leaf is a symlink to another path, it restarts
the traversal either from root or from a different path. In such cases,
dn_new must be re-initialized

Passes "make check".

Fixes: CID 86750
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agobuild: Update to reflect minimum clang version 8.0
Darren Kenny [Fri, 21 Oct 2022 13:33:01 +0000 (13:33 +0000)] 
build: Update to reflect minimum clang version 8.0

After doing some validation with clang from versions 3.8 and up, the
builds prior to version 8.0.0 fail due to the use of safemath functions
at link time.

Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoconfigure: Fix building with clang
Darren Kenny [Fri, 21 Oct 2022 13:33:00 +0000 (13:33 +0000)] 
configure: Fix building with clang

Building the current code with clang and the latest gnulib fails due to
the use of a variable-length-array (vla) warning, which turns in to an
error due to the presence of the -Werror during the build.

The gnulib team stated that their code should not be built with -Werror.

At present, the only way to do this is for the complete code-base, by
using the --disable-werror option to configure.

Rather than doing this, and failing to gain any benefit that it provides,
instead, if building with clang, this patch makes it possible to specifically
not error on vlas, while retaining the -Werror functionality otherwise.

Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agognulib: Provide abort() implementation for gnulib
Darren Kenny [Fri, 21 Oct 2022 13:32:59 +0000 (13:32 +0000)] 
gnulib: Provide abort() implementation for gnulib

The recent gnulib updates require an implementation of abort(), but the
current macro provided by changeset:

  cd37d3d3916c gnulib: Drop no-abort.patch

to config.h.in does not work with the clang compiler since it doesn't
provide a __builtin_trap() implementation, so this element of the
changeset needs to be reverted, and replaced.

After some discussion with Vladimir 'phcoder' Serbinenko and Daniel Kiper
it was suggested to bring back in the change from the changeset:

  db7337a3d353 * grub-core/gnulib/regcomp.c (regerror): ...

Which implements abort() as an inline call to grub_abort(), but since
that was made static by changeset:

  a8f15bceeafe * grub-core/kern/misc.c (grub_abort): Make static

it is also necessary to revert the specific part that makes it a static
function too.

Another implementation of abort() was found in grub-core/kern/compiler-rt.c
which needs to also be removed to be consistent.

Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodisk/cryptodisk: Fix unintentional integer overflow
Alec Brown [Fri, 14 Oct 2022 21:47:08 +0000 (17:47 -0400)] 
disk/cryptodisk: Fix unintentional integer overflow

In the function grub_cryptodisk_endecrypt(), a for loop is incrementing the
variable i by (1U << log_sector_size). The variable i is of type grub_size_t
which is a 64-bit unsigned integer on x86_64 architecture. On the other hand, 1U
is a 32-bit unsigned integer. By performing a left shift on a 32-bit value and
assigning it to a 64-bit variable, the 64-bit variable may have incorrect values
in the high 32-bits if the shift has an overflow. To avoid this, we replace 1U
with (grub_size_t)1.

Fixes: CID 307788
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agomm: Try invalidate disk caches last when out of memory
Zhang Boyang [Sat, 15 Oct 2022 14:15:11 +0000 (22:15 +0800)] 
mm: Try invalidate disk caches last when out of memory

Every heap grow will cause all disk caches invalidated which decreases
performance severely. This patch moves disk cache invalidation code to
the last of memory squeezing measures. So, disk caches are released only
when there are no other ways to get free memory.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
2 years agoutil/grub-mkfont: Use valid conversion specifiers in printf() and fprintf()
Qiumiao Zhang [Tue, 11 Oct 2022 12:31:02 +0000 (20:31 +0800)] 
util/grub-mkfont: Use valid conversion specifiers in printf() and fprintf()

For printf()/fprintf() functions, unsigned integers should use %u as the
valid conversion specifier instead of %d.

Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoefi: Compile kernel.img with -fshort-wchar on all EFI targets
Chris Coulson [Tue, 11 Oct 2022 12:26:33 +0000 (13:26 +0100)] 
efi: Compile kernel.img with -fshort-wchar on all EFI targets

The stack check logs a console message on failure, and the EFI API expects
a NULL terminated UCS-2 string. In order to define a UCS-2 string literal,
kernel.img on amd64 and i386 EFI targets is built with -fshort-wchar.

Also compile kernel.img on other EFI targets with -fshort-wchar.

Fixes: 37ddd94 (kern/efi/init: Log a console error during a stack check failure)
Reported-by: Glenn Washburn <development@efficientek.com>
Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agonormal/menu: Add Ctrl-L to refresh the menu
Benjamin Herrenschmidt [Fri, 7 Oct 2022 02:35:59 +0000 (13:35 +1100)] 
normal/menu: Add Ctrl-L to refresh the menu

This is useful on cloud instances with remote serial ports as it can be
difficult to connect "fast enough" to get the initial menu display

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/grub-install: Set point of no return for powerpc-ieee1275 install
Michael Chang [Thu, 25 Aug 2022 06:05:01 +0000 (14:05 +0800)] 
util/grub-install: Set point of no return for powerpc-ieee1275 install

The point of no return is used to define a point where no change should
be reverted in a wake of fatal error that consequently aborts the
process. The powerpc-ieee1275 install apparently missed this point of no
return definition that newly installed modules could be inadvertently
reverted after successful image embedding so that boot failure is
incurred due to inconsistent state.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodisk/diskfilter: Check calloc() result for NULL
Daniel Axtens [Sun, 21 Aug 2022 12:22:35 +0000 (22:22 +1000)] 
disk/diskfilter: Check calloc() result for NULL

With wildly corrupt inputs, we can end up trying to calloc a very
large amount of memory, which will fail and give us a NULL pointer.
We need to check that to avoid a crash. (And, even if we blocked
such inputs, it is good practice to check the results of allocations
anyway.)

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodisk/cryptodisk: Allows UUIDs to be compared in a dash-insensitive manner
Glenn Washburn [Fri, 19 Aug 2022 23:06:15 +0000 (18:06 -0500)] 
disk/cryptodisk: Allows UUIDs to be compared in a dash-insensitive manner

A user can now specify UUID strings with dashes, instead of having to remove
dashes. This is backwards-compatibility preserving and also fixes a source
of user confusion over the inconsistency with how UUIDs are specified
between file system UUIDs and cryptomount UUIDs. Since cryptsetup, the
reference implementation for LUKS, displays and generates UUIDs with dashes
there has been additional confusion when using the UUID strings from
cryptsetup as exact input into GRUB does not find the expected cryptodisk.

A new function grub_uuidcasecmp() is added that is general enough to be used
other places where UUIDs are being compared.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agokern/corecmd: Quote variable values when displayed by the set command
Glenn Washburn [Fri, 26 Aug 2022 00:53:51 +0000 (19:53 -0500)] 
kern/corecmd: Quote variable values when displayed by the set command

Variable values may contain spaces at the end or newlines. However, when
displayed without quotes this is not obvious and can lead to confusion as
to the actual contents of variables. Also for some variables grub_env_get()
returns a NULL pointer instead of a pointer to an empty string and
previously would be printed as "var=(null)". Now such variables will be
displayed as "var=''".

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotemplates: Add support for acpi on Hurd
Samuel Thibault [Mon, 26 Sep 2022 19:51:32 +0000 (21:51 +0200)] 
templates: Add support for acpi on Hurd

This adds acpi as bootstrap module whenever it is available. This opens the
path for proper IRQ routing for fully-userland disk drivers.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoutil/grub-module-verifierXX: Enable running standalone checkers
Peter Jones [Wed, 5 Oct 2022 13:48:37 +0000 (09:48 -0400)] 
util/grub-module-verifierXX: Enable running standalone checkers

Allow treating util/grub-module-verifierXX.c as a file you can build
directly so syntax checkers like vim's "syntastic" plugin, which uses
"gcc -x c -fsyntax-only" to build it, will work.

One still has to do whatever setup is required to make it pick the
right include dirs, which -I options we use, etc., but this makes
it so you can do the checking on the file you're editing, rather
than on a different file.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agokern/compiler-rt: Fix __clzsi2() logic
Tuan Phan [Mon, 3 Oct 2022 18:29:21 +0000 (11:29 -0700)] 
kern/compiler-rt: Fix __clzsi2() logic

Fix the incorrect return value of __clzsi2() function.

Fixes: e795b90 (RISC-V: Add libgcc helpers for clz)
Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoefi: Increase default memory allocation to 32 MiB
Daniel Axtens [Mon, 19 Sep 2022 14:30:30 +0000 (00:30 +1000)] 
efi: Increase default memory allocation to 32 MiB

We have multiple reports of things being slower with a 1 MiB initial static
allocation, and a report (more difficult to nail down) of a boot failure
as a result of the smaller initial allocation.

Make the initial memory allocation 32 MiB.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotemplates: Filter C.UTF-8 locale for translation
Christian Hesse [Mon, 19 Sep 2022 13:31:28 +0000 (15:31 +0200)] 
templates: Filter C.UTF-8 locale for translation

In addition to C locale there is also C.UTF-8 locale now. Filter that as
well, by using ${grub_lang}, which contains a stripped value.
This fixes the following message and resulting boot failure:

    error: file `/boot/grub/locale/C.gmo' not found.

Signed-off-by: Christian Hesse <mail@eworm.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agotests: Explicitly unset SOURCE_DATE_EPOCH before running fs tests
Steve McIntyre [Sun, 18 Sep 2022 22:12:02 +0000 (23:12 +0100)] 
tests: Explicitly unset SOURCE_DATE_EPOCH before running fs tests

In some filesystem utils like mksquashfs, they will silently change
behaviour and cause timestamps to unexpectedly change. Build
environments like Debian's set SOURCE_DATE_EPOCH in the environment,
so remove it. Reproducible builds are good and useful for shipped
artifacts, but this causes build-time tests to fail.

Signed-off-by: Steve McIntyre <steve@einval.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agocommands/efi/lsefisystab: Short text for EFI_CONFORMANCE_PROFILES_TABLE
Heinrich Schuchardt [Fri, 2 Sep 2022 12:58:45 +0000 (14:58 +0200)] 
commands/efi/lsefisystab: Short text for EFI_CONFORMANCE_PROFILES_TABLE

The EFI_CONFORMANCE_PROFILES_TABLE_GUID is used for a table of GUIDs for conformance
profiles (cf. UEFI specification 2.10, 4.6.5 EFI_CONFORMANCE_PROFILE_TABLE).

The lsefisystab command is used to display installed EFI configuration tables.
Currently it only shows the GUID but not a short text for the table.

Provide a short text for the EFI_CONFORMANCE_PROFILES_TABLE_GUID.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agofs/ext2: Ignore the large_dir incompat feature
Theodore Ts'o [Wed, 31 Aug 2022 02:41:59 +0000 (22:41 -0400)] 
fs/ext2: Ignore the large_dir incompat feature

Recently, ext4 added the large_dir feature, which adds support for
a 3 level htree directory support.

The GRUB supports existing file systems with htree directories by
ignoring their existence, and since the index nodes for the hash tree
look like deleted directory entries (by design), the GRUB can simply do
a brute force O(n) linear search of directories. The same is true for
3 level deep htrees indicated by large_dir feature flag.

Hence, it is safe for the GRUB to ignore the large_dir incompat feature.

Fixes: https://savannah.gnu.org/bugs/?61606
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodisk/loopback: Support transparent decompression of backing file
Glenn Washburn [Fri, 26 Aug 2022 04:08:57 +0000 (23:08 -0500)] 
disk/loopback: Support transparent decompression of backing file

A new option is added to the loopback command, -D or --decompress, which
when specified transparently decompresses the backing file. This allows
compressed images to be used as if they were uncompressed.

Add documentation to support this change.

Suggested-by: Li Gen <ligenlive@gmail.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoconfigure: Add -DGRUB_HAS_PCI when compiling C/C++ files on targets that support PCI
Glenn Washburn [Fri, 26 Aug 2022 03:52:26 +0000 (22:52 -0500)] 
configure: Add -DGRUB_HAS_PCI when compiling C/C++ files on targets that support PCI

The list of targets that support PCI is in gentpl.py. However, there is no
support for generating makefile script from a .def file that will apply
globally to the makefile, but on a per target basis. So instead, use
gentpl.py in configure to get the list of targets and check if the current
build target is one of them. If it is, set the automake conditional
COND_HAVE_PCI. Then in conf/Makefile.common add -DGRUB_HAS_PCI for the
platform if COND_HAVE_PCI is true.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agocommands/read: Fix overflow in grub_getline()
Li Gen [Fri, 26 Aug 2022 00:59:09 +0000 (19:59 -0500)] 
commands/read: Fix overflow in grub_getline()

Store returned value from grub_getkey() in int instead of char to
prevent throwing away the extended bits. This was a problem because,
for instance, the left arrow key press would return
(GRUB_TERM_EXTENDED | 0x4b), which would have the GRUB_TERM_EXTENDED
thrown away leaving 0x4b or 'K'. These extended keys should either
work as intended or do nothing. This change has them do nothing,
instead of inserting a key not pressed by the user.

Signed-off-by: Li Gen <ligenlive@gmail.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoefi: Correct function prototype for register_key_notify() method of grub_efi_simple_t...
Li Gen [Thu, 25 Aug 2022 05:12:17 +0000 (00:12 -0500)] 
efi: Correct function prototype for register_key_notify() method of grub_efi_simple_text_input_ex_interface

The register_key_notify() method should have an output parameter which is
a pointer to the unique handle assigned to the registered notification.

Signed-off-by: Li Gen <ligenlive@gmail.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agonet/drivers/ieee1275/ofnet: Fix incorrect netmask
Masahiro Matsuya [Wed, 24 Aug 2022 17:36:37 +0000 (13:36 -0400)] 
net/drivers/ieee1275/ofnet: Fix incorrect netmask

The netmask configured in firmware is not respected on ppc64 (big endian).
When 255.255.252.0 is set as netmask in firmware, the following is the
value of bootpath string in grub_ieee1275_parse_bootpath():

  /vdevice/l-lan@30000002:speed=auto,duplex=auto,192.168.88.10,,192.168.89.113,192.168.88.1,5,5,255.255.252.0,512

The netmask in this bootpath is not a problem, since it's a value specified
in firmware. But the value of subnet_mask.ipv4 was set with 0xfffffc00, and
__builtin_ctz(~grub_le_to_cpu32(subnet_mask.ipv4)) returned 16 (not 22).
As a result, 16 was used for netmask wrongly:

  1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4(=0xfffffc00)
  0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32(subnet_mask.ipv4)
  1111 1111 0000 0011 0000 0000 0000 0000 # ~grub_le_to_cpu32(subnet_mask.ipv4)

and the count of zero with __builtin_ctz() can be 16. This patch changes
it as below:

  1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4(=0xfffffc00)
  0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32(subnet_mask.ipv4)
  1111 1111 1111 1111 1111 1100 0000 0000 # grub_be_to_cpu32(subnet_mask.ipv4)
  0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_be_to_cpu32(subnet_mask.ipv4)

The count of zero with __builtin_clz() can be 22 (clz counts the number
of one bits preceding the most significant zero bit).

Signed-off-by: Masahiro Matsuya <mmatsuya@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agoloader/i386/bsd: Initialize BSD relocator state variables
Ross Philipson [Wed, 24 Aug 2022 14:47:02 +0000 (10:47 -0400)] 
loader/i386/bsd: Initialize BSD relocator state variables

Numerous register fields in the relocator state are simply not
used depending on the relocator. This causes Coverity to flag
these fields but there is no real bug here. Simply initializing
the variable to {0} solves the issue. Fixed in the else case too
for consistency.

Fixes: CID 396932
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2 years agodocs: Add a link to environment variables
Andrea G. Monaco [Sat, 9 Jan 2021 18:30:34 +0000 (19:30 +0100)] 
docs: Add a link to environment variables

This is trivial, but it might save some time to beginners.

Signed-off-by: Andrea G. Monaco <andrea.monaco@autistici.org>
Reviewed-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>