Re: [PATCH] crypto: ccp: Require a writable file for SNP_COMMIT
From: Herbert Xu
Date: Fri Dec 04 2026 - 01:03:23 EST
Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@xxxxxxxxxx> wrote:
> From: Suyuan Wang <stevewong@xxxxxxxxxxx>
>
> sev_ioctl() works out whether the file was opened for writing and passes
> that down to every command that changes platform state:
>
> bool writable = file->f_mode & FMODE_WRITE;
> ...
> case SNP_SET_CONFIG:
> ret = sev_ioctl_do_snp_set_config(&input, writable);
>
> SNP_COMMIT is the exception. sev_ioctl_do_snp_commit() takes no writable
> argument and runs SEV_CMD_SNP_COMMIT unconditionally, so a process that
> opened /dev/sev read-only can still commit the SNP firmware version.
> Committing the current firmware updates the committed version and the
> reported TCB, and prevents rolling back to a previously committed
> firmware version -- the kind of state change the FMODE_WRITE check
> exists to gate.
>
> Pass writable to sev_ioctl_do_snp_commit() and reject the command with
> -EPERM on a read-only file, like the other state-changing commands
> (reset, PEK/PDH gen, PEK import, SNP_SET_CONFIG, VLEK_LOAD).
>
> Found with a static analysis tool and checked by hand.
>
> Fixes: fad133c79afa ("crypto: ccp: Add the SNP_COMMIT command")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
> Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
> Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
> ---
> Compile tested only (x86_64, W=1 and sparse show no new warnings). I
> don't have an SEV-SNP platform.
> ---
> drivers/crypto/ccp/sev-dev.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt