Skip to content

Commit 332d2c1

Browse files
mdrothbonzini
authored andcommitted
crypto: ccp: Add the SNP_VLEK_LOAD command
When requesting an attestation report a guest is able to specify whether it wants SNP firmware to sign the report using either a Versioned Chip Endorsement Key (VCEK), which is derived from chip-unique secrets, or a Versioned Loaded Endorsement Key (VLEK) which is obtained from an AMD Key Derivation Service (KDS) and derived from seeds allocated to enrolled cloud service providers (CSPs). For VLEK keys, an SNP_VLEK_LOAD SNP firmware command is used to load them into the system after obtaining them from the KDS. Add a corresponding userspace interface so to allow the loading of VLEK keys into the system. See SEV-SNP Firmware ABI 1.54, SNP_VLEK_LOAD for more details. Reviewed-by: Tom Lendacky <[email protected]> Signed-off-by: Michael Roth <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 5d76650 commit 332d2c1

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

Documentation/virt/coco/sev-guest.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,25 @@ to SNP_CONFIG command defined in the SEV-SNP spec. The current values of
176176
the firmware parameters affected by this command can be queried via
177177
SNP_PLATFORM_STATUS.
178178

179+
2.7 SNP_VLEK_LOAD
180+
-----------------
181+
:Technology: sev-snp
182+
:Type: hypervisor ioctl cmd
183+
:Parameters (in): struct sev_user_data_snp_vlek_load
184+
:Returns (out): 0 on success, -negative on error
185+
186+
When requesting an attestation report a guest is able to specify whether
187+
it wants SNP firmware to sign the report using either a Versioned Chip
188+
Endorsement Key (VCEK), which is derived from chip-unique secrets, or a
189+
Versioned Loaded Endorsement Key (VLEK) which is obtained from an AMD
190+
Key Derivation Service (KDS) and derived from seeds allocated to
191+
enrolled cloud service providers.
192+
193+
In the case of VLEK keys, the SNP_VLEK_LOAD SNP command is used to load
194+
them into the system after obtaining them from the KDS, and corresponds
195+
closely to the SNP_VLEK_LOAD firmware command specified in the SEV-SNP
196+
spec.
197+
179198
3. SEV-SNP CPUID Enforcement
180199
============================
181200

drivers/crypto/ccp/sev-dev.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,39 @@ static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writable
20272027
return __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error);
20282028
}
20292029

2030+
static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable)
2031+
{
2032+
struct sev_device *sev = psp_master->sev_data;
2033+
struct sev_user_data_snp_vlek_load input;
2034+
void *blob;
2035+
int ret;
2036+
2037+
if (!sev->snp_initialized || !argp->data)
2038+
return -EINVAL;
2039+
2040+
if (!writable)
2041+
return -EPERM;
2042+
2043+
if (copy_from_user(&input, u64_to_user_ptr(argp->data), sizeof(input)))
2044+
return -EFAULT;
2045+
2046+
if (input.len != sizeof(input) || input.vlek_wrapped_version != 0)
2047+
return -EINVAL;
2048+
2049+
blob = psp_copy_user_blob(input.vlek_wrapped_address,
2050+
sizeof(struct sev_user_data_snp_wrapped_vlek_hashstick));
2051+
if (IS_ERR(blob))
2052+
return PTR_ERR(blob);
2053+
2054+
input.vlek_wrapped_address = __psp_pa(blob);
2055+
2056+
ret = __sev_do_cmd_locked(SEV_CMD_SNP_VLEK_LOAD, &input, &argp->error);
2057+
2058+
kfree(blob);
2059+
2060+
return ret;
2061+
}
2062+
20302063
static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
20312064
{
20322065
void __user *argp = (void __user *)arg;
@@ -2087,6 +2120,9 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
20872120
case SNP_SET_CONFIG:
20882121
ret = sev_ioctl_do_snp_set_config(&input, writable);
20892122
break;
2123+
case SNP_VLEK_LOAD:
2124+
ret = sev_ioctl_do_snp_vlek_load(&input, writable);
2125+
break;
20902126
default:
20912127
ret = -EINVAL;
20922128
goto out;

include/uapi/linux/psp-sev.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum {
3131
SNP_PLATFORM_STATUS,
3232
SNP_COMMIT,
3333
SNP_SET_CONFIG,
34+
SNP_VLEK_LOAD,
3435

3536
SEV_MAX,
3637
};
@@ -214,6 +215,32 @@ struct sev_user_data_snp_config {
214215
__u8 rsvd1[52];
215216
} __packed;
216217

218+
/**
219+
* struct sev_data_snp_vlek_load - SNP_VLEK_LOAD structure
220+
*
221+
* @len: length of the command buffer read by the PSP
222+
* @vlek_wrapped_version: version of wrapped VLEK hashstick (Must be 0h)
223+
* @rsvd: reserved
224+
* @vlek_wrapped_address: address of a wrapped VLEK hashstick
225+
* (struct sev_user_data_snp_wrapped_vlek_hashstick)
226+
*/
227+
struct sev_user_data_snp_vlek_load {
228+
__u32 len; /* In */
229+
__u8 vlek_wrapped_version; /* In */
230+
__u8 rsvd[3]; /* In */
231+
__u64 vlek_wrapped_address; /* In */
232+
} __packed;
233+
234+
/**
235+
* struct sev_user_data_snp_vlek_wrapped_vlek_hashstick - Wrapped VLEK data
236+
*
237+
* @data: Opaque data provided by AMD KDS (as described in SEV-SNP Firmware ABI
238+
* 1.54, SNP_VLEK_LOAD)
239+
*/
240+
struct sev_user_data_snp_wrapped_vlek_hashstick {
241+
__u8 data[432]; /* In */
242+
} __packed;
243+
217244
/**
218245
* struct sev_issue_cmd - SEV ioctl parameters
219246
*

0 commit comments

Comments
 (0)