All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gokul K" <gokul02k@gmail.com>,
	"Ashish Kalra" <ashish.kalra@amd.com>,
	"Tom Lendacky" <thomas.lendacky@amd.com>,
	"John Allen" <john.allen@amd.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org
Cc: "Sean Christopherson" <seanjc@google.com>,
	"David Rientjes" <rientjes@google.com>,
	"Peter Gonda" <pgonda@google.com>,
	"Atish Patra" <atishp@meta.com>
Subject: Re: [PATCH] crypto: ccp - Do not hand a short INIT_EX file to the firmware
Date: Thu, 26 Nov 2026 09:29:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-235136@kernel.org> (raw)
In-Reply-To: <20261126092001.2099312-1-gokul02k@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] crypto: ccp: inaccurate Fixes trailer for
  sev_read_init_ex_file() short read
--

commit c74101dd406e137499f025e32571e23c036489af
Author: Gokul K <gokul02k@gmail.com>

> crypto: ccp - Do not hand a short INIT_EX file to the firmware
>
> sev_read_init_ex_file() reads the INIT_EX non-volatile state from
> init_ex_path into sev_init_ex_buffer. When the read returns anything other
> than NV_LENGTH it logs the fact and then returns 0, so the caller carries
> on and __sev_init_ex_locked() passes the buffer to the PSP as the
> platform's saved state.
>
> For a truncated file that buffer holds a prefix of the old contents
> followed by the zeroes the page was allocated with, which is not a state
> the firmware ever wrote. A negative return from kernel_read() is treated
> the same way, and then the buffer holds nothing but zeroes while the code
> still reports success.
>
> This is not what the interface promises. Documentation/virt/kvm/x86/
> amd-memory-encryption.rst says of init_ex_path:
>
>   If the file specified by ``init_ex_path`` does not exist or is invalid,
>   the OS will create or override the file with PSP non-volatile storage.
>
> A file that cannot be read in full is invalid, so discard what was read
> and let INIT_EX run from a zeroed buffer, exactly as it does when the file
> does not exist yet. The firmware then repopulates the buffer and
> sev_write_init_ex_file_if_required() writes it back, which is the
> "override" half of the documented behavior.
>
> Doing this for a negative kernel_read() return means a transient read
> error costs the platform its persisted state rather than failing the
> init. That is the deliberate trade: the documented contract allows the
> file to be overridden, and feeding the firmware a buffer it did not write
> is worse than starting over.
>
> This was found while looking at the INIT_EX failure reported by Sean
> Christopherson, where an interrupted writeback leaves the platform
> unusable. It addresses only the case of a file that is short or unreadable
> on the next init. An interrupted write leaves a full-length file holding a
> mix of old and new bytes, which a length check cannot detect, so the
> reported failure is not fully fixed by this patch.
>
> Fixes: 3d725965f836 ("crypto: ccp - Add SEV_INIT_EX support")
> Reported-by: Sean Christopherson <seanjc@google.com>
> Closes: https://lore.kernel.org/all/abSWm4wyY91I4zf8@google.com/
> Signed-off-by: Gokul K <gokul02k@gmail.com>

[Severity: Low]
In commit 3d725965f836 ("crypto: ccp - Add SEV_INIT_EX support"),
sev_read_init_ex_file() returned -EIO when kernel_read() did not return
NV_LENGTH, so __sev_init_ex_locked() aborted before issuing
SEV_CMD_INIT_EX to the firmware.

Returning 0 on a short or failed read while leaving partial contents in
sev_init_ex_buffer was introduced by commit d8da2da21fdb ("crypto: ccp -
Initialize PSP when reading psp data file failed"). Should the Fixes: tag
cite that commit instead:

  Fixes: d8da2da21fdb ("crypto: ccp - Initialize PSP when reading psp data file failed")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126092001.2099312-1-gokul02k@gmail.com?part=1

  reply	other threads:[~2026-11-26  9:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:20 [PATCH] crypto: ccp - Do not hand a short INIT_EX file to the firmware Gokul K
2026-11-26  9:29 ` sashiko-bot [this message]
2026-11-30 19:58 ` Tom Lendacky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-235136@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ashish.kalra@amd.com \
    --cc=atishp@meta.com \
    --cc=davem@davemloft.net \
    --cc=gokul02k@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.allen@amd.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=pgonda@google.com \
    --cc=rientjes@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seanjc@google.com \
    --cc=thomas.lendacky@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.