All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] efi_64: Fix a missing-check bug in arch/x86/platform/efi/efi_64.c of Linux 5.1
@ 2019-05-17  8:26 Gen Zhang
  2019-05-17  8:41 ` Ard Biesheuvel
  0 siblings, 1 reply; 11+ messages in thread
From: Gen Zhang @ 2019-05-17  8:26 UTC (permalink / raw)
  To: ard.biesheuvel, dvhart; +Cc: linux-kernel

save_pgd is allocated by kmalloc_array. And it is dereferenced in the
following codes. However, memory allocation functions such as
kmalloc_array may fail. Dereferencing this save_pgd null pointer may 
cause the kernel go wrong. Thus we should check this allocation and add
error handling code.

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>

---
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index cf0347f..fb9ae57 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -91,6 +91,8 @@ pgd_t * __init efi_call_phys_prolog(void)
 
 	n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
 	save_pgd = kmalloc_array(n_pgds, sizeof(*save_pgd), GFP_KERNEL);
+	if (!save_pgd)
+		goto err;
 
 	/*
 	 * Build 1:1 identity mapping for efi=old_map usage. Note that
@@ -142,6 +144,9 @@ pgd_t * __init efi_call_phys_prolog(void)
 	__flush_tlb_all();
 
 	return save_pgd;
+err:
+	__flush_tlb_all();
+	return ERR_PTR(-ENOMEM);
 }
 
 void __init efi_call_phys_epilog(pgd_t *save_pgd)
---

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-05-25  9:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-17  8:26 [PATCH] efi_64: Fix a missing-check bug in arch/x86/platform/efi/efi_64.c of Linux 5.1 Gen Zhang
2019-05-17  8:41 ` Ard Biesheuvel
2019-05-17  9:06   ` Gen Zhang
2019-05-17  9:24     ` Ard Biesheuvel
2019-05-17  9:43       ` Gen Zhang
2019-05-21  2:57       ` [PATCH v2] efi_64: Fix a missing-check bug in arch/x86/platform/efi/efi_64.c Gen Zhang
2019-05-23  0:51       ` Gen Zhang
2019-05-24 16:07         ` Ard Biesheuvel
2019-05-25  2:36           ` Gen Zhang
2019-05-25  9:18             ` Ard Biesheuvel
2019-05-25  9:40               ` Gen Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.