]> git.proxmox.com Git - grub2.git/log
grub2.git
3 years agokern/partition: Check for NULL before dereferencing input string
Darren Kenny [Fri, 23 Oct 2020 09:49:59 +0000 (09:49 +0000)]
kern/partition: Check for NULL before dereferencing input string

There is the possibility that the value of str comes from an external
source and continuing to use it before ever checking its validity is
wrong. So, needs fixing.

Additionally, drop unneeded part initialization.

Fixes: CID 292444
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agozstd: Initialize seq_t structure fully
Darren Kenny [Thu, 5 Nov 2020 10:29:59 +0000 (10:29 +0000)]
zstd: Initialize seq_t structure fully

While many compilers will initialize this to zero, not all will, so it
is better to be sure that fields not being explicitly set are at known
values, and there is code that checks this fields value elsewhere in the
code.

Fixes: CID 292440
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoio/lzopio: Resolve unnecessary self-assignment errors
Darren Kenny [Wed, 21 Oct 2020 14:44:10 +0000 (14:44 +0000)]
io/lzopio: Resolve unnecessary self-assignment errors

These 2 assignments are unnecessary since they are just assigning
to themselves.

Fixes: CID 73643
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib/regcomp: Fix uninitialized re_token
Darren Kenny [Tue, 24 Nov 2020 18:04:22 +0000 (18:04 +0000)]
gnulib/regcomp: Fix uninitialized re_token

This issue has been fixed in the latest version of gnulib, so to
maintain consistency, I've backported that change rather than doing
something different.

Fixes: CID 73828
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib/regexec: Fix possible null-dereference
Darren Kenny [Thu, 5 Nov 2020 10:57:14 +0000 (10:57 +0000)]
gnulib/regexec: Fix possible null-dereference

It appears to be possible that the mctx->state_log field may be NULL,
and the name of this function, clean_state_log_if_needed(), suggests
that it should be checking that it is valid to be cleaned before
assuming that it does.

Fixes: CID 86720
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib/argp-help: Fix dereference of a possibly NULL state
Darren Kenny [Wed, 28 Oct 2020 14:43:01 +0000 (14:43 +0000)]
gnulib/argp-help: Fix dereference of a possibly NULL state

All other instances of call to __argp_failure() where there is
a dgettext() call is first checking whether state is NULL before
attempting to dereference it to get the root_argp->argp_domain.

Fixes: CID 292436
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib/regcomp: Fix uninitialized token structure
Darren Kenny [Thu, 22 Oct 2020 13:54:06 +0000 (13:54 +0000)]
gnulib/regcomp: Fix uninitialized token structure

The code is assuming that the value of br_token.constraint was
initialized to zero when it wasn't.

While some compilers will ensure that, not all do, so it is better to
fix this explicitly than leave it to chance.

Fixes: CID 73749
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agognulib/regexec: Resolve unused variable
Darren Kenny [Wed, 21 Oct 2020 14:41:27 +0000 (14:41 +0000)]
gnulib/regexec: Resolve unused variable

This is a really minor issue where a variable is being assigned to but
not checked before it is overwritten again.

The reason for this issue is that we are not building with DEBUG set and
this in turn means that the assert() that reads the value of the
variable match_last is being processed out.

The solution, move the assignment to match_last in to an ifdef DEBUG too.

Fixes: CID 292459
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/efi/mm: Fix possible NULL pointer dereference
Darren Kenny [Fri, 11 Dec 2020 15:03:13 +0000 (15:03 +0000)]
kern/efi/mm: Fix possible NULL pointer dereference

The model of grub_efi_get_memory_map() is that if memory_map is NULL,
then the purpose is to discover how much memory should be allocated to
it for the subsequent call.

The problem here is that with grub_efi_is_finished set to 1, there is no
check at all that the function is being called with a non-NULL memory_map.

While this MAY be true, we shouldn't assume it.

The solution to this is to behave as expected, and if memory_map is NULL,
then don't try to use it and allow memory_map_size to be filled in, and
return 0 as is done later in the code if the buffer is too small (or NULL).

Additionally, drop unneeded ret = 1.

Fixes: CID 96632
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/efi: Fix memory leak on failure
Darren Kenny [Thu, 5 Nov 2020 10:15:25 +0000 (10:15 +0000)]
kern/efi: Fix memory leak on failure

Free the memory allocated to name before returning on failure.

Fixes: CID 296222
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/parser: Fix resource leak if argc == 0
Darren Kenny [Fri, 22 Jan 2021 12:32:41 +0000 (12:32 +0000)]
kern/parser: Fix resource leak if argc == 0

After processing the command-line yet arriving at the point where we are
setting argv, we are allocating memory, even if argc == 0, which makes
no sense since we never put anything into the allocated argv.

The solution is to simply return that we've successfully processed the
arguments but that argc == 0, and also ensure that argv is NULL when
we're not allocating anything in it.

There are only 2 callers of this function, and both are handling a zero
value in argc assuming nothing is allocated in argv.

Fixes: CID 96680
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/tftp: Fix dangling memory pointer
Darren Kenny [Fri, 19 Feb 2021 17:12:23 +0000 (17:12 +0000)]
net/tftp: Fix dangling memory pointer

The static code analysis tool, Parfait, reported that the valid of
file->data was left referencing memory that was freed by the call to
grub_free(data) where data was initialized from file->data.

To ensure that there is no unintentional access to this memory
referenced by file->data we should set the pointer to NULL.

Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agonet/net: Fix possible dereference to of a NULL pointer
Darren Kenny [Fri, 27 Nov 2020 15:10:26 +0000 (15:10 +0000)]
net/net: Fix possible dereference to of a NULL pointer

It is always possible that grub_zalloc() could fail, so we should check for
a NULL return. Otherwise we run the risk of dereferencing a NULL pointer.

Fixes: CID 296221
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agommap: Fix memory leak when iterating over mapped memory
Darren Kenny [Thu, 3 Dec 2020 14:39:45 +0000 (14:39 +0000)]
mmap: Fix memory leak when iterating over mapped memory

When returning from grub_mmap_iterate() the memory allocated to present
is not being released causing it to leak.

Fixes: CID 96655
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agousb: Avoid possible out-of-bound accesses caused by malicious devices
Javier Martinez Canillas [Fri, 11 Dec 2020 18:19:21 +0000 (19:19 +0100)]
usb: Avoid possible out-of-bound accesses caused by malicious devices

The maximum number of configurations and interfaces are fixed but there is
no out-of-bound checking to prevent a malicious USB device to report large
values for these and cause accesses outside the arrays' memory.

Fixes: CVE-2020-25647
Reported-by: Joseph Tartaro <joseph.tartaro@ioactive.com>
Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodl: Only allow unloading modules that are not dependencies
Javier Martinez Canillas [Tue, 29 Sep 2020 12:08:55 +0000 (14:08 +0200)]
dl: Only allow unloading modules that are not dependencies

When a module is attempted to be removed its reference counter is always
decremented. This means that repeated rmmod invocations will cause the
module to be unloaded even if another module depends on it.

This may lead to a use-after-free scenario allowing an attacker to execute
arbitrary code and by-pass the UEFI Secure Boot protection.

While being there, add the extern keyword to some function declarations in
that header file.

Fixes: CVE-2020-25632
Reported-by: Chris Coulson <chris.coulson@canonical.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agodocs: Document the cutmem command
Javier Martinez Canillas [Sat, 7 Nov 2020 00:03:18 +0000 (01:03 +0100)]
docs: Document the cutmem command

The command is not present in the docs/grub.texi user documentation.

Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agoloader/xnu: Don't allow loading extension and packages when locked down
Javier Martinez Canillas [Wed, 24 Feb 2021 13:44:38 +0000 (14:44 +0100)]
loader/xnu: Don't allow loading extension and packages when locked down

The shim_lock verifier validates the XNU kernels but no its extensions
and packages. Prevent these to be loaded when the GRUB is locked down.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agogdb: Restrict GDB access when locked down
Javier Martinez Canillas [Wed, 24 Feb 2021 14:03:26 +0000 (15:03 +0100)]
gdb: Restrict GDB access when locked down

The gdbstub* commands allow to start and control a GDB stub running on
local host that can be used to connect from a remote debugger. Restrict
this functionality when the GRUB is locked down.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocommands/hdparm: Restrict hdparm command when locked down
Javier Martinez Canillas [Wed, 24 Feb 2021 11:59:29 +0000 (12:59 +0100)]
commands/hdparm: Restrict hdparm command when locked down

The command can be used to get/set ATA disk parameters. Some of these can
be dangerous since change the disk behavior. Restrict it when locked down.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocommands/setpci: Restrict setpci command when locked down
Javier Martinez Canillas [Wed, 24 Feb 2021 21:59:59 +0000 (22:59 +0100)]
commands/setpci: Restrict setpci command when locked down

This command can set PCI devices register values, which makes it dangerous
in a locked down configuration. Restrict it so can't be used on this setup.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocommands: Restrict commands that can load BIOS or DT blobs when locked down
Javier Martinez Canillas [Wed, 24 Feb 2021 08:00:05 +0000 (09:00 +0100)]
commands: Restrict commands that can load BIOS or DT blobs when locked down

There are some more commands that should be restricted when the GRUB is
locked down. Following is the list of commands and reasons to restrict:

  * fakebios:   creates BIOS-like structures for backward compatibility with
                existing OSes. This should not be allowed when locked down.

  * loadbios:   reads a BIOS dump from storage and loads it. This action
                should not be allowed when locked down.

  * devicetree: loads a Device Tree blob and passes it to the OS. It replaces
                any Device Tree provided by the firmware. This also should
                not be allowed when locked down.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agommap: Don't register cutmem and badram commands when lockdown is enforced
Javier Martinez Canillas [Wed, 14 Oct 2020 14:33:42 +0000 (16:33 +0200)]
mmap: Don't register cutmem and badram commands when lockdown is enforced

The cutmem and badram commands can be used to remove EFI memory regions
and potentially disable the UEFI Secure Boot. Prevent the commands to be
registered if the GRUB is locked down.

Fixes: CVE-2020-27779
Reported-by: Teddy Reed <teddy.reed@gmail.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoacpi: Don't register the acpi command when locked down
Javier Martinez Canillas [Mon, 28 Sep 2020 18:08:41 +0000 (20:08 +0200)]
acpi: Don't register the acpi command when locked down

The command is not allowed when lockdown is enforced. Otherwise an
attacker can instruct the GRUB to load an SSDT table to overwrite
the kernel lockdown configuration and later load and execute
unsigned code.

Fixes: CVE-2020-14372
Reported-by: Máté Kukri <km@mkukri.xyz>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Use grub_is_lockdown() instead of hardcoding a disabled modules list
Javier Martinez Canillas [Mon, 28 Sep 2020 18:08:33 +0000 (20:08 +0200)]
efi: Use grub_is_lockdown() instead of hardcoding a disabled modules list

Now the GRUB can check if it has been locked down and this can be used to
prevent executing commands that can be utilized to circumvent the UEFI
Secure Boot mechanisms. So, instead of hardcoding a list of modules that
have to be disabled, prevent the usage of commands that can be dangerous.

This not only allows the commands to be disabled on other platforms, but
also properly separate the concerns. Since the shim_lock verifier logic
should be only about preventing to run untrusted binaries and not about
defining these kind of policies.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Lockdown the GRUB when the UEFI Secure Boot is enabled
Javier Martinez Canillas [Mon, 28 Sep 2020 18:08:29 +0000 (20:08 +0200)]
efi: Lockdown the GRUB when the UEFI Secure Boot is enabled

If the UEFI Secure Boot is enabled then the GRUB must be locked down
to prevent executing code that can potentially be used to subvert its
verification mechanisms.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern/lockdown: Set a variable if the GRUB is locked down
Javier Martinez Canillas [Tue, 2 Feb 2021 18:59:48 +0000 (19:59 +0100)]
kern/lockdown: Set a variable if the GRUB is locked down

It may be useful for scripts to determine whether the GRUB is locked
down or not. Add the lockdown variable which is set to "y" when the GRUB
is locked down.

Suggested-by: Dimitri John Ledkov <xnox@ubuntu.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agokern: Add lockdown support
Javier Martinez Canillas [Mon, 28 Sep 2020 18:08:02 +0000 (20:08 +0200)]
kern: Add lockdown support

When the GRUB starts on a secure boot platform, some commands can be
used to subvert the protections provided by the verification mechanism and
could lead to booting untrusted system.

To prevent that situation, allow GRUB to be locked down. That way the code
may check if GRUB has been locked down and further restrict the commands
that are registered or what subset of their functionality could be used.

The lockdown support adds the following components:

* The grub_lockdown() function which can be used to lockdown GRUB if,
  e.g., UEFI Secure Boot is enabled.

* The grub_is_lockdown() function which can be used to check if the GRUB
  was locked down.

* A verifier that flags OS kernels, the GRUB modules, Device Trees and ACPI
  tables as GRUB_VERIFY_FLAGS_DEFER_AUTH to defer verification to other
  verifiers. These files are only successfully verified if another registered
  verifier returns success. Otherwise, the whole verification process fails.

  For example, PE/COFF binaries verification can be done by the shim_lock
  verifier which validates the signatures using the shim_lock protocol.
  However, the verification is not deferred directly to the shim_lock verifier.
  The shim_lock verifier is hooked into the verification process instead.

