Michal Suchanek 2be580
From 90b5d4fe0b3ba7f589c6723c6bfb559d9e83956a Mon Sep 17 00:00:00 2001
Michal Suchanek 2be580
From: Michael Ellerman <mpe@ellerman.id.au>
Michal Suchanek 2be580
Date: Thu, 28 Jul 2022 00:32:17 +1000
Michal Suchanek 2be580
Subject: [PATCH] powerpc/powernv: Avoid crashing if rng is NULL
Michal Suchanek 2be580
Michal Suchanek 2be580
References: bsc#1065729
Michal Suchanek 2be580
Patch-mainline: v6.0-rc1
Michal Suchanek 2be580
Git-commit: 90b5d4fe0b3ba7f589c6723c6bfb559d9e83956a
Michal Suchanek 2be580
Michal Suchanek 2be580
On a bare-metal Power8 system that doesn't have an "ibm,power-rng", a
Michal Suchanek 2be580
malicious QEMU and guest that ignore the absence of the
Michal Suchanek 2be580
KVM_CAP_PPC_HWRNG flag, and calls H_RANDOM anyway, will dereference a
Michal Suchanek 2be580
NULL pointer.
Michal Suchanek 2be580
Michal Suchanek 2be580
In practice all Power8 machines have an "ibm,power-rng", but let's not
Michal Suchanek 2be580
rely on that, add a NULL check and early return in
Michal Suchanek 2be580
powernv_get_random_real_mode().
Michal Suchanek 2be580
Michal Suchanek 2be580
Fixes: e928e9cb3601 ("KVM: PPC: Book3S HV: Add fast real-mode H_RANDOM implementation.")
Michal Suchanek 2be580
Cc: stable@vger.kernel.org # v4.1+
Michal Suchanek 2be580
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Michal Suchanek 2be580
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Michal Suchanek 2be580
Link: https://lore.kernel.org/r/20220727143219.2684192-1-mpe@ellerman.id.au
Michal Suchanek 2be580
Acked-by: Michal Suchanek <msuchanek@suse.de>
Michal Suchanek 2be580
---
Michal Suchanek 2be580
 arch/powerpc/platforms/powernv/rng.c | 2 ++
Michal Suchanek 2be580
 1 file changed, 2 insertions(+)
Michal Suchanek 2be580
Michal Suchanek 2be580
diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c
Michal Suchanek 2be580
index 3805ad13b8f3..2287c9cd0cd5 100644
Michal Suchanek 2be580
--- a/arch/powerpc/platforms/powernv/rng.c
Michal Suchanek 2be580
+++ b/arch/powerpc/platforms/powernv/rng.c
Michal Suchanek 2be580
@@ -63,6 +63,8 @@ int powernv_get_random_real_mode(unsigned long *v)
Michal Suchanek 2be580
 	struct powernv_rng *rng;
Michal Suchanek 2be580
 
Michal Suchanek 2be580
 	rng = raw_cpu_read(powernv_rng);
Michal Suchanek 2be580
+	if (!rng)
Michal Suchanek 2be580
+		return 0;
Michal Suchanek 2be580
 
Michal Suchanek 2be580
 	*v = rng_whiten(rng, __raw_rm_readq(rng->regs_real));
Michal Suchanek 2be580
 
Michal Suchanek 2be580
-- 
Michal Suchanek 2be580
2.35.3
Michal Suchanek 2be580