[PATCH 1/2] efi: Fix krealloc defect

From: Joe Perches
Date: Fri Jan 03 2014 - 19:09:36 EST


krealloc should use a temporary pointer for allocations
and check the temporary pointer returned against NULL too.

Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
cc: Matthew Garrett <matthew.garrett@xxxxxxxxxx>
---
arch/x86/platform/efi/efi.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index cceb813..ef7b7b4 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -798,6 +798,8 @@ void __init efi_enter_virtual_mode(void)
}

for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
+ void *new_memmap2;
+
md = p;
if (!(md->attribute & EFI_MEMORY_RUNTIME)) {
#ifdef CONFIG_X86_64
@@ -834,9 +836,13 @@ void __init efi_enter_virtual_mode(void)
systab += md->virt_addr - md->phys_addr;
efi.systab = (efi_system_table_t *) (unsigned long) systab;
}
- new_memmap = krealloc(new_memmap,
- (count + 1) * memmap.desc_size,
- GFP_KERNEL);
+ new_memmap2 = krealloc(new_memmap,
+ (count + 1) * memmap.desc_size,
+ GFP_KERNEL);
+ if (!new_memmap2)
+ continue;
+
+ new_memmap = new_memmap2;
memcpy(new_memmap + (count * memmap.desc_size), md,
memmap.desc_size);
count++;
--
1.8.1.2.459.gbcd45b4.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/