* A set of grub_{command,extcmd}_lockdown functions that can be used by
  code registering command handlers, to only register unsafe commands if
  the GRUB has not been locked down.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoefi: Move the shim_lock verifier to the GRUB core
Marco A Benatto [Wed, 23 Sep 2020 18:21:14 +0000 (14:21 -0400)]
efi: Move the shim_lock verifier to the GRUB core

Move the shim_lock verifier from its own module into the core image. The
Secure Boot lockdown mechanism has the intent to prevent the load of any
unsigned code or binary when Secure Boot is enabled.

The reason is that GRUB must be able to prevent executing untrusted code
if UEFI Secure Boot is enabled, without depending on external modules.

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 agoverifiers: Move verifiers API to kernel image
Marco A Benatto [Wed, 23 Sep 2020 15:33:33 +0000 (11:33 -0400)]
verifiers: Move verifiers API to kernel image

Move verifiers API from a module to the kernel image, so it can be
used there as well. There are no functional changes in this patch.

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 agodocs: Add documentation of disk size limitations
Glenn Washburn [Wed, 16 Dec 2020 00:47:34 +0000 (18:47 -0600)]
docs: Add documentation of disk size limitations

Document the artificially imposed 1 EiB disk size limit and size limitations
with LUKS volumes.

Fix a few punctuation issues.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Use grub_log2ull() to calculate log_sector_size and improve readability
Glenn Washburn [Tue, 15 Dec 2020 23:31:11 +0000 (17:31 -0600)]
luks2: Use grub_log2ull() to calculate log_sector_size and improve readability

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agomisc: Add grub_log2ull() macro for calculating log base 2 of 64-bit integers
Glenn Washburn [Tue, 15 Dec 2020 23:31:10 +0000 (17:31 -0600)]
misc: Add grub_log2ull() macro for calculating log base 2 of 64-bit integers

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agomips: Enable __clzdi2()
Glenn Washburn [Tue, 15 Dec 2020 23:31:09 +0000 (17:31 -0600)]
mips: Enable __clzdi2()

This patch is similar to commit 9dab2f51e (sparc: Enable __clzsi2() and
__clzdi2()) but for MIPS target and __clzdi2() only, __clzsi2() was
already enabled.

Suggested-by: Daniel Kiper <dkiper@net-space.pl>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Better error handling when setting up the cryptodisk
Glenn Washburn [Tue, 15 Dec 2020 23:31:08 +0000 (17:31 -0600)]
luks2: Better error handling when setting up the cryptodisk

Do some sanity checking on data coming from the LUKS2 header. If segment.size
is "dynamic", verify that the offset is not past the end of disk. Otherwise,
check for errors from grub_strtoull() when converting segment size from
string. If a GRUB_ERR_BAD_NUMBER error was returned, then the string was
not a valid parsable number, so skip the key. If GRUB_ERR_OUT_OF_RANGE was
returned, then there was an overflow in converting to a 64-bit unsigned
integer. So this could be a very large disk (perhaps large RAID array).
In this case skip the key too. Additionally, enforce some other limits
and fail if needed.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Do not handle disks of size GRUB_DISK_SIZE_UNKNOWN for now
Glenn Washburn [Tue, 15 Dec 2020 23:31:07 +0000 (17:31 -0600)]
luks2: Do not handle disks of size GRUB_DISK_SIZE_UNKNOWN for now

Check to make sure that source disk has a known size. If not, print
a message and return error. There are 4 cases where GRUB_DISK_SIZE_UNKNOWN
is set (biosdisk, obdisk, ofdisk, and uboot), and in all those cases
processing continues. So this is probably a bit conservative. However,
3 of the cases seem pathological, and the other, biosdisk, happens when
booting from a CD-ROM. Since I doubt booting from a LUKS2 volume on
a CD-ROM is a big use case, we'll error until someone complains.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Convert to crypt sectors from GRUB native sectors
Glenn Washburn [Tue, 15 Dec 2020 23:31:06 +0000 (17:31 -0600)]
luks2: Convert to crypt sectors from GRUB native sectors

