]> git.ipfire.org Git - thirdparty/grub.git/log
thirdparty/grub.git
3 years agoutil/probe: Remove unused header includes
Glenn Washburn [Thu, 12 May 2022 03:19:47 +0000 (22:19 -0500)] 
util/probe: Remove unused header includes

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocommands/macbless: Remove whitespace between N_ macro and open parenthesis
Glenn Washburn [Thu, 12 May 2022 03:19:46 +0000 (22:19 -0500)] 
commands/macbless: Remove whitespace between N_ macro and open parenthesis

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotests: Add /sbin and /usr/sbin to path in partmap test
Glenn Washburn [Thu, 12 May 2022 03:19:45 +0000 (22:19 -0500)] 
tests: Add /sbin and /usr/sbin to path in partmap test

The partmap test requires no elevated privileges. However, it uses parted
which can be used as a normal user, but is usually located in /sbin or
/usr/bin (eg. on Debian systems). Whereas the normal user does not usually
have /sbin or /usr/sbin added to their path, thus parted will not be found
causing the test to abort. Add /sbin and /usr/sbin to the path for the
partmap test so that the test can run successfully as an unprivileged user.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotests: Show host determined fs UUID when hfs UUID test fails
Glenn Washburn [Thu, 12 May 2022 03:19:44 +0000 (22:19 -0500)] 
tests: Show host determined fs UUID when hfs UUID test fails

On failure, the hfs test should show both the host and GRUB determined fs
UUID. Prior to this change, both outputs where generated by GRUB, which is
less helpful in determining the cause of failure.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Add section for general undocumented commands
Glenn Washburn [Thu, 12 May 2022 02:56:24 +0000 (21:56 -0500)] 
docs: Add section for general undocumented commands

The section is an itemized list of commands that are not listed else where
in the command sections.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Add under documented loader commands to beginning of loader section
Glenn Washburn [Thu, 12 May 2022 02:56:23 +0000 (21:56 -0500)] 
docs: Add under documented loader commands to beginning of loader section

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Create command section for loader commands
Glenn Washburn [Thu, 12 May 2022 02:56:22 +0000 (21:56 -0500)] 
docs: Create command section for loader commands

Move loader commands documented in the general commands list into the
loader command section.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Markup loader commands with @command tag
Glenn Washburn [Thu, 12 May 2022 02:56:21 +0000 (21:56 -0500)] 
docs: Markup loader commands with @command tag

Also, add period to terminate sentence.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Make note of i386-pc specific usage of halt command
Glenn Washburn [Thu, 12 May 2022 02:56:20 +0000 (21:56 -0500)] 
docs: Make note of i386-pc specific usage of halt command

The --no-apm option is only available on the i396-pc target.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Make note that sendkey is only available on i386-pc
Glenn Washburn [Thu, 12 May 2022 02:56:19 +0000 (21:56 -0500)] 
docs: Make note that sendkey is only available on i386-pc

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Fix spelling typo and remove unnecessary spaces
Glenn Washburn [Thu, 12 May 2022 02:56:18 +0000 (21:56 -0500)] 
docs: Fix spelling typo and remove unnecessary spaces

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/net: Fix incorrect condition for calling grub_net_tcp_retransmit()
Glenn Washburn [Thu, 12 May 2022 02:44:01 +0000 (21:44 -0500)] 
net/net: Fix incorrect condition for calling grub_net_tcp_retransmit()

The commit 848724273e4 (net/net: Avoid unnecessary calls to
grub_net_tcp_retransmit()) needs to have its condition inverted to avoid
unnecessary calls to grub_net_tcp_retransmit(). As it is, it creates many
unnecessary calls and does not call grub_net_tcp_retransmit() when needed.
The call to grub_net_tcp_retransmit() should only be made when
grub_net_cards does _not_ equal NULL, meaning that there are potentially
network cards that need TCP retransmission.

Fixes: 848724273e4 (net/net: Avoid unnecessary calls to grub_net_tcp_retransmit())
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotemplates: Improve initramfs detection
Oskari Pirhonen [Tue, 3 May 2022 04:12:56 +0000 (23:12 -0500)] 
templates: Improve initramfs detection

Add detection for initramfs of the form *.img.old. For example, Gentoo's
sys-kernel/genkernel installs it as initramfs-*.img and moves any existing
one to initramfs-*.img.old.

Apply the same scheme to initrd-*.img and initrd-*.gz files for consistency.

Signed-off-by: Oskari Pirhonen <xxc3ncoredxx@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoosdep/hurd: Support device entries with @/dev/disk: qualifier
Samuel Thibault [Wed, 27 Apr 2022 21:00:29 +0000 (23:00 +0200)] 
osdep/hurd: Support device entries with @/dev/disk: qualifier

Those are used with non-bootstrap disk drivers, for which libstore has to
open /dev/disk before calling device_open on it instead of on the device
master port. Normally in that case all /dev/ entries also have the @/dev/disk:
qualifier, so we can just drop it.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogrub-mkimage: Creating aarch64 images from x86 host is broken
Darren Kenny [Wed, 27 Apr 2022 10:46:48 +0000 (10:46 +0000)] 
grub-mkimage: Creating aarch64 images from x86 host is broken

A recent fix that made appears to have broken the ability to create an
aarch64 boot image on a x86-based host.

This was due to an overzealous testing of the architecture when building
grub-mkimage and removing the code that build an ARM image when not built
on ARM.

On the occasion remove redundant break.

Fixes: 8541f319 (grub-mkimage: Only check aarch64 relocations when built for aarch64)
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Tested-by: Selva Ganesan <selvaganesan89@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogrub-install: Allow to install to non-EFI ESP when --force
Icenowy Zheng [Sun, 24 Apr 2022 07:36:33 +0000 (15:36 +0800)] 
grub-install: Allow to install to non-EFI ESP when --force

