Re: [PATCH v2] crypto: ccp - Do not hand a short INIT_EX file to the firmware

From: Jacky Li

Date: Tue Dec 01 2026 - 16:21:10 EST


Hi Gokul,

Thanks for the patch, and for the Cc.

I have no objection to the code change -- treating a short read the same
way as a missing file is reasonable hardening. My comments below are
only about the changelog and tags (I wrote d8da2da21fdb, so I may well
be biased about what it intended).

On Tue, Dec 01, 2026 at 10:59:47AM +0530, Gokul K wrote:
> 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.

Calling this "the platform's saved state" is a bit misleading. In
__sev_platform_init_locked(), the driver relies on the PSP's integrity
check and the SEV_RET_SECURE_DATA_INVALID retry path to reset invalid NV
state. On a valid read, sev_init_ex_buffer holds "the platform's saved
state", whereas on a missing/invalid read, it is just zeroed/garbage
data that is meant to trigger the PSP reset and retry.

> 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.

An all-zero buffer isn't a state the firmware ever wrote either (per the
SEV spec a fresh NV buffer is 32KB of 0xFF, and that is also what the
PSP resets it to).

> This dates from commit d8da2da21fdb ("crypto: ccp - Initialize PSP when
> reading psp data file failed"), which stopped a failed read from failing
> the init, so that the PSP is still initialized, but left whatever had
> been read in the buffer. Before it, a short read returned -EIO.

That is an accurate description of what the commit changed. Leaving the
contents in the buffer was deliberate, though. From its changelog:

Before the first INIT_EX call, if the content is invalid or missing,
continue the process by feeding those contents into PSP instead of
aborting. PSP will then override it with 32KB 0xFF and return
SEV_RET_SECURE_DATA_INVALID status code. In the second INIT_EX call,
this 32KB 0xFF content will then be fed and PSP will write the valid
data to the file.

> 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.

A truncated file is expected to fail the PSP's integrity check, the
retry path re-initializes the NV state, and
sev_write_init_ex_file_if_required() overrides the file. A zeroed
buffer takes the exact same retry path, so I don't think the current
behavior violates the documented contract.

> 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: d8da2da21fdb ("crypto: ccp - Initialize PSP when reading psp data file failed")
> Reported-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Closes: https://lore.kernel.org/all/abSWm4wyY91I4zf8@xxxxxxxxxx/

As you note, this patch doesn't fully fix the reported issue, so Closes:
is probably not accurate here (maybe Link: instead). I realize the v1
feedback pointed you at d8da2da21fdb, but since that behavior was
intended and I'm not aware of a failure it causes, this feels more like
hardening than a fix, so I'd lean towards dropping the Fixes: tag.

Thanks,
Jacky