Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3326901rwa; Tue, 23 Aug 2022 02:55:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR65MuT2X8XqakIaIMqANpBs2XikvF+zlQ4pWOsVZemLjMNt4PrlsDPP5lg/OfKyZo9iaM3H X-Received: by 2002:a63:2051:0:b0:42a:4611:a207 with SMTP id r17-20020a632051000000b0042a4611a207mr15006607pgm.62.1661248541176; Tue, 23 Aug 2022 02:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248541; cv=none; d=google.com; s=arc-20160816; b=w/BrJX77onrCvKZZjygjdH6+ZXNgH3eCaH8g8K2YEiJUEPJAroGlasim2Ay0gGq7JO cKNuAGjwpxzkNz2buDTdMt7Wsitj8kLpwgNwSVxFc9Ke3cHxwQY1PqBbgX/HND7KrX1Z xmn/mby90pX9lGgGcVOmUCZghyVjRGzztejPjHYH9tUjT45nJ4/TEkgaHjwW/h18EPZI pnE1dZ6sFRrfxlaFrbzUxoKHbQwLIC2+OgbViGZPtA1MkYoshqwNzxeAolTVub25vGAa sSO8rVAXvQm7uwopwboNxZtUlbNq8UjvWM+SOBN3YPkDQXwKd3xf+gwJ/n2ByOLkuou3 yNXw== 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=adzSIAgXgM4vHt75E7zDz1J5aoJGoXnTcTHAHbrWO2uWuMW3k0HBA7qiYC/lg09kB0 /fUQvhOvUFxndFjtcPwK13MkbR9FlBCGxo8Ledtw7gzu9OvoznWx2oZpBCnWEEm1aBIg oSfVb54oAoHxuW07y7v0UFT1U4xTz2BKzZZcuyO9hAibl1wqIp/xtTInJhlQTD+7rlUy wT3ojHZrUGKA2xMqEi/AbP8QL2vELCAbfHeNpDpv/i+NGxV8nSRsipQMo9KcWRpkl6vc m9cLYBWeTjjf2+m4D3sEBp9pZZ/Qn6i9jGyDeZ4KsLJdEoQQVTSewTr+PuFxRuVnHNe5 pn3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xByAZDET; 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 v10-20020a63610a000000b0040e64eee87fsi1810273pgb.722.2022.08.23.02.55.30; Tue, 23 Aug 2022 02:55:41 -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=xByAZDET; 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 S1351137AbiHWJgs (ORCPT + 99 others); Tue, 23 Aug 2022 05:36:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351129AbiHWJfP (ORCPT ); Tue, 23 Aug 2022 05:35:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 290A695E7F; Tue, 23 Aug 2022 01:39: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 dfw.source.kernel.org (Postfix) with ESMTPS id 889106132D; Tue, 23 Aug 2022 08:38:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 788F4C433D6; Tue, 23 Aug 2022 08:38:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243915; bh=b09QnvDg7xfHPslMRVg7vHUSCPbJTeYQlqKvtTja7U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xByAZDETCrENvkjbaP4OnqiZ4zUWxKq99jrHto5unDhGUvAv9jYC1vx8/U4NoWemc LWoAJbAiqFW9lCzCZ/Rqv/IWt/vfR4/oYvDm6uAWOpxyXSbBYFalHRbiQEfMPzrGvH tTNkrAzLLScRcFGDzIHr0xToJ4BxaKN7I6utPcbw= 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 4.14 035/229] powerpc/powernv: Avoid crashing if rng is NULL Date: Tue, 23 Aug 2022 10:23:16 +0200 Message-Id: <20220823080054.807322627@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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));