Re: [PATCH v4 2/4] virt: tdx-guest: Calculate the Quote buffer size safely

From: Kiryl Shutsemau

Date: Wed Sep 16 2026 - 08:27:44 EST


On Tue, Sep 15, 2026 at 02:26:01AM -0700, Peter Fang wrote:
> struct tdx_quote_buf has a trailing flexible array member.
> struct_size_t() 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_len > buf_size"
>
> ...is more readable than "data_len > buf_size - header_size".
>
> Signed-off-by: Peter Fang <peter.fang@xxxxxxxxx>
> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx>
> Reviewed-by: Tony Lindgren <tony.lindgren@xxxxxxxxxxxxxxx>
> Reviewed-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
> Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>

Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>

--
Kiryl Shutsemau / Kirill A. Shutemov