]> git.proxmox.com Git - grub2.git/log
grub2.git
3 years agoluks2: Make sure all fields of output argument in luks2_parse_digest() are written to
Glenn Washburn [Tue, 8 Dec 2020 22:45:36 +0000 (16:45 -0600)]
luks2: Make sure all fields of output argument in luks2_parse_digest() are written to

We should assume that the output argument "out" is uninitialized and could
have random data. So, make sure to initialize the segments and keyslots bit
fields because potentially not all bits of those fields are written to.
Otherwise, the digest could say it belongs to keyslots and segments that it
does not.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Remove unused argument in grub_error() call
Glenn Washburn [Tue, 8 Dec 2020 22:45:35 +0000 (16:45 -0600)]
luks2: Remove unused argument in grub_error() call

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Convert 8 spaces to tabs
Glenn Washburn [Tue, 8 Dec 2020 22:45:34 +0000 (16:45 -0600)]
luks2: Convert 8 spaces to tabs

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agomisc: Add parentheses around ALIGN_UP() and ALIGN_DOWN() arguments
Glenn Washburn [Tue, 8 Dec 2020 22:45:33 +0000 (16:45 -0600)]
misc: Add parentheses around ALIGN_UP() and ALIGN_DOWN() arguments

This ensures that expected order of operations is preserved when arguments
are expressions.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodisk: Rename grub_disk_get_size() to grub_disk_native_sectors()
Glenn Washburn [Tue, 8 Dec 2020 22:45:32 +0000 (16:45 -0600)]
disk: Rename grub_disk_get_size() to grub_disk_native_sectors()

The function grub_disk_get_size() is confusingly named because it actually
returns a sector count where the sectors are sized in the GRUB native sector
size. Rename to something more appropriate.

Suggested-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoloopback: Do not automaticaly replace existing loopback dev, error instead
Glenn Washburn [Fri, 4 Dec 2020 01:57:11 +0000 (19:57 -0600)]
loopback: Do not automaticaly replace existing loopback dev, error instead

If there is a loopback device with the same name as the one to be created,
instead of closing the old one and replacing it with the new one, return an
error instead. If the loopback device was created, its probably being used
by something and just replacing it may cause GRUB to crash unexpectedly.
This fixes obvious problems like "loopback d (d)/somefile". Its not too
onerous to force the user to delete the loopback first with the "-d" switch.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodisk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h
Glenn Washburn [Tue, 1 Dec 2020 05:16:19 +0000 (23:16 -0600)]
disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h

There is a hardcoded maximum disk size that can be read or written from,
currently set at 1 EiB in grub_disk_adjust_range(). Move the literal into a
macro in disk.h, so our assumptions are more visible. This hard coded limit
does not prevent using larger disks, just GRUB won't read/write past the
limit. The comment accompanying this restriction didn't quite make sense to
me, so its been modified too.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agofs: Fix block lists not being able to address to end of disk sometimes
Glenn Washburn [Mon, 23 Nov 2020 09:27:42 +0000 (03:27 -0600)]
fs: Fix block lists not being able to address to end of disk sometimes

When checking if a block list goes past the end of the disk, make sure
the total size of the disk is in GRUB native sector sizes, otherwise there
will be blocks at the end of the disk inaccessible by block lists.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agombr: Document new limitations on MBR gap support
Vladimir Serbinenko [Tue, 10 Nov 2020 19:23:56 +0000 (20:23 +0100)]
mbr: Document new limitations on MBR gap support

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agombr: Warn if MBR gap is small and user uses advanced modules
Vladimir Serbinenko [Mon, 27 Apr 2020 15:50:04 +0000 (17:50 +0200)]
mbr: Warn if MBR gap is small and user uses advanced modules

We don't want to support small MBR gap in pair with anything but the
simplest config of biosdisk + part_msdos + simple filesystem. In this
path "simple filesystems" are all current filesystems except ZFS and
Btrfs.

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi/tpm: Extract duplicate code into independent functions
Tianjia Zhang [Thu, 29 Oct 2020 13:49:49 +0000 (21:49 +0800)]
efi/tpm: Extract duplicate code into independent functions

Part of the code logic for processing the return value of efi
log_extend_event is repetitive and complicated. Extract the
repetitive code into an independent function.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi/tpm: Add debug information for device protocol and eventlog
Tianjia Zhang [Thu, 29 Oct 2020 13:49:29 +0000 (21:49 +0800)]
efi/tpm: Add debug information for device protocol and eventlog

Add a number of debug logs to the tpm module. The condition tag
for opening debugging is "tpm". On TPM machines, this will bring
great convenience to diagnosis and debugging.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoloader/linux: Report the UEFI Secure Boot status to the Linux kernel
Daniel Kiper [Thu, 3 Dec 2020 15:01:50 +0000 (16:01 +0100)]
loader/linux: Report the UEFI Secure Boot status to the Linux kernel

Now that the GRUB has a grub_efi_get_secureboot() function to check the
UEFI Secure Boot status, use it to report that to the Linux kernel.

Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Only register shim_lock verifier if shim_lock protocol is found and SB enabled
Javier Martinez Canillas [Thu, 3 Dec 2020 15:01:49 +0000 (16:01 +0100)]
efi: Only register shim_lock verifier if shim_lock protocol is found and SB enabled

The shim_lock module registers a verifier to call shim's verify, but the
handler is registered even when the shim_lock protocol was not installed.

This doesn't cause a NULL pointer dereference in shim_lock_write() because
the shim_lock_init() function just returns GRUB_ERR_NONE if sl isn't set.

But in that case there's no point to even register the shim_lock verifier
since won't do anything. Additionally, it is only useful when Secure Boot
is enabled.

Finally, don't assume that the shim_lock protocol will always be present
when the shim_lock_write() function is called, and check for it on every
call to this function.

Reported-by: Michael Chang <mchang@suse.com>
Reported-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Add secure boot detection
Daniel Kiper [Thu, 3 Dec 2020 15:01:48 +0000 (16:01 +0100)]
efi: Add secure boot detection

Introduce grub_efi_get_secureboot() function which returns whether
UEFI Secure Boot is enabled or not on UEFI systems.

Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Add a function to read EFI variables with attributes
Daniel Kiper [Thu, 3 Dec 2020 15:01:47 +0000 (16:01 +0100)]
efi: Add a function to read EFI variables with attributes

