[PATCH AUTOSEL 4.14 31/37] x86/hpet: Prevent potential NULL pointer dereference

From: Sasha Levin
Date: Fri Mar 29 2019 - 21:02:55 EST


From: Aditya Pakki <pakki001@xxxxxxx>

[ Upstream commit 2e84f116afca3719c9d0a1a78b47b48f75fd5724 ]

hpet_virt_address may be NULL when ioremap_nocache fail, but the code lacks
a check.

Add a check to prevent NULL pointer dereference.

Signed-off-by: Aditya Pakki <pakki001@xxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: kjlu@xxxxxxx
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Kees Cook <keescook@xxxxxxxxxxxx>
Cc: Joe Perches <joe@xxxxxxxxxxx>
Cc: Nicolai Stange <nstange@xxxxxxx>
Cc: Roland Dreier <roland@xxxxxxxxxxxxxxx>
Link: https://lkml.kernel.org/r/20190319021958.17275-1-pakki001@xxxxxxx
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
arch/x86/kernel/hpet.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index afa1a204bc6d..df767e6de8dd 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -909,6 +909,8 @@ int __init hpet_enable(void)
return 0;

hpet_set_mapping();
+ if (!hpet_virt_address)
+ return 0;

/*
* Read the period and check for a sane value:
--
2.19.1