Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2929550rwb; Mon, 15 Aug 2022 14:15:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR7KhlJwHZRCUI637vvDZBt8tjBx/P29kVQUXzDNwyq8jcwXhxo8Mq+qW1oHPwff3ldPwWlN X-Received: by 2002:a17:907:9804:b0:731:8692:f570 with SMTP id ji4-20020a170907980400b007318692f570mr11254126ejc.463.1660598117536; Mon, 15 Aug 2022 14:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660598117; cv=none; d=google.com; s=arc-20160816; b=hGB6PG1lfzjRD5nCtbGVNyMM1ayxcYzH4FKpXMVoKZTUWUf2Gd2fUHRhgEl3QUow6q AezAUbO17CwFTzo4Hox/nRqvKpw96Nq3E7rRLt/fNXXX/VcI+/UPbybMGOXzwMJ8oxZp VBj22seF+GB+xNQCgk1slfyf3iQRouJNMlvTTE4FHMbB2a0YyDmeBce56ZOtrwAh/2Ux GuiLQIY93LB6DLAho/27sG0exCSSDBrVySmsC2W0JjXcPFGC0wFXTGczCF1zSmcPcdI6 m3tg18v9jOmx+7Oh2SDjcZsVqWCm5GrE/kT4xotVN6fzNmBOkBqE3KDRCvG+TP+hll8U rxwA== 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=uG+I0JVuFES30CPHInacJrjZRNSTdYDh6xB/vbK+rxY=; b=bX+o7yLDM+oCXBgShijjw62d+zMkIxDd2oShQu02rAvZWg2njKs1SZohnKImTKKLZz PRpdIPlV1pBQ28AqXMi/uHfw3Znhz3X4jhadMY9Md9UZcWO7fDwQzMC06M+Gcpcu851i sDk4n6aNuH6IqQvh/kQZjfeV3SMZ3E3gEqwYIA3tJX8lv2ao3iRvQDlyxZCj2UF/XQTN udVWmrj0EnGbsSym/yGDNYD7zN1EPw/01x1H9K+nn0L4lqsN8dy3DgngNx1r/3/vxuRt kK2caALoKBdaP8nbK/YqFQ0m72h6WwtSOzvJtkrsytnm1H229JNevbvQqDABYVeg6FJq nqvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RW6UV2oz; 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 he7-20020a1709073d8700b0070f153ebd89si10117073ejc.7.2022.08.15.14.14.51; Mon, 15 Aug 2022 14:15:17 -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=RW6UV2oz; 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 S243741AbiHOVJE (ORCPT + 99 others); Mon, 15 Aug 2022 17:09:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344781AbiHOVDy (ORCPT ); Mon, 15 Aug 2022 17:03:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19CF651436; Mon, 15 Aug 2022 12:14:46 -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 64E0EB810A3; Mon, 15 Aug 2022 19:14:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD73CC433B5; Mon, 15 Aug 2022 19:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590883; bh=kS8tbc67MJN5uKPeEWqHN9GJd2RwXw/4SoQNaYonMcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RW6UV2ozL6GJOJHUh09kponEPOnrYfK2tU7Jxv5m99q1PZkxERnQKFuptQ+GQ0HN2 zDq0T8u23vjJfNEcVw0Eh5iSMk+t+kwIK6xY7M9kajmCg8Rq1Fup3VaEEHAVf4lGmH cfFihIvpW3MLW9X9uxvn9++vGcjk88qe4A9iPh7A= 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.18 0370/1095] crypto: ccp - During shutdown, check SEV data pointer before using Date: Mon, 15 Aug 2022 19:56:09 +0200 Message-Id: <20220815180445.028779075@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 812c1356a0f8..95dbab0ffab2 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