From patchwork Wed Oct 19 08:31:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp369552wrs; Wed, 19 Oct 2022 07:52:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5rK1IaeR8AvjdJwRGzFtELcS+OOZMf7scUQmyV9AlMu8yso9/QQLqaocb6WahfEdUW62d0 X-Received: by 2002:aa7:de9a:0:b0:44d:8191:44c5 with SMTP id j26-20020aa7de9a000000b0044d819144c5mr7729650edv.232.1666191129378; Wed, 19 Oct 2022 07:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666191129; cv=none; d=google.com; s=arc-20160816; b=uBfqZ1x4pYBSaL6Ov1AUxxBJytpMkJRqGv+lzhmpmU/f7UwVHgF9lzy06NRTcVB9Ri zUjYsgpJO4Z6ToiLGVHg3YEX+biRcwstHfOIe5nbLaHNp546rakk4oFTsvLcNpVaCZxR Al85UvKlpfO741Eh7CXVH65k8MddoRxgHJriD9EXyvHNz3okbYKDBHOioTfFranruUb/ WCf0FbIqGmp1l+IAsj3U4fv9DyNRtDSe/d6vNDFrgaHCsjcGRqRmQYjZak9JztqTGDTN EeHGVHz+/iAW3Er0NnHMKr5riWf28CdNJsKDVQIIrFuVCzr8pSNdyNqsEIYpZ5i0RALt NhoA== 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=w6tz0U8UPKbtwhOkHEsa6Qf5NzLol/nzDz/Eru6RGwY=; b=YIhc7n8sfRqg3nknQZXyM7oI89V1Pjh0hwA23EZwQprmbxQ5gstLq+KgXOQ4WdXs+u 16/TH3IcP6iUSyCpgYv8rzeWguuYYXgMqiraoemOFC7g4T2S9M34WzaEDqbsOTHp2adA ldmS3Sr1T80wBcY59zBP8bFmvxI7AJ+nbuwky2IVddBX8Nj6P34pSeDGr9SGW9w2Nd68 dkQFFehBoW8YskFmzarWoJ1DHH1ZiXtZQOckA1IfxD8azkAprnkTL5KJm3CD5Tds4Vii dVQtopZSyNVNknfGZxW2uBRBMRznsC0BLrow+oK5z+qLsjjpS4iFaVZFXTHbLw+QR5K5 zm9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m9UHvTas; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a056402350f00b0044ee4ec8915si16639092edd.39.2022.10.19.07.51.44; Wed, 19 Oct 2022 07:52:09 -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=m9UHvTas; 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 S229944AbiJSOqi (ORCPT + 99 others); Wed, 19 Oct 2022 10:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbiJSOqP (ORCPT ); Wed, 19 Oct 2022 10:46:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0260DF5F; Wed, 19 Oct 2022 07:32:36 -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 EE6BF6177D; Wed, 19 Oct 2022 09:06:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EA3EC433D7; Wed, 19 Oct 2022 09:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170364; bh=Oez0xSkPvwxIgWUhwxsQd8h6OI5hQd7QDtdeIIXp/vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m9UHvTasj6dlWCzd90IDPgDcANHzSWjtdkCDTRWS/DolJIYUt/J8VPSxtA09EgxZh elOJJGZnP6bIHBLMV44D7AmG0xBMCayoZZjE/+RCtDaQfJaBQ4EuGdtY4jAAQL4X17 oIdqzIeEOHL5Tm7IYoreYiQnv+EA793zaeK2YdtU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Gonda , kernel test robot , Jacky Li , David Rientjes , Tom Lendacky , Herbert Xu , Sasha Levin Subject: [PATCH 6.0 627/862] crypto: ccp - Fail the PSP initialization when writing psp data file failed Date: Wed, 19 Oct 2022 10:31:54 +0200 Message-Id: <20221019083317.625376706@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747128029910500580?= X-GMAIL-MSGID: =?utf-8?q?1747128029910500580?= From: Jacky Li [ Upstream commit efb4b01c1c993d245e6608076684ff2162cf9dc6 ] Currently the OS continues the PSP initialization when there is a write failure to the init_ex_file. Therefore, the userspace would be told that SEV is properly INIT'd even though the psp data file is not updated. This is problematic because later when asked for the SEV data, the OS won't be able to provide it. Fixes: 3d725965f836 ("crypto: ccp - Add SEV_INIT_EX support") Reported-by: Peter Gonda Reported-by: kernel test robot Signed-off-by: Jacky Li Acked-by: David Rientjes Acked-by: Tom Lendacky Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/ccp/sev-dev.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 9f588c9728f8..6c49e6d06114 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -231,7 +231,7 @@ static int sev_read_init_ex_file(void) return 0; } -static void sev_write_init_ex_file(void) +static int sev_write_init_ex_file(void) { struct sev_device *sev = psp_master->sev_data; struct file *fp; @@ -241,14 +241,16 @@ static void sev_write_init_ex_file(void) lockdep_assert_held(&sev_cmd_mutex); if (!sev_init_ex_buffer) - return; + return 0; fp = open_file_as_root(init_ex_path, O_CREAT | O_WRONLY, 0600); if (IS_ERR(fp)) { + int ret = PTR_ERR(fp); + dev_err(sev->dev, - "SEV: could not open file for write, error %ld\n", - PTR_ERR(fp)); - return; + "SEV: could not open file for write, error %d\n", + ret); + return ret; } nwrite = kernel_write(fp, sev_init_ex_buffer, NV_LENGTH, &offset); @@ -259,18 +261,20 @@ static void sev_write_init_ex_file(void) dev_err(sev->dev, "SEV: failed to write %u bytes to non volatile memory area, ret %ld\n", NV_LENGTH, nwrite); - return; + return -EIO; } dev_dbg(sev->dev, "SEV: write successful to NV file\n"); + + return 0; } -static void sev_write_init_ex_file_if_required(int cmd_id) +static int sev_write_init_ex_file_if_required(int cmd_id) { lockdep_assert_held(&sev_cmd_mutex); if (!sev_init_ex_buffer) - return; + return 0; /* * Only a few platform commands modify the SPI/NV area, but none of the @@ -285,10 +289,10 @@ static void sev_write_init_ex_file_if_required(int cmd_id) case SEV_CMD_PEK_GEN: break; default: - return; + return 0; } - sev_write_init_ex_file(); + return sev_write_init_ex_file(); } static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) @@ -361,7 +365,7 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) cmd, reg & PSP_CMDRESP_ERR_MASK); ret = -EIO; } else { - sev_write_init_ex_file_if_required(cmd); + ret = sev_write_init_ex_file_if_required(cmd); } print_hex_dump_debug("(out): ", DUMP_PREFIX_OFFSET, 16, 2, data,