[SECURITY PATCH 028/117] io/lzopio: Resolve unnecessary self-assignment errors

2021-03-02 Thread Daniel Kiper
From: Darren Kenny These 2 assignments are unnecessary since they are just assigning to themselves. Fixes: CID 73643 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper --- grub-core/io/lzopio.c | 4 1 file changed, 4 deletions(-) diff --git a/grub-core/io/lzopio.c

[SECURITY PATCH 020/117] kern/parser: Fix resource leak if argc == 0

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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

[SECURITY PATCH 018/117] net/net: Fix possible dereference to of a NULL pointer

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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 Reviewed-by: Daniel Kiper --- grub-core/net/net.c | 9 +++-- 1 file

[SECURITY PATCH 032/117] disk/ldm: If failed then free vg variable too

2021-03-02 Thread Daniel Kiper
From: Paulo Flabiano Smorigo Fixes: CID 73809 Signed-off-by: Paulo Flabiano Smorigo Reviewed-by: Daniel Kiper --- grub-core/disk/ldm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c index 48942549a..c25941ec9 100644 --- a/grub-core/disk/ldm.c

[SECURITY PATCH 024/117] gnulib/regcomp: Fix uninitialized token structure

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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 Reviewed-by:

[SECURITY PATCH 006/117] efi: Use grub_is_lockdown() instead of hardcoding a disabled modules list

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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

[SECURITY PATCH 036/117] zfs: Fix possible negative shift operation

2021-03-02 Thread Daniel Kiper
From: Darren Kenny While it is possible for the return value from zfs_log2() to be zero (0), it is quite unlikely, given that the previous assignment to blksz is shifted up by SPA_MINBLOCKSHIFT (9) before 9 is subtracted at the assignment to epbs. But, while unlikely during a normal operation,

[SECURITY PATCH 007/117] acpi: Don't register the acpi command when locked down

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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

[SECURITY PATCH 043/117] syslinux: Fix memory leak while parsing

2021-03-02 Thread Daniel Kiper
From: Darren Kenny In syslinux_parse_real() the 2 points where return is being called didn't release the memory stored in buf which is no longer required. Fixes: CID 176634 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper --- grub-core/lib/syslinux_parse.c | 6 +- 1 file changed, 5

[SECURITY PATCH 022/117] kern/efi/mm: Fix possible NULL pointer dereference

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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

[SECURITY PATCH 045/117] commands/hashsum: Fix a memory leak

2021-03-02 Thread Daniel Kiper
From: Chris Coulson check_list() uses grub_file_getline(), which allocates a buffer. If the hash list file contains invalid lines, the function leaks this buffer when it returns an error. Fixes: CID 176635 Signed-off-by: Chris Coulson Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 025/117] gnulib/argp-help: Fix dereference of a possibly NULL state

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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 Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 009/117] commands: Restrict commands that can load BIOS or DT blobs when locked down

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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

[SECURITY PATCH 048/117] video/fb/fbfill: Fix potential integer overflow

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The multiplication of 2 unsigned 32-bit integers may overflow before promotion to unsigned 64-bit. We should ensure that the multiplication is done with overflow detection. Additionally, use grub_sub() for subtraction. Fixes: CID 73640, CID 73697, CID 73702, CID 73823

[SECURITY PATCH 011/117] commands/hdparm: Restrict hdparm command when locked down

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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 Reviewed-by: Daniel Kiper --- grub-core/commands/hdparm.c | 6 +++--- 1

[SECURITY PATCH 049/117] video/fb/video_fb: Fix multiple integer overflows

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The calculation of the unsigned 64-bit value is being generated by multiplying 2, signed or unsigned, 32-bit integers which may overflow before promotion to unsigned 64-bit. Fix all of them. Fixes: CID 73703, CID 73767, CID 73833 Signed-off-by: Darren Kenny Reviewed-by:

[SECURITY PATCH 015/117] dl: Only allow unloading modules that are not dependencies

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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

[SECURITY PATCH 026/117] gnulib/regexec: Fix possible null-dereference

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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

[SECURITY PATCH 055/117] loader/xnu: Free driverkey data when an error is detected in grub_xnu_writetree_toheap()

2021-03-02 Thread Daniel Kiper
From: Marco A Benatto ... to avoid memory leaks. Fixes: CID 96640 Signed-off-by: Marco A Benatto Reviewed-by: Daniel Kiper --- grub-core/loader/xnu.c | 24 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c

