Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1863039rwb; Fri, 19 Aug 2022 10:37:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR4WeAOPSCYxwOJhqjECBl1mxnUXMXgd4zU2qvH+SdJ9ZqiApeh+1LTkRZBRvTfczm6pyfRi X-Received: by 2002:a17:90b:4f8e:b0:1f4:ed30:d286 with SMTP id qe14-20020a17090b4f8e00b001f4ed30d286mr9809306pjb.66.1660930677502; Fri, 19 Aug 2022 10:37:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930677; cv=none; d=google.com; s=arc-20160816; b=vrgVQe2Rnws7uoD1ZUbaNJie2ijB6MiTJvEUw8zbvMf2CVHTvoYImwsQx2lL+VqwnI xY31REUwaaym7cd2sj6ibYbVQ3lm2JmLR/KLkticitUiTcIGrDWQjStqxr9Q+V/2Apg8 yZpkTMSzbf1XRUJ/WBVHGAthGfaik3L2JvlWWVXv5LGqQPs6y8dwha+CiyXJYT737ntm gS6yZF5nL3+LSRzsqVxwX6T6dF4l6ZCHDNOMXR279U/V3jruqEcev3c9pPwsay5/2vZt 2+Zt0mTpAejD3QpA5Tteg8FmCUnTLPsuGe2M2fQY+Yj4FKT13Q1npOl2i6ue+8VoiMTB PbSA== 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=KyBHAaaYroiCVGlVmjATeQf+rS4jxmnRySIZ+j6MGU4=; b=hyWBcUm1TuSzT8KApjJIAX6LP1ZkIJ63W9ZL+R3L7CuhuuI6IccGbRkbMQfjNW8Sh7 PBO8zkddEAtD5vyef+pS0NULftEbaQ43WDKQi4kkBrzYZjsNv6hNqVxGwb/SG8/YBHDR PG0Bw/sOxOw0mvzLyTYPhRK+O+O27Pi/uAy7Ihzy3ZIcaVA3B8pFQcdHhTEvpFInUlxF nnHLJfTei4wOQEy2nT9ZU84F84sJmWGjNBYZ7JwFbNSfJ+fQhnFOsPEkATZI+ejwCH43 Jcw9dfDWhjrSoNFPG1q1VJinUR9DKXCngHEN7Oikpw6fhnUqOrfPSTDW/Atycveol2Qm TeoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1oRNgpEH; 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 i8-20020a17090332c800b00172aa1ed560si4720666plr.138.2022.08.19.10.37.46; Fri, 19 Aug 2022 10:37:57 -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=1oRNgpEH; 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 S1351532AbiHSQKN (ORCPT + 99 others); Fri, 19 Aug 2022 12:10:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349831AbiHSQGp (ORCPT ); Fri, 19 Aug 2022 12:06:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AEC8104B0A; Fri, 19 Aug 2022 08:56:00 -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 906C1615E7; Fri, 19 Aug 2022 15:56:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 830F0C433C1; Fri, 19 Aug 2022 15:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924560; bh=VgUsXg6j2xmflmD+gNyUG1zzFZ+GaO+YqXg3TuUkSz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1oRNgpEH5Kh6V/cSCj+ksbjg1IMnHVGnjbyj5grBsaJznk96cuLXXdI4pOjzwe6zq FRPIgesneLvXlX3aXccUOoT+fSJi50TtiK94yTvLeZyrPDvGV8JEANhW0wfC673lEg 3eHsqLU7Ak6M6xmQ9cn7WsVzbBkZUOTl8nkfshuk= 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.10 183/545] crypto: ccp - During shutdown, check SEV data pointer before using Date: Fri, 19 Aug 2022 17:39:13 +0200 Message-Id: <20220819153837.550802866@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: 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 57b57d4db500..ed39a22e1b2b 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -278,7 +278,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