]> git.proxmox.com Git - grub2.git/commit
kern/efi/mm: Fix possible NULL pointer dereference
authorDarren Kenny <darren.kenny@oracle.com>
Fri, 11 Dec 2020 15:03:13 +0000 (15:03 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:16 +0000 (15:54 +0100)
commit6aee4bfd6973c714056fb7b56890b8d524e94ee1
treef3faab3e86dee3eff121ddfe73121da6c5d58b9e
parented286ceba6015d37a9304f04602451c47bf195d7
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>
grub-core/kern/efi/mm.c