[SECURITY PATCH 013/117] loader/xnu: Don't allow loading extension and packages when locked down

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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 Reviewed-by: Daniel Kiper --- grub-core/loader/xnu.c | 31

[SECURITY PATCH 030/117] kern/partition: Check for NULL before dereferencing input string

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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 Reviewed-by:

[SECURITY PATCH 065/117] commands/menuentry: Fix quoting in setparams_prefix()

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Commit 9acdcbf32542 (use single quotes in menuentry setparams command) says that expressing a quoted single quote will require 3 characters. It actually requires (and always did require!) 4 characters: str: a'b => a'\''b len: 3 => 6 (2 for the letters + 4 for the

[SECURITY PATCH 031/117] disk/ldm: Make sure comp data is freed before exiting from make_vg()

2021-03-02 Thread Daniel Kiper
From: Marco A Benatto Several error handling paths in make_vg() do not free comp data before jumping to fail2 label and returning from the function. This will leak memory. So, let's fix all issues of that kind. Fixes: CID 73804 Signed-off-by: Marco A Benatto Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 035/117] hfsplus: Check that the volume name length is valid

2021-03-02 Thread Daniel Kiper
From: Darren Kenny HFS+ documentation suggests that the maximum filename and volume name is 255 Unicode characters in length. So, when converting from big-endian to little-endian, we should ensure that the name of the volume has a length that is between 0 and 255, inclusive. Fixes: CID 73641

[SECURITY PATCH 066/117] kern/misc: Always set *end in grub_strtoull()

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Currently, if there is an error in grub_strtoull(), *end is not set. This differs from the usual behavior of strtoull(), and also means that some callers may use an uninitialized value for *end. Set *end unconditionally. Signed-off-by: Daniel Axtens Reviewed-by: Daniel

[SECURITY PATCH 017/117] mmap: Fix memory leak when iterating over mapped memory

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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 Reviewed-by: Daniel Kiper --- grub-core/mmap/mmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git

[SECURITY PATCH 072/117] fs/hfsplus: Don't fetch a key beyond the end of the node

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Otherwise you get a wild pointer, leading to a bunch of invalid reads. Check it falls inside the given node. Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/fs/hfsplus.c | 4 1 file changed, 4 insertions(+) diff --git a/grub-core/fs/hfsplus.c

[SECURITY PATCH 041/117] libgcrypt/mpi: Fix possible unintended sign extension

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The array of unsigned char gets promoted to a signed 32-bit int before it is finally promoted to a size_t. There is the possibility that this may result in the signed-bit being set for the intermediate signed 32-bit int. We should ensure that the promotion is to the correct

[SECURITY PATCH 073/117] fs/hfsplus: Don't use uninitialized data on corrupt filesystems

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Valgrind identified the following use of uninitialized data: ==2782220== Conditional jump or move depends on uninitialised value(s) ==2782220==at 0x42B364: grub_hfsplus_btree_search (hfsplus.c:566) ==2782220==by 0x42B21D: grub_hfsplus_read_block (hfsplus.c:185)

[SECURITY PATCH 051/117] video/readers/jpeg: Test for an invalid next marker reference from a jpeg file

2021-03-02 Thread Daniel Kiper
From: Darren Kenny While it may never happen, and potentially could be caught at the end of the function, it is worth checking up front for a bad reference to the next marker just in case of a maliciously crafted file being provided. Fixes: CID 73694 Signed-off-by: Darren Kenny Reviewed-by:

[SECURITY PATCH 052/117] gfxmenu/gui_list: Remove code that coverity is flagging as dead

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The test of value for NULL before calling grub_strdup() is not required, since the if condition prior to this has already tested for value being NULL and cannot reach this code if it is. Fixes: CID 73659 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 083/117] io/gzio: Add init_dynamic_block() clean up if unpacking codes fails

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens init_dynamic_block() didn't clean up gzio->tl and td in some error paths. This left td pointing to part of tl. Then in grub_gzio_close(), when tl was freed the storage for td would also be freed. The code then attempts to free td explicitly, performing a UAF and then a double

[SECURITY PATCH 023/117] gnulib/regexec: Resolve unused variable

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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

