From nobody Fri Sep 5 20:09:25 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF206C32772 for ; Tue, 23 Aug 2022 11:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242439AbiHWLL6 (ORCPT ); Tue, 23 Aug 2022 07:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357262AbiHWLKb (ORCPT ); Tue, 23 Aug 2022 07:10:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81819B6D06; Tue, 23 Aug 2022 02:17:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5960060F85; Tue, 23 Aug 2022 09:17:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ED9BC433D6; Tue, 23 Aug 2022 09:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246225; bh=b09QnvDg7xfHPslMRVg7vHUSCPbJTeYQlqKvtTja7U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GAwaf9ljDuOcApSQWmSmwzRRRpLZW3pJVsfBndEDTTnt5l38BsChcjim3Gq9w6TpP w5ve/lkQj6a4HPKkZpFPDVlvuGJx9FbQMEHM4Gxth4fkYjmxpaaLfg9NlCTzmJj9/M 84I0KGz4fd+Eo/HpTyH+TdqhwHVY35jNheGN6o7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , Michael Ellerman Subject: [PATCH 5.4 042/389] powerpc/powernv: Avoid crashing if rng is NULL Date: Tue, 23 Aug 2022 10:22:00 +0200 Message-Id: <20220823080117.372655712@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Michael Ellerman commit 90b5d4fe0b3ba7f589c6723c6bfb559d9e83956a upstream. On a bare-metal Power8 system that doesn't have an "ibm,power-rng", a malicious QEMU and guest that ignore the absence of the KVM_CAP_PPC_HWRNG flag, and calls H_RANDOM anyway, will dereference a NULL pointer. In practice all Power8 machines have an "ibm,power-rng", but let's not rely on that, add a NULL check and early return in powernv_get_random_real_mode(). Fixes: e928e9cb3601 ("KVM: PPC: Book3S HV: Add fast real-mode H_RANDOM impl= ementation.") Cc: stable@vger.kernel.org # v4.1+ Signed-off-by: Jason A. Donenfeld Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220727143219.2684192-1-mpe@ellerman.id.au Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/platforms/powernv/rng.c | 2 ++ 1 file changed, 2 insertions(+) --- a/arch/powerpc/platforms/powernv/rng.c +++ b/arch/powerpc/platforms/powernv/rng.c @@ -63,6 +63,8 @@ int powernv_get_random_real_mode(unsigne struct powernv_rng *rng; =20 rng =3D raw_cpu_read(powernv_rng); + if (!rng) + return 0; =20 *v =3D rng_whiten(rng, __raw_rm_readq(rng->regs_real));