The function grub_disk_native_sectors(source) returns the number of sectors
of source in GRUB native (512-byte) sectors, not source sized sectors. So
the conversion needs to use GRUB_DISK_SECTOR_BITS, the GRUB native sector
size.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Error check segment.sector_size
Glenn Washburn [Tue, 8 Dec 2020 22:45:46 +0000 (16:45 -0600)]
luks2: Error check segment.sector_size

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Properly handle non-512 byte sized sectors
Glenn Washburn [Tue, 8 Dec 2020 22:45:44 +0000 (16:45 -0600)]
cryptodisk: Properly handle non-512 byte sized sectors

By default, dm-crypt internally uses an IV that corresponds to 512-byte
sectors, even when a larger sector size is specified. What this means is
that when using a larger sector size, the IV is incremented every sector.
However, the amount the IV is incremented is the number of 512 byte blocks
in a sector (i.e. 8 for 4K sectors). Confusingly the IV does not correspond
to the number of, for example, 4K sectors. So each 512 byte cipher block in
a sector will be encrypted with the same IV and the IV will be incremented
afterwards by the number of 512 byte cipher blocks in the sector.

There are some encryption utilities which do it the intuitive way and have
the IV equal to the sector number regardless of sector size (ie. the fifth
sector would have an IV of 4 for each cipher block). And this is supported
by dm-crypt with the iv_large_sectors option and also cryptsetup as of 2.3.3
with the --iv-large-sectors, though not with LUKS headers (only with --type
plain). However, support for this has not been included as grub does not
support plain devices right now.

One gotcha here is that the encrypted split keys are encrypted with a hard-
coded 512-byte sector size. So even if your data is encrypted with 4K sector
sizes, the split key encrypted area must be decrypted with a block size of
512 (ie the IV increments every 512 bytes). This made these changes less
aesthetically pleasing than desired.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors
Glenn Washburn [Tue, 8 Dec 2020 22:45:43 +0000 (16:45 -0600)]
luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors

We need to convert the sectors from the size of the underlying device to the
cryptodisk sector size; segment.size is in bytes which need to be converted
to cryptodisk sectors as well.

Also, removed an empty statement.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Add macros GRUB_TYPE_U_MAX/MIN(type) to replace literals
Glenn Washburn [Tue, 8 Dec 2020 22:45:42 +0000 (16:45 -0600)]
cryptodisk: Add macros GRUB_TYPE_U_MAX/MIN(type) to replace literals

Add GRUB_TYPE_U_MAX/MIN(type) macros to get the max/min values for an
unsigned number with size of type.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agocryptodisk: Add macro GRUB_TYPE_BITS() to replace some literals
Glenn Washburn [Tue, 8 Dec 2020 22:45:41 +0000 (16:45 -0600)]
cryptodisk: Add macro GRUB_TYPE_BITS() to replace some literals

The new macro GRUB_TYPE_BITS(type) returns the number of bits
allocated for type.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Add string "index" to user strings using a json index
Glenn Washburn [Tue, 8 Dec 2020 22:45:40 +0000 (16:45 -0600)]
luks2: Add string "index" to user strings using a json index

This allows error messages to be more easily distinguishable between indexes
and slot keys. The former include the string "index" in the error/debug
string, and the later are surrounded in quotes.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Rename json index variables to names that they are obviously json indexes
Glenn Washburn [Tue, 8 Dec 2020 22:45:39 +0000 (16:45 -0600)]
luks2: Rename json index variables to names that they are obviously json indexes

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Use more intuitive object name instead of json index in user messages
Glenn Washburn [Tue, 8 Dec 2020 22:45:38 +0000 (16:45 -0600)]
luks2: Use more intuitive object name instead of json index in user messages

Use the object name in the json array rather than the 0 based index in the
json array for keyslots, segments, and digests. This is less confusing for
the end user. For example, say you have a LUKS2 device with a key in slot 1
and slot 4. When using the password for slot 4 to unlock the device, the
messages using the index of the keyslot will mention keyslot 1 (its a
zero-based index). Furthermore, with this change the keyslot number will
align with the number used to reference the keyslot when using the
--key-slot argument to cryptsetup.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3 years agoluks2: Add idx member to struct grub_luks2_keyslot/segment/digest
Glenn Washburn [Tue, 8 Dec 2020 22:45:37 +0000 (16:45 -0600)]
luks2: Add idx member to struct grub_luks2_keyslot/segment/digest

This allows code using these structs to know the named key associated with
these json data structures. In the future we can use these to provide better
error messages to the user.

Get rid of idx local variable in luks2_get_keyslot() which was overloaded to
be used for both keyslot and segment slot keys.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>