* [PATCH] crypto: ccp: Require a writable file for SNP_COMMIT
@ 2026-11-18 14:21 Suyuan Wang via B4 Relay
2026-11-23 15:51 ` Tom Lendacky
0 siblings, 1 reply; 2+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-18 14:21 UTC (permalink / raw)
To: ashish.kalra, john.allen, thomas.lendacky; +Cc: linux-kernel, linux-crypto
From: Suyuan Wang <stevewong@hust.edu.cn>
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@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
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(-)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 52fb208b71ab..9d1c40a371e3 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -2666,11 +2666,14 @@ static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp)
return ret;
}
-static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp)
+static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp, bool writable)
{
struct sev_data_snp_commit buf;
int ret;
+ if (!writable)
+ return -EPERM;
+
buf.len = sizeof(buf);
mutex_lock(&sev_cmd_mutex);
@@ -2796,7 +2799,7 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
ret = sev_ioctl_do_snp_platform_status(&input);
break;
case SNP_COMMIT:
- ret = sev_ioctl_do_snp_commit(&input);
+ ret = sev_ioctl_do_snp_commit(&input, writable);
break;
case SNP_SET_CONFIG:
ret = sev_ioctl_do_snp_set_config(&input, writable);
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] crypto: ccp: Require a writable file for SNP_COMMIT
2026-11-18 14:21 [PATCH] crypto: ccp: Require a writable file for SNP_COMMIT Suyuan Wang via B4 Relay
@ 2026-11-23 15:51 ` Tom Lendacky
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lendacky @ 2026-11-23 15:51 UTC (permalink / raw)
To: shyckless, ashish.kalra; +Cc: linux-kernel, linux-crypto
On 11/18/26 08:21, Suyuan Wang via B4 Relay wrote:
> From: Suyuan Wang <stevewong@hust.edu.cn>
>
> 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.
This will change the ABI, but I don't believe anyone is truly using
SNP_COMMIT, yet. It is needed for the live firmware update support of SNP,
which is still being reviewed.
When loading the CCP/ASP driver, the firmware update that happens is
automatically committed, so SNP_COMMIT is not needed for that.
If there are no objections from anyone, them I'm ok with the change. Let's
wait a bit to see if there are any replies.
Thanks,
Tom
>
> Fixes: fad133c79afa ("crypto: ccp: Add the SNP_COMMIT command")
> Cc: stable@vger.kernel.org
> Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
> ---
> 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(-)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 52fb208b71ab..9d1c40a371e3 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -2666,11 +2666,14 @@ static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp)
> return ret;
> }
>
> -static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp)
> +static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp, bool writable)
> {
> struct sev_data_snp_commit buf;
> int ret;
>
> + if (!writable)
> + return -EPERM;
> +
> buf.len = sizeof(buf);
>
> mutex_lock(&sev_cmd_mutex);
> @@ -2796,7 +2799,7 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
> ret = sev_ioctl_do_snp_platform_status(&input);
> break;
> case SNP_COMMIT:
> - ret = sev_ioctl_do_snp_commit(&input);
> + ret = sev_ioctl_do_snp_commit(&input, writable);
> break;
> case SNP_SET_CONFIG:
> ret = sev_ioctl_do_snp_set_config(&input, writable);
>
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 15:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 14:21 [PATCH] crypto: ccp: Require a writable file for SNP_COMMIT Suyuan Wang via B4 Relay
2026-11-23 15:51 ` Tom Lendacky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox