Skip to content

Commit 534c89c

Browse files
kengiterKAGA-KOKO
authored andcommitted
x86/hyperv: Prevent potential NULL pointer dereference
The page allocation in hv_cpu_init() can fail, but the code does not have a check for that. Add a check and return -ENOMEM when the allocation fails. [ tglx: Massaged changelog ] Signed-off-by: Kangjie Lu <kjlu@umn.edu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Mukesh Ojha <mojha@codeaurora.org> Acked-by: "K. Y. Srinivasan" <kys@microsoft.com> Cc: pakki001@umn.edu Cc: Haiyang Zhang <haiyangz@microsoft.com> Cc: Stephen Hemminger <sthemmin@microsoft.com> Cc: Sasha Levin <sashal@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: linux-hyperv@vger.kernel.org Link: https://lkml.kernel.org/r/20190314054651.1315-1-kjlu@umn.edu
1 parent 2e84f11 commit 534c89c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ static int hv_cpu_init(unsigned int cpu)
103103
u64 msr_vp_index;
104104
struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()];
105105
void **input_arg;
106+
struct page *pg;
106107

107108
input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
108-
*input_arg = page_address(alloc_page(GFP_KERNEL));
109+
pg = alloc_page(GFP_KERNEL);
110+
if (unlikely(!pg))
111+
return -ENOMEM;
112+
*input_arg = page_address(pg);
109113

110114
hv_get_vp_index(msr_vp_index);
111115

0 commit comments

Comments
 (0)