[SECURITY PATCH 063/117] lib/arg: Block repeated short options that require an argument

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Fuzzing found the following crash: search -hf We didn't allocate enough option space for 13 hints because the allocation code counts the number of discrete arguments (i.e. argc). However, the shortopt parsing code will happily keep processing a combination of

[SECURITY PATCH 079/117] fs/nilfs2: Reject too-large keys

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens NILFS2 has up to 7 keys, per the data structure. Do not permit array indices in excess of that. This catches some OOB reads. I don't know how controllable the invalidly read data is or if that could be used later in the program. Signed-off-by: Daniel Axtens Reviewed-by:

[SECURITY PATCH 070/117] term/gfxterm: Don't set up a font with glyphs that are too big

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Catch the case where we have a font so big that it causes the number of rows or columns to be 0. Currently we continue and allocate a virtual_screen.text_buffer of size 0. We then try to use that for glpyhs and things go badly. On the emu platform, malloc() may give us a

[SECURITY PATCH 087/117] disk/lvm: Don't blast past the end of the circular metadata buffer

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens This catches at least some OOB reads, and it's possible I suppose that if 2 * mda_size is less than GRUB_LVM_MDA_HEADER_SIZE it might catch some OOB writes too (although that hasn't showed up as a crash in fuzzing yet). It's a bit ugly and I'd appreciate better suggestions.

[SECURITY PATCH 027/117] gnulib/regcomp: Fix uninitialized re_token

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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 Reviewed-by: Daniel Kiper --- bootstrap.conf

[SECURITY PATCH 064/117] script/execute: Don't crash on a "for" loop with no items

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens The following crashes the parser: for x in; do 0 done This is because grub_script_arglist_to_argv() doesn't consider the possibility that arglist is NULL. Catch that explicitly. This avoids a NULL pointer dereference. Signed-off-by: Daniel Axtens Reviewed-by:

[SECURITY PATCH 033/117] disk/ldm: Fix memory leak on uninserted lv references

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The problem here is that the memory allocated to the variable lv is not yet inserted into the list that is being processed at the label fail2. As we can already see at line 342, which correctly frees lv before going to fail2, we should also be doing that at these earlier

[SECURITY PATCH 039/117] zfsinfo: Correct a check for error allocating memory

2021-03-02 Thread Daniel Kiper
From: Darren Kenny While arguably the check for grub_errno is correct, we should really be checking the return value from the function since it is always possible that grub_errno was set elsewhere, making this code behave incorrectly. Fixes: CID 73668 Signed-off-by: Darren Kenny Reviewed-by:

[SECURITY PATCH 069/117] video/readers/jpeg: Don't decode data before start of stream

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens When a start of stream marker is encountered, we call grub_jpeg_decode_sos() which allocates space for a bitmap. When a restart marker is encountered, we call grub_jpeg_decode_data() which then fills in that bitmap. If we get a restart marker before the start of stream

[SECURITY PATCH 076/117] fs/jfs: Do not move to leaf level if name length is negative

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Fuzzing JFS revealed crashes where a negative number would be passed to le_to_cpu16_copy(). There it would be cast to a large positive number and the copy would read and write off the end of the respective buffers. Catch this at the top as well as the bottom of the loop.

[SECURITY PATCH 095/117] kern/parser: Fix a memory leak

2021-03-02 Thread Daniel Kiper
From: Chris Coulson The getline() function supplied to grub_parser_split_cmdline() returns a newly allocated buffer and can be called multiple times, but the returned buffer is never freed. Signed-off-by: Chris Coulson Reviewed-by: Daniel Kiper --- grub-core/kern/parser.c | 20

[SECURITY PATCH 068/117] video/readers/jpeg: Catch OOB reads/writes in grub_jpeg_decode_du()

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens The key line is: du[jpeg_zigzag_order[pos]] = val * (int) data->quan_table[qt][pos]; jpeg_zigzag_order is grub_uint8_t[64]. I don't understand JPEG decoders quite well enough to explain what's going on here. However, I observe sometimes pos=64, which leads to an OOB read

[SECURITY PATCH 038/117] zfs: Fix possible integer overflows

2021-03-02 Thread Daniel Kiper
From: Darren Kenny In all cases the problem is that the value being acted upon by a left-shift is a 32-bit number which is then being used in the context of a 64-bit number. To avoid overflow we ensure that the number being shifted is 64-bit before the shift is done. Fixes: CID 73684, CID

