Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2925956rwb; Mon, 15 Aug 2022 14:11:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Qx3Cd/BIYJPA4nHqLJdl3YDEpL3aM5ISn8+jvaYgatQSR1MhXxqs0uS5aadClBNmc3zOA X-Received: by 2002:a05:6402:888:b0:43c:fce0:2f0e with SMTP id e8-20020a056402088800b0043cfce02f0emr15713986edy.247.1660597863796; Mon, 15 Aug 2022 14:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597863; cv=none; d=google.com; s=arc-20160816; b=ch7EDGeoI2dtQUfMK2OumD4Fn8+vmUC/XQslWXSV2tmPn4j5vU/c7qRS85hhtNRP0l U/lf98NlqqQoBzFUjsjQyf1kqZPLEvrHB5OLl7+3f+h9StNSSz52la/zno8RBW7z/EVX nOmNn/zhp2yBFx9DwcrokOuHl+R4Ul+EGQ/YYGxcjYc+vP6NJYm8w9ZznIZZAJw5aWjm R6cwf+IYKBswMxkxKSwfdXP6SUCALc5zOrRGun3pnfAiWhvSxoeDQP7qGtRpFB3DXWU4 QC+Vu6OtG0FVgqlBUtmLs2WzyGo7r/iZHANy2jvhhbCWbzaEsnPb0nWIqRjDZpoX4vdk zCCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QekmsPfd8JN0hfXTy4LipAwt49IOI80M7FC6tE+8mU4=; b=PH0a3PRwsnlDM2q9yB5vE+wbkrEx8gcpRO044do+MhJLE0PvZLhVLONacLq+B4lYH+ c6wvtCZZ8JtbstADX32MtGJozylPd1K94kp2xahwTAgrMu9NLYmDNBOOyId1XYZdY/Yt k0kVKbf4RnAWeBcMPUPUuSInRSVnJhHFuDL9+rKPTgChZogTbevKOk3INv/s0I2GzmtJ NZlW59DQwwEAG6UOtgDV7FGzsq7D/TVAsmQLoA8a5Cd+B4ZXOIOgAECb+jxrTPsGeFju eRo9/DEqjA9+8gJVDPTyQs02J7n5ctNkoMKLAolt+JO8qjJAWF38vLoKdGlAhVKfYdBm fiNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iDGCABB0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay5-20020a056402202500b0043c1802a7b1si7549239edb.588.2022.08.15.14.10.38; Mon, 15 Aug 2022 14:11:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iDGCABB0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347042AbiHOUZB (ORCPT + 99 others); Mon, 15 Aug 2022 16:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347070AbiHOUQq (ORCPT ); Mon, 15 Aug 2022 16:16:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2501D9676E; Mon, 15 Aug 2022 12:00: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 ams.source.kernel.org (Postfix) with ESMTPS id 67601B81107; Mon, 15 Aug 2022 19:00:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5B27C433C1; Mon, 15 Aug 2022 19:00:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590004; bh=b09QnvDg7xfHPslMRVg7vHUSCPbJTeYQlqKvtTja7U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iDGCABB0x9Bf7NiprYHOjZJu6ucO6Wuc5KvLGbxz7VYGRf9iQ4CuZusQrw1cSLNFn TWZwyhkVk9ClcFJGApSSlbY1d+I55wtVitLn2GzFPxG4XI4xmZhVm7D271sFz7w3eA zyVMbwreHFqme9BkYw5EMcu99Ym0BgyZGOvXYBTw= 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.18 0119/1095] powerpc/powernv: Avoid crashing if rng is NULL Date: Mon, 15 Aug 2022 19:51:58 +0200 Message-Id: <20220815180434.515138467@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 implementation.") 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; rng = raw_cpu_read(powernv_rng); + if (!rng) + return 0; *v = rng_whiten(rng, __raw_rm_readq(rng->regs_real));