Skip to content

Commit c3fd16c

Browse files
zsm-ossdjbw
authored andcommitted
virt: tdx-guest: Fix handling of host controlled 'quote' buffer length
Validate host controlled value `quote_buf->out_len` that determines how many bytes of the quote are copied out to guest userspace. In TDX environments with remote attestation, quotes are not considered private, and can be forwarded to an attestation server. Catch scenarios where the host specifies a response length larger than the guest's allocation, or otherwise races modifying the response while the guest consumes it. This prevents contents beyond the pages allocated for `quote_buf` (up to TSM_REPORT_OUTBLOB_MAX) from being read out to guest userspace, and possibly forwarded in attestation requests. Recall that some deployments want per-container configs-tsm-report interfaces, so the leak may cross container protection boundaries, not just local root. Fixes: f4738f5 ("virt: tdx-guest: Add Quote generation support using TSM_REPORTS") Cc: [email protected] Signed-off-by: Zubin Mithra <[email protected]> Reviewed-by: Dan Williams <[email protected]> Reviewed-by: Kiryl Shutsemau (Meta) <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent f338e77 commit c3fd16c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/virt/coco/tdx-guest/tdx-guest.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ static void tdx_mr_deinit(const struct attribute_group *mr_grp)
171171
#define GET_QUOTE_SUCCESS 0
172172
#define GET_QUOTE_IN_FLIGHT 0xffffffffffffffff
173173

174+
#define TDX_QUOTE_MAX_LEN (GET_QUOTE_BUF_SIZE - sizeof(struct tdx_quote_buf))
175+
174176
/* struct tdx_quote_buf: Format of Quote request buffer.
175177
* @version: Quote format version, filled by TD.
176178
* @status: Status code of Quote request, filled by VMM.
@@ -269,6 +271,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)
269271
u8 *buf;
270272
struct tdx_quote_buf *quote_buf = quote_data;
271273
struct tsm_report_desc *desc = &report->desc;
274+
u32 out_len;
272275
int ret;
273276
u64 err;
274277

@@ -306,12 +309,17 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)
306309
return ret;
307310
}
308311

309-
buf = kvmemdup(quote_buf->data, quote_buf->out_len, GFP_KERNEL);
312+
out_len = READ_ONCE(quote_buf->out_len);
313+
314+
if (out_len > TDX_QUOTE_MAX_LEN)
315+
return -EFBIG;
316+
317+
buf = kvmemdup(quote_buf->data, out_len, GFP_KERNEL);
310318
if (!buf)
311319
return -ENOMEM;
312320

313321
report->outblob = buf;
314-
report->outblob_len = quote_buf->out_len;
322+
report->outblob_len = out_len;
315323

316324
/*
317325
* TODO: parse the PEM-formatted cert chain out of the quote buffer when

0 commit comments

Comments
 (0)