[SECURITY PATCH 094/117] fs/btrfs: Squash some uninitialized reads

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens We need to check errors before calling into a function that uses the result. Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/fs/btrfs.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grub-core/fs/btrfs.c

[SECURITY PATCH 075/117] fs/sfs: Fix over-read of root object name

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens There's a read of the name of the root object that assumes that the name is nul-terminated within the root block. This isn't guaranteed - it seems SFS would require you to read multiple blocks to get a full name in general, but maybe that doesn't apply to the root object.

[SECURITY PATCH 100/117] kern/parser: Fix a stack buffer overflow

2021-03-02 Thread Daniel Kiper
From: Chris Coulson grub_parser_split_cmdline() expands variable names present in the supplied command line in to their corresponding variable contents and uses a 1 kiB stack buffer for temporary storage without sufficient bounds checking. If the function is called with a command line that

[SECURITY PATCH 040/117] affs: Fix memory leaks

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The node structure reference is being allocated but not freed if it reaches the end of the function. If any of the hooks had returned a non-zero value, then node would have been copied in to the context reference, but otherwise node is not stored and should be freed.

[SECURITY PATCH 001/117] verifiers: Move verifiers API to kernel image

2021-03-02 Thread Daniel Kiper
From: Marco A Benatto 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 Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Kiper --- grub-core/Makefile.am

[SECURITY PATCH 089/117] disk/lvm: Do not crash if an expected string is not found

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Clean up a bunch of cases where we could have strstr() fail and lead to us dereferencing NULL. We'll still leak memory in some cases (loops don't clean up allocations from earlier iterations if a later iteration fails) but at least we're not crashing. Signed-off-by: Daniel

[SECURITY PATCH 101/117] kern/efi: Add initial stack protector implementation

2021-03-02 Thread Daniel Kiper
From: Chris Coulson It works only on UEFI platforms but can be quite easily extended to others architectures and platforms if needed. Signed-off-by: Chris Coulson Signed-off-by: Daniel Kiper Reviewed-by: Marco A Benatto Reviewed-by: Javier Martinez Canillas --- acinclude.m4

[SECURITY PATCH 002/117] efi: Move the shim_lock verifier to the GRUB core

2021-03-02 Thread Daniel Kiper
From: Marco A Benatto 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

[SECURITY PATCH 047/117] video/efi_gop: Remove unnecessary return value of grub_video_gop_fill_mode_info()

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The return value of grub_video_gop_fill_mode_info() is never able to be anything other than GRUB_ERR_NONE. So, rather than continue to return a value and checking it each time, it is more correct to redefine the function to not return anything and remove checks of its return

[SECURITY PATCH 053/117] loader/bsd: Check for NULL arg up-front

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The code in the next block suggests that it is possible for .set to be true but .arg may still be NULL. This code assumes that it is never NULL, yet later is testing if it is NULL - that is inconsistent. So we should check first if .arg is not NULL, and remove this check

[SECURITY PATCH 096/117] kern/parser: Introduce process_char() helper

2021-03-02 Thread Daniel Kiper
From: Chris Coulson grub_parser_split_cmdline() iterates over each command line character. In order to add error checking and to simplify the subsequent error handling, split the character processing in to a separate function. Signed-off-by: Chris Coulson Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 109/117] util/mkimage: Add an option to import SBAT metadata into a .sbat section

2021-03-02 Thread Daniel Kiper
From: Peter Jones Add a --sbat option to the grub-mkimage tool which allows us to import an SBAT metadata formatted as a CSV file into a .sbat section of the EFI binary. Signed-off-by: Peter Jones Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Kiper --- docs/grub.texi

[SECURITY PATCH 003/117] kern: Add lockdown support

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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

[SECURITY PATCH 004/117] kern/lockdown: Set a variable if the GRUB is locked down

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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 Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 097/117] kern/parser: Introduce terminate_arg() helper

2021-03-02 Thread Daniel Kiper
From: Chris Coulson process_char() and grub_parser_split_cmdline() use similar code for terminating the most recent argument. Add a helper function for this. Signed-off-by: Chris Coulson Reviewed-by: Daniel Kiper --- grub-core/kern/parser.c | 23 +-- 1 file changed, 13

[SECURITY PATCH 056/117] loader/xnu: Check if pointer is NULL before using it

2021-03-02 Thread Daniel Kiper
From: Paulo Flabiano Smorigo Fixes: CID 73654 Signed-off-by: Paulo Flabiano Smorigo Reviewed-by: Daniel Kiper --- grub-core/loader/xnu.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index 1a590dbc0..1c0cf6a43

[SECURITY PATCH 090/117] disk/lvm: Do not overread metadata

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens We could reach the end of valid metadata and not realize, leading to some buffer overreads. Check if we have reached the end and bail. Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/disk/lvm.c | 35 +-- 1 file changed,

[SECURITY PATCH 057/117] util/grub-install: Fix NULL pointer dereferences

2021-03-02 Thread Daniel Kiper
Two grub_device_open() calls does not have associated NULL checks for returned values. Fix that and appease the Coverity. Fixes: CID 314583 Signed-off-by: Daniel Kiper Reviewed-by: Javier Martinez Canillas --- util/grub-install.c | 4 1 file changed, 4 insertions(+) diff --git

[SECURITY PATCH 010/117] commands/setpci: Restrict setpci command when locked down

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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 Reviewed-by: Daniel Kiper --- grub-core/commands/setpci.c | 8

[SECURITY PATCH 107/117] util/mkimage: Improve data_size value calculation

2021-03-02 Thread Daniel Kiper
From: Peter Jones According to "Microsoft Portable Executable and Common Object File Format Specification", the Optional Header SizeOfInitializedData field contains: Size of the initialized data section, or the sum of all such sections if there are multiple data sections. Make this

[SECURITY PATCH 058/117] util/grub-editenv: Fix incorrect casting of a signed value

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The return value of ftell() may be negative (-1) on error. While it is probably unlikely to occur, we should not blindly cast to an unsigned value without first testing that it is not negative. Fixes: CID 73856 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 012/117] gdb: Restrict GDB access when locked down

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas 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 Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 115/117] gfxmenu/gui: Check printf() format in the gui_progress_bar and gui_label

2021-03-02 Thread Daniel Kiper
From: Thomas Frauendorfer | Miray Software The gui_progress_bar and gui_label components can display the timeout value. The format string can be set through a theme file. This patch adds a validation step to the format string. If a user loads a theme file into the GRUB without this patch then a

[SECURITY PATCH 062/117] script/execute: Avoid crash when using "$#" outside a function scope

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens "$#" represents the number of arguments to a function. It is only defined in a function scope, where "scope" is non-NULL. Currently, if we attempt to evaluate "$#" outside a function scope, "scope" will be NULL and we will crash with a NULL pointer dereference. Do not

[SECURITY PATCH 114/117] kern/misc: Add function to check printf() format against expected format

2021-03-02 Thread Daniel Kiper
From: Thomas Frauendorfer | Miray Software The grub_printf_fmt_check() function parses the arguments of an untrusted printf() format and an expected printf() format and then compares the arguments counts and arguments types. The arguments count in the untrusted format string must be less or

[SECURITY PATCH 014/117] docs: Document the cutmem command

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas The command is not present in the docs/grub.texi user documentation. Reported-by: Daniel Kiper Signed-off-by: Javier Martinez Canillas Signed-off-by: Daniel Kiper Reviewed-by: Javier Martinez Canillas --- docs/grub.texi | 21 + 1 file

[SECURITY PATCH 071/117] fs/fshelp: Catch impermissibly large block sizes in read helper

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens A fuzzed HFS+ filesystem had log2blocksize = 22. This gave log2blocksize + GRUB_DISK_SECTOR_BITS = 31. 1 << 31 = 0x8000, which is -1 as an int. This caused some wacky behavior later on in the function, leading to out-of-bounds writes on the destination buffer. Catch

[SECURITY PATCH 021/117] kern/efi: Fix memory leak on failure

2021-03-02 Thread Daniel Kiper
From: Darren Kenny Free the memory allocated to name before returning on failure. Fixes: CID 296222 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper --- grub-core/kern/efi/efi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c

[SECURITY PATCH 067/117] video/readers/jpeg: Catch files with unsupported quantization or Huffman tables

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Our decoder only supports 2 quantization tables. If a file asks for a quantization table with index > 1, reject it. Similarly, our decoder only supports 4 Huffman tables. If a file asks for a Huffman table with index > 3, reject it. This fixes some out of bounds reads. It's

