efi: fix potential NULL deref in efi_mem_reserve_persistent
authorAnton Gusev <aagusev@ispras.ru>
Fri, 3 Feb 2023 13:22:13 +0000 (16:22 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Feb 2023 10:26:38 +0000 (11:26 +0100)
commitd8fc0b5fb3e816a4a8684bcd3ed02cbef0fce23c
treece90e2218d24463978a52fe89d37d0337e28ccd0
parentf423c2efd51d7eb1d143c2be7eea233241d9bbbf
efi: fix potential NULL deref in efi_mem_reserve_persistent

[ Upstream commit 966d47e1f27c45507c5df82b2a2157e5a4fd3909 ]

When iterating on a linked list, a result of memremap is dereferenced
without checking it for NULL.

This patch adds a check that falls back on allocating a new page in
case memremap doesn't succeed.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 18df7577adae ("efi/memreserve: deal with memreserve entries in unmapped memory")
Signed-off-by: Anton Gusev <aagusev@ispras.ru>
[ardb: return -ENOMEM instead of breaking out of the loop]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/firmware/efi/efi.c