Skip to content

Commit 2b9ac0b

Browse files
nikunjadbp3tk0v
authored andcommitted
virt: sev-guest: Ensure the SNP guest messages do not exceed a page
Currently, struct 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 - a 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 a magic number for the payload, declare struct snp_guest_msg in a way that payload plus the message header do not exceed a page. [ bp: Massage. ] Suggested-by: Tom Lendacky <[email protected]> Signed-off-by: Nikunj A Dadhania <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Acked-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5f7c38f commit 2b9ac0b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

arch/x86/include/asm/sev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct snp_guest_msg_hdr {
164164

165165
struct snp_guest_msg {
166166
struct snp_guest_msg_hdr hdr;
167-
u8 payload[4000];
167+
u8 payload[PAGE_SIZE - sizeof(struct snp_guest_msg_hdr)];
168168
} __packed;
169169

170170
struct sev_guest_platform_data {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,8 @@ static int __init sev_guest_probe(struct platform_device *pdev)
10921092
void __iomem *mapping;
10931093
int ret;
10941094

1095+
BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE);
1096+
10951097
if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
10961098
return -ENODEV;
10971099

0 commit comments

Comments
 (0)