Skip to content

Commit dd09eb4

Browse files
committed
Merge tag 'tsm-fixes-7.0-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/devsec/tsm
Pull tsm fix from Dan Williams: - Fix a VMM controlled buffer length used to emit TDX attestation reports * tag 'tsm-fixes-7.0-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/devsec/tsm: virt: tdx-guest: Fix handling of host controlled 'quote' buffer length
2 parents faf44e5 + c3fd16c commit dd09eb4

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)