From patchwork Wed Jul 31 15:07:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748881 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2079.outbound.protection.outlook.com [40.107.100.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9A951BD4E9; Wed, 31 Jul 2024 15:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438529; cv=fail; b=pePGKBA3xvry3UNuCDbvAXSXeor2kWrFQeeK83sZ35ISTzIGgDXm8ypxLJBIaqmNAWudTgc+pT3xOTNTJTBY5ZFRQqp+rKrIen2+OC5HGFtEg7oxTtJjrdffnlZZhj8Vl83d5Nl5KtLeDmvCQwRQZJakLgQoJ0v2Y2q/PMFni2M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438529; c=relaxed/simple; bh=Mmvg97okGCyiJtHTPCEbYYo70LTO+mCOglmOhzElZoM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZKMQiGd/ZSx3wXzx9iYss3iuvan/Bltp8dIaiGPEcOJWA12eKqZvtIoWiL2VnJbYE4Q+Me7SuxAZe8ThrR6TxuGgYCEIFGtnlySgggACBKTn/kZ0EhXPSnPFSw05fC7Ss4ALjkmQBpRNyrMdNcXgCZNg4jk0cNCGU/8jyKWJbYI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=sWsm8Ek8; arc=fail smtp.client-ip=40.107.100.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="sWsm8Ek8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P/3jPH9KW3qmya2IAbUk4ROcwHP+MD/y712Vk0krcDCRcSj166kftYgo3zyEw1sqHGLV/TI+ELMt2113C0lN+vpcmEICOhinVXh5LUeocTtw2DAXSikUNWhGOnC905VOr4VeJU42mNYTIcPwjClBsEg+GVd5RqItsjPkuS+amIg9wz1Tbkzal3ohLdc3nXXYVH9/4uth1ciOOSw0Bvi7CFdJzQ2YEEpzeJx9UpgSJ0yGsuITDs72h6tgPGVSgevsGocZv64l9rr+6dDxbqQgyD2iD7m4+DTnv8uPycdwq5leWhiuuEurXAgZT5Ao+rWvgudbT6+TJkSJwv0tVYU6jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FbjWWUGOuINJ9pQgi9EEriHDcboXIVDNMMGrDh8DLoc=; b=XM18sQbJsBee2C3jcetBUyRP0RO83AipIx6nupoHGVfU+PAORMR6FVLdngiAESBnvXBZpz06lDMghv6h8NiYWYFrz+JC1rDlY24qLwR4CN3w4drn57aK6YfYrarahTQ9go7fp8xtp9MFHj68jR0pf7z3bBEEf0Z1JYqUZcysoP8lK05OTosf2Kj1k1sP9BFHUif49zqAHlrjx7cLdQ2M8brlyxdUWJddmdd9LHZY6VazReh2lv5yuFJki012Zoey7mE45gfSlTHbZYg0mDqm65/c7UuSyqN+M5JY57hkmVzZDsT+XuxU+su1FhBid1XSUg1n9cfaWenkW/bruUZjHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FbjWWUGOuINJ9pQgi9EEriHDcboXIVDNMMGrDh8DLoc=; b=sWsm8Ek8GFohpOcBxT9xWA42L+jmhuxM1bhoqVoU0JgQ7NdqTDjVA/GrumU0hMRkiNqVB5yhJ/mJ1g+3uvKOOSJ0qQVnuarh7RKb1ZeyfqFmkOkZo1YFIKF9Ho9MPozCuhESq3oUklo9XNUnxSQ9PLhYeC4rTPbruE5MYuzhB7o= Received: from DM6PR07CA0091.namprd07.prod.outlook.com (2603:10b6:5:337::24) by IA1PR12MB8406.namprd12.prod.outlook.com (2603:10b6:208:3da::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Wed, 31 Jul 2024 15:08:44 +0000 Received: from DS3PEPF0000C37E.namprd04.prod.outlook.com (2603:10b6:5:337:cafe::81) by DM6PR07CA0091.outlook.office365.com (2603:10b6:5:337::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.35 via Frontend Transport; Wed, 31 Jul 2024 15:08:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37E.mail.protection.outlook.com (10.167.23.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:44 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:40 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 04/20] virt: sev-guest: Ensure the SNP guest messages do not exceed a page Date: Wed, 31 Jul 2024 20:37:55 +0530 Message-ID: <20240731150811.156771-5-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37E:EE_|IA1PR12MB8406:EE_ X-MS-Office365-Filtering-Correlation-Id: 62bc6c1f-b0a0-4a9c-9d4a-08dcb172abae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|82310400026|376014; X-Microsoft-Antispam-Message-Info: rZBbNmNB3tbbfs9s0wyAIfbgwxp5rqPKhqneedSuxZnVQ21tNZL12O4mi72Pk00CGzwQ5CsyEbnFho4flOP9s6Bi3vwsJAyxVQQTHjFALvm0jvKkQlnCGw3wY2OJhkXG78AtVdL2j6riv4BjNfzje3dL5jZMrx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q0bquJ4PYe61Kaimwy4Uj3jx8NRdXQZsYRwApcXolJkJMv0x0fC2mwtHbsyIOOZiD5KazZgGVEVhMcCo5lLZk91sMUA+gaeumvc9MaJM383TcXCJiT1qvX87KsGXra2CmL6ZS4QJoW6qPHo6PW7NouqABtPoplyD707s/c1S5smAYuNKz4ZpcTtjZkJzqPZ3CmC1I6HDjgUoYbV/hZ2xF8JYr7ctI1RdLCHr8 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:44.3409 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62bc6c1f-b0a0-4a9c-9d4a-08dcb172abae X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8406 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, declare the snp_guest_msg in a way that payload plus the message header do not exceed a page. Signed-off-by: Nikunj A Dadhania Suggested-by: Tom Lendacky Acked-by: Borislav Petkov (AMD) --- arch/x86/include/asm/sev.h | 2 +- drivers/virt/coco/sev-guest/sev-guest.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 79bbe2be900e..ee34ab00a8d6 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -164,7 +164,7 @@ struct snp_guest_msg_hdr { struct snp_guest_msg { struct snp_guest_msg_hdr hdr; - u8 payload[4000]; + u8 payload[PAGE_SIZE - sizeof(struct snp_guest_msg_hdr)]; } __packed; struct sev_guest_platform_data { diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 3b76cbf78f41..0b950069bfcb 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -1131,6 +1131,9 @@ static int __init sev_guest_probe(struct platform_device *pdev) snp_dev->dev = dev; snp_dev->secrets = secrets; + /* Ensure SNP guest messages do not span more than a page */ + BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE); + /* Allocate the shared page used for the request and response message. */ snp_dev->request = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); if (!snp_dev->request)