Although the EFI specification enforces support for FAT ESP, it's free
for EFI implementations to implement support for ESPs with other formats
(e.g. ext4, ntfs, etc), and at least U-Boot EFI will support ext4 ESP if
U-Boot is built with ext4 support. In some situations a GRUB installation
on such a non-FAT ESP could be useful (e.g. a NTFS-based USB disk that
can dual boot a Windows installation media and a Linux LiveCD).

As this is advanced and implementation-dependent behavior, let grub-install
allow this kind of installation, but only when --force is specified.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet: Fix NULL pointer dereference when parsing ICMP6_ROUTER_ADVERTISE messages
Qiumiao Zhang [Sat, 16 Apr 2022 01:50:11 +0000 (09:50 +0800)] 
net: Fix NULL pointer dereference when parsing ICMP6_ROUTER_ADVERTISE messages

During UEFI PXE boot in IPv6 network, if the DHCP server adopts stateful
automatic configuration, then the client receives a ICMP6_ROUTER_ADVERTISE
multicast message from the server. This may be received without the interface
having a configured network address, so orig_inf will be NULL, which can lead
to a NULL dereference when creating the default route. Actually, in this case,
the client obtains the default route through DHCPv6 instead of RA messages.
So if orig_inf == NULL and route_inf == NULL, we should not set the
default route.

Fixes: https://savannah.gnu.org/bugs/?62072
Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotests: Ensure that loopback devices and zfs devices are cleaned up
Glenn Washburn [Sun, 6 Feb 2022 22:00:12 +0000 (16:00 -0600)] 
tests: Ensure that loopback devices and zfs devices are cleaned up

ZFS file systems are not unmounted using umount, but instead by exporting
them. So export the ZFS file system that has the same label as the one that
was created during the test, if such one exists. This is required to delete
the loopback device that uses the ZFS image file. Otherwise the added code
to delete all loopback devices setup during the test run will never be able
to finish because the loopback device can not be deleted while in use.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotests: Ensure that mountpoints are unmounted before exiting
Glenn Washburn [Sun, 6 Feb 2022 22:00:11 +0000 (16:00 -0600)] 
tests: Ensure that mountpoints are unmounted before exiting

When all tests complete successfully, filesystems mounted by grub-fs-tester
will be unmounted before exiting. However, on certain test failures the
tester will exit with a failure code and not unmount previously mounted
filesystems. Now keep track of mounts and umounts and run an exit handler
on exit or process interruption that will umount all mounts that haven't
already been unmounted.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Use correct list format
Glenn Washburn [Tue, 12 Apr 2022 16:56:20 +0000 (16:56 +0000)] 
docs: Use correct list format

Using "*" to prefix list items leads to undesirable display output for
at least the generation of the html documentation. Use the @itemize and
@item directives to get itemized list output.

Also fix some wording and punctuation issues.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Clarify meaning of "list" and "cond" for "if" and "while" commands respectively
Glenn Washburn [Tue, 12 Apr 2022 16:56:19 +0000 (16:56 +0000)] 
docs: Clarify meaning of "list" and "cond" for "if" and "while" commands respectively

It is not clear from the documentation what a "list" is in the context
of the "if" command. Note that its a list of simple commands separated
by a ";" and that only the exit status of the last command matters.
The same is true for the "cond" parameter to the "while" command.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Add note that drivemap is only available on i386-pc
Glenn Washburn [Tue, 12 Apr 2022 16:56:18 +0000 (16:56 +0000)] 
docs: Add note that drivemap is only available on i386-pc

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotests: Give grub-fs-tester temp directory a better name
Glenn Washburn [Sat, 9 Apr 2022 02:44:47 +0000 (02:44 +0000)] 
tests: Give grub-fs-tester temp directory a better name

Instead of "tmp" the name is prefixed by the name of the scripts (e.g.
grub-fs-tester). A timestamp is added in the name to allow for easily
seeing a chronological sorting of runs and the name of the filesystem
being tested. The random component is set to the minimal possible,
3 characters, because the timestamp should provide enough uniqueness.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotests: Disable blkid cache usage
Glenn Washburn [Sat, 9 Apr 2022 02:44:46 +0000 (02:44 +0000)] 
tests: Disable blkid cache usage

Using the blkid cache can cause issues when running many file system tests
in parallel. We do not need it, as its only there to improve performance,
and using the cache does not provide significant performance improvements.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfigure: Fix default -O2 being added when CFLAGS not set
Glenn Washburn [Sat, 9 Apr 2022 02:29:59 +0000 (02:29 +0000)] 
configure: Fix default -O2 being added when CFLAGS not set

Autoconf will set a default CFLAGS of "-g -O2" if CFLAGS is not set.
CFLAGS was defaulted to "" early in configure to prevent this. A recent
commit ad9ccf660 (configure: Fix various new autotools warnings) added
AC_USE_SYSTEM_EXTENSIONS, which pulls in the autoconf CFLAGS check,
before we default CFLAGS and thus setting the autoconf default for
CFLAGS. Move the default setting of CFLAGS to before AC_USE_SYSTEM_EXTENSIONS
so that autoconf will see CFLAGS as set and not give it a default.

CFLAGS is also moved above AC_CONFIG_AUX_DIR, because CFLAGS should be
defaulted to "" as soon as possible to catch any autoconf macros that try
to use some other default. Regardless, this currently has no effect as that
macro does not consider the CFLAGS variable.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agovideo/readers/jpeg: Fix possible invalid loop boundary condition
Darren Kenny [Tue, 5 Apr 2022 18:25:52 +0000 (18:25 +0000)] 
video/readers/jpeg: Fix possible invalid loop boundary condition

The value of next_marker is adjusted based on the word sized value
read from data->file.

The updated next_marker value should reference a location in the file
just beyond the huffman table, and as such should not have a value
larger than the size of the file.

Fixes: CID 73657
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agolib/reed_solomon: Fix array subscript 0 is outside array bounds
Michael Chang [Mon, 28 Mar 2022 07:00:54 +0000 (15:00 +0800)] 
lib/reed_solomon: Fix array subscript 0 is outside array bounds