[SECURITY PATCH 117/117] kern/mm: Fix grub_debug_calloc() compilation error

2021-03-02 Thread Daniel Kiper
From: Marco A Benatto Fix compilation error due to missing parameter to grub_printf() when MM_DEBUG is defined. Fixes: 64e26162e (calloc: Make sure we always have an overflow-checking calloc() available) Signed-off-by: Marco A Benatto Reviewed-by: Daniel Kiper --- grub-core/kern/mm.c | 2

[SECURITY PATCH 113/117] kern/misc: Add STRING type for internal printf() format handling

2021-03-02 Thread Daniel Kiper
From: Thomas Frauendorfer | Miray Software Set printf() argument type for "%s" to new type STRING. This is in preparation for a follow up patch to compare a printf() format string against an expected printf() format string. For "%s" the corresponding printf() argument is dereferenced as pointer

[SECURITY PATCH 082/117] io/gzio: Bail if gzio->tl/td is NULL

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens This is an ugly fix that doesn't address why gzio->tl comes to be NULL. However, it seems to be sufficient to patch up a bunch of NULL derefs. It would be good to revisit this in future and see if we can have a cleaner solution that addresses some of the causes of the

[SECURITY PATCH 019/117] net/tftp: Fix dangling memory pointer

2021-03-02 Thread Daniel Kiper
From: Darren Kenny 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

[SECURITY PATCH 034/117] disk/cryptodisk: Fix potential integer overflow

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The encrypt and decrypt functions expect a grub_size_t. So, we need to ensure that the constant bit shift is using grub_size_t rather than unsigned int when it is performing the shift. Fixes: CID 307788 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 078/117] fs/jfs: Catch infinite recursion

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens It's possible with a fuzzed filesystem for JFS to keep getblk()-ing the same data over and over again, leading to stack exhaustion. Check if we'd be calling the function with exactly the same data as was passed in, and if so abort. I'm not sure what the performance impact

[SECURITY PATCH 084/117] io/gzio: Catch missing values in huft_build() and bail

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens In huft_build(), "v" is a table of values in order of bit length. The code later (when setting up table entries in "r") assumes that all elements of this array corresponding to a code are initialized and less than N_MAX. However, it doesn't enforce this. With sufficiently

[SECURITY PATCH 037/117] zfs: Fix resource leaks while constructing path

2021-03-02 Thread Daniel Kiper
From: Paulo Flabiano Smorigo There are several exit points in dnode_get_path() that are causing possible memory leaks. In the while(1) the correct exit mechanism should not be to do a direct return, but to instead break out of the loop, setting err first if it is not already set. The reason

[SECURITY PATCH 086/117] disk/lvm: Don't go beyond the end of the data we read from disk

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens We unconditionally trusted offset_xl from the LVM label header, even if it told us that the PV header/disk locations were way off past the end of the data we read from disk. Require that the offset be sane, fixing an OOB read and crash. Fixes: CID 314367, CID 314371

[SECURITY PATCH 044/117] normal/completion: Fix leaking of memory when processing a completion

2021-03-02 Thread Daniel Kiper
From: Darren Kenny It is possible for the code to reach the end of the function without freeing the memory allocated to argv and argc still to be 0. We should always call grub_free(argv). The grub_free() will handle a NULL argument correctly if it reaches that code without the memory being

[SECURITY PATCH 042/117] libgcrypt/mpi: Fix possible NULL dereference

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The code in gcry_mpi_scan() assumes that buffer is not NULL, but there is no explicit check for that, so we add one. Fixes: CID 73757 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper --- grub-core/lib/libgcrypt/mpi/mpicoder.c | 3 +++ 1 file changed, 3 insertions(+)

[SECURITY PATCH 088/117] disk/lvm: Bail on missing PV list

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens There's an if block for the presence of "physical_volumes {", but if that block is absent, then p remains NULL and a NULL-deref will result when looking for logical volumes. It doesn't seem like LVM makes sense without physical volumes, so error out rather than crashing.

[SECURITY PATCH 093/117] fs/btrfs: Validate the number of stripes/parities in RAID5/6

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens This prevents a divide by zero if nstripes == nparities, and also prevents propagation of invalid values if nstripes ends up less than nparities. Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/fs/btrfs.c | 3 +++ 1 file changed, 3 insertions(+) diff

