mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
virt: tdx-guest: Calculate the Quote buffer size safely
struct tdx_quote_buf has a trailing flexible array member. struct_size() calculates the size of this kind of struct safely. It handles overflow, which helps since the Quote size comes from the host. Use it to rewrite the bounds check logic, since "header_size + data_size > buf_size" ... is more readable than "data_size > buf_size - header_size". This also prepares for a later change that needs the same "header_size + data_size" calculation for the Quote buffer size. AI was used under supervision to collect/apply feedback, review code and workshop logs. Signed-off-by: Peter Fang <peter.fang@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org> Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Link: https://patch.msgid.link/20260930103739.2851980-4-peter.fang@intel.com
This commit is contained in:
parent
0d3fe9bad7
commit
683cc6010d
|
|
@ -170,8 +170,6 @@ static void tdx_mr_deinit(const struct attribute_group *mr_grp)
|
|||
#define GET_QUOTE_SUCCESS 0
|
||||
#define GET_QUOTE_IN_FLIGHT 0xffffffffffffffff
|
||||
|
||||
#define TDX_QUOTE_MAX_LEN (GET_QUOTE_BUF_SIZE - sizeof(struct tdx_quote_buf))
|
||||
|
||||
/* struct tdx_quote_buf: Format of Quote request buffer.
|
||||
* @version: Quote format version, filled by TD.
|
||||
* @status: Status code of Quote request, filled by VMM.
|
||||
|
|
@ -313,7 +311,7 @@ static int tdx_report_new_locked(struct tsm_report *report)
|
|||
|
||||
out_len = READ_ONCE(quote_buf->out_len);
|
||||
|
||||
if (out_len > TDX_QUOTE_MAX_LEN)
|
||||
if (struct_size(quote_buf, data, out_len) > GET_QUOTE_BUF_SIZE)
|
||||
return -EFBIG;
|
||||
|
||||
buf = kvmemdup(quote_buf->data, out_len, GFP_KERNEL);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user