Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3396645rwa; Tue, 23 Aug 2022 04:12:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR5NxTIyHLYzrzwz2zejOi0jAcZTfvIiasRPYMhv21o45AHd+vxfaofNG0coDDaHdMM8Mj6F X-Received: by 2002:a17:90b:4b04:b0:1f5:2da0:b2f6 with SMTP id lx4-20020a17090b4b0400b001f52da0b2f6mr2760100pjb.195.1661253165790; Tue, 23 Aug 2022 04:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253165; cv=none; d=google.com; s=arc-20160816; b=eZP/+8c6ztjJrfxGLyPWEXClIup3MKwZuedfDP0bHfvOZCJuJP7++L82d7tIJLIzhj ZbiDcFeh7myaEVkHrw/KFmbXq/gDA608OQJ1lLYq1TvAGeOm/CSpmEQGJOxrH0w6VoT8 XfIgnRcOtGpjvtHInjOnsNRHpZ/kxmpqmA00BmlpsB03kKx8m27EEY1l9sJt7ieqQH0i +gENcjvjE7ks8dPVMoISmi/wEscVwWHZlsK2RFvT7ARG1DZ7miNJ3od85EDnpxYH01Ox iwENUq6ComTp67dhP95BvLtfBGvTvbcQKKoSmGEfpACTKUzhvGCgeh/Qw53mYN7GOtJ9 F7Tw== 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=0BvWtdEyQKdgRI7agC/zrwDx/1sk7EBPIlyr8tGN2dY=; b=cuH7Pgr2zVf2kMlasw3ac1L4DfJO5E+aB+a9u6idKQGLsW16wHtdliEB6/gASxmktI LnW++UaIw0j0g9Owd67pfmOCh2NOGw0SvnJGBLrGOXY8VKjgB8KRizMyWYNTDRSrBZ10 iRKbapQelTZa5t1JE+qaC4IQtcGycxkrXnigkc3DAtVpxnWko0Z6TglDZxDMOb/C7WXc 0epTB0oioAMGWaJvR5xWD77d8AaNUJkCo5S5ZVkAXLT+QtckIvdXqI2TnuaA1unUiSGQ olR2oxEEjc5clE2ShHBWFxg1Gu51Poi4mDSmaKgLSkQ60s7p/PKhh17QvxhNMWUJ6mZM P3Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BUY5Fdpb; 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 y71-20020a638a4a000000b0042af7ef1bf4si929390pgd.569.2022.08.23.04.12.34; Tue, 23 Aug 2022 04:12:45 -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=BUY5Fdpb; 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 S1355019AbiHWKeE (ORCPT + 99 others); Tue, 23 Aug 2022 06:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353467AbiHWKRm (ORCPT ); Tue, 23 Aug 2022 06:17:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0632B80E97; Tue, 23 Aug 2022 02:01:42 -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 2B4E161459; Tue, 23 Aug 2022 09:01:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 196DAC433C1; Tue, 23 Aug 2022 09:01:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245301; bh=8qBu+Wy73CshuRL9OPhCBJpD529VMcEgyIbLWYP9h+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BUY5FdpbkHJ6LZD38Qxdn2lGpPv6XhBpk2IRqaxFjJh7nYddRU8WRvfIUhLyDtXjx JekYe2A+TyJi/whIGcjE7CJOU1kF7HiMa/x1ktsEJ/BZd90PfW6GLkE7lhUz291++B kdK4L8C4AJaft9wLBTF//g9qo9ieCn8xp9FLK8/I= 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.19 034/287] powerpc/powernv: Avoid crashing if rng is NULL Date: Tue, 23 Aug 2022 10:23:23 +0200 Message-Id: <20220823080101.422070912@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 @@ -67,6 +67,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));