[SECURITY PATCH 046/117] commands/probe: Fix a resource leak when probing disks

2021-03-02 Thread Daniel Kiper
From: Darren Kenny Every other return statement in this code is calling grub_device_close() to clean up dev before returning. This one should do that too. Fixes: CID 292443 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper --- grub-core/commands/probe.c | 6 +- 1 file changed, 5

[SECURITY PATCH 050/117] video/fb/video_fb: Fix possible integer overflow

2021-03-02 Thread Daniel Kiper
From: Darren Kenny It is minimal possibility that the values being used here will overflow. So, change the code to use the safemath function grub_mul() to ensure that doesn't happen. Fixes: CID 73761 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper --- grub-core/video/fb/video_fb.c | 8

[SECURITY PATCH 074/117] fs/hfs: Disable under lockdown

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens HFS has issues such as infinite mutual recursion that are simply too complex to fix for such a legacy format. So simply do not permit it to be loaded under lockdown. Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/fs/hfs.c | 7 +-- 1 file changed,

[SECURITY PATCH 092/117] disk/lvm: Do not allow a LV to be it's own segment's node's LV

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens This prevents infinite recursion in the diskfilter verification code. Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/disk/lvm.c | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c

[SECURITY PATCH 054/117] loader/xnu: Fix memory leak

2021-03-02 Thread Daniel Kiper
From: Darren Kenny The code here is finished with the memory stored in name, but it only frees it if there curvalue is valid, while it could actually free it regardless. The fix is a simple relocation of the grub_free() to before the test of curvalue. Fixes: CID 96646 Signed-off-by: Darren

[SECURITY PATCH 103/117] util/mkimage: Use grub_host_to_target32() instead of grub_cpu_to_le32()

2021-03-02 Thread Daniel Kiper
From: Peter Jones The latter doesn't take into account the target image endianness. There is a grub_cpu_to_le32_compile_time() but no compile time variant for function grub_host_to_target32(). So, let's keep using the other one for this case. Signed-off-by: Peter Jones Signed-off-by: Javier

[SECURITY PATCH 059/117] util/glue-efi: Fix incorrect use of a possibly negative value

2021-03-02 Thread Daniel Kiper
From: Darren Kenny It is possible for the ftell() function to return a negative value, although it is fairly unlikely here, we should be checking for a negative value before we assign it to an unsigned value. Fixes: CID 73744 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper ---

[SECURITY PATCH 111/117] shim_lock: Only skip loading shim_lock verifier with explicit consent

2021-03-02 Thread Daniel Kiper
From: Dimitri John Ledkov Commit 32ddc42c (efi: Only register shim_lock verifier if shim_lock protocol is found and SB enabled) reintroduced CVE-2020-15705 which previously only existed in the out-of-tree linuxefi patches and was fixed as part of the BootHole patch series. Under Secure Boot

[SECURITY PATCH 061/117] commands/ls: Require device_name is not NULL before printing

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens This can be triggered with: ls -l (0 0*) and causes a NULL deref in grub_normal_print_device_info(). I'm not sure if there's any implication with the IEEE 1275 platform. Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/commands/ls.c | 2 +- 1 file

[SECURITY PATCH 060/117] script/execute: Fix NULL dereference in grub_script_execute_cmdline()

2021-03-02 Thread Daniel Kiper
From: Daniel Axtens Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/script/execute.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index ce83edd4b..3ad468fce 100644 ---

[SECURITY PATCH 102/117] util/mkimage: Remove unused code to add BSS section

2021-03-02 Thread Daniel Kiper
From: Javier Martinez Canillas The code is compiled out so there is no reason to keep it. Additionally, don't set bss_size field since we do not add a BSS section. Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Kiper --- util/mkimage.c | 17 - 1 file changed, 17

[SECURITY PATCH 116/117] templates: Disable the os-prober by default

2021-03-02 Thread Daniel Kiper
From: Alex Burmashev The os-prober is enabled by default what may lead to potentially dangerous use cases and borderline opening attack vectors. This patch disables the os-prober, adds warning messages and updates GRUB_DISABLE_OS_PROBER configuration option documentation. This way we make it

  1   2   >