anolis: virt: csv-guest: Add support for extended attestation aware request in the CSV3 guest
ANBZ: #22214 The struct csv3_data_attestation_report is the communication structure between the CSV3 guest and Hygon PSP. The reserved1 field in the struct csv3_data_attestation_report has been changed to a flags field, which is used to store the attestation extension flags. When the flags field is 0, the firmware returns a legacy attestation report; otherwise, it returns an extended attestation report. The struct csv_guest_user_data_attestation is the user-space buffer for legacy attestation, and this buffer can provide challenge data (see the user_data and mnonce fields) to the firmware. The struct csv_guest_user_data_attestation_ext is the user-space buffer for extended attestation, and it can also provide challenge data (see the user_data and mnonce fields) to the firmware. Since user space always provides a buffer larger than the struct csv_guest_user_data_attestation, the csv-guest module cannot determine whether the user-space request is for extended attestation. To address this, we added a magic field to the struct csv_guest_user_data_attestation_ext. If the magic field is populated with the string "ATTESTATION_EXT", the csv-guest module considers this is an extended attestation request, and the flags field in the struct csv_guest_user_data_attestation_ext will be copied to the struct csv3_data_attestation_report so that the firmware will serve the attestation request as intended. The definition of the struct csv_guest_user_data_attestation has been moved to the csv-guest local header file. Signed-off-by: hanliyang <hanliyang@hygon.cn> Reviewed-by: Guixin Liu <kanie@Linux.aliabab.com> Reviewed-by: Guixin Liu <kanie@linux.alibaba.com> Link: https://gitee.com/anolis/cloud-kernel/pulls/5464
This commit is contained in:
parent
35ab5abf43
commit
58792ceff6
|
@ -23,6 +23,9 @@
|
|||
/* Mutex to serialize the command handling. */
|
||||
static DEFINE_MUTEX(csv_cmd_mutex);
|
||||
|
||||
/* The magic string is used to identify extended attestation aware requests. */
|
||||
static char csv_attestation_magic[CSV_ATTESTATION_MAGIC_LEN] = CSV_ATTESTATION_MAGIC_STRING;
|
||||
|
||||
static int csv_get_report(unsigned long arg)
|
||||
{
|
||||
u8 *csv_report;
|
||||
|
@ -68,6 +71,7 @@ static int csv3_get_report(unsigned long arg)
|
|||
struct csv3_data_attestation_report *cmd_buff = NULL;
|
||||
void *req_buff = NULL;
|
||||
void *resp_buff = NULL;
|
||||
struct csv_guest_user_data_attestation_ext *udata = NULL;
|
||||
int ret;
|
||||
|
||||
if (copy_from_user(&input, (void __user *)arg, sizeof(input)))
|
||||
|
@ -82,6 +86,28 @@ static int csv3_get_report(unsigned long arg)
|
|||
return -ENOMEM;
|
||||
cmd_buff = (struct csv3_data_attestation_report *)page_address(page);
|
||||
|
||||
/*
|
||||
* If user space issues an extended attestation aware request, then sync
|
||||
* the flags to @cmd_buff.
|
||||
*/
|
||||
if (input.len >= CSV_ATTESTATION_USER_DATA_EXT_LEN) {
|
||||
udata = kzalloc(CSV_ATTESTATION_USER_DATA_EXT_LEN, GFP_KERNEL);
|
||||
if (!udata) {
|
||||
ret = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (copy_from_user((void *)udata, input.report_data,
|
||||
CSV_ATTESTATION_USER_DATA_EXT_LEN)) {
|
||||
ret = -EFAULT;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!strncmp((char *)udata->magic, csv_attestation_magic,
|
||||
CSV_ATTESTATION_MAGIC_LEN))
|
||||
cmd_buff->flags = udata->flags;
|
||||
}
|
||||
|
||||
/*
|
||||
* Query the firmware to get minimum length of request buffer and
|
||||
* respond buffer.
|
||||
|
@ -146,6 +172,8 @@ err:
|
|||
if (cmd_buff)
|
||||
free_page((unsigned long)cmd_buff);
|
||||
|
||||
kfree(udata);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,62 @@
|
|||
#define CSV_REPORT_INPUT_DATA_LEN (CSV_REPORT_USER_DATA_LEN + CSV_REPORT_MNONCE_LEN \
|
||||
+ CSV_REPORT_HASH_LEN)
|
||||
|
||||
/**
|
||||
* struct csv_guest_user_data_attestation - ATTESTATION command parameters.
|
||||
* This is used for legacy attestation.
|
||||
*
|
||||
* In the legacy attestation, the size of tee info portion of the
|
||||
* attestation report is 0x150. The tee info does not contain rtmr.
|
||||
*
|
||||
* @user_data: user defined data, it's suggest that contains challenge data
|
||||
* from the relying party.
|
||||
* @mnonce: user's random nonce, just for anti-replay attack protection.
|
||||
* @hash: the sm3 hash of the @user_data and @mnonce.
|
||||
*/
|
||||
struct csv_guest_user_data_attestation {
|
||||
__u8 user_data[CSV_REPORT_USER_DATA_LEN]; /* In */
|
||||
__u8 mnonce[CSV_REPORT_MNONCE_LEN]; /* In */
|
||||
__u8 hash[CSV_REPORT_HASH_LEN]; /* In */
|
||||
} __packed;
|
||||
|
||||
#define CSV_ATTESTATION_USER_DATA_EXT_LEN 132U
|
||||
|
||||
#define CSV_ATTESTATION_MAGIC_LEN 16
|
||||
#define CSV_ATTESTATION_MAGIC_STRING "ATTESTATION_EXT"
|
||||
|
||||
#define CSV_ATTESTATION_FLAG_REPORT_EXT_BIT 0
|
||||
#define CSV_ATTESTATION_FLAG_REPORT_EXT (1U << CSV_ATTESTATION_FLAG_REPORT_EXT)
|
||||
|
||||
/**
|
||||
* struct csv_guest_user_data_attestation_ext - ATTESTATION command parameters.
|
||||
* This is used for extended attestation.
|
||||
*
|
||||
* In the extended attestation, the size of tee info portion of the
|
||||
* attestation report is 0x490. The tee info contains rtmr by default.
|
||||
*
|
||||
* Currently, the extended attestation only supported for CSV3 guest.
|
||||
*
|
||||
* @user_data: user defined data, it's suggest that contains challenge data
|
||||
* from the relying party.
|
||||
* @mnonce: user's random nonce, just for anti-replay attack protection.
|
||||
* @hash: the sm3 hash of the @user_data and @mnonce.
|
||||
* @magic: The magic string indicates this is an extended attestation aware
|
||||
* request. Due to historical reasons, users always provide a buffer
|
||||
* that is much larger than the size of structure
|
||||
* csv_guest_user_data_attestation_ext. The magic string will be used to
|
||||
* determine whether the user space uses the extended attestation aware
|
||||
* request. If the user space is using such a request, the flags field
|
||||
* will be used to indicate the format of the attestation report.
|
||||
* @flags: the bit flags used to indicate how to extend the attestation report.
|
||||
*/
|
||||
struct csv_guest_user_data_attestation_ext {
|
||||
__u8 user_data[CSV_REPORT_USER_DATA_LEN]; /* In */
|
||||
__u8 mnonce[CSV_REPORT_MNONCE_LEN]; /* In */
|
||||
__u8 hash[CSV_REPORT_HASH_LEN]; /* In */
|
||||
__u8 magic[CSV_ATTESTATION_MAGIC_LEN]; /* In */
|
||||
__u32 flags; /* In */
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* struct csv_report_req - Request struct for CSV_CMD_GET_REPORT IOCTL.
|
||||
*
|
||||
|
|
|
@ -198,6 +198,9 @@ struct csv_data_dbg_read_mem {
|
|||
* struct csv3_data_attestation_report - ATTESTATION secure call command parameters
|
||||
*
|
||||
* @handle: handle of the VM to process
|
||||
* @flags: the bit flags used to indicate how to extend the attestation report.
|
||||
* It's copied from user space's parameter before issuing the ATTESTATION
|
||||
* secure call command.
|
||||
* @resp_gpa: guest physical address to save the generated report
|
||||
* @resp_length: length of the generated report
|
||||
* @req_gpa: guest physical address of the input for the report
|
||||
|
@ -206,7 +209,7 @@ struct csv_data_dbg_read_mem {
|
|||
*/
|
||||
struct csv3_data_attestation_report {
|
||||
u32 handle; /* Out */
|
||||
u32 reserved1;
|
||||
u32 flags; /* In */
|
||||
u64 resp_gpa; /* In */
|
||||
u8 reserved2[16];
|
||||
u32 resp_len; /* In/Out */
|
||||
|
|
|
@ -13,20 +13,6 @@
|
|||
|
||||
#include <linux/types.h>
|
||||
|
||||
/**
|
||||
* struct csv_guest_user_data_attestation - ATTESTATION command parameters
|
||||
*
|
||||
* @user_data: user specified data for the attestation report
|
||||
* @mnonce: user's random nonce
|
||||
* @hash: sm3 hash of the @user_data and @mnonce
|
||||
*/
|
||||
struct csv_guest_user_data_attestation {
|
||||
__u8 user_data[64]; /* In */
|
||||
__u8 monce[16]; /* In */
|
||||
__u8 hash[32]; /* In */
|
||||
} __packed;
|
||||
|
||||
|
||||
/* The CSV RTMR version in the kernel */
|
||||
#define CSV_RTMR_VERSION_MAX 1U
|
||||
#define CSV_RTMR_VERSION_MIN 1U
|
||||
|
|
Loading…
Reference in New Issue