It will be used to properly detect and report UEFI Secure Boot status to
the x86 Linux kernel. The functionality will be added by subsequent patches.

Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Return grub_efi_status_t from grub_efi_get_variable()
Daniel Kiper [Thu, 3 Dec 2020 15:01:46 +0000 (16:01 +0100)]
efi: Return grub_efi_status_t from grub_efi_get_variable()

This is needed to properly detect and report UEFI Secure Boot status
to the x86 Linux kernel. The functionality will be added by subsequent
patches.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Make shim_lock GUID and protocol type public
Daniel Kiper [Thu, 3 Dec 2020 15:01:45 +0000 (16:01 +0100)]
efi: Make shim_lock GUID and protocol type public

The GUID will be used to properly detect and report UEFI Secure Boot
status to the x86 Linux kernel. The functionality will be added by
subsequent patches. The shim_lock protocol type is made public for
completeness.

Additionally, fix formatting of four preceding GUIDs.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoarm/term: Fix linking error due multiple ps2_state definitions
Javier Martinez Canillas [Thu, 3 Dec 2020 15:01:44 +0000 (16:01 +0100)]
arm/term: Fix linking error due multiple ps2_state definitions

When building with --target=arm-linux-gnu --with-platform=coreboot
a linking error occurs caused by multiple definitions of the
ps2_state variable.

Mark them as static since they aren't used outside their compilation unit.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoinclude/grub/i386/linux.h: Include missing <grub/types.h> header
Javier Martinez Canillas [Thu, 3 Dec 2020 15:01:43 +0000 (16:01 +0100)]
include/grub/i386/linux.h: Include missing <grub/types.h> header

This header uses types defined in <grub/types.h> but does not include it,
which leads to compile errors like the following:

In file included from ../include/grub/cpu/linux.h:19,
                 from kern/efi/sb.c:21:
../include/grub/i386/linux.h:80:3: error: unknown type name ‘grub_uint64_t’
   80 |   grub_uint64_t addr;

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoi386: Don't include <grub/cpu/linux.h> in coreboot and ieee1275 startup.S
Javier Martinez Canillas [Thu, 3 Dec 2020 15:01:42 +0000 (16:01 +0100)]
i386: Don't include <grub/cpu/linux.h> in coreboot and ieee1275 startup.S

Nothing defined in the header file is used in the assembly code but it
may lead to build errors if some headers are included through this and
contains definitions that are not recognized by the assembler, e.g.:

