Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3023258rwb; Mon, 15 Aug 2022 16:20:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Ms/o4931ZF+B+5VtV2IIoiLYJxELvrU2r1PmFieZagaEnf7PCmRLZAexSlq0KZIODLliY X-Received: by 2002:a63:90c8:0:b0:41b:bcab:2c93 with SMTP id a191-20020a6390c8000000b0041bbcab2c93mr15614455pge.420.1660605649399; Mon, 15 Aug 2022 16:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605649; cv=none; d=google.com; s=arc-20160816; b=K7+pVYAeFDy8lTQ2y5Wb8+aklBQCgPo93YEEkSN7uBYGeUOPxTd3kcBmLP+e+Ql/fk DPQaNh7EhrtXuC08BGlHHfQRBvRe0uLwL2TJ5X1JSZw8tyhPT0m3MLIYGnhMASjA6Wb+ lMVzTynM3JNdmwGCIMsx+ofN8N5OMgreDwwx7kOkgSdtFAqYrtr35yY1WZSjbg11Lz11 IE9Op3Ww1f091/Qjs2WboB4XdWVz6ATsoabB9Cf7i/e0i1rZ6l2y94X89+BDDYEQO61p 4ZDdbjawh4Nl/I/dkLFZiVb7h1XGF4V4HvA3TcV5P0sp2heTWc7b8E8zKlCC1c7068pk d+fQ== 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=pndsRxRDIz6OGaWu06ncDwWJhQUB2aaNy3lZbXPDww2Laf9h2cJ3gvcGBhqsqolxcy dubut7OLuXR44ANWe+mDovC0e1gCa4PUNp7ipLg+dNNsEBZ+D+qFVomRhI+LJunqWBBu QHw4u5m/1ZZHcRjvFagyTPoz0zagbkN44A4WaH5dw4/LpzpWjxQCtBUOUjkO/J8F15pd 5u83+rgWrw4Kz1phdzzXsqH+nApDYtK7asUKR8KdNmGNZUyshiT2uW1dCI76rg53ph6P dhJT+MZntfoLYyfBSjoYCoMsPPnS6N62R/tcRe5DhN7iu3ogYYlD7tSk7CGavd5gQObd G5eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="NazJukh/"; 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 oj6-20020a17090b4d8600b001f30ceb03fasi12676256pjb.61.2022.08.15.16.20.38; Mon, 15 Aug 2022 16:20:49 -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="NazJukh/"; 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 S1348833AbiHOWZt (ORCPT + 99 others); Mon, 15 Aug 2022 18:25:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350827AbiHOWSj (ORCPT ); Mon, 15 Aug 2022 18:18:39 -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 E9BEDC50; Mon, 15 Aug 2022 12:42:37 -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 A5419B80EAB; Mon, 15 Aug 2022 19:42:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04B75C433C1; Mon, 15 Aug 2022 19:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592555; bh=b09QnvDg7xfHPslMRVg7vHUSCPbJTeYQlqKvtTja7U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NazJukh/X15o7SbaM9daahqt/2KMPqpzBEHy77mkRnaHM0wAcRx9k3dlVrRK04eNY z5FfT1otwRlmU6dp5L4mnXao3BXucIvJ9wjWhLo5Nva0qlcUe7iA3F9GcuYVh2WYcN KhOb+/Y6mxTZjRWUodGyqTbnBkwmZHvk2wrhfAA8= 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.19 0129/1157] powerpc/powernv: Avoid crashing if rng is NULL Date: Mon, 15 Aug 2022 19:51:25 +0200 Message-Id: <20220815180444.766219146@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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));