From: Michael Roth <michael.roth@amd.com>
To: <linux-crypto@vger.kernel.org>
Cc: <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
<ackerleytng@google.com>, <thomas.lendacky@amd.com>,
<ashish.kalra@amd.com>, <aik@amd.com>, <seanjc@google.com>
Subject: [PATCH 2/4] crypto: ccp - Check SNP initialization state after copying user inputs
Date: Wed, 14 Oct 2026 08:20:31 -0500 [thread overview]
Message-ID: <20261014132145.1726322-3-michael.roth@amd.com> (raw)
In-Reply-To: <20261014132145.1726322-1-michael.roth@amd.com>
From: Ackerley Tng <ackerleytng@google.com>
When servicing SNP configuration and VLEK load ioctl commands, the
driver checks whether SNP is initialized before copying command inputs
from userspace.
The SNP initialization state is protected by the global SEV command
mutex. To prepare for acquiring the global SEV command mutex only
around firmware command execution rather than across userspace memory
copies, move the SNP initialization check after the userspace copies
and buffer allocations, right before issuing the firmware command.
No functional change intended.
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
drivers/crypto/ccp/sev-dev.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 7de3b6bf71e1..e42cf3aee50a 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -2639,12 +2639,12 @@ static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writable
if (!writable)
return -EPERM;
- if (!sev->snp_initialized)
- return -ENODEV;
-
if (copy_from_user(&config, (void __user *)argp->data, sizeof(config)))
return -EFAULT;
+ if (!sev->snp_initialized)
+ return -ENODEV;
+
return __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error);
}
@@ -2661,9 +2661,6 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable)
if (!writable)
return -EPERM;
- if (!sev->snp_initialized)
- return -ENODEV;
-
if (copy_from_user(&input, u64_to_user_ptr(argp->data), sizeof(input)))
return -EFAULT;
@@ -2677,7 +2674,11 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable)
input.vlek_wrapped_address = __psp_pa(blob);
- ret = __sev_do_cmd_locked(SEV_CMD_SNP_VLEK_LOAD, &input, &argp->error);
+ if (!sev->snp_initialized)
+ ret = -ENODEV;
+ else
+ ret = __sev_do_cmd_locked(SEV_CMD_SNP_VLEK_LOAD, &input, &argp->error);
+
kfree(blob);
return ret;
--
2.43.0
next prev parent reply other threads:[~2026-10-14 13:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 13:20 [PATCH 0/4] crypto: ccp - Make sev_cmd_mutex more granular Michael Roth
2026-10-14 13:20 ` [PATCH 1/4] crypto: ccp - Shut down SEV firmware before copying to user Michael Roth
2026-10-14 13:37 ` Tom Lendacky
2026-10-14 13:20 ` Michael Roth [this message]
2026-10-14 13:45 ` [PATCH 2/4] crypto: ccp - Check SNP initialization state after copying user inputs Tom Lendacky
2026-10-14 13:20 ` [PATCH 3/4] crypto: ccp - Make usage of sev_cmd_mutex more granular Michael Roth
2026-10-14 13:58 ` Tom Lendacky
2026-10-14 13:20 ` [PATCH 4/4] crypto: ccp - Allocate status page outside sev_cmd_mutex in SNP_PLATFORM_STATUS Michael Roth
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=20261014132145.1726322-3-michael.roth@amd.com \
--to=michael.roth@amd.com \
--cc=ackerleytng@google.com \
--cc=aik@amd.com \
--cc=ashish.kalra@amd.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox