Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1864340rwb; Fri, 19 Aug 2022 10:39:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR61TNrSroH1E+ZCTV4eMbm4dNmsYDh95FNtR4YUa9NCy+XYjw53QSQThiswpN+Vf8y1cVZO X-Received: by 2002:a17:902:760c:b0:172:adc5:fc9 with SMTP id k12-20020a170902760c00b00172adc50fc9mr8507540pll.102.1660930761334; Fri, 19 Aug 2022 10:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930761; cv=none; d=google.com; s=arc-20160816; b=zJcitbuT93mr+XieCYvFlEML/aasHcRR4m6q1oCgtZ4sdOsyrFsugXDQhQQgFFR4lY pD482+dsQX/VjczQhr6qmaQgKjrP2RbH3mB+wcrH8Vm6UV1h2skkzhOFEVJ7jwaaKFuD CEG2R1PO008AZ0VN48PRGwCM9hjCUjjYdlzHaK1ui5v3xttANcEF/fH/xZxvXPFUPxiO YFMCcjY6o5ie+qmJfeYxq27nAP2517U7OFf/5X63+udAJX8BK8Te11j+fBv6klh7dqEK vrbtODht+KfH0vg7yyNUk+SPdTFz1ibVrI+49edlypQvDl3q2cj6H0VY45SXHDb5vwYp K6bQ== 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=m1jiev5tWKoYoWyCV1awmzAZ7jo84Sv3c90SbVv42FI9a1jGnyfkgY2GYNI9kgegpG rPtw9a8vqtMmUZFN4v04ln9+0lRoHWnTxbno/UxMOFY+HRuviNmO4MacBKEabo5G6Uta NirJDmwbXnN83BtPHEGa6hwBOIQvV8FRyCv9dZP0pOvKzzCSPCLATYwIKQaHz7WG2PNl M/HLHZYVwiHmSIaK3KWWTMS8ATOTdKvX2pQgpv1RW4wIlLZOJ7lKRqIuGPwBas/WbJ3Y iElZyVREGRrOcJUubEtZcs4NErEcK3ieiI8pTPxunzWPPKhZj3yOqghuhOGNnrAqK4BJ 4rdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AOiJQRie; 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 x4-20020a17090a970400b001fab3876563si2005279pjo.107.2022.08.19.10.39.10; Fri, 19 Aug 2022 10:39:21 -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=AOiJQRie; 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 S1350472AbiHSPwv (ORCPT + 99 others); Fri, 19 Aug 2022 11:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350253AbiHSPvU (ORCPT ); Fri, 19 Aug 2022 11:51:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160C64F684; Fri, 19 Aug 2022 08:48:38 -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 5B111B82811; Fri, 19 Aug 2022 15:48:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7AE1C433D6; Fri, 19 Aug 2022 15:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924117; bh=b09QnvDg7xfHPslMRVg7vHUSCPbJTeYQlqKvtTja7U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOiJQRieqHgb4P+4Sv8oaTLfo6M5zUtqdc8veue/p+llwlrnLsN9Pc12lTM4w7QOM /kyDE8tFOU9I7YtAtGYS+WZ+YNlKu9ROs6U9pBnMC3qI7MOXzovsmOzrXp4+hFiX4I 4c4nzitpxRo1Js9oOiSm+ltk9ZN/Lsne5Bv5Z40M= 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.10 062/545] powerpc/powernv: Avoid crashing if rng is NULL Date: Fri, 19 Aug 2022 17:37:12 +0200 Message-Id: <20220819153832.012015356@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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));