Re: [PATCH v9 03/24] virt: sev-guest: Make payload a variable length array

Nikunj A. Dadhania
2024-06-24T10:03:59Z

On 6/24/2024 11:41 AM, Borislav Petkov wrote:
> On Sun, Jun 23, 2024 at 09:46:09PM +0530, Nikunj A. Dadhania wrote:
>> Yes, payload was earlier fixed at 4000 bytes, without considering the size
>> of snp_guest_msg.
>
> Sorry, you'd need to try explaining this again. Who wasn't considering the
> size of snp_guest_msg?

Sorry, I meant snp_guest_msg_hdr here.

snp_guest_msg includes header and payload. There is an implicit assumption
that the snp_guest_msg_hdr will always be 96 bytes, and with that assumption
the payload array size is set to 4000 bytes magic number.

> AFAICT, the code currently does sizeof(struct snp_guest_msg) which contains
> both the header *and* the payload.
>
> What could help is if you structure your commit message this way:

How about the below commit message:

-----------------------------------------------------------------------
Currently, snp_guest_msg includes a message header (96 bytes) and a
payload (4000 bytes). There is an implicit assumption here that the SNP
message header will always be 96 bytes, and with that assumption the
payload array size has been set to 4000 bytes magic number. If any new
member is added to the SNP message header, the SNP guest message will
span more than a page.

Instead of using magic number '4000' for the payload array in the
snp_guest_msg structure, use a variable length array for payload. Allocate
snp_guest_msg of constant size (SNP_GUEST_MSG_SIZE=4096). This will ensure
that message size won't grow beyond the page size even if the message header
size increases. Also, add SNP_GUEST_MSG_PAYLOAD_SIZE for checking buffer
over runs.

While at it, rename the local guest message variables for clarity.
-----------------------------------------------------------------------

Regards
Nikunj