Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3041739rwb; Mon, 15 Aug 2022 16:44:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR4cIzCT2MXddvqDJEd29pn1RCwDK3N7rSwirxJAadj0GGte2UsJGUz2LI7TiapIqHd5oU56 X-Received: by 2002:a17:907:272a:b0:731:4699:b375 with SMTP id d10-20020a170907272a00b007314699b375mr11838391ejl.633.1660607053175; Mon, 15 Aug 2022 16:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660607053; cv=none; d=google.com; s=arc-20160816; b=egrox0GuaK/ZhpNWQ1Eh9brmhHN9ITfHLUnV/oU0OYqxMqkdMBTun2wYrrgk+5YqQN wtM1/IozKI3oO86qEUNTBlxjEmiCSIVuJmC3WjTPGzYndNvcTLzoLtl4/uuwAa0zy/B3 ar67/sATrPV9sB6c2X+/ojBqOXANX8uOPRj7ThVB8B+BiixhTP54wQmhTe1Z/hA/0TQB LH6jpXduQwKBDkJ4o754zA7neUeGYWhVv/hvzS1v+cGXAZA4DcxPh2mZz3zmCmXBxk9N IFn6qXjrl2YY4c373vhWPv/1T/ScLgCPt5hkwmmI5bW6ciwF8IixaBzTlxd1Ig9Yv84a 3Erg== 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=X/2PNNwrRtHkzYxJYXaLi8jj8LPSEmvxwkCSHjc5BOA=; b=JUJ20HQj+OZiFTlBXpEGh1GKH1ZmKULDWrPQmDrBsXEMiHCu/lUhbkiaoqJmwvLxtX Fd9ut3eTDyAcl5POUafOsaDhzr3vE08j+o57FppoZzNNob2u/Pqo7HHRvuuxXlTIlSQM zJmQ4awpA6l02hgvaodDvyxKQdbqCtnzmH1YQnpk8L5YCC4O7a0LoC2UajhJeLlFCGCC AuzCiTH+GFdJE3gCt+FO3xm4bM/ocs8v2weieMa/N6otq5mAgxQ4UN6CrdBj9BBKDm2/ Y3TSbjqx+OJ9lWKZ0xe+b/AJDhH3yKfOm+Ppt7f73ouVqWSKBBsTur9B8J+ZOuPB0kWE +knQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xU69hgcJ; 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 hv13-20020a17090760cd00b007382da624cbsi6106469ejc.539.2022.08.15.16.43.46; Mon, 15 Aug 2022 16:44:13 -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=xU69hgcJ; 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 S1354033AbiHOXky (ORCPT + 99 others); Mon, 15 Aug 2022 19:40:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353671AbiHOXhw (ORCPT ); Mon, 15 Aug 2022 19:37:52 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74DA2BD1EB; Mon, 15 Aug 2022 13:10:01 -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 sin.source.kernel.org (Postfix) with ESMTPS id 9A74DCE12EB; Mon, 15 Aug 2022 20:09:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67E27C433C1; Mon, 15 Aug 2022 20:09:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594197; bh=3a/0iYeb7AK1RwoIK1dPVzlUnp+fNBDwrmN1efzJZA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xU69hgcJWroZeeyZxQyZT+ForhNRHOOfCi2gzdTBrLBDo2GwevELn/L4axdLoHWKi JYDidCxCeht6apuRb5XgxAlWIZCgbV4IjzCkxehSWVe4VcCFngyGR891Phr3TS4Z3n oegvNiPaAzXdifE/zFheRRWqk6Z7z80WT3WMhv2s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Lendacky , Herbert Xu , Sasha Levin Subject: [PATCH 5.19 0393/1157] crypto: ccp - During shutdown, check SEV data pointer before using Date: Mon, 15 Aug 2022 19:55:49 +0200 Message-Id: <20220815180455.411363444@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: Tom Lendacky [ Upstream commit 1b05ece0c931536c0a38a9385e243a7962e933f6 ] On shutdown, each CCP device instance performs shutdown processing. However, __sev_platform_shutdown_locked() uses the controlling psp structure to obtain the pointer to the sev_device structure. However, during driver initialization, it is possible that an error can be received from the firmware that results in the sev_data pointer being cleared from the controlling psp structure. The __sev_platform_shutdown_locked() function does not check for this situation and will segfault. While not common, this scenario should be accounted for. Add a check for a NULL sev_device structure before attempting to use it. Fixes: 5441a07a127f ("crypto: ccp - shutdown SEV firmware on kexec") Signed-off-by: Tom Lendacky Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/ccp/sev-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 0c92d940ac4e..9f588c9728f8 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -503,7 +503,7 @@ static int __sev_platform_shutdown_locked(int *error) struct sev_device *sev = psp_master->sev_data; int ret; - if (sev->state == SEV_STATE_UNINIT) + if (!sev || sev->state == SEV_STATE_UNINIT) return 0; ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error); -- 2.35.1