The grub_absolute_pointer() is a compound expression that can only work
within a function. We are out of luck here when the pointer variables
require global definition due to ATTRIBUTE_TEXT that have to use fully
initialized global definition because of the way linkers work.

  static gf_single_t * const gf_powx ATTRIBUTE_TEXT = (void *) 0x100000;

For the reason given above, use GCC diagnostic pragmas to suppress the
array-bounds warning.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agobuild: Fix -Werror=array-bounds array subscript 0 is outside array bounds
Michael Chang [Mon, 28 Mar 2022 07:00:53 +0000 (15:00 +0800)] 
build: Fix -Werror=array-bounds array subscript 0 is outside array bounds

The GRUB is failing to build with GCC-12 in many places like this:

  In function 'init_cbfsdisk',
      inlined from 'grub_mod_init' at ../../grub-core/fs/cbfs.c:391:3:
  ../../grub-core/fs/cbfs.c:345:7: error: array subscript 0 is outside array bounds of 'grub_uint32_t[0]' {aka 'unsigned int[]'} [-Werror=array-bounds]
    345 |   ptr = *(grub_uint32_t *) 0xfffffffc;
        |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is caused by GCC regression in 11/12 [1]. In a nut shell, the
warning is about detected invalid accesses at non-zero offsets to NULL
pointers. Since hardwired constant address is treated as NULL plus an
offset in the same underlying code, the warning is therefore triggered.

Instead of inserting #pragma all over the places where literal pointers
are accessed to avoid diagnosing array-bounds, we can try to borrow the
idea from Linux kernel that the absolute_pointer() macro [2][3] is used
to disconnect a pointer using literal address from it's original object,
hence GCC won't be able to make assumptions on the boundary while doing
pointer arithmetic. With that we can greatly reduce the code we have to
cover up by making initial literal pointer assignment to use the new
wrapper but not having to track everywhere literal pointers are
accessed. This also makes code looks cleaner.

Please note the grub_absolute_pointer() macro requires to be invoked in
a function as long as it is compound expression. Some global variables
with literal pointers has been changed to local ones in order to use
grub_absolute_pointer() to initialize it. The shuffling is basically done
in a selective and careful way that the variable's scope doesn't matter
being local or global, for example, the global variable must not get
modified at run time throughout. For the record, here's the list of
global variables got shuffled in this patch:

  grub-core/commands/i386/pc/drivemap.c:int13slot
  grub-core/term/i386/pc/console.c:bios_data_area
  grub-core/term/ns8250.c:serial_hw_io_addr

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
[2] https://elixir.bootlin.com/linux/v5.16.14/source/include/linux/compiler.h#L180
[3] https://elixir.bootlin.com/linux/v5.16.14/source/include/linux/compiler-gcc.h#L31

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoutil/mkimage: Fix dangling pointer may be used error
Michael Chang [Mon, 28 Mar 2022 07:00:52 +0000 (15:00 +0800)] 
util/mkimage: Fix dangling pointer may be used error

The warning is real as long as dangling pointer to tmp_ may be used if
o32 and o64 are both NULL. However that is not going to happen and can
be ignored safely because the PE_OHDR is being used in a context that
either o32 or o64 must have been properly initialized. Sadly compiler
seems not to always optimize that unused tmp_ away so explicit
suppression remain needed here.

  ../util/mkimage.c: In function 'grub_install_generate_image':
  ../util/mkimage.c:1422:41: error: dangling pointer to 'tmp_' may be used [-Werror=dangling-pointer=]
   1422 |         PE_OHDR (o32, o64, header_size) = grub_host_to_target32 (header_size);
  ../util/mkimage.c:857:28: note: 'tmp_' declared here
    857 |   __typeof__((o64)->field) tmp_;                \
        |                            ^~~~

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/drivers/efi/efinet: Configure VLAN from UEFI device used for PXE
Chad Kimes [Mon, 21 Mar 2022 22:07:32 +0000 (18:07 -0400)] 
net/drivers/efi/efinet: Configure VLAN from UEFI device used for PXE

This patch handles automatic configuration of VLAN when booting from PXE
on UEFI hardware.

Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/efi/efi: Print VLAN info in EFI device path
Chad Kimes [Mon, 21 Mar 2022 22:07:31 +0000 (18:07 -0400)] 
kern/efi/efi: Print VLAN info in EFI device path

Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/net: Add net_set_vlan command
Chad Kimes [Mon, 21 Mar 2022 21:29:16 +0000 (17:29 -0400)] 
net/net: Add net_set_vlan command

Previously there was no way to set the 802.1Q VLAN identifier, despite
support for vlantag in the net module. The only location vlantag was
being populated was from PXE boot and only for Open Firmware hardware.
This commit allows users to manually configure VLAN information for any
interface.

Example usage:
  grub> net_ls_addr
  efinet1 00:11:22:33:44:55 192.0.2.100
  grub> net_set_vlan efinet1 100
  grub> net_ls_addr
  efinet1 00:11:22:33:44:55 192.0.2.100 vlan100
  grub> net_set_vlan efinet1 0
  efinet1 00:11:22:33:44:55 192.0.2.100

Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/net: Add vlan information to net_ls_addr output
Chad Kimes [Mon, 21 Mar 2022 21:29:15 +0000 (17:29 -0400)] 
net/net: Add vlan information to net_ls_addr output

Example output:
  grub> net_ls_addr
  efinet1 00:11:22:33:44:55 192.0.2.100 vlan100

Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/efi/init: Log a console error during a stack check failure
Chris Coulson [Mon, 21 Mar 2022 15:14:39 +0000 (15:14 +0000)] 
kern/efi/init: Log a console error during a stack check failure

The initial implementation of the stack protector just busy looped
in __stack_chk_fail in order to reduce the amount of code being
executed after the stack has been compromised because of a lack of
firmware memory protections. With future firmware implementations
incorporating memory protections such as W^X, call in to boot services
when an error occurs in order to log a message to the console before
automatically rebooting the machine.

Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoloader/i386/xnu: Fix uninitialized scalar variable
Alec Brown [Mon, 21 Mar 2022 06:29:01 +0000 (02:29 -0400)] 
loader/i386/xnu: Fix uninitialized scalar variable

