Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2807534rwb; Mon, 15 Aug 2022 11:44:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR4oOMuk/KhmWeRkxZdK9BCmRoJ6UOwVZGShXqF/rzWoL9Xep33Y9wcTM8pOMj1gWzqVKRfj X-Received: by 2002:a05:6402:248d:b0:437:dd4c:e70e with SMTP id q13-20020a056402248d00b00437dd4ce70emr15337709eda.75.1660589092568; Mon, 15 Aug 2022 11:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660589092; cv=none; d=google.com; s=arc-20160816; b=bHl5NwWEUQrjT/v0aSQ6Q7UmNf7kIDodKq6gskjTM91HQInbKA0MYWeBeWdyXbhKK0 5s3XNExDyEXVzgzEqxWaBsHtQcLyIQJPziccBVcn9vYOOVGRadtdDT59+uH0xs8WFZji tYpt9MXB96T08zBTrhqi2lZhuEogrjPd+aL3OI17i0oUqYbmht/24lCip3rYNTf4PMgx e/EMT/P2zRFto2jew6/5uZrNP3+T6YIAl53oOr83qVFpmIrpp627wG7kndX8RMiyIgXE 1NDWsiJaOD4FkGrmzw2FVCEc/PCmH/MwTo4cLvTtyJhgIABJ0OGA+Q8ISoYL4JTJ01hC Gj/A== 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=tRn1RBTHj62Ke965+hINooqGY+CaHr5Eez3y6VhJtDfcnCF25w+Ebn7pAvCGe8CgUh ian9Rt1Cb2uj8Pv0TuNgd2D26jEu0ZkWPwFgd4nqlunzEmMB27/HeBu2RruTG554zrxE a9xaBf+YpGSkGvfN1ndOoWrgsP8QA7ccW8Jh5En+g68/DYu1m8ryU1MUzgfNpU5724YW W744hdl/NiIhnHiy5FBmNFcNZlbiNlbKIBqQmtRaU7jqngRMlHS2VSDomSXWEX8H+wHs WXN/XwppDu5fVXZPoDIGDFWjArwkP3gVD+t2fZ0Akpky1yHEaFB1oI8c7XDMJZKwCIc6 I00w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jr8agBlt; 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 g16-20020a50ec10000000b0044202417985si7758858edr.108.2022.08.15.11.44.26; Mon, 15 Aug 2022 11:44:52 -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=jr8agBlt; 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 S241564AbiHOSYa (ORCPT + 99 others); Mon, 15 Aug 2022 14:24:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241464AbiHOSXz (ORCPT ); Mon, 15 Aug 2022 14:23:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB3D82A95B; Mon, 15 Aug 2022 11:17:58 -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 A110EB81074; Mon, 15 Aug 2022 18:17:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEB9BC433D6; Mon, 15 Aug 2022 18:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660587472; bh=b09QnvDg7xfHPslMRVg7vHUSCPbJTeYQlqKvtTja7U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jr8agBlt3qYTcPISecKCW+zo6QRJJP/rWplYocG6j50eP12r033o9YwHdIVQA1u10 I32LhDtIEtDvdM0+I5AtN1GjKj+OfPGaUMpRBwHRx/hnsrQy3zR0fxBf1pIPyuC6Dy zgKL/LQ20KHnD5Ne/6CQ0OHuZ9skD56FfTB3jcw4= 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.15 096/779] powerpc/powernv: Avoid crashing if rng is NULL Date: Mon, 15 Aug 2022 19:55:40 +0200 Message-Id: <20220815180341.411950132@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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));