Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3888307rwi; Sat, 22 Oct 2022 01:36:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ehH8IIBLPmbEBoX7/IQzeL0rDKh5ydk5XuTS66Hvb4n6RRXGrhjRVfSvn989MT5vE42pL X-Received: by 2002:a63:4f4f:0:b0:434:b9db:b9f with SMTP id p15-20020a634f4f000000b00434b9db0b9fmr20054170pgl.438.1666427771916; Sat, 22 Oct 2022 01:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427771; cv=none; d=google.com; s=arc-20160816; b=sw7qL25rLWjgellfhBifExA6AwnuhDm2ysAPnN1s4kQlsifbBs6+FEYKy66Dh+raVR jDTubpuJMSjyh8vdlHH6eUnILAUrWKhiSDAtDvSs4+9UcU+7yoypLKSRGkVZdUXyOLUB OF6L1rxlnqeQCHiWG+ZO8I7UKM6UGLE8dbsdwkwgTS5nz2GghR+VxA++4eVuMFKU5GKe Tslk4KrL/TzwUVpD1LxWYRpHV4BhWgpSrQ+hvXBmOM8jPvY5z9BImO3MIdnEA8oPpCte CeiAoGYGoxfLoMu7IzTnQupyyCndoNOQ+D6lejVfTvnhI/P7UHakR6YElZU/+gBzp3vD fd3A== 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=EqOFn4ba1WfCL9PfKYlChLFt2Zz73bVsyjlbTocJDrVcLW/shNK3KV+i5zcjuUJLof ltdWP/XlexBl8wov467LD+TXUoEBTHKt9WPxLVqtFz2eSRWT4X9yEwWUyFO8eW/bIGXM ABDA5uuX+O3Af0XlXEJWW+vem9tE3yYxQAHfEWVaypsO9dHInpyP+Xu7RlpZLodqn8b6 6CHFSJzbfbagvhGdu88F5s63d8rT+b3/8wE31eIg2cawZUzjZIjN0wUn08+tjB6pI88I a6EaVr2VMsIfFO0wmMIqn+WAJF/x1HVb/zokZKiqnxw0voeiUejLi5E5zi4F/WJ6nsCc +RTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jz+tY4my; 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 5-20020a631145000000b004428327e6dfsi29123035pgr.174.2022.10.22.01.35.55; Sat, 22 Oct 2022 01:36:11 -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=jz+tY4my; 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 S230048AbiJVIV0 (ORCPT + 99 others); Sat, 22 Oct 2022 04:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233813AbiJVITs (ORCPT ); Sat, 22 Oct 2022 04:19:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 086162DF47B; Sat, 22 Oct 2022 00:58:27 -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 99A5160B09; Sat, 22 Oct 2022 07:57:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E5BDC433D7; Sat, 22 Oct 2022 07:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425467; bh=Oez0xSkPvwxIgWUhwxsQd8h6OI5hQd7QDtdeIIXp/vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jz+tY4myBboT5enhvmu2t2vkaZ/vTI879TdBtEHSjKS3lUtfeC3I8bromMRq7ll/X UtuLSR34El4RfTG3HTUqh0rC3HLMXclEZj3vbzvX+w3U5CRXILK4TNMPFpfKlUBxKO mW5iFlNFnX2yohb9eaZRCymgwZXwYyMrXGIHTUwI= 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 5.19 510/717] crypto: ccp - Fail the PSP initialization when writing psp data file failed Date: Sat, 22 Oct 2022 09:26:29 +0200 Message-Id: <20221022072520.817573312@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@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.3 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 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, -- 2.35.1