In the function grub_xnu_boot(), struct grub_relocator32_state state is called
but isn't being initialized. This results in the members grub_uint32_t ebx,
grub_uint32_t ecx, grub_uint32_t edx, grub_uint32_t edi, and grub_uint32_t esi
being filled with junk data from the stack since none of them are being set to
any values. We can prevent this by setting state to {0}.

Fixes: CID 375035
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>
3 years agoloader/i386/xnu: Fix uninitialized scalar variable
Alec Brown [Mon, 21 Mar 2022 06:28:59 +0000 (02:28 -0400)] 
loader/i386/xnu: Fix uninitialized scalar variable

In the function grub_xnu_boot_resume(), struct grub_relocator32_state state is
called but isn't being initialized. This results in the members grub_uint32_t
ebx, grub_uint32_t ecx, grub_uint32_t edx, grub_uint32_t esi, and grub_uint32_t
edi being filled with junk data from the stack since none of them are being set
to any values. We can prevent this by setting state to {0}.

Fixes: CID 375031
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>
3 years agoloader/i386/pc/linux: Fix uninitialized scalar variable
Alec Brown [Mon, 21 Mar 2022 06:28:57 +0000 (02:28 -0400)] 
loader/i386/pc/linux: Fix uninitialized scalar variable

In the function grub_linux16_boot(), struct grub_relocator16_state state is
called but isn't being initialized. This results in the members grub_uint32_t
ebx, grub_uint32_t edx, grub_uint32_t esi, and grub_uint32_t ebp being filled
with junk data from the stack since none of them are being set to any values.
We can prevent this by setting state to {0}.

Fixes: CID 375028
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>
3 years agoloader/i386/bsd: Fix uninitialized scalar variable
Alec Brown [Mon, 21 Mar 2022 06:28:56 +0000 (02:28 -0400)] 
loader/i386/bsd: Fix uninitialized scalar variable

In the function grub_netbsd_setup_video(), struct grub_netbsd_btinfo_framebuf
params is called but isn't being initialized. The member grub_uint8_t
reserved[16] isn't set to any values and is instead filled with junk data from
the stack. We can prevent this by setting params to {0}.

Fixes: CID 375026
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>
3 years agonet/net: Fix uninitialized scalar variable
Alec Brown [Mon, 21 Mar 2022 06:29:00 +0000 (02:29 -0400)] 
net/net: Fix uninitialized scalar variable

In the function grub_net_ipv6_get_link_local(), grub_net_network_level_address_t
addr is called but isn't being initialized. This results in the member
grub_dns_option_t option being filled with junk data from the stack. We can
prevent this by setting the option member in addr to 0.

Fixes: CID 375033
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>
3 years agonet/bootp: Fix uninitialized scalar variable
Alec Brown [Mon, 21 Mar 2022 06:29:02 +0000 (02:29 -0400)] 
net/bootp: Fix uninitialized scalar variable

In the function grub_net_configure_by_dhcp_ack(),
grub_net_network_level_address_t addr is called but isn't being initialized.
This results in the member grub_dns_option_t option being filled with junk data
from the stack. To prevent this, we can set the option member in addr to 0.

Fixes: CID 375036
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>
3 years agonet/arp: Fix uninitialized scalar variable
Alec Brown [Mon, 21 Mar 2022 06:28:58 +0000 (02:28 -0400)] 
net/arp: Fix uninitialized scalar variable

In the function grub_net_arp_receive(), grub_net_network_level_address_t
sender_addr and target_addr are being called but aren't being initialized.
In both of these structs, each member is being set to a value except for
grub_dns_option_t option. This results in this member being filled with junk
data from the stack. To prevent this, we can set the option member in both
structs to 0.

Fixes: CID 375030
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>
3 years agonet/tcp: Only call grub_get_time_ms() when there are sockets to potentially retransmi...
Glenn Washburn [Fri, 18 Mar 2022 06:51:33 +0000 (01:51 -0500)] 
net/tcp: Only call grub_get_time_ms() when there are sockets to potentially retransmit for

If the machine has network cards found, but there are no tcp open sockets
(because the user doesn't use the network to boot), then grub_net_tcp_retransmit()
should be a noop. Thus GRUB doesn't need to call grub_get_time_ms(), which
does a call into firmware on powerpc-ieee1275, and probably other targets.
So only call grub_get_time_ms() if there are tcp sockets.

Aside from improving performance, its also useful to stay out of the firmware
as much as possible when debugging via QEMU because its a pain to get back
in to GRUB execution. grub_net_tcp_retransmit() can get called very frequently
via grub_net_poll_cards_idle() when GRUB is waiting for a keypress
(grub_getkey_noblock() calls grub_net_poll_cards_idle()). This can be annoying
when debugging an issue in GRUB on PowerPC in QEMU with GDB when GRUB is waiting
for a keypress because interrupting via GDB nearly always lands in the OpenBIOS
firmware's milliseconds call.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/net: Avoid unnecessary calls to grub_net_tcp_retransmit()
Glenn Washburn [Fri, 18 Mar 2022 06:51:32 +0000 (01:51 -0500)] 
net/net: Avoid unnecessary calls to grub_net_tcp_retransmit()

In grub_net_poll_cards_idle_real(), only call grub_net_tcp_retransmit() if there
are network cards found. If there are no network card found, there can be no
tcp sockets to transmit on. So no need to go through that logic.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/net: Unset grub_net_poll_cards_idle when net module has been unloaded
Glenn Washburn [Fri, 18 Mar 2022 06:51:31 +0000 (01:51 -0500)] 
net/net: Unset grub_net_poll_cards_idle when net module has been unloaded

This looks like it was a copy/paste error. If the net module is unloaded,
grub_net_poll_cards_idle should be NULL so that GRUB does not try to call
a function which now doesn't exist.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoINSTALL: Add information on using --build when cross-compiling
Glenn Washburn [Fri, 18 Mar 2022 06:43:46 +0000 (01:43 -0500)] 
INSTALL: Add information on using --build when cross-compiling

The autoconf 2.65 manual [1] strongly recommends specifying the --build
option when the --host is used. Add this to the example and add a note
that this is recommended.

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Hosts-and-Cross_002dCompilation.html

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfigure: Whitespace changes to improve readability
Glenn Washburn [Fri, 18 Mar 2022 06:41:39 +0000 (01:41 -0500)] 
configure: Whitespace changes to improve readability

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfigure: Remove unused CFLAGS definitions
Glenn Washburn [Fri, 18 Mar 2022 06:41:38 +0000 (01:41 -0500)] 
configure: Remove unused CFLAGS definitions

These CFLAGS definitions are reset below them before they have a change to
affect anything. The exception is the *-emu case, which is put in the next
if block, which is the only place its used before getting reset.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfigure: Remove dead code
Glenn Washburn [Fri, 18 Mar 2022 06:41:37 +0000 (01:41 -0500)] 
configure: Remove dead code

It appears as though the intent of this code is to define abort() and main()
symbols for some configure tests. However, it never gets used because the if
is only entered when not building for *-emu, but the next if block only runs
when building for *-emu. And the if block after that unconditionally resets
CFLAGS. So this code can have no effect.

Additionally, s/aclocal.m4/acinclude.m4/ and move grub_ASM_USCORE to put
with other marcos defined in acinclude.m4.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfigure: Sort AM_CONDITIONALs alphabetically
Glenn Washburn [Fri, 18 Mar 2022 06:41:36 +0000 (01:41 -0500)] 
configure: Sort AM_CONDITIONALs alphabetically

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfigure: Allow HOST_CC to override CC
Glenn Washburn [Fri, 18 Mar 2022 06:41:35 +0000 (01:41 -0500)] 
configure: Allow HOST_CC to override CC

According to the INSTALL, "The HOST_* variables override not prefixed
variables". This change makes it so, instead of previous behavior, which
was to ignore the HOST_CC environment variable.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogdb: Add malloc and free symbols to kernel.exec to improve gdb functionality
Glenn Washburn [Fri, 18 Mar 2022 06:34:05 +0000 (01:34 -0500)] 
gdb: Add malloc and free symbols to kernel.exec to improve gdb functionality

Add linker flags when linking kernel.exec to have malloc and free point to
grub_malloc() and grub_free() respectively. Some gdb functionality depends on
gdb locating the symbols "malloc" and "free", such as dynamically creating
strings for arguments to injected function calls. A trivial example would
the gdb command 'p strlen("astring")'. Make sure not to do this on emu
platforms, or an infinite loop occurs because emu has a special
grub_malloc() that calls malloc().

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocommands/search: Add new --efidisk-only option for EFI systems
Renaud Métrich [Mon, 7 Mar 2022 10:06:20 +0000 (11:06 +0100)] 
commands/search: Add new --efidisk-only option for EFI systems

When using "search" on EFI systems, we sometimes want to exclude devices
that are not EFI disks, e.g. md, lvm. This is typically used when
wanting to chainload when having a software raid (md) for EFI partition:
with no option, "search --file /EFI/redhat/shimx64.efi" sets root envvar
to "md/boot_efi" which cannot be used for chainloading since there is no
effective EFI device behind.

Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocommands/search: Refactor --no-floppy option to have something generic
Renaud Métrich [Mon, 7 Mar 2022 10:06:19 +0000 (11:06 +0100)] 
commands/search: Refactor --no-floppy option to have something generic

Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/main: Suppress the "Welcome to GRUB!" message in EFI builds
Hans de Goede [Fri, 28 Jan 2022 10:30:33 +0000 (11:30 +0100)] 
kern/main: Suppress the "Welcome to GRUB!" message in EFI builds

GRUB EFI builds are now often used in combination with flicker-free
boot, but this breaks with upstream GRUB because the "Welcome to GRUB!"
message will kick the EFI fb into text mode and show the msg, breaking
the flicker-free experience.

EFI systems are so fast, that when the menu or the countdown are
enabled the message will be immediately overwritten, so in these cases
not printing the message does not matter.

And in case when the timeout_style is set to TIMEOUT_STYLE_HIDDEN,
the user has asked GRUB to be quiet (for example to allow flickfree
boot) and thus the message should not be printed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonormal/menu: Don't show "Booting `%s'" msg when auto-booting with TIMEOUT_STYLE_HIDDEN
Hans de Goede [Fri, 28 Jan 2022 10:30:32 +0000 (11:30 +0100)] 
normal/menu: Don't show "Booting `%s'" msg when auto-booting with TIMEOUT_STYLE_HIDDEN

When the user has asked the menu code to be hidden/quiet and the current
entry is being autobooted because the timeout has expired don't show
the "Booting `%s'" msg.

This is necessary to let flicker-free boots really be flicker free,
otherwise the "Booting `%s'" msg will kick the EFI fb into text mode
and show the msg, breaking the flicker-free experience.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoterm/efi/console: Do not set cursor until the first text output
Hans de Goede [Fri, 28 Jan 2022 11:43:49 +0000 (12:43 +0100)] 
term/efi/console: Do not set cursor until the first text output

To allow flickerfree boot the EFI console code does not call
grub_efi_set_text_mode(1) until some text is actually output. Depending
on if the output text is because of an error loading, e.g. the .cfg
file, or because of showing the menu the cursor needs to be on or off
when the first text is shown. So far the cursor was hardcoded to being
on, but this is causing drawing artifacts + slow drawing of the menu as
reported here: https://bugzilla.redhat.com/show_bug.cgi?id=1946969
Handle the cursorstate in the same way as the colorstate to fix this,
when no text has been output yet, just cache the cursorstate and then
use the last set value when the first text is output.

Fixes: 2d7c3abd871f (efi/console: Do not set text-mode until we actually need it)
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1946969
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoterm/efi/console: Do not set colorstate until the first text output
Hans de Goede [Fri, 28 Jan 2022 11:43:48 +0000 (12:43 +0100)] 
term/efi/console: Do not set colorstate until the first text output

GRUB_MOD_INIT(normal) does an unconditional:

  grub_env_set ("color_normal", "light-gray/black");

which triggers a grub_term_setcolorstate() call. The original version
of the "efi/console: Do not set text-mode until we actually need it" patch,
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html,
protected against this by caching the requested state in
grub_console_setcolorstate() and then only applying it when the first
text output actually happens. During refactoring to move the
grub_console_setcolorstate() up higher in the grub-core/term/efi/console.c
file the code to cache the color-state + bail early was accidentally dropped.
Restore the cache the color-state + bail early behavior from the original.

Fixes: 2d7c3abd871f (efi/console: Do not set text-mode until we actually need it)
Cc: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/rescue_parser: Ensure that parser allocated memory is not leaked
Darren Kenny [Wed, 16 Mar 2022 17:25:05 +0000 (17:25 +0000)] 
kern/rescue_parser: Ensure that parser allocated memory is not leaked

While it would appear unlikely that the memory allocated in *argv in
grub_parser_split_cmdline() would be leaked, we should try ensure that
it doesn't leak by calling grub_free() before we return from
grub_rescue_parse_line().

To avoid a possible double-free, grub_parser_split_cmdline() is being
changed to assign *argv = NULL when we've called grub_free() in the fail
section.

Fixes: CID 96680
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogrub-mkimage: Only check aarch64 relocations when built for aarch64
Darren Kenny [Wed, 16 Mar 2022 17:25:04 +0000 (17:25 +0000)] 
grub-mkimage: Only check aarch64 relocations when built for aarch64

Coverity flagged the switch checks for R_AARCH64_* as being logically
dead code, since it could never happen on x86 due to the masking of the
values earlier in the code.

A check for building on __arm__ (which gcc and clang define) and for
MKIMAGE_ELF64 (which GRUB defines) has been added to avoid this dead
code being built in.

Fixes: CID 158599
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agolib/posix_wrap/errno.h: Add __set_errno() macro
Daniel Kiper [Tue, 15 Mar 2022 18:05:45 +0000 (14:05 -0400)] 
lib/posix_wrap/errno.h: Add __set_errno() macro

$ ./configure --target=x86_64-w64-mingw32 --with-platform=efi --host=x86_64-w64-mingw32
$ make

[...]

cat syminfo.lst | sort | gawk -f ./genmoddep.awk > moddep.lst || (rm -f moddep.lst; exit 1)
__imp__errno in regexp is not defined

This happens because grub-core/lib/gnulib/malloc/dynarray_resize.c and
grub-core/lib/gnulib/malloc/dynarray_emplace_enlarge.c (both are used by
regexp module) from the latest Gnulib call __set_errno() which originally
sets errno variable (Windows builds add __imp__ prefix). Of course it is
not defined and grub_errno should be used instead.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfigure: Fix various new autotools warnings
Robbie Harwood [Tue, 15 Mar 2022 18:05:44 +0000 (14:05 -0400)] 
configure: Fix various new autotools warnings

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib: Handle warnings introduced by updated gnulib
Robbie Harwood [Tue, 15 Mar 2022 18:05:43 +0000 (14:05 -0400)] 
gnulib: Handle warnings introduced by updated gnulib

- Fix type of size variable in luks2_verify_key()
- Avoid redefinition of SIZE_MAX and ATTRIBUTE_ERROR
- Work around gnulib's int types on older compilers

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib: Update gnulib version and drop most gnulib patches
Robbie Harwood [Tue, 15 Mar 2022 18:05:42 +0000 (14:05 -0400)] 
gnulib: Update gnulib version and drop most gnulib patches

In addition to the changes carried in our gnulib patches, several
Coverity and code hygiene fixes that were previously downstream are also
included in this 3-year gnulib increment.

Unfortunately, fix-width.patch is retained.

Bump minimum autoconf version from 2.63 to 2.64 and automake from 1.11
to 1.14, as required by gnulib.

Sync bootstrap script itself with gnulib.

Update regexp module for new dynarray dependency.

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib: Drop no-abort.patch
Robbie Harwood [Tue, 15 Mar 2022 18:05:41 +0000 (14:05 -0400)] 
gnulib: Drop no-abort.patch

Originally added in commit db7337a3d (grub-core/lib/posix_wrap/stdlib.h
(abort): Removed), this patched out all relevant invocations of abort()
in gnulib. While it was not documented why at the time, testing suggests
that there's no abort() implementation available for gnulib to use.

gnulib's position is that the use of abort() is correct here, since it
happens when input violates a "shall" from POSIX. Additionally, the
code in question is probably not reachable. Since abort() is more
friendly to user-space, they prefer to make no change, so we can just
carry a define instead (suggested by Paul Eggert).

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib: Drop fix-base64.patch
Robbie Harwood [Tue, 15 Mar 2022 18:05:40 +0000 (14:05 -0400)] 
gnulib: Drop fix-base64.patch

Originally added in commit 9fbdec2f (bootstrap: Add gnulib's base64
module) and subsequently modified in commit 552c9fd08 (gnulib: Fix build
of base64 when compiling with memory debugging), fix-base64.patch
handled two problems we have using gnulib, which are exercised by the
base64 module but not directly caused by it.

First, GRUB defines its own bool type, while gnulib expects the
equivalent of stdbool.h to be present. Rather than patching gnulib,
instead use gnulib's stdbool module to provide a bool type if needed
(suggested by Simon Josefsson).

Second, our config.h doesn't always inherit config-util.h, which is
where gnulib-related options like _GL_ATTRIBUTE_CONST end up.
fix-base64.h worked around this by defining the attribute away, but this
workaround is better placed in config.h itself, not a gnulib patch.

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfig: Where present, ensure config-util.h precedes config.h
Robbie Harwood [Tue, 15 Mar 2022 18:05:39 +0000 (14:05 -0400)] 
config: Where present, ensure config-util.h precedes config.h

gnulib defines go in config-util.h, and we need to know whether to
provide duplicates in config.h or not.

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoconfig.h.in: Use visual indentation
Robbie Harwood [Tue, 15 Mar 2022 18:05:38 +0000 (14:05 -0400)] 
config.h.in: Use visual indentation

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoINSTALL: Drop mention of libusb
Robbie Harwood [Wed, 9 Mar 2022 20:31:51 +0000 (15:31 -0500)] 
INSTALL: Drop mention of libusb

The commit 9d25b0da9 (Remove emu libusb support.) dropped use of libusb,
but did not remove mention of it from INSTALL file.

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoINSTALL: Add more cross-compiling Debian packages
Daniel Kiper [Thu, 10 Mar 2022 20:59:58 +0000 (21:59 +0100)] 
INSTALL: Add more cross-compiling Debian packages

The mingw-w64-tools is especially important because with out it some
Windows builds may fail due to lack of proper pkg-config.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
3 years agoconfigure: Drop ${grub_coredir} unneeded references
Daniel Kiper [Thu, 10 Mar 2022 20:44:48 +0000 (21:44 +0100)] 
configure: Drop ${grub_coredir} unneeded references

These are probably stray references left after earlier removals.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
3 years agoconf/i386-cygwin-img-ld: Do not discard .data and .edata sections
Daniel Kiper [Thu, 10 Mar 2022 17:49:35 +0000 (18:49 +0100)] 
conf/i386-cygwin-img-ld: Do not discard .data and .edata sections

$ ./configure --target=i686-w64-mingw32 --with-platform=efi --host=i686-w64-mingw32

[...]

checking if __bss_start is defined by the compiler... no
checking if edata is defined by the compiler... no
checking if _edata is defined by the compiler... no
configure: error: none of __bss_start, edata or _edata is defined

This happens on machines with quite recent ld due to an error:

  `edata' referenced in section `.text' of /tmp/cc72w9E4.o: defined in discarded section `.data' of conftest.exe
  collect2: error: ld returned 1 exit status

So, we have to tell linker to not discard .data and .edata sections.
The trick comes from ld documentation:

  3.6.7 Output Section Discarding

  The linker will not normally create output sections with no contents.
  This is for convenience when referring to input sections that may or may
  not be present in any of the input files. For example:

  .foo : { *(.foo) }

  will only create a ‘.foo’ section in the output file if there is a
  ‘.foo’ section in at least one input file, and if the input sections are
  not all empty. Other link script directives that allocate space in an
  output section will also create the output section. So too will
  assignments to dot even if the assignment does not create space, except
  for ‘. = 0’, ‘. = . + 0’, ‘. = sym’, ‘. = . + sym’ and ‘. = ALIGN (. !=
  0, expr, 1)’ when ‘sym’ is an absolute symbol of value 0 defined in the
  script. This allows you to force output of an empty section with ‘. = .’.

This change does not impact generated binaries because the
conf/i386-cygwin-img-ld.sc linker script is used only when
you run configure.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
3 years agocommands/i386/pc/sendkey: Fix "writing 1 byte into a region of size 0" build error
Daniel Kiper [Thu, 10 Mar 2022 15:48:50 +0000 (16:48 +0100)] 
commands/i386/pc/sendkey: Fix "writing 1 byte into a region of size 0" build error

Latest GCC may complain in that way:

  commands/i386/pc/sendkey.c: In function ‘grub_sendkey_postboot’:
  commands/i386/pc/sendkey.c:223:21: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
    223 |   *((char *) 0x41a) = 0x1e;
        |   ~~~~~~~~~~~~~~~~~~^~~~~~

The volatile keyword addition helps and additionally assures us the
compiler will not optimize out fixed assignments.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
3 years agoloader/i386/bsd: Initialize ptr variable in grub_bsd_add_meta()
Daniel Kiper [Thu, 10 Mar 2022 15:40:43 +0000 (16:40 +0100)] 
loader/i386/bsd: Initialize ptr variable in grub_bsd_add_meta()

Latest GCC may complain in that way:

  In file included from ../include/grub/disk.h:31,
                   from ../include/grub/file.h:26,
                   from ../include/grub/loader.h:23,
                   from loader/i386/bsd.c:19:
  loader/i386/bsd.c: In function ‘grub_cmd_openbsd’:
  ../include/grub/misc.h:71:10: error: ‘ptr’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     71 |   return grub_memmove (dest, src, n);
        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  loader/i386/bsd.c:266:9: note: ‘ptr’ was declared here
    266 |   void *ptr;
        |         ^~~

So, let's fix it by assigning NULL to ptr in grub_bsd_add_meta().

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
3 years agoosdep/windows/platform: Disable gcc9 -Waddress-of-packed-member
Daniel Kiper [Thu, 10 Mar 2022 15:10:17 +0000 (16:10 +0100)] 
osdep/windows/platform: Disable gcc9 -Waddress-of-packed-member

$ ./configure --target=x86_64-w64-mingw32 --with-platform=efi --host=x86_64-w64-mingw32
$ make

[...]

In file included from grub-core/osdep/platform.c:4:
grub-core/osdep/windows/platform.c: In function ‘grub_install_register_efi’:
grub-core/osdep/windows/platform.c:382:41: error: taking address of packed member of ‘struct grub_efi_file_path_device_path’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
  382 |   path16_len = grub_utf8_to_utf16 (filep->path_name,
      |                                    ~~~~~^~~~~~~~~~~

Disable the -Wadress-of-packaed-member diagnostic for grub_utf8_to_utf16()
call which contains filep->path_name reference. It seems safe because the
structure is defined according to the UEFI spec and we hope authors did not
make any mistake... :-)

This fix is similar to the fix in the commit 8e8723a6b
(f2fs: Disable gcc9 -Waddress-of-packed-member).

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
3 years agopo: Un-transliterate the %zu format code
Glenn Washburn [Fri, 11 Mar 2022 07:08:32 +0000 (01:08 -0600)] 
po: Un-transliterate the %zu format code

Commit 45bffae13 (util/resolve: Bail with error if moddep.lst file line is
too long) uses the %zu format specifier which has not been used in
any translated strings yet. So the sed scripts used for transliterating
certain languages need to be updated otherwise creation of the message
indexes will fail on an unknown format code. This is essentially the same
issue fixed for the %m format code in commit 2e246b6f (po: Fix replacement
of %m in sed programs).

Also reorder transliteration lines to be more lexicographically ordered.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet: Check against nb->tail in grub_netbuff_pull()
Daniel Axtens [Fri, 4 Mar 2022 13:39:04 +0000 (00:39 +1100)] 
net: Check against nb->tail in grub_netbuff_pull()

GRUB netbuff structure members track 2 different things: the extent of memory
allocated for the packet, and the extent of memory currently being worked on.

This works out in the structure as follows:

  nb->head: beginning of the allocation
  nb->data: beginning of the working data
  nb->tail: end of the working data
  nb->end:  end of the allocation

The head and end pointers are set in grub_netbuff_alloc() and do not change.
The data and tail pointers are initialised to point at start of the
allocation (that is, head == data == tail initially), and are then
manipulated by grub_netbuff_*() functions. Key functions are as follows:

  - grub_netbuff_put():     "put" more data into the packet - advance nb->tail
  - grub_netbuff_unput():   trim the tail of the packet - retract nb->tail
  - grub_netbuff_pull():    "consume" some packet data - advance nb->data
  - grub_netbuff_reserve(): reserve space for future headers - advance nb->data and nb->tail
  - grub_netbuff_push():    "un-consume" data to allow headers to be written - retract nb->data

Each of those functions does some form of error checking. For example,
grub_netbuff_put() does not allow nb->tail to exceed nb->end, and
grub_netbuff_push() does not allow nb->data to be before nb->head.

However, grub_netbuff_pull()'s error checking is a bit weird. It advances nb->data
and checks that it does not exceed nb->end. That allows you to get into the
situation where nb->data > nb->tail, which should not be.

Make grub_netbuff_pull() check against both nb->tail and nb->end. In theory just
checking against ->tail should be sufficient but the extra check should be
cheap and seems like good defensive practice.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogrub-mount: Add support for libfuse3
Fabian Vogt [Mon, 17 Jan 2022 14:34:37 +0000 (15:34 +0100)] 
grub-mount: Add support for libfuse3

The libfuse 3.0.0 got released in 2016, with some API changes compared to 2.x.
This commit introduces support for 3.x while keeping it compatible with 2.6
as a fallback still.

To detect fuse3, switch configure over to use pkg-config, which is simpler yet
more reliable than looking for library and header manually. Also set
FUSE_USE_VERSION that way, as it depends on the used libfuse version.

Now that the CFLAGS are read from pkg-config, use just <fuse.h>, which works
with 2.x as well as 3.x and is recommended by libfuse upstream.

One behavior change of libfuse3 is that FUSE_ATOMIC_O_TRUNC is set by default,
which means that open with O_TRUNC is passed as-is instead of calling the
truncate operation. With libfuse2, truncate failed with -ENOSYS and that was
returned to the application. To make O_TRUNC fail with libfuse3, return -EROFS
explicitly if writing was requested.

Signed-off-by: Fabian Vogt <fvogt@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoinclude: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:15 +0000 (07:42 +0100)] 
include: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoutil: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:14 +0000 (07:42 +0100)] 
util: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agovideo: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:13 +0000 (07:42 +0100)] 
video: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotests: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:12 +0000 (07:42 +0100)] 
tests: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoterm: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:11 +0000 (07:42 +0100)] 
term: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoscript: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:10 +0000 (07:42 +0100)] 
script: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agopartmap: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:09 +0000 (07:42 +0100)] 
partmap: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoosdep: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:08 +0000 (07:42 +0100)] 
osdep: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonormal: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:07 +0000 (07:42 +0100)] 
normal: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:06 +0000 (07:42 +0100)] 
net: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoloader: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:05 +0000 (07:42 +0100)] 
loader: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agolib: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:04 +0000 (07:42 +0100)] 
lib: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:03 +0000 (07:42 +0100)] 
kern: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoio: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:02 +0000 (07:42 +0100)] 
io: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogfxmenu: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:01 +0000 (07:42 +0100)] 
gfxmenu: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogfxmenu: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:42:00 +0000 (07:42 +0100)] 
gfxmenu: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agofs: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:41:59 +0000 (07:41 +0100)] 
fs: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agofont: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:41:58 +0000 (07:41 +0100)] 
font: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodisk: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:41:57 +0000 (07:41 +0100)] 
disk: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocommands: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:41:56 +0000 (07:41 +0100)] 
commands: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agobus: Remove trailing whitespaces
Elyes Haouas [Fri, 4 Mar 2022 06:41:55 +0000 (07:41 +0100)] 
bus: Remove trailing whitespaces

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/ethernet: Fix VLAN networking on little-endian systems
Chad Kimes [Wed, 2 Mar 2022 19:21:22 +0000 (14:21 -0500)] 
net/ethernet: Fix VLAN networking on little-endian systems

VLAN configuration seems to have never worked on little-endian systems.
This is likely because VLANTAG_IDENTIFIER is not byte-swapped before
copying into the net buffer, nor is inf->vlantag. We can resolve this by
using grub_cpu_to_be16{_compile_time}() and its inverse when copying
VLAN info to/from the net buffer.

Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocommands/efi/lsefisystab: Short text EFI_IMAGE_SECURITY_DATABASE_GUID
Heinrich Schuchardt [Tue, 1 Mar 2022 11:14:31 +0000 (12:14 +0100)] 
commands/efi/lsefisystab: Short text EFI_IMAGE_SECURITY_DATABASE_GUID

The EFI_IMAGE_SECURITY_DATABASE_GUID is used for the image execution
information table (cf. UEFI specification 2.9, 32.5.3.1 Using The Image
Execution Information 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_IMAGE_SECURITY_DATABASE_GUID.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>