Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2815406rwb; Mon, 15 Aug 2022 11:55:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR55D3nsLxZvUdxlOgBar6gXEZ3vLeihW6SycKPXERfhWndKuzz54kswdcVTcU8TtCEdfo4V X-Received: by 2002:a17:907:86ac:b0:731:5180:8aa0 with SMTP id qa44-20020a17090786ac00b0073151808aa0mr11289387ejc.366.1660589715853; Mon, 15 Aug 2022 11:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660589715; cv=none; d=google.com; s=arc-20160816; b=jA7Zfq8EF9yIr708X9OQVqSCcgKmthUrQOxiKxHbxbh4DO7ELuGQIosFhWU7MsQtau n5XFA85AHXX57m0zqbzdL433QO7PFFza7WIfVHvxbPyDlY+1J/pmEiFlBfYtByQInsgw Ri4YBqtQvck5rlUzDn0ju5FZvApbn0ncfUiurQpbrP0+9oX3ZETmUtH30w45TGrQBhmy 1FJGqgilw7M+FzkwyswL3bx2YETvEDVkpxpkkQEWbCSVl+/un/CYS2FhiaRmzQTp5UTd j4WcD/huzIZQJoSHz2ZfxBTSsAwqEsVBVQJ05oCnFc7eMfe3MVuValY+PT7rAo0ek71G cAJQ== 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=OpR3nXhUn08DnrF4DB9SYpTK9+qbECBcW+eshLI5UpI=; b=OmzxEnMRYwZv7N38gkwTg+pTsnmZLwmRJjtM3jhqc326eMkOS1bThS3QVtbEnOJEPr XztIxt7ga2hQUdJ/N/hWKR7IMyHfO5PwpRiroa0Yx5b/rUaBMJ2C8ca+nN5cnyiqVqSQ UANfIEcBLTIlR7uBALMqV6AOpIqe3ISTI4fVK8iQ+ucgjbruUqGbCeMK1KFgoiIF3TAT jWyG5bHXpAos3G/SzDgHcEceZJN8TtZ/TM7ZsdWV5oN1O/Ack3F1SHXaGSrL863SAt4Y /KOD5DmiXKfRjAKiMcbFVc3a13MSrU19JwHm0nFh0VKImZctJgbmypG1jnc4xG8H516t JQbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q08h0VUt; 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 m9-20020a056402430900b0043d6718da9bsi9769045edc.83.2022.08.15.11.54.47; Mon, 15 Aug 2022 11:55:15 -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=q08h0VUt; 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 S244308AbiHOSuz (ORCPT + 99 others); Mon, 15 Aug 2022 14:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243978AbiHOSqO (ORCPT ); Mon, 15 Aug 2022 14:46:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF7BB3FA29; Mon, 15 Aug 2022 11:27:57 -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 5BF2BB8106C; Mon, 15 Aug 2022 18:27:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E914C433D6; Mon, 15 Aug 2022 18:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588075; bh=hYBvICLMS9A7g+4gD3UtJkpPzToAMIOOW5sERuULXvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q08h0VUtnSeUR8ni9Ajkm8G6nDELeqBiy3kBQm1UQ4vKTEqEWKJY8y+aw29IrNvak 4k8ILVoBVlNXRwe99ImUaVofYolVLM5cfSP7W/gkVw+iDxUhFu2KojSX7YDYPz11vU ka/3OO0tDSmIVSOnn+GMYDMJI07OcGMxoD9Z3HwY= 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.15 286/779] crypto: ccp - During shutdown, check SEV data pointer before using Date: Mon, 15 Aug 2022 19:58:50 +0200 Message-Id: <20220815180349.525914719@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 8cf86dae20a4..900727b5edda 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -314,7 +314,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