Skip to content

Commit 92567ed

Browse files
tych0gregkh
authored andcommitted
crypto: ccp - Do not initialize SNP for ioctl(SNP_VLEK_LOAD)
commit f91e9db upstream. Sashiko notes: > if SEV initialization fails and KVM is actively running normal VMs, could a > userspace process trigger this code path via /dev/sev ioctls (e.g., > SEV_PDH_GEN) and zero out MSR_VM_HSAVE_PA globally? Would the next VMRUN > execution for an active VM trigger a general protection fault and crash the > host? The SEV firmware docs for SNP_VLEK_LOAD note: > On SNP_SHUTDOWN, the VLEK is deleted. That is, the initialization/shutdown wrapper here is pointless, because the firmware immediately throws away the key anyway. Instead, refuse to do anything if SNP has not been previously initialized. This is an ABI break: before, this was a no-op and almost certainly a mistake by userspace, and now it returns -ENODEV. ABI compatibility could be maintained here by simply returning 0 in the check instead. Fixes: ceac7fb ("crypto: ccp - Ensure implicit SEV/SNP init and shutdown in ioctls") Reported-by: Sashiko Assisted-by: Gemini:gemini-3.1-pro-preview Link: https://sashiko.dev/#/patchset/20260324161301.1353976-1-tycho%40kernel.org CC: <stable@vger.kernel.org> Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7a361c7 commit 92567ed

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

drivers/crypto/ccp/sev-dev.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,16 +2455,18 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable)
24552455
{
24562456
struct sev_device *sev = psp_master->sev_data;
24572457
struct sev_user_data_snp_vlek_load input;
2458-
bool shutdown_required = false;
2459-
int ret, error;
24602458
void *blob;
2459+
int ret;
24612460

24622461
if (!argp->data)
24632462
return -EINVAL;
24642463

24652464
if (!writable)
24662465
return -EPERM;
24672466

2467+
if (!sev->snp_initialized)
2468+
return -ENODEV;
2469+
24682470
if (copy_from_user(&input, u64_to_user_ptr(argp->data), sizeof(input)))
24692471
return -EFAULT;
24702472

@@ -2478,18 +2480,7 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable)
24782480

24792481
input.vlek_wrapped_address = __psp_pa(blob);
24802482

2481-
if (!sev->snp_initialized) {
2482-
ret = snp_move_to_init_state(argp, &shutdown_required);
2483-
if (ret)
2484-
goto cleanup;
2485-
}
2486-
24872483
ret = __sev_do_cmd_locked(SEV_CMD_SNP_VLEK_LOAD, &input, &argp->error);
2488-
2489-
if (shutdown_required)
2490-
__sev_snp_shutdown_locked(&error, false);
2491-
2492-
cleanup:
24932484
kfree(blob);
24942485

24952486
return ret;

0 commit comments

Comments
 (0)