../include/grub/types.h: Assembler messages:
../include/grub/types.h:76: Error: no such instruction: `typedef signed char grub_int8_t'
../include/grub/types.h:77: Error: no such instruction: `typedef short grub_int16_t'
../include/grub/types.h:78: Error: no such instruction: `typedef int grub_int32_t'

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Rename index variable "j" to "i" in luks2_get_keyslot()
Glenn Washburn [Sat, 7 Nov 2020 04:44:27 +0000 (22:44 -0600)]
luks2: Rename index variable "j" to "i" in luks2_get_keyslot()

Looping variable "j" was named such because the variable name "i" was taken.
Since "i" has been renamed in the previous patch, we can rename "j" to "i".

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Rename variable "i" to "keyslot_idx" in luks2_get_keyslot()
Glenn Washburn [Sat, 7 Nov 2020 04:44:26 +0000 (22:44 -0600)]
luks2: Rename variable "i" to "keyslot_idx" in luks2_get_keyslot()

Variables named "i" are usually looping variables. So, rename it to
"keyslot_idx" to ease luks2_get_keyslot() reading.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Use correct index variable when looping in luks2_get_keyslot()
Glenn Washburn [Sat, 7 Nov 2020 04:44:25 +0000 (22:44 -0600)]
luks2: Use correct index variable when looping in luks2_get_keyslot()

The loop variable "j" should be used to index the digests and segments json
array, instead of the variable "i", which is the keyslot index.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Rename source disk variable named "disk" to "source" as in luks.c
Glenn Washburn [Sat, 7 Nov 2020 04:44:23 +0000 (22:44 -0600)]
luks2: Rename source disk variable named "disk" to "source" as in luks.c

This makes it more obvious to the reader that the disk referred to is the
source disk, as opposed to say the disk holding the cryptodisk.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Rename "offset" in grub_cryptodisk_t to "offset_sectors"
Glenn Washburn [Sat, 7 Nov 2020 04:44:22 +0000 (22:44 -0600)]
cryptodisk: Rename "offset" in grub_cryptodisk_t to "offset_sectors"

This makes it clear that the offset represents sectors, not bytes, in
order to improve readability.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Rename "total_length" field in grub_cryptodisk_t to "total_sectors"
Glenn Washburn [Sat, 7 Nov 2020 04:44:21 +0000 (22:44 -0600)]
cryptodisk: Rename "total_length" field in grub_cryptodisk_t to "total_sectors"

This creates an alignment with grub_disk_t naming of the same field and is
more intuitive as to how it should be used.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotypes: Define GRUB_CHAR_BIT based on compiler macro instead of using literal
Glenn Washburn [Sat, 7 Nov 2020 04:44:24 +0000 (22:44 -0600)]
types: Define GRUB_CHAR_BIT based on compiler macro instead of using literal

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoinclude/grub/arm64/linux.h: Include missing <grub/types.h> header
Javier Martinez Canillas [Mon, 9 Nov 2020 10:40:14 +0000 (11:40 +0100)]
include/grub/arm64/linux.h: Include missing <grub/types.h> header

This header uses types defined in <grub/types.h> but does not include it,
which leads to compile errors like the following:

../include/grub/cpu/linux.h:27:3: error: unknown type name ‘grub_uint32_t’
   27 |   grub_uint32_t code0;  /* Executable code */
      |   ^~~~~~~~~~~~~

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoinclude/grub/arm/system.h: Include missing <grub/symbol.h> header
Javier Martinez Canillas [Thu, 5 Nov 2020 14:58:57 +0000 (15:58 +0100)]
include/grub/arm/system.h: Include missing <grub/symbol.h> header

The header uses the EXPORT_FUNC() macro defined in <grub/types.h> but
doesn't include it, which leads to the following compile error on arm:

../include/grub/cpu/system.h:12:13: error: ‘EXPORT_FUNC’ declared as function returning a function
   12 | extern void EXPORT_FUNC(grub_arm_disable_caches_mmu) (void);
      |             ^~~~~~~~~~~
../include/grub/cpu/system.h:12:1: warning: parameter names (without types) in function declaration
   12 | extern void EXPORT_FUNC(grub_arm_disable_caches_mmu) (void);
      | ^~~~~~
make[3]: *** [Makefile:36581: kern/efi/kernel_exec-sb.o] Error 1

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: grub-install --pubkey has been supported for some time
Daniel Axtens [Wed, 28 Oct 2020 01:57:19 +0000 (12:57 +1100)]
docs: grub-install --pubkey has been supported for some time

grub-install --pubkey is supported, so we can now document it.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: grub-install is no longer a shell script
Daniel Axtens [Wed, 28 Oct 2020 01:57:18 +0000 (12:57 +1100)]
docs: grub-install is no longer a shell script

Since commit cd46aa6cefab in 2013, grub-install hasn't been a shell
script. The para doesn't really add that much, especially since it's
the user manual, so just drop it.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoMakefile: Remove unused GRUB_PKGLIBDIR definition
Jacob Kroon [Sat, 20 Jun 2020 13:01:43 +0000 (15:01 +0200)]
Makefile: Remove unused GRUB_PKGLIBDIR definition

Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agolzma: Fix compilation error under clang 10
Daniel Axtens [Mon, 20 Jul 2020 07:07:49 +0000 (17:07 +1000)]
lzma: Fix compilation error under clang 10

Compiling under clang 10 gives:

grub-core/lib/LzmaEnc.c:1362:9: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]
        {
        ^
grub-core/lib/LzmaEnc.c:1358:7: note: previous statement is here
      if (repIndex == 0)
      ^
1 error generated.

It's not really that unclear in context: there's a commented-out
if-statement. But tweak the alignment anyway so that clang is happy.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/i386/realmode: Update comment
Cao jin [Tue, 28 Jul 2020 05:42:04 +0000 (13:42 +0800)]
kern/i386/realmode: Update comment

Commit b81d609e4c did not update it.

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Fix cipher IV mode "plain64" always being set as "plain"
Glenn Washburn [Mon, 19 Oct 2020 23:09:53 +0000 (18:09 -0500)]
cryptodisk: Fix cipher IV mode "plain64" always being set as "plain"

When setting cipher IV mode, detection is done by prefix matching the
cipher IV mode part of the cipher mode string. Since "plain" matches
"plain64", we must check for "plain64" first. Otherwise, "plain64" will
be detected as "plain".

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocrypto: Remove GPG_ERROR_CFLAGS from gpg_err_code_t enum
Glenn Washburn [Fri, 31 Jul 2020 14:33:23 +0000 (09:33 -0500)]
crypto: Remove GPG_ERROR_CFLAGS from gpg_err_code_t enum

This was probably added by accident when originally creating the file.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoscript: Do not allow a delimiter between function name and block start
Glenn Washburn [Fri, 31 Jul 2020 14:33:22 +0000 (09:33 -0500)]
script: Do not allow a delimiter between function name and block start

Currently the following is valid syntax but should be a syntax error:

  grub> function f; { echo HERE; }
  grub> f
  HERE

This fix is not backward compatible, but current syntax is not documented
either and has no functional value. So any scripts with this unintended
syntax are technically syntactically incorrect and should not be relying
on this behavior.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Support for loading and concatenating multiple initrds
Glenn Washburn [Fri, 31 Jul 2020 14:33:21 +0000 (09:33 -0500)]
docs: Support for loading and concatenating multiple initrds

This has been available since January of 2012 but has not been documented.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agolexer: char const * should be const char *
Glenn Washburn [Fri, 31 Jul 2020 14:33:20 +0000 (09:33 -0500)]
lexer: char const * should be const char *

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Use cipher name instead of object in error message
Glenn Washburn [Fri, 31 Jul 2020 14:33:19 +0000 (09:33 -0500)]
cryptodisk: Use cipher name instead of object in error message

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotests: F2FS test should use MOUNTDEVICE like other tests
Glenn Washburn [Fri, 28 Aug 2020 23:30:25 +0000 (18:30 -0500)]
tests: F2FS test should use MOUNTDEVICE like other tests

LODEVICES is not an array variable and should not be accessed as such.
This allows the f2fs test to pass as it was failing because a device
name had a space prepended to the path.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Acked-by: Jaegeuk Kim <jaegeuk@kernel.org>
Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogrub-mkconfig: If $hints is not set reduce the output into grub.cfg to just 1 line
Florian La Roche [Tue, 1 Sep 2020 05:13:20 +0000 (07:13 +0200)]
grub-mkconfig: If $hints is not set reduce the output into grub.cfg to just 1 line

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotravis: Run bootstrap to fix build
Petr Vorel [Wed, 9 Sep 2020 20:02:18 +0000 (22:02 +0200)]
travis: Run bootstrap to fix build

autogen.sh isn't enough:

  $ ./autogen.sh
  Gnulib not yet bootstrapped; run ./bootstrap instead.
  The command "./autogen.sh" exited with 1.

Additionally, using bootstrap requires to install autopoint package.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Strip dashes off of the UUID
Patrick Steinhardt [Sat, 30 May 2020 12:25:11 +0000 (14:25 +0200)]
luks2: Strip dashes off of the UUID

The UUID header for LUKS2 uses a format with dashes, same as for
LUKS(1). But while we strip these dashes for the latter, we don't for
the former. This isn't wrong per se, but it's definitely inconsistent
for users as they need to use the dashed format for LUKS2 and the
non-dashed format for LUKS when e.g. calling "cryptomount -u $UUID".

Fix this inconsistency by stripping dashes off of the LUKS2 UUID.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi/tpm: Remove unused functions and structures
Tianjia Zhang [Wed, 29 Jul 2020 13:31:14 +0000 (21:31 +0800)]
efi/tpm: Remove unused functions and structures

Although the tpm_execute() series of functions are defined they are not
used anywhere. Several structures in the include/grub/efi/tpm.h header
file are not used too. There is even nonexistent grub_tpm_init()
declaration in this header. Delete all that unneeded stuff.

If somebody needs the functionality implemented in the dropped code then
he/she can re-add it later. Now it needlessly increases the GRUB
code/image size.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoshim_lock: Enable module for all EFI architectures
Tianjia Zhang [Wed, 29 Jul 2020 07:11:09 +0000 (15:11 +0800)]
shim_lock: Enable module for all EFI architectures

Like the tpm the shim_lock module is only enabled for x86_64 target.
However, there's nothing specific to x86_64 in the implementation and
it can be enabled for all EFI architectures.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi/tpm: Fix typo in grub_efi_tpm2_protocol struct
Daniel Kiper [Mon, 25 May 2020 19:02:15 +0000 (21:02 +0200)]
efi/tpm: Fix typo in grub_efi_tpm2_protocol struct

Rename get_active_pcr_blanks() to get_active_pcr_banks().

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agoi386/efi/init: Drop bogus include
Daniel Kiper [Mon, 25 May 2020 19:02:14 +0000 (21:02 +0200)]
i386/efi/init: Drop bogus include

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agodocs: Fix devicetree command description
Daniel Kiper [Mon, 25 May 2020 19:02:12 +0000 (21:02 +0200)]
docs: Fix devicetree command description

Specifically fix the subsection and drop bogus reference to the GNU/Linux.

Reported-by: Patrick Higgins <higgi1pt@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agogrub-install: Fix inverted test for NLS enabled when copying locales
Martin Whitaker [Mon, 25 May 2020 19:02:10 +0000 (21:02 +0200)]
grub-install: Fix inverted test for NLS enabled when copying locales

Commit 3d8439da8 (grub-install: Locale depends on nls) attempted to avoid
copying locale files to the target directory when NLS was disabled.
However the test is inverted, and it does the opposite.

Signed-off-by: Martin Whitaker <fsf@martin-whitaker.me.uk>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agotftp: Roll-over block counter to prevent data packets timeouts
Javier Martinez Canillas [Thu, 10 Sep 2020 15:17:57 +0000 (17:17 +0200)]
tftp: Roll-over block counter to prevent data packets timeouts

Commit 781b3e5efc3 (tftp: Do not use priority queue) caused a regression
when fetching files over TFTP whose size is bigger than 65535 * block size.

  grub> linux /images/pxeboot/vmlinuz
  grub> echo $?
  0
  grub> initrd /images/pxeboot/initrd.img
  error: timeout reading '/images/pxeboot/initrd.img'.
  grub> echo $?
  28

It is caused by the block number counter being a 16-bit field, which leads
to a maximum file size of ((1 << 16) - 1) * block size. Because GRUB sets
the block size to 1024 octets (by using the TFTP Blocksize Option from RFC
2348 [0]), the maximum file size that can be transferred is 67107840 bytes.

The TFTP PROTOCOL (REVISION 2) RFC 1350 [1] does not mention what a client
should do when a file size is bigger than the maximum, but most TFTP hosts
support the block number counter to be rolled over. That is, acking a data
packet with a block number of 0 is taken as if the 65356th block was acked.

It was working before because the block counter roll-over was happening due
an overflow. But that got fixed by the mentioned commit, which led to the
regression when attempting to fetch files larger than the maximum size.

To allow TFTP file transfers of unlimited size again, re-introduce a block
counter roll-over so the data packets are acked preventing the timeouts.

[0]: https://tools.ietf.org/html/rfc2348
[1]: https://tools.ietf.org/html/rfc1350

Fixes: 781b3e5efc3 (tftp: Do not use priority queue)
Suggested-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotemplates: Remove unnecessary trailing semicolon
Florian La Roche [Tue, 1 Sep 2020 05:11:59 +0000 (07:11 +0200)]
templates: Remove unnecessary trailing semicolon

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Fix incorrect calculation of start sector
Glenn Washburn [Mon, 7 Sep 2020 15:27:59 +0000 (17:27 +0200)]
cryptodisk: Fix incorrect calculation of start sector

Here dev is a grub_cryptodisk_t and dev->offset is offset in sectors of size
native to the cryptodisk device. The sector is correctly transformed into
native grub sector size, but then added to dev->offset which is not
transformed. It would be nice if the type system would help us with this.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Unregister cryptomount command when removing module
Glenn Washburn [Mon, 7 Sep 2020 15:27:55 +0000 (17:27 +0200)]
cryptodisk: Unregister cryptomount command when removing module

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Improve error reporting when decrypting/verifying key
Patrick Steinhardt [Mon, 7 Sep 2020 15:27:50 +0000 (17:27 +0200)]
luks2: Improve error reporting when decrypting/verifying key

While we already set up error messages in both luks2_verify_key() and
luks2_decrypt_key(), we do not ever print them. This makes it really
hard to discover why a given key actually failed to decrypt a disk.

Improve this by including the error message in the user-visible output.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks: Fix out-of-bounds copy of UUID
Patrick Steinhardt [Mon, 7 Sep 2020 15:27:36 +0000 (17:27 +0200)]
luks: Fix out-of-bounds copy of UUID

When configuring a LUKS disk, we copy over the UUID from the LUKS header
into the new grub_cryptodisk_t structure via grub_memcpy(). As size
we mistakenly use the size of the grub_cryptodisk_t UUID field, which
is guaranteed to be strictly bigger than the LUKS UUID field we're
copying. As a result, the copy always goes out-of-bounds and copies some
garbage from other surrounding fields. During runtime, this isn't
noticed due to the fact that we always NUL-terminate the UUID and thus
never hit the trailing garbage.

Fix the issue by using the size of the local stripped UUID field.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agojson: Remove invalid typedef redefinition
Patrick Steinhardt [Mon, 7 Sep 2020 15:27:32 +0000 (17:27 +0200)]
json: Remove invalid typedef redefinition

The C standard does not allow for typedef redefinitions, even if they
map to the same underlying type. In order to avoid including the
jsmn.h in json.h and thus exposing jsmn's internals, we have exactly
such a forward-declaring typedef in json.h. If enforcing the GNU99 C
standard, clang may generate a warning about this non-standard
construct.

Fix the issue by using a simple "struct jsmntok" forward declaration
instead of using a typedef.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Tested-by: Chuck Tuffli <chuck@freebsd.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoi386/relocator_common: Drop empty #ifdef
Cao jin [Wed, 12 Aug 2020 09:28:14 +0000 (17:28 +0800)]
i386/relocator_common: Drop empty #ifdef

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agovideo/bochs: Fix typo
Ave Milia [Mon, 3 Aug 2020 21:22:49 +0000 (21:22 +0000)]
video/bochs: Fix typo

Signed-off-by: Ave Milia <avemilia@protonmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agolinux: Fix integer overflows in initrd size handling
Colin Watson [Sat, 25 Jul 2020 11:15:37 +0000 (12:15 +0100)]
linux: Fix integer overflows in initrd size handling

These could be triggered by a crafted filesystem with very large files.

Fixes: CVE-2020-15707
Signed-off-by: Colin Watson <cjwatson@debian.org>
Reviewed-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoloader/linux: Avoid overflow on initrd size calculation
Peter Jones [Fri, 24 Jul 2020 17:57:27 +0000 (13:57 -0400)]
loader/linux: Avoid overflow on initrd size calculation

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Fix use-after-free in halt/reboot path
Alexey Makhalov [Mon, 20 Jul 2020 23:03:05 +0000 (23:03 +0000)]
efi: Fix use-after-free in halt/reboot path

commit 92bfc33db984 ("efi: Free malloc regions on exit")
introduced memory freeing in grub_efi_fini(), which is
used not only by exit path but by halt/reboot one as well.
As result of memory freeing, code and data regions used by
modules, such as halt, reboot, acpi (used by halt) also got
freed. After return to module code, CPU executes, filled
by UEFI firmware (tested with edk2), 0xAFAFAFAF pattern as
a code. Which leads to #UD exception later.

grub> halt
!!!! X64 Exception Type - 06(#UD - Invalid Opcode)  CPU Apic ID - 00000000 !!!!
RIP  - 0000000003F4EC28, CS  - 0000000000000038, RFLAGS - 0000000000200246
RAX  - 0000000000000000, RCX - 00000000061DA188, RDX - 0A74C0854DC35D41
RBX  - 0000000003E10E08, RSP - 0000000007F0F860, RBP - 0000000000000000
RSI  - 00000000064DB768, RDI - 000000000832C5C3
R8   - 0000000000000002, R9  - 0000000000000000, R10 - 00000000061E2E52
R11  - 0000000000000020, R12 - 0000000003EE5C1F, R13 - 00000000061E0FF4
R14  - 0000000003E10D80, R15 - 00000000061E2F60
DS   - 0000000000000030, ES  - 0000000000000030, FS  - 0000000000000030
GS   - 0000000000000030, SS  - 0000000000000030
CR0  - 0000000080010033, CR2 - 0000000000000000, CR3 - 0000000007C01000
CR4  - 0000000000000668, CR8 - 0000000000000000
DR0  - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
DR3  - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
GDTR - 00000000079EEA98 0000000000000047, LDTR - 0000000000000000
IDTR - 0000000007598018 0000000000000FFF,   TR - 0000000000000000
FXSAVE_STATE - 0000000007F0F4C0

Proposal here is to continue to free allocated memory for
exit boot services path but keep it for halt/reboot path
as it won't be much security concern here.
Introduced GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY
loader flag to be used by efi halt/reboot path.

Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi/chainloader: Propagate errors from copy_file_path()
Daniel Kiper [Wed, 29 Jul 2020 11:38:31 +0000 (13:38 +0200)]
efi/chainloader: Propagate errors from copy_file_path()

Without any error propagated to the caller, make_file_path()
would then try to advance the invalid device path node with
GRUB_EFI_NEXT_DEVICE_PATH(), which would fail, returning a NULL
pointer that would subsequently be dereferenced. Hence, propagate
errors from copy_file_path().

Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Fix some malformed device path arithmetic errors
Peter Jones [Sun, 19 Jul 2020 20:53:27 +0000 (16:53 -0400)]
efi: Fix some malformed device path arithmetic errors

Several places we take the length of a device path and subtract 4 from
it, without ever checking that it's >= 4. There are also cases where
this kind of malformation will result in unpredictable iteration,
including treating the length from one dp node as the type in the next
node. These are all errors, no matter where the data comes from.

This patch adds a checking macro, GRUB_EFI_DEVICE_PATH_VALID(), which
can be used in several places, and makes GRUB_EFI_NEXT_DEVICE_PATH()
return NULL and GRUB_EFI_END_ENTIRE_DEVICE_PATH() evaluate as true when
the length is too small. Additionally, it makes several places in the
code check for and return errors in these cases.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoemu: Make grub_free(NULL) safe
Peter Jones [Sun, 19 Jul 2020 20:08:08 +0000 (16:08 -0400)]
emu: Make grub_free(NULL) safe

The grub_free() implementation in grub-core/kern/mm.c safely handles
NULL pointers, and code at many places depends on this. We don't know
that the same is true on all host OSes, so we need to handle the same
behavior in grub-emu's implementation.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agolvm: Fix two more potential data-dependent alloc overflows
Peter Jones [Sun, 19 Jul 2020 19:48:20 +0000 (15:48 -0400)]
lvm: Fix two more potential data-dependent alloc overflows

It appears to be possible to make a (possibly invalid) lvm PV with
a metadata size field that overflows our type when adding it to the
address we've allocated. Even if it doesn't, it may be possible to do so
with the math using the outcome of that as an operand. Check them both.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agohfsplus: Fix two more overflows
Peter Jones [Sun, 19 Jul 2020 18:43:31 +0000 (14:43 -0400)]
hfsplus: Fix two more overflows

Both node->size and node->namelen come from the supplied filesystem,
which may be user-supplied. We can't trust them for the math unless we
know they don't overflow. Making sure they go through grub_add() or
grub_calloc() first will give us that.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agorelocator: Fix grub_relocator_alloc_chunk_align() top memory allocation
Alexey Makhalov [Fri, 17 Jul 2020 05:17:26 +0000 (05:17 +0000)]
relocator: Fix grub_relocator_alloc_chunk_align() top memory allocation

Current implementation of grub_relocator_alloc_chunk_align()
does not allow allocation of the top byte.

Assuming input args are:
  max_addr = 0xfffff000;
  size = 0x1000;

And this is valid. But following overflow protection will
unnecessarily move max_addr one byte down (to 0xffffefff):
  if (max_addr > ~size)
    max_addr = ~size;

~size + 1 will fix the situation. In addition, check size
for non zero to do not zero max_addr.

Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoscript: Avoid a use-after-free when redefining a function during execution
Chris Coulson [Fri, 10 Jul 2020 13:41:45 +0000 (14:41 +0100)]
script: Avoid a use-after-free when redefining a function during execution

Defining a new function with the same name as a previously defined
function causes the grub_script and associated resources for the
previous function to be freed. If the previous function is currently
executing when a function with the same name is defined, this results
in use-after-frees when processing subsequent commands in the original
function.

Instead, reject a new function definition if it has the same name as
a previously defined function, and that function is currently being
executed. Although a behavioural change, this should be backwards
compatible with existing configurations because they can't be
dependent on the current behaviour without being broken.

Fixes: CVE-2020-15706
Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoscript: Remove unused fields from grub_script_function struct
Chris Coulson [Fri, 10 Jul 2020 10:21:14 +0000 (11:21 +0100)]
script: Remove unused fields from grub_script_function struct

Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agorelocator: Protect grub_relocator_alloc_chunk_align() max_addr against integer underflow
Alexey Makhalov [Wed, 8 Jul 2020 01:44:38 +0000 (01:44 +0000)]
relocator: Protect grub_relocator_alloc_chunk_align() max_addr against integer underflow

This commit introduces integer underflow mitigation in max_addr calculation
in grub_relocator_alloc_chunk_align() invocation.

It consists of 2 fixes:
  1. Introduced grub_relocator_alloc_chunk_align_safe() wrapper function to perform
     sanity check for min/max and size values, and to make safe invocation of
     grub_relocator_alloc_chunk_align() with validated max_addr value. Replace all
     invocations such as grub_relocator_alloc_chunk_align(..., min_addr, max_addr - size, size, ...)
     by grub_relocator_alloc_chunk_align_safe(..., min_addr, max_addr, size, ...).
  2. Introduced UP_TO_TOP32(s) macro for the cases where max_addr is 32-bit top
     address (0xffffffff - size + 1) or similar.

Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agorelocator: Protect grub_relocator_alloc_chunk_addr() input args against integer under...
Alexey Makhalov [Wed, 15 Jul 2020 06:42:37 +0000 (06:42 +0000)]
relocator: Protect grub_relocator_alloc_chunk_addr() input args against integer underflow/overflow

Use arithmetic macros from safemath.h to accomplish it. In this commit,
I didn't want to be too paranoid to check every possible math equation
for overflow/underflow. Only obvious places (with non zero chance of
overflow/underflow) were refactored.

Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agotftp: Do not use priority queue
Alexey Makhalov [Thu, 9 Jul 2020 08:10:40 +0000 (08:10 +0000)]
tftp: Do not use priority queue

There is not need to reassemble the order of blocks. Per RFC 1350,
server must wait for the ACK, before sending next block. Data packets
can be served immediately without putting them to priority queue.

Logic to handle incoming packet is this:
  - if packet block id equal to expected block id, then
    process the packet,
  - if packet block id is less than expected - this is retransmit
    of old packet, then ACK it and drop the packet,
  - if packet block id is more than expected - that shouldn't
    happen, just drop the packet.

It makes the tftp receive path code simpler, smaller and faster.
As a benefit, this change fixes CID# 73624 and CID# 96690, caused
by following while loop:

  while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0)

where tftph pointer is not moving from one iteration to another, causing
to serve same packet again. Luckily, double serving didn't happen due to
data->block++ during the first iteration.

Fixes: CID 73624, CID 96690
Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agomultiboot2: Fix memory leak if grub_create_loader_cmdline() fails
Konrad Rzeszutek Wilk [Fri, 26 Jun 2020 14:51:43 +0000 (10:51 -0400)]
multiboot2: Fix memory leak if grub_create_loader_cmdline() fails

Fixes: CID 292468
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoudf: Fix memory leak
Konrad Rzeszutek Wilk [Wed, 8 Jul 2020 02:02:31 +0000 (22:02 -0400)]
udf: Fix memory leak

Fixes: CID 73796
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
3 years agoterm: Fix overflow on user inputs
Konrad Rzeszutek Wilk [Tue, 7 Jul 2020 19:12:25 +0000 (15:12 -0400)]
term: Fix overflow on user inputs

This requires a very weird input from the serial interface but can cause
an overflow in input_buf (keys) overwriting the next variable (npending)
with the user choice:

(pahole output)

struct grub_terminfo_input_state {
        int                        input_buf[6];         /*     0    24 */
        int                        npending;             /*    24     4 */ <- CORRUPT
        ...snip...

The magic string requires causing this is "ESC,O,],0,1,2,q" and we overflow
npending with "q" (aka increase npending to 161). The simplest fix is to
just to disallow overwrites input_buf, which exactly what this patch does.

Fixes: CID 292449
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agolzma: Make sure we don't dereference past array
Konrad Rzeszutek Wilk [Thu, 9 Jul 2020 03:05:23 +0000 (03:05 +0000)]
lzma: Make sure we don't dereference past array

The two dimensional array p->posSlotEncoder[4][64] is being dereferenced
using the GetLenToPosState() macro which checks if len is less than 5,
and if so subtracts 2 from it. If len = 0, that is 0 - 2 = 4294967294.
Obviously we don't want to dereference that far out so we check if the
position found is greater or equal kNumLenToPosStates (4) and bail out.

N.B.: Upstream LZMA 18.05 and later has this function completely rewritten
without any history.

Fixes: CID 51526
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agojson: Avoid a double-free when parsing fails.
Chris Coulson [Thu, 9 Jul 2020 18:04:43 +0000 (19:04 +0100)]
json: Avoid a double-free when parsing fails.

When grub_json_parse() succeeds, it returns the root object which
contains a pointer to the provided JSON string. Callers are
responsible for ensuring that this string outlives the root
object and for freeing its memory when it's no longer needed.

If grub_json_parse() fails to parse the provided JSON string,
it frees the string before returning an error. This results
in a double free in luks2_recover_key(), which also frees the
same string after grub_json_parse() returns an error.

This changes grub_json_parse() to never free the JSON string
passed to it, and updates the documentation for it to make it
clear that callers are responsible for ensuring that the string
outlives the root JSON object.

Fixes: CID 292465
Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoxnu: Fix double free in grub_xnu_devprop_add_property()
Alexey Makhalov [Wed, 8 Jul 2020 21:30:43 +0000 (21:30 +0000)]
xnu: Fix double free in grub_xnu_devprop_add_property()

grub_xnu_devprop_add_property() should not free utf8 and utf16 as it get
allocated and freed in the caller.

Minor improvement: do prop fields initialization after memory allocations.

Fixes: CID 292442, CID 292457, CID 292460, CID 292466
Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogfxmenu: Fix double free in load_image()
Alexey Makhalov [Wed, 8 Jul 2020 20:41:56 +0000 (20:41 +0000)]
gfxmenu: Fix double free in load_image()

self->bitmap should be zeroed after free. Otherwise, there is a chance
to double free (USE_AFTER_FREE) it later in rescale_image().

Fixes: CID 292472
Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agofont: Do not load more than one NAME section
Daniel Kiper [Tue, 7 Jul 2020 13:36:26 +0000 (15:36 +0200)]
font: Do not load more than one NAME section

The GRUB font file can have one NAME section only. Though if somebody
crafts a broken font file with many NAME sections and loads it then the
GRUB leaks memory. So, prevent against that by loading first NAME
section and failing in controlled way on following one.

Reported-by: Chris Coulson <chris.coulson@canonical.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
3 years agoiso9660: Don't leak memory on realloc() failures
Peter Jones [Sat, 4 Jul 2020 16:25:09 +0000 (12:25 -0400)]
iso9660: Don't leak memory on realloc() failures

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agomalloc: Use overflow checking primitives where we do complex allocations
Peter Jones [Mon, 15 Jun 2020 16:28:27 +0000 (12:28 -0400)]
malloc: Use overflow checking primitives where we do complex allocations

This attempts to fix the places where we do the following where
arithmetic_expr may include unvalidated data:

  X = grub_malloc(arithmetic_expr);

It accomplishes this by doing the arithmetic ahead of time using grub_add(),
grub_sub(), grub_mul() and testing for overflow before proceeding.

Among other issues, this fixes:
  - allocation of integer overflow in grub_video_bitmap_create()
    reported by Chris Coulson,
  - allocation of integer overflow in grub_png_decode_image_header()
    reported by Chris Coulson,
  - allocation of integer overflow in grub_squash_read_symlink()
    reported by Chris Coulson,
  - allocation of integer overflow in grub_ext2_read_symlink()
    reported by Chris Coulson,
  - allocation of integer overflow in read_section_as_string()
    reported by Chris Coulson.

Fixes: CVE-2020-14309, CVE-2020-14310, CVE-2020-14311
Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocalloc: Use calloc() at most places
Peter Jones [Mon, 15 Jun 2020 16:26:01 +0000 (12:26 -0400)]
calloc: Use calloc() at most places

This modifies most of the places we do some form of:

  X = malloc(Y * Z);

to use calloc(Y, Z) instead.

Among other issues, this fixes:
  - allocation of integer overflow in grub_png_decode_image_header()
    reported by Chris Coulson,
  - allocation of integer overflow in luks_recover_key()
    reported by Chris Coulson,
  - allocation of integer overflow in grub_lvm_detect()
    reported by Chris Coulson.

Fixes: CVE-2020-14308
Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocalloc: Make sure we always have an overflow-checking calloc() available
Peter Jones [Mon, 15 Jun 2020 16:15:29 +0000 (12:15 -0400)]
calloc: Make sure we always have an overflow-checking calloc() available

This tries to make sure that everywhere in this source tree, we always have
an appropriate version of calloc() (i.e. grub_calloc(), xcalloc(), etc.)
available, and that they all safely check for overflow and return NULL when
it would occur.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agosafemath: Add some arithmetic primitives that check for overflow
Peter Jones [Mon, 15 Jun 2020 14:58:42 +0000 (10:58 -0400)]
safemath: Add some arithmetic primitives that check for overflow

This adds a new header, include/grub/safemath.h, that includes easy to
use wrappers for __builtin_{add,sub,mul}_overflow() declared like:

  bool OP(a, b, res)

where OP is grub_add, grub_sub or grub_mul. OP() returns true in the
case where the operation would overflow and res is not modified.
Otherwise, false is returned and the operation is executed.

These arithmetic primitives require newer compiler versions. So, bump
these requirements in the INSTALL file too.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoyylex: Make lexer fatal errors actually be fatal
Peter Jones [Wed, 15 Apr 2020 19:45:02 +0000 (15:45 -0400)]
yylex: Make lexer fatal errors actually be fatal

When presented with a command that can't be tokenized to anything
smaller than YYLMAX characters, the parser calls YY_FATAL_ERROR(errmsg),
expecting that will stop further processing, as such:

  #define YY_DO_BEFORE_ACTION \
        yyg->yytext_ptr = yy_bp; \
        yyleng = (int) (yy_cp - yy_bp); \
        yyg->yy_hold_char = *yy_cp; \
        *yy_cp = '\0'; \
        if ( yyleng >= YYLMAX ) \
                YY_FATAL_ERROR( "token too large, exceeds YYLMAX" ); \
        yy_flex_strncpy( yytext, yyg->yytext_ptr, yyleng + 1 , yyscanner); \
        yyg->yy_c_buf_p = yy_cp;

The code flex generates expects that YY_FATAL_ERROR() will either return
for it or do some form of longjmp(), or handle the error in some way at
least, and so the strncpy() call isn't in an "else" clause, and thus if
YY_FATAL_ERROR() is *not* actually fatal, it does the call with the
questionable limit, and predictable results ensue.

Unfortunately, our implementation of YY_FATAL_ERROR() is:

   #define YY_FATAL_ERROR(msg)                     \
     do {                                          \
       grub_printf (_("fatal error: %s\n"), _(msg));     \
     } while (0)

The same pattern exists in yyless(), and similar problems exist in users
of YY_INPUT(), several places in the main parsing loop,
yy_get_next_buffer(), yy_load_buffer_state(), yyensure_buffer_stack,
yy_scan_buffer(), etc.

All of these callers expect YY_FATAL_ERROR() to actually be fatal, and
the things they do if it returns after calling it are wildly unsafe.

Fixes: CVE-2020-10713
Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agoarm: Fix 32-bit ARM handling of the CTR register
Marc Zyngier [Sun, 24 May 2020 11:32:48 +0000 (12:32 +0100)]
arm: Fix 32-bit ARM handling of the CTR register

When booting on an ARMv8 core that implements either CTR.IDC or CTR.DIC
(indicating that some of the cache maintenance operations can be
removed when dealing with I/D-cache coherency, GRUB dies with a
"Unsupported cache type 0x........" message.

This is pretty likely to happen when running in a virtual machine
hosted on an arm64 machine (I've triggered it on a system built around
a bunch of Cortex-A55 cores, which implements CTR.IDC).

It turns out that the way GRUB deals with the CTR register is a bit
harsh for anything from ARMv7 onwards. The layout of the register is
backward compatible, meaning that nothing that gets added is allowed to
break earlier behaviour. In this case, ignoring IDC is completely fine,
and only results in unnecessary cache maintenance.

We can thus avoid being paranoid, and align the 32bit behaviour with
its 64bit equivalent.

This patch has the added benefit that it gets rid of a (gnu-specific)
case range too.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agotemplates/20_linux_xen: Support Xen Security Modules (XSM/FLASK)
Ian Jackson [Wed, 20 May 2020 12:14:20 +0000 (13:14 +0100)]
templates/20_linux_xen: Support Xen Security Modules (XSM/FLASK)

XSM is enabled by adding "flask=enforcing" as a Xen command line
argument, and providing the policy file as a grub module.

We make entries for both with and without XSM. If XSM is not compiled
into Xen, then there are no policy files, so no change to the boot
options.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agotemplates/20_linux_xen: Ignore xenpolicy and config files too
Ian Jackson [Wed, 20 May 2020 12:14:19 +0000 (13:14 +0100)]
templates/20_linux_xen: Ignore xenpolicy and config files too

file_is_not_sym() currently only checks for xen-syms. Extend it to
disregard xenpolicy (XSM policy files) and files ending .config (which
are built by the Xen upstream build system in some configurations and
can therefore end up in /boot).

Rename the function accordingly, to file_is_not_xen_garbage().

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agonet: Break out nested function
Javier Martinez Canillas [Tue, 19 May 2020 15:53:03 +0000 (17:53 +0200)]
net: Break out nested function

Nested functions are not supported in C, but are permitted as an extension
in the GNU C dialect. Commit cb2f15c5448 ("normal/main: Search for specific
config files for netboot") added a nested function which caused the build
to break when compiling with clang.

Break that out into a static helper function to make the code portable again.

Reported-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Tested-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agotpm: Enable module for all EFI platforms
Javier Martinez Canillas [Tue, 19 May 2020 09:20:59 +0000 (11:20 +0200)]
tpm: Enable module for all EFI platforms

The module is only enabled for x86_64, but there's nothing specific to
x86_64 in the implementation and can be enabled for all EFI platforms.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agoINSTALL/configure: Update install doc and configure comment
Daniel Kiper [Wed, 13 May 2020 12:02:49 +0000 (14:02 +0200)]
INSTALL/configure: Update install doc and configure comment

..to reflect the GRUB build reality in them.

Additionally, fix text formatting a bit.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
4 years agoconfigure: Set gnu99 C language standard by default
Daniel Kiper [Wed, 13 May 2020 12:02:48 +0000 (14:02 +0200)]
configure: Set gnu99 C language standard by default

Commit d5a32255d (misc: Make grub_strtol() "end" pointers have safer
const qualifiers) introduced "restrict" keyword into some functions
definitions. This keyword was introduced in C99 standard. However, some
compilers by default may use C89 or something different. This behavior
leads to the breakage during builds when c89 or gnu89 is in force. So,
let's set gnu99 C language standard for all compilers by default. This
way a bit random build issue will be fixed and the GRUB source will be
build consistently regardless of type and version of the compiler.

It was decided to use gnu99 C language standard because it fixes the
issue mentioned above and also provides some useful extensions which are
used here and there in the GRUB source. Potentially we can use gnu11
too. However, this may reduce pool of older compilers which can be used
to build the GRUB. So, let's live with gnu99 until we discover that we
strongly require a feature from newer C standard.

The user is still able to override C language standard using relevant
*_CFLAGS variables.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
4 years agotpm: Rename function grub_tpm_log_event() to grub_tpm_measure()
Tianjia Zhang [Wed, 13 May 2020 13:13:29 +0000 (21:13 +0800)]
tpm: Rename function grub_tpm_log_event() to grub_tpm_measure()

grub_tpm_log_event() and grub_tpm_measure() are two functions that
have the same effect. So, keep grub_tpm_log_event() and rename it
to grub_tpm_measure(). This way we get also a more clear semantics.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agoautogen: Replace -iname with -ipath in find command
Daniel Kiper [Wed, 13 May 2020 12:02:51 +0000 (14:02 +0200)]
autogen: Replace -iname with -ipath in find command

..because -iname cannot be used to match paths.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
Reviewed-by: Daniel Axtens <dja@axtens.net>
4 years agoINSTALL: Update configure example
Daniel Kiper [Wed, 13 May 2020 12:02:50 +0000 (14:02 +0200)]
INSTALL: Update configure example

..to make it more relevant.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
4 years agoconfigure: Drop unneeded TARGET_CFLAGS expansion
Daniel Kiper [Wed, 13 May 2020 12:02:47 +0000 (14:02 +0200)]
configure: Drop unneeded TARGET_CFLAGS expansion

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
4 years agodocs/grub: Support for probing partition UUID on MSDOS disks
Jacob Kroon [Wed, 13 May 2020 09:04:37 +0000 (11:04 +0200)]
docs/grub: Support for probing partition UUID on MSDOS disks

Support was implemented in commit c7cb11b21 (probe: Support probing for
msdos PARTUUID).

Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>