From patchwork Fri Aug 27 13:28:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C08F1C25AE9 for ; Fri, 27 Aug 2021 13:21:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A601A60F91 for ; Fri, 27 Aug 2021 13:21:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245255AbhH0NWO (ORCPT ); Fri, 27 Aug 2021 09:22:14 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:25074 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245186AbhH0NWC (ORCPT ); Fri, 27 Aug 2021 09:22:02 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RCCJtu015338; Fri, 27 Aug 2021 13:20:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=pJScYFSSXd48rFQcO4SNhCOzggVxNzAwYUqdt8STBUE=; b=rqd9i2IozoipD/s1NOuw87+MbjJ7pYJ4JYsEiLIdRwGfTj1O/G9VSYKDY6bbAihHrsvB VHGQ2kPP57+Gtqp7vb1/ORkDOfsM3Vx6hd91YPYQQnuhnI+HjQghyTTLcgKAgtSu+jQh QNJpN8x8qpQG5W10CgrlR/lQWg55WnastYwDm0Yxnf/spPD5qEshHZ4QqylARI/gYFJO anv3S5Wtc6l4+DedUaprAMBXdMAl5WVIeRpTYFThsCdq6Jam9w7oS0L45B5AO4YfpihZ Np47Yl4FWB1Cux9ETh/yoPTKLxRrKBkl6MbrzvLaLt1hNqTp2ZmmuDtFzR/Feg8vMVCV yg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=pJScYFSSXd48rFQcO4SNhCOzggVxNzAwYUqdt8STBUE=; b=ZKZ4Vpgl/oTxzenm4H3M+WDkh5XZXcrbbsjCkQTkrScNqZeN0OgVrs01/2JosbL0n7Oj ldr6UaE4vr3bpckAxYAfMgeDjJ3//zPWwESFuCjUYYnUrmluP4hpakq1PIxGaCnIgV3W aZKpfBnzS006UbQ7A74VI/pqDHIvSNQZQAUxMltbzqcUQIQC0sMJ1DVeuP5XYKvAkhVq e7HMzG0mew1tYLjCHq1fWZhHoOA81NtH1xqvpjF+gmuQhR+pYbveCE590WqFhFEaV5wo 7CHI3PctlPEmsrBbDnO3UUF4/+FRDFmtTTKfdLnOA+FO7laVvlmbYdMnXWeqo697NBmV OQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3apvjr0ktb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:41 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RDBYUS007537; Fri, 27 Aug 2021 13:20:40 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2168.outbound.protection.outlook.com [104.47.55.168]) by aserp3030.oracle.com with ESMTP id 3ajqhmjm17-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T8eVhOO6q8/REYxGWG1pXfZ1s8VIqkEzoiVRNC3CEsEhKR0ohN5HzrRqtjZCT8q+t83jekVNyH9qNCl3QPRmAZAhsW3mvEkKAX5ybGIx2aXHzyEIesrgEqC+wz03IZpEnHjhSXhU3bPXWOY2abmDt8cG7wwh1K9yZ3Vwi43cXZ8GiAosDVUV0h8FM2unst3+8IcIhWcQl0bjxlcqwGwr+I5PctkdFixAHtqBmWKnW8pRfwu7EEsiQ7devK+z+q2FoG1Nyu6jwUvDU51OtVM3eixz7tW+ZEFmxck5AWBowxmJB+WzVj/NERSZWkXrWzF3P8Uew3TscFv3hkij1ApXKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pJScYFSSXd48rFQcO4SNhCOzggVxNzAwYUqdt8STBUE=; b=fgd3AkGsNwYmbU/OeYQveC3/sbgsuVWQv4oQakgZcjoSles+zClHdLNOzclJ/tRZTUE1swuLCHMA6LzYuyQ0wGSEw93CtFtVS04M3b+T4PHqp1t44gWTfdBweov09pbyOPhkHi3057zU1Mz/2JLOgQARjVue9puES80mEou0h3buGe+XABD7Yas03r/4xsS1XZeeJjOI/flvQlWjp4wb8Wq6GiHXTQaSmO88p4811oxdNI/QvflncVSRD3st7SOT+PccL+NuLfYr8uimQXW2OwOsmZVQG9qvJQWyPBjp9omWgosXmNRYKr0jOEc6qxvw7nduIenYfwdfFVZ8sVG9LA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pJScYFSSXd48rFQcO4SNhCOzggVxNzAwYUqdt8STBUE=; b=hebzis/EEKayBzcRy9qXArU1D44AO6YPnmziWyTg6Ub5IOI/T+yYx1jFGpc63LfVsP37/rhCttINta6evJLnX09qTC+EKEMUNezOIZriKeNks51VrdBLnngsY9q9NlAoxmrRAgFlK9CyQ1rDts/i3jBZM862MRlTcffASTvHpcg= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3621.namprd10.prod.outlook.com (2603:10b6:a03:121::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Fri, 27 Aug 2021 13:20:38 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:38 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 01/14] x86/boot: Fix memremap of setup_indirect structures Date: Fri, 27 Aug 2021 09:28:24 -0400 Message-Id: <1630070917-9896-2-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 41eef716-7bd2-4273-85a5-08d9695d75cb X-MS-TrafficTypeDiagnostic: BYAPR10MB3621: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZCO0W+3Jq8kpIPYRnuVfGke8X5NWG22UZKAGffokxcu7ScfnH8F9MvP0SDu1Yp7msJ9iAckTKDZvtbq4SzYX7XrhVeUlh/Z8KhS7BCPc9+M292yKlXU+ETOdOS0rEa0qKFDWdi2OCkV0xpXbdNLZVvS8RZSl6839SVaMcb4Bh2TeTD0GmmaiMHiLYR4VHMI3XPakZwbAgo4DwDBZ7N6cuobTVzB2eCnaV5krRCmvwnicC3SkgiwHVxDYsl1GnWtBg5wwNQJexytuimnwE/Tp1i7xRIiZa9laxLtsoF95kC5TEzys+ZUb0O6PVbdkqWQZQnlxxX3jE/piMo+6dAVH7Ifdqe5oGaPUWsUT8563pgabq5aVKlhYMWAPFDUaEeUvKw7oU3yoMyRVc0V8iaK3PWftPyuq9EYLyUrc4I1cNPdcEKK91BDTJVQzbXl2kNtW1CyTD3C+Xst7mBhMjFmJaxx/hIel3Mo8fH2MYGZ8//DoipGqMZA9uaOQPPdguq2v3q8XwZovpnaUY9KlavQSy1/A0o3u4UTy/9UT0iNqQy3FLRODtXx+/v59t3gjIkmyNAr8CGeghIW1WOPmYGxE32RXwjJMN95ohaB4M1yCzkqQHDQhQDLO416s7/1i1PzxF5b3fKZy/UqoisuaLvjcdRr8+0DFSQnBIL1j7tmUAM4ltNKJ6aNC5XF292GJxgp/B/AZiW3ODK6aNmFfCmIQdQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(346002)(376002)(39860400002)(396003)(136003)(26005)(44832011)(316002)(86362001)(186003)(36756003)(83380400001)(7416002)(5660300002)(478600001)(6486002)(38100700002)(52116002)(7696005)(4326008)(38350700002)(8936002)(8676002)(6666004)(66556008)(2906002)(2616005)(956004)(66946007)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dEwIULASFFIe1q3HlHEVxrDpBs8VLOLAGyg60acNUArulT+gLsRa1m+onWp4xBcG6iFUArJocNLQturQALcmtyOGqwfWwWDwi1gT9P1TQpMfiu2UdHQDO/AlrTvbk5jXtFFHRkQtIVoALfQwTTdmmOAvNlsCElrCkmaBjM2kO5m9x+bhE62U8gXUyKZUiPA+7sgVJMk5C6RWH53V1d2oQVxXMT6h54LzIlqyGnbSBghlTw10oNFnCzy/1PbQWnZVoSMwEMVMbW3SmNy6bCioZmayXHXgcDZ87I5K3tLD4TPhQrnX0BQu2pvyLc8sHKVkzpoYRGFp4pNqorv745XaZyTlv1FwBXaWltWs1Axl/dRAofKWyhDYsTJHdR6aKUPKlaedbVxTrMFpEwXDLT//6/EE9fmPgQQZ+4s6cYiyOYDItaCs5Xe3BJy2xiML8nFEm/HQ7uJNryHQqivfrFN1uk7nmPmy4w4ZCWZsFX+JstDOmdkAlROaa4SnJ2CovHJNWDDBXhLq0LgwGHwSRfPtPwRFSgdDD5sfBoaxDcVVbbnZJWRu+wt4fGqGvRBxMhrlXqPFo9/dTrVLZ0+imyXD+JcA+G8uInWxyeMYQkUmerHH/HvwEU9fdCRUDXsbtoVfl5RIww9txs1xNOqKPnWlKOeMaSKjmiqlXvNSx8EJDcpkph/kYGtoPN+xdpaahOn6KUzUbG6H2yBAEk4ATn1RkJ+Bs/rVhFEVbwZcoiSi9bvbZCT308IAoaemZfHeTgu9GBbKTGJaL8hA0eExLLAf5gpxJqcDfWY84zlYTYJqJme1anr5rMgFbz/GKaw4ZhWWfdZCKmA3S9uf+vy4SfQLh1OfzeLp87bIjRB94/Rl5Rx2rf1ubgn7Hkm3+z5M9WpzAVZxKt3m29T/1vRjBSOdjfceX9SMEV4EesTQNFW/Y5BikbemjWs92lfyxctn2cRRZYWfhB21rYp0AP13Xr4id5j2Epevzoa8bANDgr/A/IiLAXsfP/CxKtW5F9pOdp9YX3N04LsnPRI3GQRhf8bK5l0NdZknLGP5FtmrczamDKllxHJq7VbTSAWgqYZlDE6q7bfABmcMY80TZVFi6vHmpVo/UzoJZhFyg3mGj98AUTWTMsH+lNRK4FZGB0ZhbMq+QfzzEtZPscgc9cOVy/Z3zT4tt4sTmYBv0Lz6gcRhp/BcDhgccC26ZGnYadZJqszAdyfRXxdoNGAztGgU3T2f9JUAPbBC1IxYRpg7CH+I8VscB3Omxnjckc88ZwYn0dcp+9VbZ9DpxF27mqY6t2CZJn/XMAoGx0mkP0x+strJSndEm3zuiRbxG3FMwbsb3/sk X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41eef716-7bd2-4273-85a5-08d9695d75cb X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:38.0272 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jWf8jLVBHI3UeYGG05beZk5Z5OtMM/hHhk13AUdA5eRLfmDJ4ZizjEze9XiveHOcOhZQNFW0vYzhIKkQ3QwNZ/EeNjFYvdLORN0tH/MiC2Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3621 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: SiC7RZdrY63723bWudWmqcDwK6QoFQCn X-Proofpoint-ORIG-GUID: SiC7RZdrY63723bWudWmqcDwK6QoFQCn Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org As documented, the setup_indirect structure is nested inside the setup_data structures in the setup_data list. The code currently accesses the fields inside the setup_indirect structure but only the sizeof(struct setup_data) is being memremapped. No crash occured but this is just due to how the area is remapped under the covers. The fix is to properly memremap both the setup_data and setup_indirect structures in these cases before accessing them. Fixes: b3c72fc9a78e ("x86/boot: Introduce setup_indirect") Signed-off-by: Ross Philipson Reviewed-by: Daniel Kiper --- arch/x86/kernel/e820.c | 31 ++++++++++++++++--------- arch/x86/kernel/kdebugfs.c | 32 +++++++++++++++++++------- arch/x86/kernel/ksysfs.c | 56 ++++++++++++++++++++++++++++++++++++---------- arch/x86/kernel/setup.c | 23 +++++++++++++------ arch/x86/mm/ioremap.c | 13 +++++++---- 5 files changed, 113 insertions(+), 42 deletions(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index bc0657f..e023950 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -996,7 +996,8 @@ static int __init parse_memmap_opt(char *str) void __init e820__reserve_setup_data(void) { struct setup_data *data; - u64 pa_data; + u64 pa_data, pa_next; + u32 len; pa_data = boot_params.hdr.setup_data; if (!pa_data) @@ -1004,6 +1005,9 @@ void __init e820__reserve_setup_data(void) while (pa_data) { data = early_memremap(pa_data, sizeof(*data)); + len = sizeof(*data); + pa_next = data->next; + e820__range_update(pa_data, sizeof(*data)+data->len, E820_TYPE_RAM, E820_TYPE_RESERVED_KERN); /* @@ -1015,18 +1019,23 @@ void __init e820__reserve_setup_data(void) sizeof(*data) + data->len, E820_TYPE_RAM, E820_TYPE_RESERVED_KERN); - if (data->type == SETUP_INDIRECT && - ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { - e820__range_update(((struct setup_indirect *)data->data)->addr, - ((struct setup_indirect *)data->data)->len, - E820_TYPE_RAM, E820_TYPE_RESERVED_KERN); - e820__range_update_kexec(((struct setup_indirect *)data->data)->addr, - ((struct setup_indirect *)data->data)->len, - E820_TYPE_RAM, E820_TYPE_RESERVED_KERN); + if (data->type == SETUP_INDIRECT) { + len += data->len; + early_memunmap(data, sizeof(*data)); + data = early_memremap(pa_data, len); + + if (((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { + e820__range_update(((struct setup_indirect *)data->data)->addr, + ((struct setup_indirect *)data->data)->len, + E820_TYPE_RAM, E820_TYPE_RESERVED_KERN); + e820__range_update_kexec(((struct setup_indirect *)data->data)->addr, + ((struct setup_indirect *)data->data)->len, + E820_TYPE_RAM, E820_TYPE_RESERVED_KERN); + } } - pa_data = data->next; - early_memunmap(data, sizeof(*data)); + pa_data = pa_next; + early_memunmap(data, len); } e820__update_table(e820_table); diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c index 64b6da9..e5c72d8 100644 --- a/arch/x86/kernel/kdebugfs.c +++ b/arch/x86/kernel/kdebugfs.c @@ -92,7 +92,8 @@ static int __init create_setup_data_nodes(struct dentry *parent) struct setup_data *data; int error; struct dentry *d; - u64 pa_data; + u64 pa_data, pa_next; + u32 len; int no = 0; d = debugfs_create_dir("setup_data", parent); @@ -112,12 +113,27 @@ static int __init create_setup_data_nodes(struct dentry *parent) error = -ENOMEM; goto err_dir; } - - if (data->type == SETUP_INDIRECT && - ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { - node->paddr = ((struct setup_indirect *)data->data)->addr; - node->type = ((struct setup_indirect *)data->data)->type; - node->len = ((struct setup_indirect *)data->data)->len; + pa_next = data->next; + + if (data->type == SETUP_INDIRECT) { + len = sizeof(*data) + data->len; + memunmap(data); + data = memremap(pa_data, len, MEMREMAP_WB); + if (!data) { + kfree(node); + error = -ENOMEM; + goto err_dir; + } + + if (((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { + node->paddr = ((struct setup_indirect *)data->data)->addr; + node->type = ((struct setup_indirect *)data->data)->type; + node->len = ((struct setup_indirect *)data->data)->len; + } else { + node->paddr = pa_data; + node->type = data->type; + node->len = data->len; + } } else { node->paddr = pa_data; node->type = data->type; @@ -125,7 +141,7 @@ static int __init create_setup_data_nodes(struct dentry *parent) } create_setup_data_node(d, no, node); - pa_data = data->next; + pa_data = pa_next; memunmap(data); no++; diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c index d0a1912..4cef401 100644 --- a/arch/x86/kernel/ksysfs.c +++ b/arch/x86/kernel/ksysfs.c @@ -93,24 +93,35 @@ static int __init get_setup_data_size(int nr, size_t *size) { int i = 0; struct setup_data *data; - u64 pa_data = boot_params.hdr.setup_data; + u64 pa_data = boot_params.hdr.setup_data, pa_next; + u32 len; while (pa_data) { data = memremap(pa_data, sizeof(*data), MEMREMAP_WB); if (!data) return -ENOMEM; + pa_next = data->next; + if (nr == i) { - if (data->type == SETUP_INDIRECT && - ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) - *size = ((struct setup_indirect *)data->data)->len; - else + if (data->type == SETUP_INDIRECT) { + len = sizeof(*data) + data->len; + memunmap(data); + data = memremap(pa_data, len, MEMREMAP_WB); + if (!data) + return -ENOMEM; + + if (((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) + *size = ((struct setup_indirect *)data->data)->len; + else + *size = data->len; + } else *size = data->len; memunmap(data); return 0; } - pa_data = data->next; + pa_data = pa_next; memunmap(data); i++; } @@ -122,6 +133,7 @@ static ssize_t type_show(struct kobject *kobj, { int nr, ret; u64 paddr; + u32 len; struct setup_data *data; ret = kobj_to_setup_data_nr(kobj, &nr); @@ -135,9 +147,14 @@ static ssize_t type_show(struct kobject *kobj, if (!data) return -ENOMEM; - if (data->type == SETUP_INDIRECT) + if (data->type == SETUP_INDIRECT) { + len = sizeof(*data) + data->len; + memunmap(data); + data = memremap(paddr, len, MEMREMAP_WB); + if (!data) + return -ENOMEM; ret = sprintf(buf, "0x%x\n", ((struct setup_indirect *)data->data)->type); - else + } else ret = sprintf(buf, "0x%x\n", data->type); memunmap(data); return ret; @@ -165,10 +182,25 @@ static ssize_t setup_data_data_read(struct file *fp, if (!data) return -ENOMEM; - if (data->type == SETUP_INDIRECT && - ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { - paddr = ((struct setup_indirect *)data->data)->addr; - len = ((struct setup_indirect *)data->data)->len; + if (data->type == SETUP_INDIRECT) { + len = sizeof(*data) + data->len; + memunmap(data); + data = memremap(paddr, len, MEMREMAP_WB); + if (!data) + return -ENOMEM; + + if (((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { + paddr = ((struct setup_indirect *)data->data)->addr; + len = ((struct setup_indirect *)data->data)->len; + } else { + /* + * Even though this is technically undefined, return + * the data as though it is a normal setup_data struct. + * This will at least allow it to be inspected. + */ + paddr += sizeof(*data); + len = data->len; + } } else { paddr += sizeof(*data); len = data->len; diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index bff3a78..055a834 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -368,20 +368,29 @@ static void __init parse_setup_data(void) static void __init memblock_x86_reserve_range_setup_data(void) { struct setup_data *data; - u64 pa_data; + u64 pa_data, pa_next; + u32 len; pa_data = boot_params.hdr.setup_data; while (pa_data) { data = early_memremap(pa_data, sizeof(*data)); + len = sizeof(*data); + pa_next = data->next; + memblock_reserve(pa_data, sizeof(*data) + data->len); - if (data->type == SETUP_INDIRECT && - ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) - memblock_reserve(((struct setup_indirect *)data->data)->addr, - ((struct setup_indirect *)data->data)->len); + if (data->type == SETUP_INDIRECT) { + len += data->len; + early_memunmap(data, sizeof(*data)); + data = early_memremap(pa_data, len); - pa_data = data->next; - early_memunmap(data, sizeof(*data)); + if (((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) + memblock_reserve(((struct setup_indirect *)data->data)->addr, + ((struct setup_indirect *)data->data)->len); + } + + pa_data = pa_next; + early_memunmap(data, len); } } diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index 60ade7d..ab74e4f 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -635,10 +635,15 @@ static bool memremap_is_setup_data(resource_size_t phys_addr, return true; } - if (data->type == SETUP_INDIRECT && - ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { - paddr = ((struct setup_indirect *)data->data)->addr; - len = ((struct setup_indirect *)data->data)->len; + if (data->type == SETUP_INDIRECT) { + memunmap(data); + data = memremap(paddr, sizeof(*data) + len, + MEMREMAP_WB | MEMREMAP_DEC); + + if (((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { + paddr = ((struct setup_indirect *)data->data)->addr; + len = ((struct setup_indirect *)data->data)->len; + } } memunmap(data); From patchwork Fri Aug 27 13:28:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84BA8C25AEE for ; Fri, 27 Aug 2021 13:21:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E74760F6C for ; Fri, 27 Aug 2021 13:21:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245231AbhH0NWK (ORCPT ); Fri, 27 Aug 2021 09:22:10 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:24662 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245184AbhH0NWC (ORCPT ); Fri, 27 Aug 2021 09:22:02 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RAV6kF000885; Fri, 27 Aug 2021 13:20:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=WGzvUC0KzJ1GLB+v2vHK1r6RHSdq3HuOreWgM27EDwY=; b=x4iHnrXMPAXSav3viYlr6YSsPnyJngwwcYnCsnl7yAV3iiGzJ6ochniJaewiSeOAQc2+ VEhhO99lew5uYU1y8KeC037odhd4QByxVsdllzNh8Lv1cT24pHQwCC2NC5R1lZvjDkm/ FKI42+ABisrVgWGvL4S4T0mxcl0XeqKGdMMqlLzdX9LR9YUir/ooeXig4l+cL/4AZeZK YA1/SsfOLgv6GMBm0bQOKPdzbndYO86iBSUL+fBobKURAyi8DAq2vTd2YPFVddFCFi64 OK5GLTElu5P9tWiXSw8gEf+6C1yR00H9rUsXf9nIRtrE5GmxMvYGahZ5Qh3ethGg/Ln+ HA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=WGzvUC0KzJ1GLB+v2vHK1r6RHSdq3HuOreWgM27EDwY=; b=iCL0YE3BjYJk5WYevNNRYpIjmoo4FKIUwFLwoZTwGzqgEQ5+odpIf8bvVQvsYgTZpvEM cHPaMmw/8MdDNUnTWZPrcbKXRqlNFO1R2klZsPrAcb305zXNXYjE1BOrHeZCpZaSmB9T QcdehMyT+aw+JUVHoy/FlciJiRpTGpqP9QRmVVoUaQCPULXQlJkNK05xEfExxG9UDeJb /oaL68oaQnsPM5JKBQUywdeODb92GLva6QK+SiYBUAs0MRq6UAgz3i0uBlMw/7SgrD5+ eJCYWl4J7S3KN5gzqTzC0SO8OheM5XVRHnRMJVVcMaGkDobZMpgEsdQgYwKXXuB7LTJi eg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap552bhjg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:42 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RDBYUT007537; Fri, 27 Aug 2021 13:20:41 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2168.outbound.protection.outlook.com [104.47.55.168]) by aserp3030.oracle.com with ESMTP id 3ajqhmjm17-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nYDPIALFqXTWPhF7Y887ewFpm27rwqzd9jBq1Jk47lvWkV3VLSNfYpli5U0dnc3C4cv+aOfA9Mi0fDxDCKSuSJsvE9l2KVV0QqO96Nsu7LzJOQor6/KgVpjsrQ6y3GL3i7HZpdtu05EGHjyisYDzUJQSwZvb+gil438klaChzHcKw8NoXsIqi27LAL7g84KwaWtFWUsDCSgjGqYCYPBkMbLQk3J4WYAon0juf21ds817jcpH/4yc2S742puftKTwiv8Zq7LW8pUFHA02FNfEM8hf4Uio1YE/KpqeeGOIZ+I2Gb/V4B2VKAORSuhRp+alvLlQ8pgvwrNJIdol84VThg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WGzvUC0KzJ1GLB+v2vHK1r6RHSdq3HuOreWgM27EDwY=; b=gB+tqa+IlmgJXN0yR2DNUZoNdd2I0CRJiUvR7rZ+cc7x8s9PQgDSVaPGBEGuz+2XnEy0xnryY0Z5kEuhuUt9WRt8xBHf3MyZkM/Dyw7oPWETGwU3Q76yeAKZ6Bqzgmqk7HP4gY22DyVuUpHisV2xtELq8Zf5U37wtUE68+r65fM+9/bYU8Oebp9IHfouzzqBNfmmJPizKMpSF9Ld6fMrs3wV/A7cT8bh+ek6wg1ASMzNEyawHkDPXw7IY0BEvugQDITg5ovGWp/KuaguojLKfgtCiM5AjNlQN0RANZTtIl7Pwfl8FO7qUuIlL5kqyd+JDPNMg9ZOQ1tKGBCSf08iig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WGzvUC0KzJ1GLB+v2vHK1r6RHSdq3HuOreWgM27EDwY=; b=F4rfcA2uAJyBncY2OVbgAB/sg2QMvHLVMTOa/VJs4zRYnHrFPnJcsxZnUcBTxxclw65xKz0Ijpeq/ZjJkaykoWEg1gVI0QVqE6O48o1hc4u0uPxDqTA5AF2nfKLr68qQiSH6BzyRnHadP2RHrSnKEk3i8OKXpZxpSVIy5DYD9RM= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3621.namprd10.prod.outlook.com (2603:10b6:a03:121::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Fri, 27 Aug 2021 13:20:40 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:40 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 02/14] x86/boot: Add setup_indirect support in early_memremap_is_setup_data Date: Fri, 27 Aug 2021 09:28:25 -0400 Message-Id: <1630070917-9896-3-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 236405ed-0399-4d5b-ceac-08d9695d7707 X-MS-TrafficTypeDiagnostic: BYAPR10MB3621: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HHHBDowIX4IVeQUR2GDfh26exyxSyBd5pZcanMUc0EHxxEHKS28RvwN9yEIImC+3JwNnfku626DHhxxbmbnHjmsIpZkQB8ObIZiIvRCUGlVXKfKb7lj/jw8Z1bjWvrZhDn1Y9wy4yS5eS3tc7qXLCYEISufyxz1oJ2/oBCPO26QuvDGbthZJ2FM8/HuotCLW8FPi7qoDgIdKlJizfUKrt5tPtGSyEmbogfv96EzNnAVN3ZVSvS1296+IEvVt4VM9h9KMjLhnvucWbZgdNEJ0bXQznJ7L8bvBwXEoGYFNtC35QDvgz+H9R/mAA2caCtfDb/VspJDozyZzf4dh5UsbneFT+KZw5P91sNBnmBZ7htfv8n82TTekTucVFSt9BFJ7JOX6KesK/AXZ3Ry9+De+nWGDeS1mR+qjdcphQfko+c/6+sy+RxLWv6LNHT+BOYKxejuhDs6LoUcgssq4P3owv4WP++hOjI3Cn0i7z6hNakOsUnWs/xrnXqX8eGOmk9qjr7GYVuffCLTPPlUC8/DEvkBIZIsuxWO2+YYPMzTUhG4iS1mel2s0s7WZ1JjEBhiGrSdIyWcn4d0aqqjtgFwJzcOP7SVkBl4M/GwBLGvgm2I1OnuTn568iip/Fg9Fkn+jow34dLkC/3FNNTSIpiNkDrmkfU3iEmkznU24FQYOqif5uMwYPsNkRjjXEKI++UQrnsAERMIYN1nTDyosR6ZXgw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(346002)(376002)(39860400002)(396003)(136003)(26005)(44832011)(316002)(86362001)(186003)(36756003)(83380400001)(7416002)(5660300002)(478600001)(6486002)(38100700002)(52116002)(7696005)(4326008)(38350700002)(8936002)(8676002)(6666004)(66556008)(2906002)(2616005)(956004)(66946007)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AMsTsc0H9kTFbWIBVQDyeRklh2tFm0qXwJIZ6Dfi8BeK24TQVz8Rw/aN2OQ2Xl/azu7+qEhFrWxhoAKgR4oTyyz6HxkRHuilbcSHufX5jn1r695rVOOt/9YhgnSJCyx14Kq3mshsbHh3AlROOCz9FNd2bGmkPgeUBfeIrNXS7WDWvdLsphUIvWevVEHlbwjBbxAx3d2uzKfn6U60KvCGxjgZdiP1Fc+1JoUC3X7DgCdMJJshheYyxLsn86H9wFFKdVMRFWvdxmpSKrjWcnn0rz4Z5bAVbNszRuO8ibHkpwcqvyIERae/5+337bRLCi5L5cQ8UP57/YTgQcaEzhyA60J1SeA+XtCB6hkC+1poZT8WzZ//uNnC+RvMqHDb2ZFiBdNNNFLBT5x+DqIMoFQ0/XKm3ZPXhVuB30LxS2xVTT633tTo1I9ZFQaHsjN1FWsk8LOaSWyQxNVsR/zj4hdMOnSPmFjmn6F4eLu5RR8T61n6L8oF2C3MbDWIRwOg4Cav949dR+e29rCP7ltjvchyZShFtPmY0R6zMDI1bsBFVAKgJJOLFpZE06bqwFoVQ8drCJw39AEIVx+tgzDYPCksDtGiIq0xEMc9oATyKei380/gyTEpenM2wfvHXhHEHXpGsrBLmM192LOOXYodcpiqh/gtUKKoADgCV+YOudq/WAMnxiajp4kWafrks8crHfL9uQvyoreL7gcKDhH8R1RZgHzAn1ZNYqd1DpKZ2PXKkSD59o9OjK9RPqkGSeXmDS6V0WCisvqZ8Qr+/QWODaoZhJyx8cC/yYAL+8OuEUMrIapGOjP0KAsv+U2DxN6AizExgqTbMJ56PEyeTV2xajo8MkKp2IdYqOR7kxQYgQQnnNSVlTGmGD7KW66vF5IOIzz6JGcgFpHEplvbypJqrLdCZbL0dMnOs7S+jh64NYD2GKiCMgW6jc4k+jWmbFfH5vWKgCTDrAzFYblxxhPgBZMPF40lFVUCW/b+HGF2zoL9QW95FJ0fbwETNWIgehbgYYa0bEjNwUk9Cp00g1h0GwqJmiXdHaxiX3q5ch9lm8ixgI4OPqU+o9d/l+Qu3KQvbogDAsoZrbLs92kh2v2t5DXQFYyU+YkkTArV5W7QvhrFZkmypqXKz7+5nkIyUmhi1vXIDEWhY5CgUp0wHptzGVGOPZfyAjqfpoqTswldGA4ahtyXLnM6YjH+19Y0yf99w/dbMo4feyHeAQMk7/6wlTVSihg5PEZHGlQKXDmYjAbJqyTtlaoDtb1VhCcV6L/PrLGdSNm+Ys2n5rJYNcT5rrISTYD0RCSWK6EN+zQmhUi6uaG88TONg1miNJz59UpmkI4S X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 236405ed-0399-4d5b-ceac-08d9695d7707 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:40.1130 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MLKU3TdSMPHoqv4QafiQmdH4VMrMW+bOqPJ7gHMRlFCKO5QtJnXipgnnhPJ62GYexVc1PdvSXE+2XJcPz5S0aeUMfGTozbGtfsFD5HNmhmk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3621 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: waUfI55wC4QR_fzVivaiUztW22bxIArN X-Proofpoint-ORIG-GUID: waUfI55wC4QR_fzVivaiUztW22bxIArN Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org The x86 boot documentation describes the setup_indirect structures and how they are used. Only one of the two functions in ioremap.c that needed to be modified to be aware of the introduction of setup_indirect functionality was updated. This adds comparable support to the other function where it was missing. Fixes: b3c72fc9a78e ("x86/boot: Introduce setup_indirect") Signed-off-by: Ross Philipson Reviewed-by: Daniel Kiper --- arch/x86/mm/ioremap.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index ab74e4f..f2b34c5 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -669,17 +669,34 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr = boot_params.hdr.setup_data; while (paddr) { - unsigned int len; + unsigned int len, size; if (phys_addr == paddr) return true; data = early_memremap_decrypted(paddr, sizeof(*data)); + size = sizeof(*data); paddr_next = data->next; len = data->len; - early_memunmap(data, sizeof(*data)); + if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { + early_memunmap(data, sizeof(*data)); + return true; + } + + if (data->type == SETUP_INDIRECT) { + size += len; + early_memunmap(data, sizeof(*data)); + data = early_memremap_decrypted(paddr, size); + + if (((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) { + paddr = ((struct setup_indirect *)data->data)->addr; + len = ((struct setup_indirect *)data->data)->len; + } + } + + early_memunmap(data, size); if ((phys_addr > paddr) && (phys_addr < (paddr + len))) return true; From patchwork Fri Aug 27 13:28:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BDB7C432BE for ; Fri, 27 Aug 2021 13:21:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13CAB60F92 for ; Fri, 27 Aug 2021 13:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232312AbhH0NV7 (ORCPT ); Fri, 27 Aug 2021 09:21:59 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:23200 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231730AbhH0NV6 (ORCPT ); Fri, 27 Aug 2021 09:21:58 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RA9fr6025577; Fri, 27 Aug 2021 13:20:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=uaDB31GsdQ6QYX6kwRtBtlkYbBLv8Aw3ThMjsV2imfI=; b=Cv0tkcvmGdTwlHW1P/4pDEprkKyQ4vaCxNFync3+spKcN63gmNX1j9qUjqvO1Htdn/c8 TN0HN2an5CDW76qkSBT38OA885woi5PQ65Xp1ezz+ryIyVSLlsDoq4Q4ANR8o79LYwvA COro6KOOXdqZnawBJ9Uq8WrOy7wVnsHqVmeyO96ie/3R3Foi72EEtSaWi4P+fDlsyBDj LYyPH0sDAbbYLliRJM7h21DEBgg6Vi8sr/0fj8tclv/qy1uegRgzlZiPSANwcMWcJrrd VGS4UGq94FqXfScdph2N/7hSPWUeZydNFI94igLHRQivLS0NifTWj9hXd40lmrS+XlWG gg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=uaDB31GsdQ6QYX6kwRtBtlkYbBLv8Aw3ThMjsV2imfI=; b=jcbDrC18r22P2zP4kFOEXjol+CK/clQKQZhK9fx/ExtgG98Z7ywSnghn25HNB+fI/9pI PAcR/3H8Gvmc5EzlpcyGsrqadVLBiCA5E08iv+gkCHgopZrecTuC6QOuuUDzMpueujkD y7nUrZlHvikUNAGCJoDs3+k+qJrX8w6DwwPU7wN90mSy0ctFESeGEL+RUxJ9FnX71W8E T7mJvdWpli6zLT6ovtxbKBZpM7KIRgTgutkMOlwzCmu357ZQbMCrrXdWmSpl40fteql6 GfT+8Ecnagq+30VGC050+6jWjgaXSprRrjmo44uwLInSI8Vd7mOzsU1Qvbo4wnCoTeaD QQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap3eauqkk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:45 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RD9omA076985; Fri, 27 Aug 2021 13:20:44 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2170.outbound.protection.outlook.com [104.47.55.170]) by userp3030.oracle.com with ESMTP id 3ajpm4pq7n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zhumlmi4aD+IbrJXd/HTJpssE1kxpgAaEdfGfhmkNRXWl4A7n2AXobFlnQGzm9VMCis/CvxgGO8CJx4E7NTOViDL7ped+qyksBQPGBaJC6qvFq6qNYYdn1yTFISkDnNZ+7PnYkAC4F3ZWU+ljaN9NYGWnXxoKhzsHpA8o7gik17pUwVrY4WX8xCFSg0t6SWo3O4y3n82ze+TmgUTG8m1cg50t3Mc+00f42memcisdWX6T3LwD9RdxKZmakQH2PSB/HArtCjMTs/W5F9QTfXoPEyP4DbFWxfwl1XKbQDCeHdRlwrBSIlnEUjbj+jXwN9cYai01XezF6zjZozwSJrqBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uaDB31GsdQ6QYX6kwRtBtlkYbBLv8Aw3ThMjsV2imfI=; b=LymGXQ80KETCwE3bSniOE6NZQthx+6kP/UdM6Cz8Ukcq9eRCOHuEEhNfBWEoRuAqwWL8EnAZXQe+YLaSVfFWkBUtLfib/i0h2hvrgfVOa7o0gKlUuB2pR376Wl/knmq2SWNwN2ToXhaKeOU3U1JOx2aGY0K4eEo1Olf/nJgc2IH4lEKr/k1/puchz5DrOi5NrgeqQWsAR765WB10sXsRKfIGY45VcMKaDs7dmSXddcju0uhUeXj8AZVSY2HTeXxNrPppP29LEaY5spABhVoHUkttIp/A2QrirAEhQ1akuMR5lRKTTotckHtMrCQ4OilpmqQiXx97ywhtzIN1T2ABEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uaDB31GsdQ6QYX6kwRtBtlkYbBLv8Aw3ThMjsV2imfI=; b=W+vijA/nrys3AiPBdDWxiwg43zsHr3E8h6k7xfN/Yny+QxlnQR1uDPGTqjoSCIP3KGd+L713xGHs2F17CMolCq6Hkr/kmrEKje4PeK7zOkLg58ohzpSt6EU3V9nx/LtLMka2iiSNgQ67S5Nlm/g6KAG+4Sj7M/Qu4iCgTm5ZS8A= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3432.namprd10.prod.outlook.com (2603:10b6:a03:8e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 13:20:42 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:41 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 03/14] x86/boot: Place kernel_info at a fixed offset Date: Fri, 27 Aug 2021 09:28:26 -0400 Message-Id: <1630070917-9896-4-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6d96d3c4-2992-43b3-c00b-08d9695d7813 X-MS-TrafficTypeDiagnostic: BYAPR10MB3432: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vYNC3Jo0/wTN4djWpd68bj+vLAT+OO1EdJfLACs/jKmHNirJaJePgf85+5nqio4gFe2useocSE8xUuDq1C/FZY8olTRSkABhmq/KlCtV6ABiHllMgwN4/SKtksixapOqh9iiFB5Q/xl0FLPvB4867BA7qlMU5AQjHWvlECezAD5X4ALCCBtDP+FbVa4x5fmc2ToVkIjE6t1T+Hjn6RqWynAWrYeq8qbQ7q1b4e8sE4GKl2JIGxeCUzJI0t94vAJPhLuJSHe7IUddSQgijA/uz9oLkeF/CGsAuqkOIfZZ47uwEkObmDmYvDL5udzhAKJyg+y9LNhb20X7MoBeezccC9PovyacZrLVOQsBDpDPJFMKxK1xgC7aFmx5/LNi1upo83pOzG+DkQ7JO4MDSzeNh9BRr3Ic9OIUj4NaVqL6Po8bUCK5zAPMjlwplOnv+nLCNIq4uhUxh+ceJ08DVkTeDcF8e5ld+L0JnU3WlrdlUiHQZGe/xx2ppAh8Shake0qikNOk3O5vDRqvjWAJOSkXFHhVOBL3gL4rv94BOFA1OEyLJgkt1KOQX5/GFyHLRdbBTfnYLCh6Z9dKHBbrqt16lI5tojt4aej7q4hj/PvbdTWWePgvU2nilab2c4HrHvJz3JFRjuYHNMEFJcvweTursVnjlSsf1BtBZomUVYP3pZC6jbescKSbfWduG1J27tplncEDBzh2kS1emlvBLtrlyg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(346002)(136003)(366004)(39860400002)(376002)(8936002)(2906002)(86362001)(478600001)(186003)(6666004)(5660300002)(36756003)(7696005)(4326008)(316002)(38350700002)(83380400001)(66946007)(6486002)(38100700002)(956004)(26005)(7416002)(8676002)(52116002)(44832011)(66556008)(66476007)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MQz+RMz64S8ape6Pfht1lNgw0o6mnBhx4FEDpH3KfIMnCTj6DJHYt5NXWezRtupuc4tB+Ait77x2nSeaEwWYDUTq6NIyYzgcPwmcSj7goE1zYNEZ160sp2EiuxbBfUqqJz7146wQPtVZXHtPgM0VTx17AeJEzK7yz47l5W0o44St22KQG1sADrPuy9B70VisQ9ECsKTNGF0uueV4f22bR2NEfnnd6s5+kPKW9Jc9/iJTMr6MsbyHMp8yaThjlpX2ek61CC6ybOHAeLLk7Yd8Mhzfd+cMoqbOxQeqUBMqRa6yeVM+LBJdfWAGMgaG/6ZGDdLD5kfSnAjdsPdzuJQPLsqAHmYgltxqt+NrSpbrsuyUGay7qWOxw9FL3UlfokbghefodBkS8H+8ny4KXe4aWN/uF673D38z0gKfxLaeO7PY6XXNOgnP6iHBjtr/ZH7MbAt1uiPapIUUSP9NJ88mFhyrZEKmteOhlNfhb0hmmbB7fZ7OPeewNjOaHbYusL6XAW5r1HbZ7FlA//jRlWvYWmh5YLnIRenLlyZPcjeFZsQpp8VhRAAj5YKSzMcIYmCSgtF9qAIBxHwPHRJDrEaUDkbiu5Qy8TDJggscnzd2c6IFu2NTMXpjuC7FcnwNH8hL2eYa6mmqy0xAYZU9jUQYi20i+Vx0IMebkvAgrFVG9MK7IUHW0MDe5QKjwqIv81pNiW3zjulF6A6X+V6+RakDDlABWK2v0WBHl8rnEftiaOmxXI361RyC0esOsDRhcmkfbVI+nmOPeS/Da46HKDGnjqszhSucVx7MGsgWLFpJg0LMyeBcfBywRLY27etctu1dkP9USrDOJBaTUQv6p/Z4Byl7wolYKWJ2wvNrDUjCeQxUiowXAZAjwBM3zkTQ7s1pYSVZupMGLrSXbFPCWB+1Ykg7x9xJdBQq8TX+WqE2JaQDL0AJia/KqJyWsTm7b/URqVKZJ+RTzerFUZX7SnKexRHk7cwRDNijv6FPURYnBjTdI6/k00CzE8Tkb3uJEJohG6P5Vq5APldGbGMfvW/mWSp6P8ULFO1ZUueeWqC2nFEvpksMDrV4ByBjZOS8u4319Piu8P/0JKhaVGYOx119a/O/kqKgFtEhcqZQCl//midyyNA20O+uh8qz0BP3gLRGvjK4UmJdluOJCkje8XDBECB3LPH49w+81q2KhY2JMx0UGPGvvVNFLVV8PIQ1Qhd3TH2oMT1buQeL3EfwsRp6Q3mNZYyWMkxCxrU9SxdUOb8SQObnt2MPDU4P1oCQwwjUJKw0fZS6vn7Cj38BKwDcBvPURXo6YR/2bf5qVhiX8u4udHgDXV06ngBWeRCp2AJB X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d96d3c4-2992-43b3-c00b-08d9695d7813 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:41.8760 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GFGH4JskyprSrSvj9Iav2CnpPY/CVaEj3FMnHAHaiUd+pK0JkTKgm+h5u2n3vTbmDyPbdPktBLfhCeY7h1p7F5VQR/RHPCjzZTx8wsNKoqg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3432 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-ORIG-GUID: BFcFcHv4Wvqx--95J7R8OniCamwtENwR X-Proofpoint-GUID: BFcFcHv4Wvqx--95J7R8OniCamwtENwR Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Arvind Sankar There are use cases for storing the offset of a symbol in kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header in kernel_info. Since commit (note: commit ID from tip/master) 527afc212231 ("x86/boot: Check that there are no run-time relocations") run-time relocations are not allowed in the compressed kernel, so simply using the symbol in kernel_info, as .long symbol will cause a linker error because this is not position-independent. With kernel_info being a separate object file and in a different section from startup_32, there is no way to calculate the offset of a symbol from the start of the image in a position-independent way. To enable such use cases, put kernel_info into its own section which is placed at a predetermined offset (KERNEL_INFO_OFFSET) via the linker script. This will allow calculating the symbol offset in a position-independent way, by adding the offset from the start of kernel_info to KERNEL_INFO_OFFSET. Ensure that kernel_info is aligned, and use the SYM_DATA.* macros instead of bare labels. This stores the size of the kernel_info structure in the ELF symbol table. Signed-off-by: Arvind Sankar Cc: Ross Philipson Signed-off-by: Ross Philipson --- arch/x86/boot/compressed/kernel_info.S | 19 +++++++++++++++---- arch/x86/boot/compressed/kernel_info.h | 12 ++++++++++++ arch/x86/boot/compressed/vmlinux.lds.S | 6 ++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 arch/x86/boot/compressed/kernel_info.h diff --git a/arch/x86/boot/compressed/kernel_info.S b/arch/x86/boot/compressed/kernel_info.S index f818ee8..c18f071 100644 --- a/arch/x86/boot/compressed/kernel_info.S +++ b/arch/x86/boot/compressed/kernel_info.S @@ -1,12 +1,23 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include +#include "kernel_info.h" - .section ".rodata.kernel_info", "a" +/* + * If a field needs to hold the offset of a symbol from the start + * of the image, use the macro below, eg + * .long rva(symbol) + * This will avoid creating run-time relocations, which are not + * allowed in the compressed kernel. + */ + +#define rva(X) (((X) - kernel_info) + KERNEL_INFO_OFFSET) - .global kernel_info + .section ".rodata.kernel_info", "a" -kernel_info: + .balign 16 +SYM_DATA_START(kernel_info) /* Header, Linux top (structure). */ .ascii "LToP" /* Size. */ @@ -19,4 +30,4 @@ kernel_info: kernel_info_var_len_data: /* Empty for time being... */ -kernel_info_end: +SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end) diff --git a/arch/x86/boot/compressed/kernel_info.h b/arch/x86/boot/compressed/kernel_info.h new file mode 100644 index 0000000..c127f84 --- /dev/null +++ b/arch/x86/boot/compressed/kernel_info.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BOOT_COMPRESSED_KERNEL_INFO_H +#define BOOT_COMPRESSED_KERNEL_INFO_H + +#ifdef CONFIG_X86_64 +#define KERNEL_INFO_OFFSET 0x500 +#else /* 32-bit */ +#define KERNEL_INFO_OFFSET 0x100 +#endif + +#endif /* BOOT_COMPRESSED_KERNEL_INFO_H */ diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S index 112b237..84c7b4d 100644 --- a/arch/x86/boot/compressed/vmlinux.lds.S +++ b/arch/x86/boot/compressed/vmlinux.lds.S @@ -7,6 +7,7 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) #include #include +#include "kernel_info.h" #ifdef CONFIG_X86_64 OUTPUT_ARCH(i386:x86-64) @@ -27,6 +28,11 @@ SECTIONS HEAD_TEXT _ehead = . ; } + .rodata.kernel_info KERNEL_INFO_OFFSET : { + *(.rodata.kernel_info) + } + ASSERT(ABSOLUTE(kernel_info) == KERNEL_INFO_OFFSET, "kernel_info at bad address!") + .rodata..compressed : { *(.rodata..compressed) } From patchwork Fri Aug 27 13:28:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B46CC19F35 for ; Fri, 27 Aug 2021 13:21:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BF526102A for ; Fri, 27 Aug 2021 13:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245156AbhH0NWA (ORCPT ); Fri, 27 Aug 2021 09:22:00 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:23396 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231942AbhH0NV6 (ORCPT ); Fri, 27 Aug 2021 09:21:58 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RA2VEa020754; Fri, 27 Aug 2021 13:20:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=ZzndYLWZUsiuGQo9VdjQB9BkSPTnpPKZ+XKR0Gg7EI8=; b=0YGFuUWPlzeS+IdqrsY2nglnH4NqKExmrNXusl+PyxS4JOl2uxQ+8ze3JZ/oiCroHAlu xhrPyYFl0gamAE2T33bW7bzCGga1pTcoM/rDkdCDVm9SzLzU5scab5D3iH9vddWEw9N3 d+6FQPQjcbUnCJ1/f9EeFy9+ZGcmmUcr/48hQnQvTQd308i9AGttrfjANlLLi2ZQQmiZ m1XMUd10o2ZJlBzc4kGi6i8bPlijtQ7WaDdNO6c6uG6dfDopfJ0nqS2j0oPFdcO8Lydb WVSmHLkx4bGi4dy2wQ2CkzJU/dNZTnMBDgau0G6XsBu2KlykzbJ3chUZa2dcPTlzQwHn aQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=ZzndYLWZUsiuGQo9VdjQB9BkSPTnpPKZ+XKR0Gg7EI8=; b=Mc4gP1kSJoA/mhIzIYt6Uxl1DPvYrHCmhy0U9pzBRTerM1KLOXHY+saZmDfVEZfm+wKN +m1XY/EP7vp/8FqU5ZpHtIaTtRvI+qmxekgekbJQ4Acq7e6hh1iGh2orx1fxyWR2uBsF lFNh4L8J/Ixs1LukaoqQCsr2A9xWTHeir5oPWNxKwpi43ehLE7OwQqft+lKxUd8wNTEp z35xXGYYwBuQtLKPIV9VZM12TFFtkqgA2dMShLRSmNNqdSSniYVSacHyhNdeLfkAx7TL XZA8aL89ufydNhYQN6DMSI6rZ0M4UNZ/SRRtwYiXBqHGVzbZ8W3Eaycgtl2ULeCtdkRD uw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap4ekunbx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:47 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RDBY2q007529; Fri, 27 Aug 2021 13:20:46 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2042.outbound.protection.outlook.com [104.47.51.42]) by aserp3030.oracle.com with ESMTP id 3ajqhmjm83-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ApQeq2ff7Nwp89pggCcuSUcZMSWNs5/0URzFRDjraz3I1gxHkW8kMK4O7koVFNGCyJF/hYGKiccxyWSsvpnTy0kyCPFADCklbDC3E7z2tQrq9DyYWmCKP4iAsSWdwZRQ7SOQbMqKgl7B0u5xkJi1g6SFlP6Bt7ZzNPFZLVbhXrL8g9RvH38ISGBI8jDnaPsTIowCjrZ1cyADomDOdTyZPEgKwb2duxuSG+FCaXUMfn3uptGs5m2LgwQ8MFrefUIsHYrxombiy/yPl+A7tieZLNzpKIJvg2ABH7MBBt2cJoNMB3dmh3RShk6pDw8gcXI8t8abd9G8V2tC7ElDMxaGCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZzndYLWZUsiuGQo9VdjQB9BkSPTnpPKZ+XKR0Gg7EI8=; b=aEpqTcEh+pfG+r0lkiXVhRskJRBx1isB9PssXE24mY6FYtxCFMziR/E9/3UCf90JaT6Z+57ifdbOs8xlrPY379yyVMCG1DHls206YCqRlKpCgT0V45nHhkrWwu6nZSgv3wm2ylxz6uwm4iMNkDrBxHmYorYM8zdXUJvW97lu3U9hneKlYiZIUMpLSHbuy04YZnQsmdnouFfANHMQT4+1lCC64lF87F4XlVumKqtTbM2JUEb1YSywLG9Tpm45jBkfeOy4YpxotXFAtIXhv/h1cZd7pWbRzeTNTeD9mVBCr17AuLm5l4zlwutYG6ZiyGetyTm/0mZCmfTfU7Wrf7G9zQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZzndYLWZUsiuGQo9VdjQB9BkSPTnpPKZ+XKR0Gg7EI8=; b=Q7oBjiw4n9jo8RlOGDcAhJ+j8HIA+6HEmWxqoFYNhf4mUGprEzbvdiFTVGmk3sc0cR2yFys2qmo9N4bhG6mNXTR4ZZn6hJZTVhvvJ97J8jHORyVD49QSJZhcjex/ORSQf8UydlGnXtZy4+1kw0ximrih9sNmbNGUeULpr6eVmxI= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:43 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:43 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 04/14] Documentation/x86: Secure Launch kernel documentation Date: Fri, 27 Aug 2021 09:28:27 -0400 Message-Id: <1630070917-9896-5-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 12eb0bc3-acba-4295-33f6-08d9695d791a X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xgmEwYddyipRwjKjzXxYWlQfL1Q11SqTrGww88ugRc6KrUnXUqPtbKlQiNG5aUYiHExrUPo+QeJiUn5+1iNnUdfI89ENkbCK8SyPsBS2lwEIeBcQPye00soYAv8GQALsu2v+xCO8PSCqx46BNomglDv41qXtK+2t2BGlZbzU9GjI+8aMy0vOxR7UZt0yHoJaJ9dmyggy4YAybOcR+nE2Lp4Ex521zCGxuuN0HnmYkyV+zWan9Q1Kxv9kV6hoLm2KoB9N8nOXpHF7d8tdvw5Zlbf6EN5548D3scpGnIY9jEO3YrZRFkJmg1ac8+cY6bMVsm1mq1G8rv5tswd+9LJaweRCpFYH+K6YGJhkc54+00Mop3PTd1PGeQAjaoqoo3wbXfXqp9XBBfNs3FPLojUwZfioYwhfG7kQk+1idBhwSt17/DR9pUOrTeWqNQ+3GbwEr1HzA1LTXW7zApUphiy31gSN7p905+t8dwhp/ao90g9DoU4uwV2DC6SWbWsBVExgllc4wy5P+dUaqaqaMMYaz0KrctGmLsGlsvxrHP6/Z4ABUMhmMYv3oUMbTV8eYvUB2ySA5phNnF3l8U024mEgJZxGPMLTHGXLPVSZiqX9iauu4RJU1q+MjD14v6LPKmrh9hrt7p4gGOOJRug8FEjXVlH9/CoewWl3QppeBqna+Kc6ttfSdohaFJFomKyisQcXC+6+dfWCVP/YkQ93jWxSpPLUVNY6jBepxhPTBW1hvUNlRsqB/ZQWHvXEwMRmB/GA4LSH+LxgJCGDoOAaAyXf6Vv7E8jYFk1hWb+XPlrMb5sMR0/GbgzI5MIJfyW8Hk2fWiVGzUL8P+ilSi+ENBdgeA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(30864003)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F0usQz+8aXqElnfqEgQDgy1t2//HMSqFbl3VDMfH9JW2SZf8xxC+AuNfxH9V2zVauuDIogVBMyxUu1hEk7mJVfYVFIamLY+9N7rBoL6zg22tSr3DHVz2/FCKhwcoyRHQcGLCiDuAAjAm7edJuZZeSwnHp8bWUh2Z9/9ljTF/s0wPmj62TzlSopn5sbCyru2P3GfbFZiWnqfVBO9ZyElOaRUhQx0C/xyG8pI08V8rm8H/Pd+MqJ0YG28Z2jJq7U5qksw37dey5zOnUdozgpNMGVL83wXRkekyoEDkhwsNUxFomwMnYspWEg6VMFH5yVWb+Aur/5aFAOEsw5x0CBWvH6WHwWzSf7MoETURMGgI2ZKQ13cC4w1/Vkl1qUuIRInC6iBc+HGdcuvONV590DTR9lZ+dbveA6x4WjalTA47rEjDXvNFlvWN9NQBfoNYcLKZ5th9mbOKKsPwOgsiImokjjDe3K6wPAZvOlnaz28S0ATEE5/afhH3egCbF9DNw7nnXSJIjRWS6J1AfRAqzRGviKCpG8fAAr1eoVUyT3ND3dcajoQM0ftZG+H/ZnnPVC1AVaNzSokZj695IQOGJIMLMnSG4AaqErVS4anQHtb7WSv8OC1HRHsD9HYrSdDdBD80sP2kGUushg0RgvMFD/sSH1Fj262TlInK53DfWuU3FUZDXcqRpEDxuwz56U//9L8QtLGN2XHIlurMkdq1MKURAXB2ypp1jMegW/26jth6DPuXhWcqnw9vaDK0aupIUCivgGXGM6CZxXOsJPLIOf8XIhlQWQYaFNWLIjHJTll9q6oS0N7gK8VEpZs6gPzzPNXeuw9p+pTT6RI/9Mu776T2s6ib2oro9bl4doQkb+SzeeQ295zLoAK79Eh70R1AM1LBKw+7K41ggWWnto+9C2UphdL1osmfwA+D4za/U96kmFJLaQ3FPfkqyCCtNwsbq5tPZuEylqJ3KSQyEYHxFIEJWCQVn+fjblFlY0HO73aiCH1l1rNxvbDORfPLOe4Njj3NI6R31+xA7xPUkswFsHn1pl1f6/ps1uqcYBxaLOt0Oghm+p0FsQYKDKG6PHc8XFr1QUTKFqNmO34Ms9vhs/NzQQhhmZoY+Dz8klQeZIO2doDdTrxj+Fl9Ez+sx95idGfMO55NdWEAzlmQPo2gh35fhFRbCcTOxdx0MC2UWUPmDCZSBVCuE/lqrnVATJOQaEvI3HHQI/WtWovmsZOC6YSI6mDhcZ1e4UOKxrK+dhofXTiiKDesioppH9GaJWjyWqwwbz06BrR+5Aoqn3rNtMh4ihbsv9/0Cl7hz8e54kgwu2J1xXBje/lC5kw896mBcnug X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12eb0bc3-acba-4295-33f6-08d9695d791a X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:43.5910 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HFKKLFzLlK3DJrrHAX74hfY9yYRh6Oilq4dtW6cREKimMtaQngZFEoso5HzgmNgtSZ7YnkbCHuF+QfDWhs6hC6dUicvzTFtVj2UzsB2ZuWY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: FU9UlOJ9MrvAEny2PdOvN7v7kpsijdDS X-Proofpoint-ORIG-GUID: FU9UlOJ9MrvAEny2PdOvN7v7kpsijdDS Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Introduce background, overview and configuration/ABI information for the Secure Launch kernel feature. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- Documentation/x86/index.rst | 1 + Documentation/x86/secure-launch.rst | 716 ++++++++++++++++++++++++++++++++++++ 2 files changed, 717 insertions(+) create mode 100644 Documentation/x86/secure-launch.rst diff --git a/Documentation/x86/index.rst b/Documentation/x86/index.rst index 3830483..e5a058f 100644 --- a/Documentation/x86/index.rst +++ b/Documentation/x86/index.rst @@ -31,6 +31,7 @@ x86-specific Documentation tsx_async_abort buslock usb-legacy-support + secure-launch i386/index x86_64/index sva diff --git a/Documentation/x86/secure-launch.rst b/Documentation/x86/secure-launch.rst new file mode 100644 index 0000000..95bb193 --- /dev/null +++ b/Documentation/x86/secure-launch.rst @@ -0,0 +1,716 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============= +Secure Launch +============= + +Background +========== + +The Trusted Computing Group (TCG) architecture defines two methods in +which the target operating system is started, aka launched, on a system +for which Intel and AMD provides implementations. These two launch types +are static launch and dynamic launch. Static launch is referred to as +such because it happens at one fixed point, at system startup, during +the defined life-cycle of a system. Dynamic launch is referred to as +such because it is not limited to being done once nor bound to system +startup. It can in fact happen at anytime without incurring/requiring an +associated power event for the system. Since dynamic launch can happen +at anytime, this results in dynamic launch being split into two type of +its own. The first is referred to as an early launch, where the dynamic +launch is done in conjunction with the static lunch of the system. The +second is referred to as a late launch, where a dynamic launch is +initiated after the static launch was fully completed and the system was +under the control of some target operating system or run-time kernel. +These two top-level launch methods, static launch and dynamic launch +provide different models for establishing the launch integrity, i.e. the +load-time integrity, of the target operating system. When cryptographic +hashing is used to create an integrity assessment for the launch +integrity, then for a static launch this is referred to as the Static +Root of Trust for Measurement (SRTM) and for dynamic launch it is +referred to as the Dynamic Root of Trust for Measurement (DRTM). + +The reasoning for needing the two integrity models is driven by the fact +that these models leverage what is referred to as a "transitive trust". +A transitive trust is commonly referred to as a "trust chain", which is +created through the process of an entity making an integrity assessment +of another entity and upon success transfers control to the new entity. +This process is then repeated by each entity until the Trusted Computing +Base (TCB) of system has been established. A challenge for transitive +trust is that the process is susceptible to cumulative error +and in this case that error is inaccurate or improper integrity +assessments. The way to address cumulative error is to reduce the +number of instances that can create error involved in the process. In +this case it would be to reduce then number of entities involved in the +transitive trust. It is not possible to reduce the number of firmware +components or the boot loader(s) involved during static launch. This is +where dynamic launch comes in, as it introduces the concept for a CPU to +provide an instruction that results in a transitive trust starting with +the CPU doing an integrity assessment of a special loader that can then +start a target operating system. This reduces the trust chain down to +the CPU, a special loader, and the target operation system. It is also +why it is said that the DRTM is rooted in hardware since the CPU is what +does the first integrity assessment, i.e. the first measurement, in the +trust chain. + +Overview +======== + +Prior to the start of the TrenchBoot project, the only active Open +Source project supporting dynamic launch was Intel's tboot project to +support their implementation of dynamic launch known as Intel Trusted +eXecution Technology (TXT). The approach taken by tboot was to provide +an exokernel that could handle the launch protocol implemented by +Intel's special loader, the SINIT Authenticated Code Module (ACM [3]_) +and remained in memory to manage the SMX CPU mode that a dynamic launch +would put a system. While it is not precluded from being used for doing +a late launch, tboot's primary use case was to be used as an early +launch solution. As a result the TrenchBoot project started the +development of Secure Launch kernel feature to provide a more +generalized approach. The focus of the effort is twofold, the first is to +make the Linux kernel directly aware of the launch protocol used by +Intel as well as AMD, and the second is to make the Linux kernel be able +to initiate a dynamic launch. It is through this approach that the +Secure Launch kernel feature creates a basis for the Linux kernel to be +used in a variety of dynamic launch use cases. + +The first use case that the TrenchBoot project focused on was the +ability for the Linux kernel to be started by a dynamic launch, in +particular as part of an early launch sequence. In this case the dynamic +launch will be initiated by a boot loader with associated support added +to it, for example the first targeted boot loader in this case was +GRUB2. An integral part of establishing a measurement-based launch +integrity involves measuring everything that is intended to be executed +(kernel image, initrd, etc) and everything that will configure that +kernel to execute (command line, boot params, etc). Then storing those +measurements in a protected manner. Both the Intel and AMD dynamic +launch implementations leverage the Trusted Platform Module (TPM) to +store those measurements. The TPM itself has been designed such that a +dynamic launch unlocks a specific set of Platform Configuration +Registers (PCR) for holding measurement taken during the dynamic launch. +These are referred to as the DRTM PCRs, PCRs 17-22. Further details on +this process can be found in the documentation for the GETSEC +instruction provided by Intel's TXT and the SKINIT instruction provided +by AMD's AMD-V. The documentation on these technologies can be readily +found online; see the `Resources`_ section below for references. + +Currently only Intel TXT is supported in this first release of the Secure +Launch feature. AMD/Hygon SKINIT support will be added in a subsequent +release. Also this first version does not support a late relaunch which +allows re-establishing the DRTM at various points post boot. + +To enable the kernel to be launched by GETSEC, a stub must be built +into the setup section of the compressed kernel to handle the specific +state that the dynamic launch process leaves the BSP in. Also this stub +must measure everything that is going to be used as early as possible. +This stub code and subsequent code must also deal with the specific +state that the dynamic launch leaves the APs in. + +Basic Boot Flow: +---------------- + +Pre-launch: *Phase where the environment is prepared and configured to initiate the +secure launch in the GRUB bootloader.* + + - Prepare the CPU and the TPM for the launch. + - Load the kernel, initrd and ACM [3]_ into memory. + - Setup the TXT heap and page tables describing the MLE [1]_ per the + specification. + - Initiate the secure launch with the GETSET[SENTER] instruction. + +Post-launch: *Phase where control is passed from the ACM to the MLE and the secure +kernel begins execution.* + + - Entry from the dynamic launch jumps to the SL stub. + - SL stub fixes up the world on the BSP. + - For TXT, SL stub wakes the APs, fixes up their worlds. + - For TXT, APs are left halted waiting for an NMI to wake them. + - SL stub jumps to startup_32. + - SL main locates the TPM event log and writes the measurements of + configuration and module information into it. + - Kernel boot proceeds normally from this point. + - During early setup, slaunch_setup() runs to finish some validation + and setup tasks. + - The SMP bringup code is modified to wake the waiting APs. APs vector + to rmpiggy and start up normally from that point. + - SL platform module is registered as a late initcall module. It reads + the TPM event log and extends the measurements taken into the TPM PCRs. + - SL platform module initializes the securityfs interface to allow + access to the TPM event log and TXT public registers. + - Kernel boot finishes booting normally + - SEXIT support to leave SMX mode is present on the kexec path and + the various reboot paths (poweroff, reset, halt). + + +.. note:: + A quick note on terminology. The larger open source project itself is + called TrenchBoot, which is hosted on GitHub (links below). The kernel + feature enabling the use of the x86 technology is referred to as "Secure + Launch" within the kernel code. + +Configuration +============= + +The settings to enable Secure Launch using Kconfig are under:: + + "Processor type and features" --> "Secure Launch support" + +A kernel with this option enabled can still be booted using other supported +methods. There are two Kconfig options for Secure Launch:: + + "Secure Launch Alternate PCR 19 usage" + "Secure Launch Alternate PCR 20 usage" + +The help indicates their usage as alternate post launch PCRs to separate +measurements for more flexibility (both disabled by default). + +To reduce the Trusted Computing Base (TCB) of the MLE [1]_, the build +configuration should be pared down as narrowly as one's use case allows. +The fewer drivers (less active hardware) and features reduces the attack +surface. E.g. in the extreme, the MLE could only have local disk access +and no other hardware support. Or only network access for remote attestation. + +It is also desirable if possible to embed the initrd used with the MLE kernel +image to reduce complexity. + +The following are a few important configuration necessities to always consider: + +KASLR Configuration +------------------- + +Secure Launch does not interoperate with KASLR. If possible, the MLE should be +built with KASLR disabled:: + + "Processor type and features" --> + "Build a relocatable kernel" --> + "Randomize the address of the kernel image (KASLR) [ ]" + +This unsets the Kconfig value CONFIG_RANDOMIZE_BASE. + +If not possible, KASLR must be disabled on the kernel command line when doing +a Secure Launch as follows:: + + nokaslr + +IOMMU Configuration +------------------- + +When doing a Secure Launch, the IOMMU should always be enabled and the drivers +loaded. However, IOMMU passthrough mode should never be used. This leaves the +MLE completely exposed to DMA after the PMR's [2]_ are disabled. First, IOMMU +passthrough should be disabled by default in the build configuration:: + + "Device Drivers" --> + "IOMMU Hardware Support" --> + "IOMMU passthrough by default [ ]" + +This unset the Kconfig value CONFIG_IOMMU_DEFAULT_PASSTHROUGH. + +In addition, passthrough must be disabled on the kernel command line when doing +a Secure Launch as follows:: + + iommu=nopt iommu.passthrough=0 + +Interface +========= + +The primary interfaces between the various components in TXT are the TXT MMIO +registers and the TXT heap. The MMIO register banks are described in Appendix B +of the TXT MLE [1]_ Developement Guide. + +The TXT heap is described in Appendix C of the TXT MLE [1]_ Development +Guide. Most of the TXT heap is predefined in the specification. The heap is +initialized by firmware and the pre-launch environment and is subsequently used +by the SINIT ACM. One section, called the OS to MLE Data Table, is reserved for +software to define. This table is the Secure Launch binary interface between +the pre- and post-launch environments and is defined as follows:: + + /* + * Secure Launch defined MTRR saving structures + */ + struct txt_mtrr_pair { + u64 mtrr_physbase; + u64 mtrr_physmask; + } __packed; + + struct txt_mtrr_state { + u64 default_mem_type; + u64 mtrr_vcnt; + struct txt_mtrr_pair mtrr_pair[TXT_OS_MLE_MAX_VARIABLE_MTRRS]; + } __packed; + + /* + * Secure Launch defined OS/MLE TXT Heap table + */ + struct txt_os_mle_data { + u32 version; + u32 boot_params_addr; + u64 saved_misc_enable_msr; + struct txt_mtrr_state saved_bsp_mtrrs; + u32 ap_wake_block; + u32 ap_wake_block_size; + u64 evtlog_addr; + u32 evtlog_size; + u8 mle_scratch[64]; + } __packed; + +Description of structure: + +===================== ======================================================================== +Field Use +===================== ======================================================================== +version Structure version, current value 1 +boot_params_addr Physical address of the zero page/kernel boot params +saved_misc_enable_msr Original Misc Enable MSR (0x1a0) value stored by the pre-launch + environment. This value needs to be restored post launch - this is a + requirement. +saved_bsp_mtrrs Original Fixed and Variable MTRR values stored by the pre-launch + environment. These values need to be restored post launch - this is a + requirement. +ap_wake_block Pre-launch allocated memory block to wake up and park the APs post + launch until SMP support is ready. This block is validated by the MLE + before use. +ap_wake_block_size Size of the ap_wake_block. A minimum of 16384b (4x4K pages) is required. +evtlog_addr Pre-launch allocated memory block for the TPM event log. The event + log is formatted both by the pre-launch environment and the SINIT + ACM. This block is validated by the MLE before use. +evtlog_size Size of the evtlog_addr block. +mle_scratch Scratch area used post-launch by the MLE kernel. Fields: + + - SL_SCRATCH_AP_EBX area to share %ebx base pointer among CPUs + - SL_SCRATCH_AP_JMP_OFFSET offset to abs. ljmp fixup location for APs +===================== ======================================================================== + +Resources +========= + +The TrenchBoot project including documentation: + +https://github.com/trenchboot + +TXT documentation in the Intel TXT MLE Development Guide: + +https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf + +TXT instructions documentation in the Intel SDM Instruction Set volume: + +https://software.intel.com/en-us/articles/intel-sdm + +AMD SKINIT documentation in the System Programming manual: + +https://www.amd.com/system/files/TechDocs/24593.pdf + +GRUB pre-launch support patchset (WIP): + +https://lists.gnu.org/archive/html/grub-devel/2020-05/msg00011.html + +Error Codes +=========== + +The TXT specification defines the layout for TXT 32 bit error code values. +The bit encodings indicate where the error originated (e.g. with the CPU, +in the SINIT ACM, in software). The error is written to a sticky TXT +register that persists across resets called TXT.ERRORCODE (see the TXT +MLE Development Guide). The errors defined by the Secure Launch feature are +those generated in the MLE software. They have the format:: + + 0xc0008XXX + +The low 12 bits are free for defining the following Secure Launch specific +error codes. + +====== ================ +Name: SL_ERROR_GENERIC +Value: 0xc0008001 +====== ================ + +Description: + +Generic catch all error. Currently unused. + +====== ================= +Name: SL_ERROR_TPM_INIT +Value: 0xc0008002 +====== ================= + +Description: + +The secure launch code failed to get an access to the TPM hardware interface. +This is most likely to due to misconfigured hardware or kernel. Ensure the +TPM chip is enabled and the kernel TPM support is built in (it should not be +built as a module). + +====== ========================== +Name: SL_ERROR_TPM_INVALID_LOG20 +Value: 0xc0008003 +====== ========================== + +Description: + +The secure launch code failed to find a valid event log descriptor for TPM +version 2.0 or the event log descriptor is malformed. Usually this indicates +that incompatible versions of the pre-launch environment (GRUB) and the MLE +kernel. GRUB and the kernel share a structure in the TXT heap and if this +structure (the OS-MLE table) is mismatched, this error is often seen. This +TXT heap area is setup by the pre-launch environment so the issue may originate +there. It could be the sign of an attempted attack. + +====== =========================== +Name: SL_ERROR_TPM_LOGGING_FAILED +Value: 0xc0008004 +====== =========================== + +Description: + +There was a failed attempt to write a TPM event to the event log early in the +secure launch process. This is likely the result of a malformed TPM event log +buffer. Formatting of the event log buffer information is done by the +pre-launch environment (GRUB) so the the issue issue most likely originates +there. + +====== ============================ +Name: SL_ERROR_REGION_STRADDLE_4GB +Value: 0xc0008005 +====== ============================ + +Description: + +During early validation a buffer or region was found to straddle the 4Gb +boundary. Because of the way TXT does DMA memory protection, this is an +unsafe configuration and is flagged as an error. This is most likely a +configuration issue in the pre-launch environment. It could also be the sign of +an attempted attack. + +====== =================== +Name: SL_ERROR_TPM_EXTEND +Value: 0xc0008006 +====== =================== + +Description: + +There was a failed attempt to extend a TPM PCR in the secure launch platform +module. This is most likely to due to misconfigured hardware or kernel. Ensure +the TPM chip is enabled and the kernel TPM support is built in (it should not +be built as a module). + +====== ====================== +Name: SL_ERROR_MTRR_INV_VCNT +Value: 0xc0008007 +====== ====================== + +Description: + +During early secure launch validation an invalid variable MTRR count was found. +The pre-launch environment passes a number of MSR values to the MLE to restore +including the MTRRs. The values are restored by the secure launch early entry +point code. After measuring the values supplied by the pre-launch environment, +a discrepancy was found validating the values. It could be the sign of an +attempted attack. + +====== ========================== +Name: SL_ERROR_MTRR_INV_DEF_TYPE +Value: 0xc0008008 +====== ========================== + +Description: + +During early secure launch validation an invalid default MTRR type was found. +See SL_ERROR_MTRR_INV_VCNT for more details. + +====== ====================== +Name: SL_ERROR_MTRR_INV_BASE +Value: 0xc0008009 +====== ====================== + +Description: + +During early secure launch validation an invalid variable MTRR base value was +found. See SL_ERROR_MTRR_INV_VCNT for more details. + +====== ====================== +Name: SL_ERROR_MTRR_INV_MASK +Value: 0xc000800a +====== ====================== + +Description: + +During early secure launch validation an invalid variable MTRR mask value was +found. See SL_ERROR_MTRR_INV_VCNT for more details. + +====== ======================== +Name: SL_ERROR_MSR_INV_MISC_EN +Value: 0xc000800b +====== ======================== + +Description: + +During early secure launch validation an invalid miscellaneous enable MSR value +was found. See SL_ERROR_MTRR_INV_VCNT for more details. + +====== ========================= +Name: SL_ERROR_INV_AP_INTERRUPT +Value: 0xc000800c +====== ========================= + +Description: + +The application processors (APs) wait to be woken up by the SMP initialization +code. The only interrupt that they expect is an NMI; all other interrupts +should be masked. If an AP gets some other interrupt other than an NMI it will +cause this error. This error is very unlikely to occur. + +====== ========================= +Name: SL_ERROR_INTEGER_OVERFLOW +Value: 0xc000800d +====== ========================= + +Description: + +A buffer base and size passed to the MLE caused an integer overflow when +added together. This is most likely a configuration issue in the pre-launch +environment. It could also be the sign of an attempted attack. + +====== ================== +Name: SL_ERROR_HEAP_WALK +Value: 0xc000800e +====== ================== + +Description: + +An error occurred in TXT heap walking code. The underlying issue is a failure to +early_memremap() portions of the heap, most likely due to a resource shortage. + +====== ================= +Name: SL_ERROR_HEAP_MAP +Value: 0xc000800f +====== ================= + +Description: + +This error is essentially the same as SL_ERROR_HEAP_WALK but occured during the +actual early_memremap() operation. + +====== ========================= +Name: SL_ERROR_REGION_ABOVE_4GB +Value: 0xc0008010 +====== ========================= + +Description: + +A memory region used by the MLE is above 4GB. In general this is not a problem +because memory > 4Gb can be protected from DMA. There are certain buffers that +should never be above 4Gb though and one of these caused the violation. This is +most likely a configuration issue in the pre-launch environment. It could also +be the sign of an attempted attack. + +====== ========================== +Name: SL_ERROR_HEAP_INVALID_DMAR +Value: 0xc0008011 +====== ========================== + +Description: + +The backup copy of the ACPI DMAR table which is supposed to be located in the +TXT heap could not be found. This is due to a bug in the platform's ACM module +or in firmware. + +====== ======================= +Name: SL_ERROR_HEAP_DMAR_SIZE +Value: 0xc0008012 +====== ======================= + +Description: + +The backup copy of the ACPI DMAR table in the TXT heap is to large to be stored +for later usage. This error is very unlikely to occur since the area reserved +for the copy is far larger than the DMAR should be. + +====== ====================== +Name: SL_ERROR_HEAP_DMAR_MAP +Value: 0xc0008013 +====== ====================== + +Description: + +The backup copy of the ACPI DMAR table in the TXT heap could not be mapped. The +underlying issue is a failure to early_memremap() the DMAR table, most likely +due to a resource shortage. + +====== ==================== +Name: SL_ERROR_HI_PMR_BASE +Value: 0xc0008014 +====== ==================== + +Description: + +On a system with more than 4G of RAM, the high PMR [2]_ base address should be set +to 4G. This error is due to that not being the case. This PMR value is set by +the pre-launch environment so the issue most likely originates there. It could also +be the sign of an attempted attack. + +====== ==================== +Name: SL_ERROR_HI_PMR_SIZE +Value: 0xc0008015 +====== ==================== + +Description: + +On a system with more than 4G of RAM, the high PMR [2]_ size should be set to cover +all RAM > 4G. This error is due to that not being the case. This PMR value is +set by the pre-launch environment so the issue most likely originates there. It +could also be the sign of an attempted attack. + +====== ==================== +Name: SL_ERROR_LO_PMR_BASE +Value: 0xc0008016 +====== ==================== + +Description: + +The low PMR [2]_ base should always be set to address zero. This error is due to +that not being the case. This PMR value is set by the pre-launch environment +so the issue most likely originates there. It could also be the sign of an attempted +attack. + +====== ==================== +Name: SL_ERROR_LO_PMR_MLE +Value: 0xc0008017 +====== ==================== + +Description: + +This error indicates the MLE image is not covered by the low PMR [2]_ range. The +PMR values are set by the pre-launch environment so the issue most likely originates +there. It could also be the sign of an attempted attack. + +====== ======================= +Name: SL_ERROR_INITRD_TOO_BIG +Value: 0xc0008018 +====== ======================= + +Description: + +The external initrd provided is larger than 4Gb. This is not a valid +configuration for a secure launch due to managing DMA protection. + +====== ========================= +Name: SL_ERROR_HEAP_ZERO_OFFSET +Value: 0xc0008019 +====== ========================= + +Description: + +During a TXT heap walk an invalid/zero next table offset value was found. This +indicates the TXT heap is malformed. The TXT heap is initialized by the +pre-launch environment so the issue most likely originates there. It could also +be a sign of an attempted attack. In addition, ACM is also responsible for +manipulating parts of the TXT heap so the issue could be due to a bug in the +platform's ACM module. + +====== ============================= +Name: SL_ERROR_WAKE_BLOCK_TOO_SMALL +Value: 0xc000801a +====== ============================= + +Description: + +The AP wake block buffer passed to the MLE via the OS-MLE TXT heap table is not +large enough. This value is set by the pre-launch environment so the issue most +likely originates there. It also could be the sign of an attempted attack. + +====== =========================== +Name: SL_ERROR_MLE_BUFFER_OVERLAP +Value: 0xc000801b +====== =========================== + +Description: + +One of the buffers passed to the MLE via the OS-MLE TXT heap table overlaps +with the MLE image in memory. This value is set by the pre-launch environment +so the issue most likely originates there. It could also be the sign of an attempted +attack. + +====== ========================== +Name: SL_ERROR_BUFFER_BEYOND_PMR +Value: 0xc000801c +====== ========================== + +Description: + +One of the buffers passed to the MLE via the OS-MLE TXT heap table is not +protected by a PMR. This value is set by the pre-launch environment so the +issue most likey originates there. It could also be the sign of an attempted +attack. + +====== ============================= +Name: SL_ERROR_OS_SINIT_BAD_VERSION +Value: 0xc000801d +====== ============================= + +Description: + +The version of the OS-SINIT TXT heap table is bad. It must be 6 or greater. +This value is set by the pre-launch environment so the issue most likely +originates there. It could also be the sign of an attempted attack. It is also +possible though very unlikely that the platform is so old that the ACM being +used requires an unsupported version. + +====== ===================== +Name: SL_ERROR_EVENTLOG_MAP +Value: 0xc000801e +====== ===================== + +Description: + +An error occurred in the secure launch module while mapping the TPM event log. +The underlying issue is memremap() failure, most likely due to a resource +shortage. + +====== ======================== +Name: SL_ERROR_TPM_NUMBER_ALGS +Value: 0xc000801f +====== ======================== + +Description: + +The TPM 2.0 event log reports an unsupported number of hashing algorithms. +Secure launch currently only supports a maximum of two: SHA1 and SHA256. + +====== =========================== +Name: SL_ERROR_TPM_UNKNOWN_DIGEST +Value: 0xc0008020 +====== =========================== + +Description: + +The TPM 2.0 event log reports an unsupported hashing algorithm. Secure launch +currently only supports two algorithms: SHA1 and SHA256. + +====== ========================== +Name: SL_ERROR_TPM_INVALID_EVENT +Value: 0xc0008021 +====== ========================== + +Description: + +An invalid/malformed event was found in the TPM event log while reading it. +Since only trusted entities are supposed to be writing the event log, this +would indicate either a bug or a possible attack. + +.. [1] + MLE: Measured Launch Environment is the binary runtime that is measured and + then run by the TXT SINIT ACM. The TXT MLE Development Guide describes the + requirements for the MLE in detail. + +.. [2] + PMR: Intel VTd has a feature in the IOMMU called Protected Memory Registers. + There are two of these registers and they allow all DMA to be blocked + to large areas of memory. The low PMR can cover all memory below 4Gb on 2Mb + boundaries. The high PMR can cover all RAM on the system, again on 2Mb + boundaries. This feature is used during a secure launch by TXT. + +.. [3] + ACM: Intel's Authenticated Code Module. This is the 32b bit binary blob that + is run securely by the GETSEC[SENTER] during a measured launch. It is described + in the Intel documentation on TXT and versions for various chipsets are + signed and distributed by Intel. From patchwork Fri Aug 27 13:28:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1C79C4320E for ; Fri, 27 Aug 2021 13:21:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A318660E93 for ; Fri, 27 Aug 2021 13:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245127AbhH0NV7 (ORCPT ); Fri, 27 Aug 2021 09:21:59 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:23118 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231492AbhH0NV6 (ORCPT ); Fri, 27 Aug 2021 09:21:58 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RALmsK015051; Fri, 27 Aug 2021 13:20:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=L7gypYGtph9ns61b3nol/EKGhu+qMVQmD50UClf4NnM=; b=qTETkGSMbygefuBQwui/nTC7KJHjhtO2AYsM2F31X6bpik3jvDWbScaUu0RUrB4iDW0J RqJI6PMQb1me+3vQufx2FHoKyn1zqrWjiNsVPeJ20sleX8SHHMW3KXW0OYaVmoIV8Nny AB/tDDbXM+6LmuycxmT4dFFPkgCXxevUKGNIIIVksTkXvhpO0XXaKqMfgVP4w/Qz6M0Y Sh+xg1UDRCNOW6Zs5njTiLiHPQB9OXpqC9O1nmiJqg38DN76f75FBLY+rIcCgFsQqGUg DkD9sf9XXz2rgSb/vict88Rz4itLNFwDI1hKoT2YMu/LkFj9gj8rJ8fSYosUNWpH0JCu UA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=L7gypYGtph9ns61b3nol/EKGhu+qMVQmD50UClf4NnM=; b=w5uB3hbj/WzYimBnremmoravMuIQIHYKpB1fQ94Ya+oyaJebsSdj16CWGO6ht8TNRK4L kH8SXiH+lsIQr6/fSy+fo3z0PwwdW/1mLzdiU3mw4nz8TipR61y/N928YhSCJfsXyAWI FuVeH2IPBTKgGBSE3C1TyKGqTpUZdkh+PiT0JXZtEq/6n+pdHy0+G6y/GEb7g1rlUgPw 307hezhHmECedzh5YOq6BlPkmzhGh6Ec+d11VCpljVKFuSFgpitjHOHlZFk+HKXY0kod 7xNlyOqxoYLu/F+9sI366n+y7Dyw1e2q7tpEl0tm8QXMUz3T1oXRtQiXbWFNp+uM4Koc KA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap4xv3gxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:48 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RDBY2r007529; Fri, 27 Aug 2021 13:20:47 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2042.outbound.protection.outlook.com [104.47.51.42]) by aserp3030.oracle.com with ESMTP id 3ajqhmjm83-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kO7t2h8p0MYhZukJANrDNTIblded997Vqd8hbgIM2copTPD5ajfZ/aP/1BUo074ttcW8I6SUsaF+jxSEWwxwh60PKvP+ZW4eOPyU9DCgb6BiJTBZEY92rFRdxb5W/dsdgrsiSgaCB9NMa+r+UFFieepxPOyijKx50AY18znmTElii/It0VgCUAlh1E+duZeK7VIfvVdMy7ZBrLmF9WxvNsFgfRL5KLZMXyjNHbqzBNeQ/w0vMcMpv0Hxh+qFjg9B8n/OFKGmdzVqtMz2Flrho20r+slWsn+88JU8SOSylBFlM9iPCkDnyDGk+KfgG5Q9qdSLzHicNPoFKr0vF0M3YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L7gypYGtph9ns61b3nol/EKGhu+qMVQmD50UClf4NnM=; b=M9mYRxn5QyAPgqdr57lmsqI3GuycSBuhu0sn+O6dmZIzwncNaFEA/xAhuuyrhBiToDHTybQhx4A7IhCILZDwHXeVb4VRE40qap1tI7vWyPlvKNiJMkKV5rgxlFspNgdD1xw5un3ZX1qAF9DE/pFY9NdwRCMmTQLKny3NhkCp/Lo8eycz1J0D37S+UGJWkVpl3gE7cz+Oq3vVcuixijLx7bZyfFipRMfbkqmXFeaFue5WI2v8xKyEDluyB72gmJogkehG+vs4CbmIXKmNHCT4D0WWN5ejMbejl9x7LM5WIqtg229AncVe6pySw8isqncD/G45505kwIZucNZpY7RZkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L7gypYGtph9ns61b3nol/EKGhu+qMVQmD50UClf4NnM=; b=qWXxHVZ1Gqn/L5ZE4PKPRBalOKNnbtw4BrjNXQBTDvDaPZ/10LDVWjvp9tkReZR8GtDhiWwrkQ7csSbzsslkypUvol3V5Tv7sYUhv7PHsRlzBBKWKDY7uEDxwa9h0YkYo1R/2gBHx8gLqQAA+FyJsLpEO2zlujhdIEwRe7DQUYI= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:45 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:45 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 05/14] x86: Secure Launch Kconfig Date: Fri, 27 Aug 2021 09:28:28 -0400 Message-Id: <1630070917-9896-6-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: da999d0c-40e9-4f96-1925-08d9695d7a1a X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CTSQmy7LKH1sDxSD1370gwvcL7WqNnANc0BM+U8+QmkDK01fiEjewG9UNUeHm+Mehy2/jQUV0jKFGS6vm7Qot5vfZDTcQxqq0g1VHWjWyfi2C8aQPTXAo7FomEyFoZa+t6tYtce6kk4uLeyEfijHxPWdZjmvl7d3JXgv1xlctOMzsJnWmqnt7VozPGg+Gd/KXjbYtpNz/Xd3YIb5iez5+fOWtVJNjIl3HVPnqWkHZMP7xwQJMGXbXP35/qNqPL4BOPl6m1cQVqVcbWGkkwPbXwIoX8GrU9Y+IuzEY/UXT5izygwIJxKsV4t2EMk0I+M9uFIPjObgdZtaPgSF+za94fqge0XfEVkyvIju9ZXXCYD+ARaL14Hynvd4OgahsuxgrYjROn68P4q1WaXp664MJxzB3s3oU6eB5tbXngQ7ubW7vpbIih94YxrcKhJQbl/Jqy2/e55jbjfPlelIBWLbU0kBVn94ABIIxjrKqhPPBgYy9F0fae256hqdkCnDKT/1qMOgB5wp7wYAXIT7ezBB5Z2qDpQn/ZVWmucoAPabhjwfsY4pSlEHV7MMpikPHL/frdkpbl/K6KN/n4WM/7bG/n8UshsZA4/8rkH6QE0oPbQRMP3i9+cPuGMn7EbhjWzYZsFQaSl2rhq9emz+t7A/eLYcrN0Z6qEUhCBhkAv2nRchYeJnT95sIdaOdhHxsHPku4CRW8/sc66qKQVDv7piPw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sudBSG5BOtDBhnIkERFF8UCjXebHN7QaFM/8h8HngkWxmuNzvIfSfaEy0YIEupgP7LLc6LvbC8FWgvdtQCvtpieP6aS5dDtRVpm98xNlQ6xk24ssrZLFgdx9SxlA53ZFTTmBJhNDInsVQ9m3FDWv/T0eW0woiVFoUXf5yL5vUo5wDQa5Jf/QETEHNyzxknMgVaNzNHWuwGFmrPzcIgnIy86+QcF45GIQfWG7OOw0LjDHkS6/5TnSKQsey3J/FtJjg09TKROs+lSD+cIBXa1KRk95KZJepD9nQevVEDEYogzj086JuW+3Y5GGLVVPFI2HnTekm2lLJQ2EkFG9Oo4fHP9LODRnaX7JdLsjwOyIEcSwzt8PhiNHLTzdDlSiXS7d9cVbV7sOL+W/VNtcjD/Xg/t+7e2Vo+4jMr/gECkVl403sDc0bJlTpilmBPl3YmZnNMwK8KrnQIAOx/gDrEYFm9uo3nEkTiCxzc59OxyscLt/UEtCP79QF+sMg/P2SAIpMPSTx04i6G1MP+Q9l9GmfA6Ch1361MeR3HnVPMaCcdOK99WSe8wjwuLNmSxLJfc9SVwri8mM0ECwis4n3odHRJZcOR6p+XEQxsAkeFWlG2fYAXjDDgIKRnISi3mDkbOQnN2TnIiQczQhxtt/UgeeDew8FyB7NFFLo1/VFrDqnDg2SpGGi4NFAxmMuO3XgYIXg5iFGnR9skTPlRk4ONwMi8gf3/aBX397TmqZKQsvMsceJH/rrU9iy5XHzF0UPGxSFU3DNrXk+y6gdUCN4sSTxBCS0dIeUE7izbMkg4PIBznXDj2DbeJUIYZrfnt3iJbQENpaNO3JSjahoLJkcxn4JMDWftu3z/trMwxaubrT3lz6PpHx4WHl9mIBmtwP0N1U4AP3jG87gv+s9TXgmFYkgC90mGd692PQ8sogtSTy3JHekrotjx5Mn1Tmi3zrVjTzCQnL02rpHj8VZwU5+H+BJ+VqYd3YhOZRaFA9olNflO07+e8KneH0zQ/rC/uXPITdexW5g5tYtwpK026q9Of5c4yf0+oTyrN7U6etaBQPluSBTEKy25fHcThiuuemlUh2dRhAOez1rWqDxCHYp2bfJg72/KMH7O2YmPlqFG0gvwB9rOUV4eIlSfdhT7+2tIbsIJUcgp4d76kcp9FuN9UmHvpxkf79wE2JwLl/mGesJNyZPzC0EvPrWfWeFP+DcxVRRG++oLcPs3XjlyC1mBgsfhAM1XfkW+qBL/NTaUemcAUY+GCHCpZHZqJtuLgI4BMz78pHv6meZzvKzrmZIJG5LXrXg1LJIcGFVg6D8y/4jKTaRCT1PUNi7P2K63FErclA X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: da999d0c-40e9-4f96-1925-08d9695d7a1a X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:45.2800 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Qt3XvhOzEq0a/K813u5NwwoZ/vl8UjpfZNEsX6Ki7YkK5YWW14X62i7i7TiYmrF92LcxBVjNOrOwjuoZnDbm4AyKKvYt9pXxIig4aXFk98o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-ORIG-GUID: QmqgXVzcnpKUIv8btvnB6nEQVQbScd6R X-Proofpoint-GUID: QmqgXVzcnpKUIv8btvnB6nEQVQbScd6R Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Initial bits to bring in Secure Launch functionality. Add Kconfig options for compiling in/out the Secure Launch code. Signed-off-by: Ross Philipson --- arch/x86/Kconfig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 88fb922..b5e25c5 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1949,6 +1949,38 @@ config EFI_MIXED If unsure, say N. +config SECURE_LAUNCH + bool "Secure Launch support" + default n + depends on X86_64 && X86_X2APIC + help + The Secure Launch feature allows a kernel to be loaded + directly through an Intel TXT measured launch. Intel TXT + establishes a Dynamic Root of Trust for Measurement (DRTM) + where the CPU measures the kernel image. This feature then + continues the measurement chain over kernel configuration + information and init images. + +config SECURE_LAUNCH_ALT_PCR19 + bool "Secure Launch Alternate PCR 19 usage" + default n + depends on SECURE_LAUNCH + help + In the post ACM environment, Secure Launch by default measures + configuration information into PCR18. This feature allows finer + control over measurements by moving configuration measurements + into PCR19. + +config SECURE_LAUNCH_ALT_PCR20 + bool "Secure Launch Alternate PCR 20 usage" + default n + depends on SECURE_LAUNCH + help + In the post ACM environment, Secure Launch by default measures + image data like any external initrd into PCR17. This feature + allows finer control over measurements by moving image measurements + into PCR20. + source "kernel/Kconfig.hz" config KEXEC From patchwork Fri Aug 27 13:28:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 270CAC43216 for ; Fri, 27 Aug 2021 13:21:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EC0C60FE7 for ; Fri, 27 Aug 2021 13:21:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245243AbhH0NWM (ORCPT ); Fri, 27 Aug 2021 09:22:12 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:26190 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245196AbhH0NWC (ORCPT ); Fri, 27 Aug 2021 09:22:02 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RCCJu0015338; Fri, 27 Aug 2021 13:20:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=wbARbsBnv0x79gqOC82Uzi6mCnkoaSdr+1qX8j9c4m8=; b=fow6/a+8uGF/ojHPy+OSYsKT3/I2XJX9TM3NWEOuVXk0rdBfrTTdm1C3oroLrqCjHO1A Iir+PJCoRA3ruAIxVOOHcx7MpB9cu9k8gPCV6S7zPk4SFKXGMWRXK6+mQhdoRdfSHTG0 bH2R968Eecy+uc8ABMj7ZobnQoYsHoqoJhguZtnwdPYjlZFVQFXQ6RAJdZHDdqphI95A VzaINIUj/Kfj/CDYdnt37cRCHZXT+1lNZFE1IQ/uAiqy6NUcGLHecOlV0gUP04HRNFr9 Wusquh0dMVXWrbgcXSaH1JwLTt+OAMmfSA/RsaukMb5Lp4RtkyTR4Un6SEpGc8ZqDsIJ Jw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=wbARbsBnv0x79gqOC82Uzi6mCnkoaSdr+1qX8j9c4m8=; b=hIgC65GaJ023Yl0eiA70B4IP6LJ3+9KMEG6NRr0jXAbcGu5bHsq6bfAJK50o4o4N4Xkh pbGNY4orX7wlncJ+xA2u+iLWwStsVUIJTa+tnD6CidHzfwWl3E4/ULWs1r98GmggFlnb iPgs02f/9+rk1xFYUCtsMNjsvN3IaIQcd5H5OPEOpLL+TJI8K5j+NFcsJ+eDvMg2wLie 3fUHo373pWnAKkwd6mGhlPAeZFfoAz+E7SuQnZDy55/ZgVKiIHIeHt5bJjOWv3n0ImWj kuoKT6R5Z3Hy1uq/UFkRZmUTF4k28X5XzpeTk4iu2g21XWSn2vZ5Z3blGixcIWw4dlgO cg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3apvjr0ktu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:51 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RD9ouc076983; Fri, 27 Aug 2021 13:20:49 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2041.outbound.protection.outlook.com [104.47.51.41]) by userp3030.oracle.com with ESMTP id 3ajpm4pqa4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jAhkCFk1Uk2q1gvUyLtciTTZHIq8giEZqUWFwQTzy77vOWTkSjPXTFyWK+gQlwMP4CUDGnOx7xxChSK1gGEZZwKZoOXbXPYTRIW+MxLGceJiySbTdKQZCkO68kvC6w0DPxwhmM1xJBpo9Whovy6Mr7jUCHNxkPXjoz52bhfdoCvY9pPuQBTLarV1j/6Kue/Jph6Dh6jvSoUySSuG0ivjDsDv+h9990Swg9NdnUta7J4HgdQfU0foBjoDZmdu51wLwklVUX9jJ2UdrLrBqaMwcpr+dHu7P0uBq+ZAu49qfEyKafrM0pa4LDFcU00IT/J7N8zFMPZMJq0UD9JMgzcyEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wbARbsBnv0x79gqOC82Uzi6mCnkoaSdr+1qX8j9c4m8=; b=VMaGdcFRxYBx7KmeCNGxyP+HgyKcxV0rNH2bwd3pE5tSynN3mrtGHu9G7mZEh/1oC3Qg0K/LYi+yv+p6ozavn2FY2djKye/BHruXa9XxO/UJotdpr7w+nYnftfBETrTyeAbtFVdBFH29FGOlo97pUo5B6nRkv8mc0ZTkmfy11GEecjbbPVzz09nePCs/N3Z4Kz5Nfe2uYWeCxAmcTfDaYTp8qniLihuGMw07zmFBAN1cHP0bRRp6/2j0qS+dsk8MYBX2xgvkuIDXk4mpn6Aymsc2xLkKNbw5aiMgqjEy00H+++42t3nAluG471YVdLnjcyXsfWIO3sWHePrEw9bH7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wbARbsBnv0x79gqOC82Uzi6mCnkoaSdr+1qX8j9c4m8=; b=Z5BcEaGDPB3dcjCt8V6Rk6GSHID1spAwC50OSwkoBTtHU4LmLz4eQc/LS+5s4OG/4l8HphHKGXjPeQbEGAPl9F9wFw/tNyNCAxc88aRwb76PQtwr/ibbQMWJu1ZLuW9kaUS2UB0gPHWyHPLjeB/PIM5mdyjDYsPAWPBv3kd56QI= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:47 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:47 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 06/14] x86: Secure Launch main header file Date: Fri, 27 Aug 2021 09:28:29 -0400 Message-Id: <1630070917-9896-7-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 347e2a2c-beda-4fad-af9d-08d9695d7b22 X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8CjDf79BEzuIr3bGxGyQGWWm+9t1RBWBBuPAWp/eFUXaq8soeV8k8kDV7hOtiqGTsPbG9Cw1clJjYxJ0NZEdI9j7U1Ex2EF/oz6z/iAHWJKja2heLDNQCIzmjnTZudW66BL05NxVRxivJffVpVkar+WbuUezbuAV72TYl954uC1C7PUwg4VVHr6Q/amlPUtZFg2JvMK/G6ZBQmi2PK+uJN3GD55MEnSxRwDeO8i9EJwv3rMYL1q2T95FlcgRYi5yDB+coF+yDaykRVjBVbiZ8oUOxfQauKt9m3RG5m8BAv62/7k35MSvIl/TiZqndh7WNkJOjRckBd6bb1L7WuZFqWg4IJ/EPUVQw0r8T+7wMSAZObvW40e+tGY5sCuiwD4Y5FmmPkdyGCCnkdtIJv9tw+2jc3NyqtEIKVMrHFYyj2BVhVqzdgaqYZYw1pafhntKT4EQRxCMuGWiVjc4kfwdlfdqlBJSp3y3f7GgKz8hVk1wYxr0ixRf5b7im8B8tpj4+OyHfx/MRIgXMyU9kLXcvc+v5OwneDf3k1FqqfrfXu60/0vEPlMz3kXSUQw+LL5ePg0saaUe6m6Gfb5xDcWnL15x/0VPl1LzAb8yYURAFX4Hl2GxF/HsrEzagg6E5hDw/jZ4q+HZG5eMUIc1kOWPMBY4jN24FOjUSbwaFcz/ONq2wz4p+eJ36w4y3bniElYQtp7cUSiUe0/a0zUCxCDDug== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(30864003)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AAJKWPYH+dDURApKciEgibZ5HLJz?= =?utf-8?q?sHG8p9AKVya0J7FlfNVdpt345JwHYOIJ/xsPW+18oma7t7CypmBttcfWkTEbdXHAF?= =?utf-8?q?N9q+Z28Qf4T6YAMtiWV7w6XOwA1h2w8IKlB4RqFwO5+09Wvvw86QxvdT40iGR/UUA?= =?utf-8?q?fyDmIn4Vj19chIxdZzHYPYExemGhRASdvqch5LMiHqYomqi+0zgT9UNfx45Ru6koi?= =?utf-8?q?YYZHvA7AJ3KS3HnnFPlHD+lu89h67pTXe66xqZKhYADQR71ADKVQv2GkAPTi/Ltfz?= =?utf-8?q?WNBgEY/CUqpn1Bn5JVltHbp5/7C2UE66GF5ONKqCyQmiW4lJSeoeL1e/rWfmpZ/BT?= =?utf-8?q?H65UzNgIJU8ewvGUfoCzDePlBmnBTKLrHoJ7kWwquw+XCJUwU7lg1/gdp6nTq+C3U?= =?utf-8?q?vvfpuN83tkbJ+OFjAwTHIFXgoUNSPfr4MRy+cVwuz2A0W3XiBk4r89EMu+QbGvDSw?= =?utf-8?q?cWQ87EJFx6OYFz3i9PjP+u/UiDwv73cYz3MPcSuOJxi+3gDTO003HFmuYefbWrkFo?= =?utf-8?q?cRZ0jvOFK1GeyShW/UkczPlJK1dn05sB04V4vCeyWiCwWMd1FZ9mNm2OQE0zg9JMN?= =?utf-8?q?SQRW/i8iA8X7MpCPF0eskC3P/xio4AP+R+Xlg4bgy6yA0bYBwW+7D3xS7HXaOMOJG?= =?utf-8?q?IZzYdLMwvSCDz/raDzpO4IWPWqQ8woJ2en2Pd1wcTegkCywMM/yxbiobE6AAVhSwx?= =?utf-8?q?NqzJkiAlBPUmy8hgwrD53BThizKfeRC5CBkl7TkQLhCWCSWiuDmIed/Xcz1CV3Big?= =?utf-8?q?WyA37015INIzAwZVR22XkOrO/+HYl8WcJQMeOivjry1pUrcNiCu33Y3o0YZorLW6C?= =?utf-8?q?7BFeLkwNQtDnDF14KRjFlfFA3du76pA90qSZD9oGipGO1HEQu4B8FT0BqGG1GFMLo?= =?utf-8?q?1u6UXb0iFM7KjjEBdLN4WGVdQJkGaN4jqPpXXozC7zULJtlhjkPAn6WOthppsHrFV?= =?utf-8?q?dmfmxiLzB+XrioC4VvaL3MVopq3eiayZoI+C//mTSzqrQqnXjuoES/TLgZHZ0B9e3?= =?utf-8?q?wzHNwZF9jPXPPBN5Yabth24Uu0dg419oxecW2aawiUcz+8zJqzcyeXwbYhxe9dy/J?= =?utf-8?q?e0CaPDVsg7B6MZ/eDIlrYgnI8s/H+FbabsbuEeyYfn5Z6TTLh7vyklYb42794jYIV?= =?utf-8?q?sUq3ADZhys3DH5cOyxTeQbTuqYMh6mgjdxJpc/sW+s5cqeZNpRdBkVqGTCnPLoPBf?= =?utf-8?q?6GWUcq2M4ZVIKF2JocriPw0wlCLjDMq79dKwc8DWgAiyHxFoffMWB9aCcQGBUQ0Ls?= =?utf-8?q?gUvglTp6El4ZyXoy?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 347e2a2c-beda-4fad-af9d-08d9695d7b22 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:46.9900 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LK4DSw9p1UNRkbbuJMoEmfUZLheTV1Fij0+75XkxHLjL+uDruwldGMPQBKWQtsg/jxV+YUEdsLipQTyKrwJ4GMrktq8k/qX/nlLmcwGNR4Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: tuWC_Rq9DvL0g4WnQDB91iQT8BFWMr0D X-Proofpoint-ORIG-GUID: tuWC_Rq9DvL0g4WnQDB91iQT8BFWMr0D Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Introduce the main Secure Launch header file used in the early SL stub and the early setup code. Signed-off-by: Ross Philipson --- include/linux/slaunch.h | 532 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 532 insertions(+) create mode 100644 include/linux/slaunch.h diff --git a/include/linux/slaunch.h b/include/linux/slaunch.h new file mode 100644 index 0000000..c125b67 --- /dev/null +++ b/include/linux/slaunch.h @@ -0,0 +1,532 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Main Secure Launch header file. + * + * Copyright (c) 2021, Oracle and/or its affiliates. + */ + +#ifndef _LINUX_SLAUNCH_H +#define _LINUX_SLAUNCH_H + +/* + * Secure Launch Defined State Flags + */ +#define SL_FLAG_ACTIVE 0x00000001 +#define SL_FLAG_ARCH_SKINIT 0x00000002 +#define SL_FLAG_ARCH_TXT 0x00000004 + +/* + * Secure Launch CPU Type + */ +#define SL_CPU_AMD 1 +#define SL_CPU_INTEL 2 + +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + +#define __SL32_CS 0x0008 +#define __SL32_DS 0x0010 + +/* + * Intel Safer Mode Extensions (SMX) + * + * Intel SMX provides a programming interface to establish a Measured Launched + * Environment (MLE). The measurement and protection mechanisms supported by the + * capabilities of an Intel Trusted Execution Technology (TXT) platform. SMX is + * the processor’s programming interface in an Intel TXT platform. + * + * See Intel SDM Volume 2 - 6.1 "Safer Mode Extensions Reference" + */ + +/* + * SMX GETSEC Leaf Functions + */ +#define SMX_X86_GETSEC_SEXIT 5 +#define SMX_X86_GETSEC_SMCTRL 7 +#define SMX_X86_GETSEC_WAKEUP 8 + +/* + * Intel Trusted Execution Technology MMIO Registers Banks + */ +#define TXT_PUB_CONFIG_REGS_BASE 0xfed30000 +#define TXT_PRIV_CONFIG_REGS_BASE 0xfed20000 +#define TXT_NR_CONFIG_PAGES ((TXT_PUB_CONFIG_REGS_BASE - \ + TXT_PRIV_CONFIG_REGS_BASE) >> PAGE_SHIFT) + +/* + * Intel Trusted Execution Technology (TXT) Registers + */ +#define TXT_CR_STS 0x0000 +#define TXT_CR_ESTS 0x0008 +#define TXT_CR_ERRORCODE 0x0030 +#define TXT_CR_CMD_RESET 0x0038 +#define TXT_CR_CMD_CLOSE_PRIVATE 0x0048 +#define TXT_CR_DIDVID 0x0110 +#define TXT_CR_VER_EMIF 0x0200 +#define TXT_CR_CMD_UNLOCK_MEM_CONFIG 0x0218 +#define TXT_CR_SINIT_BASE 0x0270 +#define TXT_CR_SINIT_SIZE 0x0278 +#define TXT_CR_MLE_JOIN 0x0290 +#define TXT_CR_HEAP_BASE 0x0300 +#define TXT_CR_HEAP_SIZE 0x0308 +#define TXT_CR_SCRATCHPAD 0x0378 +#define TXT_CR_CMD_OPEN_LOCALITY1 0x0380 +#define TXT_CR_CMD_CLOSE_LOCALITY1 0x0388 +#define TXT_CR_CMD_OPEN_LOCALITY2 0x0390 +#define TXT_CR_CMD_CLOSE_LOCALITY2 0x0398 +#define TXT_CR_CMD_SECRETS 0x08e0 +#define TXT_CR_CMD_NO_SECRETS 0x08e8 +#define TXT_CR_E2STS 0x08f0 + +/* TXT default register value */ +#define TXT_REGVALUE_ONE 0x1ULL + +/* TXTCR_STS status bits */ +#define TXT_SENTER_DONE_STS (1<<0) +#define TXT_SEXIT_DONE_STS (1<<1) + +/* + * SINIT/MLE Capabilities Field Bit Definitions + */ +#define TXT_SINIT_MLE_CAP_WAKE_GETSEC 0 +#define TXT_SINIT_MLE_CAP_WAKE_MONITOR 1 + +/* + * OS/MLE Secure Launch Specific Definitions + */ +#define TXT_OS_MLE_STRUCT_VERSION 1 +#define TXT_OS_MLE_MAX_VARIABLE_MTRRS 32 + +/* + * TXT Heap Table Enumeration + */ +#define TXT_BIOS_DATA_TABLE 1 +#define TXT_OS_MLE_DATA_TABLE 2 +#define TXT_OS_SINIT_DATA_TABLE 3 +#define TXT_SINIT_MLE_DATA_TABLE 4 +#define TXT_SINIT_TABLE_MAX TXT_SINIT_MLE_DATA_TABLE + +/* + * Secure Launch Defined Error Codes used in MLE-initiated TXT resets. + * + * TXT Specification + * Appendix I ACM Error Codes + */ +#define SL_ERROR_GENERIC 0xc0008001 +#define SL_ERROR_TPM_INIT 0xc0008002 +#define SL_ERROR_TPM_INVALID_LOG20 0xc0008003 +#define SL_ERROR_TPM_LOGGING_FAILED 0xc0008004 +#define SL_ERROR_REGION_STRADDLE_4GB 0xc0008005 +#define SL_ERROR_TPM_EXTEND 0xc0008006 +#define SL_ERROR_MTRR_INV_VCNT 0xc0008007 +#define SL_ERROR_MTRR_INV_DEF_TYPE 0xc0008008 +#define SL_ERROR_MTRR_INV_BASE 0xc0008009 +#define SL_ERROR_MTRR_INV_MASK 0xc000800a +#define SL_ERROR_MSR_INV_MISC_EN 0xc000800b +#define SL_ERROR_INV_AP_INTERRUPT 0xc000800c +#define SL_ERROR_INTEGER_OVERFLOW 0xc000800d +#define SL_ERROR_HEAP_WALK 0xc000800e +#define SL_ERROR_HEAP_MAP 0xc000800f +#define SL_ERROR_REGION_ABOVE_4GB 0xc0008010 +#define SL_ERROR_HEAP_INVALID_DMAR 0xc0008011 +#define SL_ERROR_HEAP_DMAR_SIZE 0xc0008012 +#define SL_ERROR_HEAP_DMAR_MAP 0xc0008013 +#define SL_ERROR_HI_PMR_BASE 0xc0008014 +#define SL_ERROR_HI_PMR_SIZE 0xc0008015 +#define SL_ERROR_LO_PMR_BASE 0xc0008016 +#define SL_ERROR_LO_PMR_MLE 0xc0008017 +#define SL_ERROR_INITRD_TOO_BIG 0xc0008018 +#define SL_ERROR_HEAP_ZERO_OFFSET 0xc0008019 +#define SL_ERROR_WAKE_BLOCK_TOO_SMALL 0xc000801a +#define SL_ERROR_MLE_BUFFER_OVERLAP 0xc000801b +#define SL_ERROR_BUFFER_BEYOND_PMR 0xc000801c +#define SL_ERROR_OS_SINIT_BAD_VERSION 0xc000801d +#define SL_ERROR_EVENTLOG_MAP 0xc000801e +#define SL_ERROR_TPM_NUMBER_ALGS 0xc000801f +#define SL_ERROR_TPM_UNKNOWN_DIGEST 0xc0008020 +#define SL_ERROR_TPM_INVALID_EVENT 0xc0008021 + +/* + * Secure Launch Defined Limits + */ +#define TXT_MAX_CPUS 512 +#define TXT_BOOT_STACK_SIZE 24 + +/* + * Secure Launch event log entry type. The TXT specification defines the + * base event value as 0x400 for DRTM values. + */ +#define TXT_EVTYPE_BASE 0x400 +#define TXT_EVTYPE_SLAUNCH (TXT_EVTYPE_BASE + 0x102) +#define TXT_EVTYPE_SLAUNCH_START (TXT_EVTYPE_BASE + 0x103) +#define TXT_EVTYPE_SLAUNCH_END (TXT_EVTYPE_BASE + 0x104) + +/* + * Measured Launch PCRs + */ +#define SL_DEF_IMAGE_PCR17 17 /* TCG Details PCR */ +#define SL_DEF_CONFIG_PCR18 18 /* TCG Authorities PCR */ +#define SL_ALT_CONFIG_PCR19 19 +#define SL_ALT_IMAGE_PCR20 20 + +/* + * MLE scratch area offsets + */ +#define SL_SCRATCH_AP_EBX 0 +#define SL_SCRATCH_AP_JMP_OFFSET 4 +#define SL_SCRATCH_AP_PAUSE 8 + +#ifndef __ASSEMBLY__ + +#include +#include +#include + +/* + * Secure Launch AP wakeup information fetched in SMP boot code. + */ +struct sl_ap_wake_info { + u32 ap_wake_block; + u32 ap_wake_block_size; + u32 ap_jmp_offset; +}; + +/* + * TXT heap extended data elements. + */ +struct txt_heap_ext_data_element { + u32 type; + u32 size; + /* Data */ +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_END 0 + +struct txt_heap_end_element { + u32 type; + u32 size; +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_TPM_EVENT_LOG_PTR 5 + +struct txt_heap_event_log_element { + u64 event_log_phys_addr; +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_EVENT_LOG_POINTER2_1 8 + +struct txt_heap_event_log_pointer2_1_element { + u64 phys_addr; + u32 allocated_event_container_size; + u32 first_record_offset; + u32 next_record_offset; +} __packed; + +/* + * Secure Launch defined MTRR saving structures + */ +struct txt_mtrr_pair { + u64 mtrr_physbase; + u64 mtrr_physmask; +} __packed; + +struct txt_mtrr_state { + u64 default_mem_type; + u64 mtrr_vcnt; + struct txt_mtrr_pair mtrr_pair[TXT_OS_MLE_MAX_VARIABLE_MTRRS]; +} __packed; + +/* + * Secure Launch defined OS/MLE TXT Heap table + */ +struct txt_os_mle_data { + u32 version; + u32 boot_params_addr; + u64 saved_misc_enable_msr; + struct txt_mtrr_state saved_bsp_mtrrs; + u32 ap_wake_block; + u32 ap_wake_block_size; + u64 evtlog_addr; + u32 evtlog_size; + u8 mle_scratch[64]; +} __packed; + +/* + * TXT specification defined BIOS data TXT Heap table + */ +struct txt_bios_data { + u32 version; /* Currently 5 for TPM 1.2 and 6 for TPM 2.0 */ + u32 bios_sinit_size; + u64 reserved1; + u64 reserved2; + u32 num_logical_procs; + /* Versions >= 5 with updates in version 6 */ + u32 sinit_flags; + u32 mle_flags; + /* Versions >= 4 */ + /* Ext Data Elements */ +} __packed; + +/* + * TXT specification defined OS/SINIT TXT Heap table + */ +struct txt_os_sinit_data { + u32 version; /* Currently 6 for TPM 1.2 and 7 for TPM 2.0 */ + u32 flags; + u64 mle_ptab; + u64 mle_size; + u64 mle_hdr_base; + u64 vtd_pmr_lo_base; + u64 vtd_pmr_lo_size; + u64 vtd_pmr_hi_base; + u64 vtd_pmr_hi_size; + u64 lcp_po_base; + u64 lcp_po_size; + u32 capabilities; + /* Version = 5 */ + u64 efi_rsdt_ptr; + /* Versions >= 6 */ + /* Ext Data Elements */ +} __packed; + +/* + * TXT specification defined SINIT/MLE TXT Heap table + */ +struct txt_sinit_mle_data { + u32 version; /* Current values are 6 through 9 */ + /* Versions <= 8 */ + u8 bios_acm_id[20]; + u32 edx_senter_flags; + u64 mseg_valid; + u8 sinit_hash[20]; + u8 mle_hash[20]; + u8 stm_hash[20]; + u8 lcp_policy_hash[20]; + u32 lcp_policy_control; + /* Versions >= 7 */ + u32 rlp_wakeup_addr; + u32 reserved; + u32 num_of_sinit_mdrs; + u32 sinit_mdrs_table_offset; + u32 sinit_vtd_dmar_table_size; + u32 sinit_vtd_dmar_table_offset; + /* Versions >= 8 */ + u32 processor_scrtm_status; + /* Versions >= 9 */ + /* Ext Data Elements */ +} __packed; + +/* + * TXT data reporting structure for memory types + */ +struct txt_sinit_memory_descriptor_record { + u64 address; + u64 length; + u8 type; + u8 reserved[7]; +} __packed; + +/* + * TXT data structure used by a responsive local processor (RLP) to start + * execution in response to a GETSEC[WAKEUP]. + */ +struct smx_rlp_mle_join { + u32 rlp_gdt_limit; + u32 rlp_gdt_base; + u32 rlp_seg_sel; /* cs (ds, es, ss are seg_sel+8) */ + u32 rlp_entry_point; /* phys addr */ +} __packed; + +/* + * TPM event log structures defined in both the TXT specification and + * the TCG documentation. + */ +#define TPM12_EVTLOG_SIGNATURE "TXT Event Container" + +struct tpm12_event_log_header { + char signature[20]; + char reserved[12]; + u8 container_ver_major; + u8 container_ver_minor; + u8 pcr_event_ver_major; + u8 pcr_event_ver_minor; + u32 container_size; + u32 pcr_events_offset; + u32 next_event_offset; + /* PCREvents[] */ +} __packed; + +/* + * Functions to extract data from the Intel TXT Heap Memory. The layout + * of the heap is as follows: + * +----------------------------+ + * | Size Bios Data table (u64) | + * +----------------------------+ + * | Bios Data table | + * +----------------------------+ + * | Size OS MLE table (u64) | + * +----------------------------+ + * | OS MLE table | + * +--------------------------- + + * | Size OS SINIT table (u64) | + * +----------------------------+ + * | OS SINIT table | + * +----------------------------+ + * | Size SINIT MLE table (u64) | + * +----------------------------+ + * | SINIT MLE table | + * +----------------------------+ + * + * NOTE: the table size fields include the 8 byte size field itself. + */ +static inline u64 txt_bios_data_size(void *heap) +{ + return *((u64 *)heap); +} + +static inline void *txt_bios_data_start(void *heap) +{ + return heap + sizeof(u64); +} + +static inline u64 txt_os_mle_data_size(void *heap) +{ + return *((u64 *)(heap + txt_bios_data_size(heap))); +} + +static inline void *txt_os_mle_data_start(void *heap) +{ + return heap + txt_bios_data_size(heap) + sizeof(u64); +} + +static inline u64 txt_os_sinit_data_size(void *heap) +{ + return *((u64 *)(heap + txt_bios_data_size(heap) + + txt_os_mle_data_size(heap))); +} + +static inline void *txt_os_sinit_data_start(void *heap) +{ + return heap + txt_bios_data_size(heap) + + txt_os_mle_data_size(heap) + sizeof(u64); +} + +static inline u64 txt_sinit_mle_data_size(void *heap) +{ + return *((u64 *)(heap + txt_bios_data_size(heap) + + txt_os_mle_data_size(heap) + + txt_os_sinit_data_size(heap))); +} + +static inline void *txt_sinit_mle_data_start(void *heap) +{ + return heap + txt_bios_data_size(heap) + + txt_os_mle_data_size(heap) + + txt_sinit_mle_data_size(heap) + sizeof(u64); +} + +/* + * TPM event logging functions. + */ +static inline struct txt_heap_event_log_pointer2_1_element* +tpm20_find_log2_1_element(struct txt_os_sinit_data *os_sinit_data) +{ + struct txt_heap_ext_data_element *ext_elem; + + /* The extended element array as at the end of this table */ + ext_elem = (struct txt_heap_ext_data_element *) + ((u8 *)os_sinit_data + sizeof(struct txt_os_sinit_data)); + + while (ext_elem->type != TXT_HEAP_EXTDATA_TYPE_END) { + if (ext_elem->type == + TXT_HEAP_EXTDATA_TYPE_EVENT_LOG_POINTER2_1) { + return (struct txt_heap_event_log_pointer2_1_element *) + ((u8 *)ext_elem + + sizeof(struct txt_heap_ext_data_element)); + } + ext_elem = + (struct txt_heap_ext_data_element *) + ((u8 *)ext_elem + ext_elem->size); + } + + return NULL; +} + +static inline int tpm12_log_event(void *evtlog_base, u32 evtlog_size, + u32 event_size, void *event) +{ + struct tpm12_event_log_header *evtlog = + (struct tpm12_event_log_header *)evtlog_base; + + if (memcmp(evtlog->signature, TPM12_EVTLOG_SIGNATURE, + sizeof(TPM12_EVTLOG_SIGNATURE))) + return -EINVAL; + + if (evtlog->container_size > evtlog_size) + return -EINVAL; + + if (evtlog->next_event_offset + event_size > evtlog->container_size) + return -E2BIG; + + memcpy(evtlog_base + evtlog->next_event_offset, event, event_size); + evtlog->next_event_offset += event_size; + + return 0; +} + +static inline int tpm20_log_event(struct txt_heap_event_log_pointer2_1_element *elem, + void *evtlog_base, u32 evtlog_size, + u32 event_size, void *event) +{ + struct tcg_pcr_event *header = + (struct tcg_pcr_event *)evtlog_base; + + /* Has to be at least big enough for the signature */ + if (header->event_size < sizeof(TCG_SPECID_SIG)) + return -EINVAL; + + if (memcmp((u8 *)header + sizeof(struct tcg_pcr_event), + TCG_SPECID_SIG, sizeof(TCG_SPECID_SIG))) + return -EINVAL; + + if (elem->allocated_event_container_size > evtlog_size) + return -EINVAL; + + if (elem->next_record_offset + event_size > + elem->allocated_event_container_size) + return -E2BIG; + + memcpy(evtlog_base + elem->next_record_offset, event, event_size); + elem->next_record_offset += event_size; + + return 0; +} + +/* + * External functions avalailable in compressed kernel. + */ +extern u32 slaunch_get_cpu_type(void); + +/* + * External functions avalailable in mainline kernel. + */ +extern void slaunch_setup_txt(void); +extern u32 slaunch_get_flags(void); +extern struct sl_ap_wake_info *slaunch_get_ap_wake_info(void); +extern struct acpi_table_header *slaunch_get_dmar_table(struct acpi_table_header *dmar); +extern void __noreturn slaunch_txt_reset(void __iomem *txt, + const char *msg, u64 error); +extern void slaunch_finalize(int do_sexit); + +#endif /* !__ASSEMBLY */ + +#else + +#define slaunch_get_cpu_type() 0 +#define slaunch_setup_txt() do { } while (0) +#define slaunch_get_flags() 0 +#define slaunch_get_dmar_table(d) (d) +#define slaunch_finalize(d) do { } while (0) + +#endif /* !IS_ENABLED(CONFIG_SECURE_LAUNCH) */ + +#endif /* _LINUX_SLAUNCH_H */ From patchwork Fri Aug 27 13:28:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBFBCC19F35 for ; Fri, 27 Aug 2021 13:21:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D75BF60FD9 for ; Fri, 27 Aug 2021 13:21:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245192AbhH0NWI (ORCPT ); Fri, 27 Aug 2021 09:22:08 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:28174 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245153AbhH0NWB (ORCPT ); Fri, 27 Aug 2021 09:22:01 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RA8dsT025578; Fri, 27 Aug 2021 13:20:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=ryFmKdn22aDzTv7hHbtLareszmknkHuvUfAEeNFJAMw=; b=xhFGcUFwrN6ewYsW+QVqZkNY5IF/4glpZhjosMVPbcsMI8MqmBPDxb270ptCxpL/SOid ntKLisXwmvqVB63nmDsIV+scIovW0Cm4YNIAobJuR4pJ4bCxNI+d3/wIdPZzNpAmhRwx PK5bdpurOFIdo2Yv8pnL4QxtoPHDj3S9O7+2Q5izKliJQht/6qy0lO2iEqmfKDP7JN1/ VJ5Nalir5pMPxbXopbuOc8O62oOnN/D4WgaMYCItIr0wHo2e2G9VHzjxETuX44S00wLx MWwR3/Fm/1xNYS4Zha8gFmYFapYrQF36a7VXPvbDf8kMeoyqrIKD2iUJ5GnhWvdj8rfk fA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=ryFmKdn22aDzTv7hHbtLareszmknkHuvUfAEeNFJAMw=; b=PmXxhYdf8zaVv19lqdt8YZ4rtP4jiF3HCmQ8PWiHCtsYwqF1nOwIGDkbX997HwUGmPA1 YMlXZBN3DzNyBo/TIRXSCh9IhYZ9I6emDJ9BWVDKfIa7Mi0qzZcX5wJ8+MJ7+pnRa5o0 4q8x+ZJAhqXaZXrriVU2mRIQ/UyedACI94lYpCM4kzGMXBT4cOYsqPt62GxEvAQcwsKI sJCCp4gct590jlUE9Jw/oK7OFDcI8C4jyDCAISyyoiLvbup7J3xO6y+4xg2k1+oAccV3 I87krG8nU9QSSdJ1FiqnWecAis2FUUhjKQMVIzJ8vOHBLwFuHpwyQFjcvJAPeTtAGJJj dA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap3eauqkt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:51 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RD9oud076983; Fri, 27 Aug 2021 13:20:50 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2041.outbound.protection.outlook.com [104.47.51.41]) by userp3030.oracle.com with ESMTP id 3ajpm4pqa4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aYyHW2sSW+E5Ziwy3YazlnLm97s8vIFRi0KoTenxUEBJb26ZtzscVi/ozbUbuH6kJMN9hg/jTkdX2ejY8PmChnK6SjfqAHhEZAbBNxHTews5317OYJI13008iQqnP9FIB3ZudtjYfXsE/WIwk7xq7Nq1o3UHWLDy9DUGZi2mUkaIQWYFJPMnLrxIBHa2UwK6AL9TNyKIeWHduTpqBPp5ZqX5Bh4Kmzf9B69x42kwbaz5mFBTDUT0B1Zveqhg0FyE9ZLKd/Nnwp7fjn47nvSIMje0Ik4gcIh8MS5lmE4xCrRDAGVqCvUYPyO3L0cLxKM5u/AwC8xwWRd+od8y/VpArw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ryFmKdn22aDzTv7hHbtLareszmknkHuvUfAEeNFJAMw=; b=cYliL/fJqjRaRxJap9LryXh5hs0BRiwUsdjFShFWrbyLhM6mHUtLiukNATIoU1X62fdsPMlFvdmULkjoRsukA95vDuFNFq54dYLOX5yF+0c/oRq90kGt7PcF+4/B582q2wUHc2t6mqjCdVPKJCjDtuJovnPODlEvbbEh3RhAffAQP9CD8MTSNufUXoZzS60Jh0eP5XjohOdzUCuhd7Kjhj+8UHbjNJ5rXwdExvsxuf6rZPE+q0xOsfvFLHqysBxPamERa8T5Q3KfOEkt5mLNW0eZvMzo16SPPWe3K20PbhakEo4ach+Yqybx9CqoxJHMgoNvUEAB7PEXkd0yvNUxmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ryFmKdn22aDzTv7hHbtLareszmknkHuvUfAEeNFJAMw=; b=Ezf/KzfqMzdeT1qfRW1jYm9WGpzRh5fzlEzL4aBg1ahcsmBAkOKOOf2wW5Nn6hYqw7G7Yvlb1b4o77eU+M83hfXaGTdHsqhXgkojE46+NXDJIPogsA7KbsUavNm4FBhKKA0GkEVTKSWISow59OCnkVKt1oMplJzbXnVv/PHkb1k= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:48 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:48 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 07/14] x86: Add early SHA support for Secure Launch early measurements Date: Fri, 27 Aug 2021 09:28:30 -0400 Message-Id: <1630070917-9896-8-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e33f5f5c-bda8-41a8-b75c-08d9695d7c24 X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O2MTsUjJtFIjmgJ/884LO9SCXZvBoDSOT/+1b5O/kUwQQJ5IudOVtzVdQqvhYj8KFDsJnUC1JgsaHNAXticBoZz5AL58cUp+xM4ZrxQ5xAgJ2NrIZ/TFrBl62cBtSwSfDZYQmy8CwdSy8JJZox0Uyw0fIrcelXmrkrP2CjB4U9D2X+5VUAyWM3KF4IdniHsK/vxKpVovGeieVhlYC4AC1FyHnX/JDuEP1txLeDft7x41BiMC73vNabQ1gMih+2Cvv/09WEHtW0F5jHs2UUVAM1Q4E5PVL/HZOna+iyuI2OWQmLn6UnZCD7x780DYBjf2uTdd+4qZQm8O/PTKHW7Ae1brerU1yds9KLGiaP51eLYsbMdOxXc10c3KZVOBdBhDaItOKHatpTNKcJ9948j81U8+ZydeGM2Cfpvqb4PsbprHlHV5O2/RvcwQBmbgnIqRDa3tvtZdqAd8IKZMPHESkU367l9T5SHWvK5WJxmxHRultN79Ht1FplPb/7W0belUdTR1KQLNXyzlE8+BRTOnhNwnY6DR+y+Px1l8almGQoQagBtp9oC9O7eotGtv5A5WflywVKziEXq4AlkaVmbcwiY0k7TCq3BrNQMV8CsjpCrutwK5B3vFUQNlZM4+dB781MumWSnJfhPq5dOO8uXQSLjRf2F+xeVAl+/7TrB3n8dxVlwu6NGOZp3c5zoLeuxSa3sjmlZzFoN+9liI6w850A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rh1DckNapPGX41PPTfvPTQbt2zD4a/ohioOziajk4T6rutPWKK6s+/BOicCpdWoSTkcGnXlIgjk+DL20P6iRJt4m+KUCXdFIr+wucSgXxqRrnNVVs+moWtT9G0rHLSAWxY4PnWf9uQUZPAt4E3gD7hTbGIUCi0+LCfChT1DpZeUPBG1WqgQHqzK5cSVaUi40PYaXNaG0wsMlgeE23g95duYvcVv/dVf8Op25a9qIHBjv4UGzv5E9BklbMvV3Xu2gg6WgmOeVwFYrfGyIXv3C+pqosaV0ZoermCaaJFWTPbVVhUKY964g5uSGiCLyNlGZHWTx/mSG8I5bHWau4yjNRV8mqIZAau5pRN+yYnzdT02pNsntTM4iNhWjO4rQyxT7vqM0HcoFWZe9u7YhLnOqgFo2S/qBqgs44rCAGPClZ9cJAnhZ6IZZLB0VKX5uTyt04GAr36A7pP6UXaNNeyOzYcxUKRGz66CVMz5/NzMwWxcbhbmHiJhknc8Qgq9Emlsc60aUHq7SN6fswFwik7CFUaUfAWd1lKHlhXmizTVRpWreH1w5jH5T61mhD3rWqwRU2tly/vVD536mjJC8GJD0wMagvVXV+QUIqYd/C4vawsdtMbWOG+0k8Ig9Fn9CHnVXrXJwKx7zWGg4tbG55fI0gu7ws4djtK8/mlG7nmx0l8eD1ulrXpVQVIOKA5/M0HrjufOStGo6OoCc3LafNI8IKHLtT3GiqHNSJpQOfqT84ZO6wHKJjIbXnowAOnKmVgbrao3iyrzUs9a9N6oHrBZTqaaESmJGLGBsCLab995j9ZPe+/DUs0y/lt7cmD7fFgpJj2M5Cc/GtmiOn93BsDedq5BkBufNRSrZXMUyicToL6Nf7yMrnzjxE/0PdrcT8nwuFE+yvQPnBGFC3AIoDQ6sPDwONpSAhbYVWJ2v1JF4dT5heU5sF5QrDgl/RRsJNU95jWUf16U8gNl7zmC3ob1uvDJrr+Bc5ZTOHbnzceiTuVYo3ZnJepe/Qes8oqnuw63vLhuFNLU8mVQAna3aVkg9YAuPW7AmwmX6UceZWDoO72hHIMqkpeBGIafBnyeU7VVeCb+NTD11vwmxBt99SqQZ4T3kxB5QuWjXCmp4qwBQKkYVmFWXcYw/gHyf2LoGKZpjq8jU0MAQoq9xA7n9nt2tGGmKrd/Mlr0VgQ+v5Z69O1ClPGPMd0kdOUbQhIPifouQVtiqZzZKGa2XMabaURCs9l9rOG89vOEzR9LpiXFCvq8vokZhI6dQj5359EouSGR/FB0RW4EFfJKQPJObPCp0ZkcYkcinyqIJnlBj7qBFMEe/AP+dxHZQxHndM6rn3Bl4 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e33f5f5c-bda8-41a8-b75c-08d9695d7c24 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:48.6591 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /8sx5g9P6PNdyI77w9Pl9xvuC9v5z9gxCa7gVHMk3MDltm5MjHFn1PFc0C3qKW8tMm3QntTG3gd4J03t4pwyF5Gfmls7kEN+Aq53JZfKt0o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-ORIG-GUID: 2miuq_qZC1s68I_qsjvuqUng2blpsPLM X-Proofpoint-GUID: 2miuq_qZC1s68I_qsjvuqUng2blpsPLM Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: "Daniel P. Smith" The SHA algorithms are necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA libraries directly in the code since the compressed kernel is not uncompressed at this point. The SHA code here has its origins in the code from the main kernel, commit c4d5b9ffa31f (crypto: sha1 - implement base layer for SHA-1). That code could not be pulled directly into the setup portion of the compressed kernel because of other dependencies it pulls in. The result is this is a modified copy of that code that still leverages the core SHA algorithms. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/boot/compressed/Makefile | 2 + arch/x86/boot/compressed/early_sha1.c | 103 ++++++++++++++++++++++++++++++++ arch/x86/boot/compressed/early_sha1.h | 17 ++++++ arch/x86/boot/compressed/early_sha256.c | 7 +++ lib/crypto/sha256.c | 8 +++ lib/sha1.c | 4 ++ 6 files changed, 141 insertions(+) create mode 100644 arch/x86/boot/compressed/early_sha1.c create mode 100644 arch/x86/boot/compressed/early_sha1.h create mode 100644 arch/x86/boot/compressed/early_sha256.c diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 431bf7f..059d49a 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -102,6 +102,8 @@ vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a +vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o + $(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE $(call if_changed,ld) diff --git a/arch/x86/boot/compressed/early_sha1.c b/arch/x86/boot/compressed/early_sha1.c new file mode 100644 index 0000000..74f4654 --- /dev/null +++ b/arch/x86/boot/compressed/early_sha1.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021 Apertus Solutions, LLC. + */ + +#include +#include +#include +#include +#include + +#include "early_sha1.h" + +#define SHA1_DISABLE_EXPORT +#include "../../../../lib/sha1.c" + +/* The SHA1 implementation in lib/sha1.c was written to get the workspace + * buffer as a parameter. This wrapper function provides a container + * around a temporary workspace that is cleared after the transform completes. + */ +static void __sha_transform(u32 *digest, const char *data) +{ + u32 ws[SHA1_WORKSPACE_WORDS]; + + sha1_transform(digest, data, ws); + + memset(ws, 0, sizeof(ws)); + /* + * As this is cryptographic code, prevent the memset 0 from being + * optimized out potentially leaving secrets in memory. + */ + wmb(); + +} + +void early_sha1_init(struct sha1_state *sctx) +{ + sha1_init(sctx->state); + sctx->count = 0; +} + +void early_sha1_update(struct sha1_state *sctx, + const u8 *data, + unsigned int len) +{ + unsigned int partial = sctx->count % SHA1_BLOCK_SIZE; + + sctx->count += len; + + if (likely((partial + len) >= SHA1_BLOCK_SIZE)) { + int blocks; + + if (partial) { + int p = SHA1_BLOCK_SIZE - partial; + + memcpy(sctx->buffer + partial, data, p); + data += p; + len -= p; + + __sha_transform(sctx->state, sctx->buffer); + } + + blocks = len / SHA1_BLOCK_SIZE; + len %= SHA1_BLOCK_SIZE; + + if (blocks) { + while (blocks--) { + __sha_transform(sctx->state, data); + data += SHA1_BLOCK_SIZE; + } + } + partial = 0; + } + + if (len) + memcpy(sctx->buffer + partial, data, len); +} + +void early_sha1_final(struct sha1_state *sctx, u8 *out) +{ + const int bit_offset = SHA1_BLOCK_SIZE - sizeof(__be64); + __be64 *bits = (__be64 *)(sctx->buffer + bit_offset); + __be32 *digest = (__be32 *)out; + unsigned int partial = sctx->count % SHA1_BLOCK_SIZE; + int i; + + sctx->buffer[partial++] = 0x80; + if (partial > bit_offset) { + memset(sctx->buffer + partial, 0x0, SHA1_BLOCK_SIZE - partial); + partial = 0; + + __sha_transform(sctx->state, sctx->buffer); + } + + memset(sctx->buffer + partial, 0x0, bit_offset - partial); + *bits = cpu_to_be64(sctx->count << 3); + __sha_transform(sctx->state, sctx->buffer); + + for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(__be32); i++) + put_unaligned_be32(sctx->state[i], digest++); + + *sctx = (struct sha1_state){}; +} diff --git a/arch/x86/boot/compressed/early_sha1.h b/arch/x86/boot/compressed/early_sha1.h new file mode 100644 index 0000000..6584ea5 --- /dev/null +++ b/arch/x86/boot/compressed/early_sha1.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2021 Apertus Solutions, LLC + */ + +#ifndef BOOT_COMPRESSED_EARLY_SHA1_H +#define BOOT_COMPRESSED_EARLY_SHA1_H + +#include + +void early_sha1_init(struct sha1_state *sctx); +void early_sha1_update(struct sha1_state *sctx, + const u8 *data, + unsigned int len); +void early_sha1_final(struct sha1_state *sctx, u8 *out); + +#endif /* BOOT_COMPRESSED_EARLY_SHA1_H */ diff --git a/arch/x86/boot/compressed/early_sha256.c b/arch/x86/boot/compressed/early_sha256.c new file mode 100644 index 0000000..db8d784 --- /dev/null +++ b/arch/x86/boot/compressed/early_sha256.c @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021 Apertus Solutions, LLC + */ + +#define SHA256_DISABLE_EXPORT +#include "../../../../lib/crypto/sha256.c" diff --git a/lib/crypto/sha256.c b/lib/crypto/sha256.c index 72a4b0b..e532220 100644 --- a/lib/crypto/sha256.c +++ b/lib/crypto/sha256.c @@ -149,13 +149,17 @@ void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len) } memcpy(sctx->buf + partial, src, len - done); } +#ifndef SHA256_DISABLE_EXPORT EXPORT_SYMBOL(sha256_update); +#endif void sha224_update(struct sha256_state *sctx, const u8 *data, unsigned int len) { sha256_update(sctx, data, len); } +#ifndef SHA256_DISABLE_EXPORT EXPORT_SYMBOL(sha224_update); +#endif static void __sha256_final(struct sha256_state *sctx, u8 *out, int digest_words) { @@ -188,13 +192,17 @@ void sha256_final(struct sha256_state *sctx, u8 *out) { __sha256_final(sctx, out, 8); } +#ifndef SHA256_DISABLE_EXPORT EXPORT_SYMBOL(sha256_final); +#endif void sha224_final(struct sha256_state *sctx, u8 *out) { __sha256_final(sctx, out, 7); } +#ifndef SHA256_DISABLE_EXPORT EXPORT_SYMBOL(sha224_final); +#endif void sha256(const u8 *data, unsigned int len, u8 *out) { diff --git a/lib/sha1.c b/lib/sha1.c index 9bd1935..0598efd 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -187,7 +187,9 @@ void sha1_transform(__u32 *digest, const char *data, __u32 *array) digest[3] += D; digest[4] += E; } +#ifndef SHA1_DISABLE_EXPORT EXPORT_SYMBOL(sha1_transform); +#endif /** * sha1_init - initialize the vectors for a SHA1 digest @@ -201,4 +203,6 @@ void sha1_init(__u32 *buf) buf[3] = 0x10325476; buf[4] = 0xc3d2e1f0; } +#ifndef SHA1_DISABLE_EXPORT EXPORT_SYMBOL(sha1_init); +#endif From patchwork Fri Aug 27 13:28:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7ED9C25AEB for ; Fri, 27 Aug 2021 13:21:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA68D6108D for ; Fri, 27 Aug 2021 13:21:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245291AbhH0NWV (ORCPT ); Fri, 27 Aug 2021 09:22:21 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:34704 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245225AbhH0NWH (ORCPT ); Fri, 27 Aug 2021 09:22:07 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RC7fkW015344; Fri, 27 Aug 2021 13:20:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=BC0NxqhSiEjAPDrjoa8FrXqMrnaIT2JAS0dXXQHPAnM=; b=uGD6Th9PPxsR5o8yWiIISULO6XK1C8Bjr4fOw08MUWKRofmmSpWZ50gDf8ZPI6dtDyqw EagRGHaz1pLCc5OLqVkiIyKElYp6HnsWC0dRPqAsuFDIm6VVI9ee5Ssi8O/folyzY3kP XwJKQ18W7IXlUpKCDzKh0on1EBfRCuXqHfztMs3MG3cCWeK0hvSurOG3eo1s6ZqrnaHk bfZ7HqcEULBgLIAafH6zEnKxc2tvUX1bkNlyHlqTADfXnALAwiH5prjYaqs8D4JIAyMB yOUnfNbREEBQMA0eV85xl/YJhWU04WvzKS71em0pq5M26xrlAVa57PNACo6GDOjGaPkQ sA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=BC0NxqhSiEjAPDrjoa8FrXqMrnaIT2JAS0dXXQHPAnM=; b=bcVrQx8GveZst/UhSQRetUzM9DlwPadMkRXwtEIdf3iMGwE5pCUCRyxeBBskbYzbv4dq BLpj4P/lFAn5vPqJZUyW5aT2j6pQn0Fc6avAlr0YEqZ3TP9+Ovx5v/1103xWFagx4SQb U+Yx/SuiCrUi6fzwUlkhZ7+ldwEQtTmlQLm1SCcNzaHX7Hvk6lUuOpR7JOUrCqaXnB02 4kwx+GhaZzoiqxQVn0ptyGPWok3yYTfe2zDiMPWYVbSOPvvl9jdRVyKHG96bQKYwgXBt sU0CCiIfJnMYxaKVMa5Uf31ZbMvh3N60gt9r/aMntJMkzbeZhBotwXImjLLjcaU4DDpl 9g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3apvjr0ku1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:54 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RDBXLL007403; Fri, 27 Aug 2021 13:20:53 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2043.outbound.protection.outlook.com [104.47.51.43]) by aserp3030.oracle.com with ESMTP id 3ajqhmjmbs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SYwtv5f94wpqn2zGHWnVCyeCatRzwb66/XEVM637rKmzEju1PKu4PU8NGqG3BveQyzIr+Mbtt/pSXRdaNQvMxBhWhIpnIIY58FFJImejfyZvEboJ/+fHMEoWNOBUjFKuSK+oB7YyNRkkGOjtu/S/+0tFDGoIimffNBmw05i8c1yZZfj4UayZMB0g1GlKSrhcVcqo+YATCxowO5QY7OoImNTYZoUiCuwZdR6cEI7RVAoxPQSE+zwQcEdxEV771aI3gXg+DVFTievZFzf4pzy3L9++pBEcw6gNNS6XePA9wb879GozQG1fh3EubStFCBbYzL6pbRCZHyhbuHB8OyKK7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BC0NxqhSiEjAPDrjoa8FrXqMrnaIT2JAS0dXXQHPAnM=; b=n71c1Z85mu5XE6cocJmR0Bp6TeLb+vZjU7j1kP0OFbghwXqaVCSNhbZkId9Wbxnr0xoEStDperf5jUVV0IfIaVOaClfOwSa8ptbcN6lWSOiUeg7E8sEjqJqr29YNIZJtlMa54kepqq+xaQ0Lmye44xVT7cVIm3gErQBnDH9U4GXMYteFSnegvoT4QbU2Hz3ePLHgVzyXIZ45qn8jKafzPA/VkRMVsMYoLJ5gjsPp6QwgYXeyr+aGaD9NEEeie2OrOlkO/BR7W+hIlVB8i4zh8Cm/xIhZKh7kpsog4klwmJSKyhbu+GHNvHXPSWWLC1YNW9zPKgzMHfDiSqEqKzskZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BC0NxqhSiEjAPDrjoa8FrXqMrnaIT2JAS0dXXQHPAnM=; b=hibQIlp8q0/8YkvEev0xPZ4I78ZR+85zDybaVJNDdot20/O3qaIN8MpXjo/ZVJ8ksK4wjk8JyBLk7sKyIymQN2sSEX3e5Kw+82i8HB3vuIbLqQM00r4Cv4JyZ4VKxH1FYHAbR6VHBEPi87EU/OfFKUIUqeWRqGqxbha/iea0MM8= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:50 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:50 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 08/14] x86: Secure Launch kernel early boot stub Date: Fri, 27 Aug 2021 09:28:31 -0400 Message-Id: <1630070917-9896-9-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: da42d0e6-d0ea-48ac-86ca-08d9695d7d25 X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3FN15+4j0IJDKRNa4ApUos4KJ3wx1llnPRCCKsq8XUh2Jdw6LwzRuTG6p98sJcfSW5qEUOZOqYBioIoXf4mQkQczRFV/bkf28BRXUDXSvYnRfON5toc7dwwh/WUUDS+toQVh++Xr1uH61J10H4mz3z4CPZOYzjGELAt0g4Nu+YGLaCZyarI1LUy8pyKb/JwJpEFdmdaz5FnjPO0DU6nVIrU7BJ6JabPGkJGYF/anDbvyCOIzwCyZyFWW5UAkuLNgPeOe6RUyxkfRQs4Hk2mHbgZbEFjc/Xjvf4Z+w/u4IFRwrAYwggBlnIBWAOMKil8ThVJcZgcRKbfS5f63YB3MUYQgdxm0/vEl5lLFqu40S0OPkDm+tyuY+ehGfBQzDATuo6T7B4lwK8U6L6/6dc7vtEeYzyWsiqA+UB0zy5TOyuiXOW6HFTIqxTScNy9hPZw8IcMQGTT0n+UtYRnge1X1QcjtIolMTuLrOa3OIya0gLziKfhjbp1UtJyJFIRFWVarp9+wFD3/nqetVeY0iyf3q0aMIpAcIpc1Fv50u1QFl3Zg0MAWoX+qiEGYUKxSU3EitmkUiOlbS9CluoKXsuM5g6o1gEa/VZKCmBY6N0FpQL82JlUipr25alIdCHl1caNHrl7DaGnyNaSh5MPYngvZjGnVlMvjqUwGspuCnoOTtrIhmUf97Vr7xqUDTOzGB1ve71KJEVEB7VEEgPZRz4Lzp3Z0rGHq3Z6FeiswdgBAlAZNs9Mh39C2qxvbRpHL6QPxqe2SpaW7JvY0PbxmZyn8QKhSvG9c5KnPTli6+u/Y+9U= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(30864003)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(966005)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002)(579004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZZpD54+W7Og24q0UJHvnCybPLLZrdSjlEJhSnyGyS1W8pXaIknu6yqKQheW5q1aEO60jf6xhKgMHrmJnq/KSgftveYCMtw8B53SUWkiI1CtAAAg0FpOB1DvbfQeWQ/41hb4WeyNSq5+8RwyixI1wHZ1cjG6RbTR+G2lJP3NQfpJMzEKSZpcF2P6Gpasw//L+CZ3LwbgeTkd9SCx4Z4aedT+3wXmESE6uhM4NmQ0PT3jHNk3SBcMOuaIA5loFFulliMQduk/MQ4Jxh454pcpH0mzWJ+LHT8T3U4rmimCevDszAI+yGT4K8Mik0pgXcwMeuwYq5++QOr2S0OSTLCFvqV0AeW/qLjul2qCvMX2VJtm0LQnz3CJg2vdEU48z+M0q0cV8paw45JZA2cXfUUMiDYo+V7i1EX+2S8EN7O04WbK+9ghd/Md8A7zuJhfLac39TVzYXmLzmL9OPCwc1ONOqtpp3pq/SyeUPcWmZyng2q0kmuFL2teUioKTYmZRncOshz4AdpypX03P245D342/1qa2K02sUSe7eJOxiqWCf06q24v7F+Q64KFKjr45OBkEqlM3eZRT99pMmvkt/hraOtMB/Iiu++82LwQBfIuNuYj1Mc6Pb/GX17z+lXJgqYzKD5IMPJUSXptUqRkSHG/bZdAOUs+R0BCYEjWFSOIgRfGONKdR7zXsN6JEjPk+vxGTc6SdJSugIipQ2dD0V3Lx++d4xurU2V+bC5Jzm0EXd6ywxqoGiGf2TCraHUBOyjosYnbPv6J+zSUlSAldCKTXRhJmr6l8jCH4dMxvsFeflufYJ0IF0Sl47AplMqQdfW24wV6n1zXHZfdUEHbLWTeFo2XDeCfrl4mWgNa9M5JmKxTgaptW0Rr4soafNpgXLxyqlvqPqrCdITOC8nCbSU4MAAUN4DEl3A423iCmD4slg9s7gTMbHB8+0atIqhUUBf74eSD8C4+5FxdIkZZPUyldQ7q1wF4qn9yjyUdBArjghhmKrgUU5rwgs36x0/QkzEwrJc9Cz7W81Q1BRBwzp50iDiHzFVxAta969nN6vPlcTdKhH0gSoSr48wQoP5L/CFsdLoz+o2YOLUbtAMIKrMCWDCVsQP/odRfYHUN2vFA4agKG574JDJ3wAYGPV9aJVIm5Nx8aAl3B+oQuHJGUrHYliaO6zJhCQMab8IrUA+vnBrVAjw4M/JyW533zpUlrkYpt8/aNkjnCoPBy9sAFEML9/az+i1UvL/OwfVfEf8ZJ004trgHJqLbkqjl46pFO8Wdd3bZ5LbVgA+dglvSLdiVE297uiaE0Iq+IJYhqIpDJFyHBsCwbFoEM+rVFrI5dgD0n X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: da42d0e6-d0ea-48ac-86ca-08d9695d7d25 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:50.4131 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VsL3nJdS5mkcRxDTZFbPtfpa6s5/hJ7th/fyWfM7t6qLfeos9vbF2amML03N0zj39KnELm+hMuC9tIQhqw7/LUZJFtRGp8nVLzmTRiAH00E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: E1oGbpUX06S7gnTK59p7Xu2rPvr_ob0C X-Proofpoint-ORIG-GUID: E1oGbpUX06S7gnTK59p7Xu2rPvr_ob0C Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org The Secure Launch (SL) stub provides the entry point for Intel TXT (and later AMD SKINIT) to vector to during the late launch. The symbol sl_stub_entry is that entry point and its offset into the kernel is conveyed to the launching code using the MLE (Measured Launch Environment) header in the structure named mle_header. The offset of the MLE header is set in the kernel_info. The routine sl_stub contains the very early late launch setup code responsible for setting up the basic environment to allow the normal kernel startup_32 code to proceed. It is also responsible for properly waking and handling the APs on Intel platforms. The routine sl_main which runs after entering 64b mode is responsible for measuring configuration and module information before it is used like the boot params, the kernel command line, the TXT heap, an external initramfs, etc. Signed-off-by: Ross Philipson --- Documentation/x86/boot.rst | 13 + arch/x86/boot/compressed/Makefile | 3 +- arch/x86/boot/compressed/head_64.S | 37 ++ arch/x86/boot/compressed/kernel_info.S | 34 ++ arch/x86/boot/compressed/sl_main.c | 549 ++++++++++++++++++++++++++ arch/x86/boot/compressed/sl_stub.S | 685 +++++++++++++++++++++++++++++++++ arch/x86/kernel/asm-offsets.c | 19 + 7 files changed, 1339 insertions(+), 1 deletion(-) create mode 100644 arch/x86/boot/compressed/sl_main.c create mode 100644 arch/x86/boot/compressed/sl_stub.S diff --git a/Documentation/x86/boot.rst b/Documentation/x86/boot.rst index 894a198..2fbcb77 100644 --- a/Documentation/x86/boot.rst +++ b/Documentation/x86/boot.rst @@ -1026,6 +1026,19 @@ Offset/size: 0x000c/4 This field contains maximal allowed type for setup_data and setup_indirect structs. +============ ================= +Field name: mle_header_offset +Offset/size: 0x0010/4 +============ ================= + + This field contains the offset to the Secure Launch Measured Launch Environment + (MLE) header. This offset is used to locate information needed during a secure + late launch using Intel TXT. If the offset is zero, the kernel does not have + Secure Launch capabilities. The MLE entry point is called from TXT on the BSP + following a success measured launch. The specific state of the processors is + outlined in the TXT Software Development Guide, the latest can be found here: + https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf + The Image Checksum ================== diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 059d49a..1fe55a5 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -102,7 +102,8 @@ vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a -vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o +vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o \ + $(obj)/sl_main.o $(obj)/sl_stub.o $(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE $(call if_changed,ld) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index a2347de..b35e072 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -498,6 +498,17 @@ trampoline_return: pushq $0 popfq +#ifdef CONFIG_SECURE_LAUNCH + pushq %rsi + + /* Ensure the relocation region coverd by a PMR */ + movq %rbx, %rdi + movl $(_bss - startup_32), %esi + callq sl_check_region + + popq %rsi +#endif + /* * Copy the compressed kernel to the end of our buffer * where decompression in place becomes safe. @@ -556,6 +567,32 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) shrq $3, %rcx rep stosq +#ifdef CONFIG_SECURE_LAUNCH + /* + * Have to do the final early sl stub work in 64b area. + * + * *********** NOTE *********** + * + * Several boot params get used before we get a chance to measure + * them in this call. This is a known issue and we currently don't + * have a solution. The scratch field doesn't matter. There is no + * obvious way to do anything about the use of kernel_alignment or + * init_size though these seem low risk with all the PMR and overlap + * checks in place. + */ + pushq %rsi + + movq %rsi, %rdi + callq sl_main + + /* Ensure the decompression location is coverd by a PMR */ + movq %rbp, %rdi + movq output_len(%rip), %rsi + callq sl_check_region + + popq %rsi +#endif + /* * If running as an SEV guest, the encryption mask is required in the * page-table setup code below. When the guest also has SEV-ES enabled diff --git a/arch/x86/boot/compressed/kernel_info.S b/arch/x86/boot/compressed/kernel_info.S index c18f071..e199b87 100644 --- a/arch/x86/boot/compressed/kernel_info.S +++ b/arch/x86/boot/compressed/kernel_info.S @@ -28,6 +28,40 @@ SYM_DATA_START(kernel_info) /* Maximal allowed type for setup_data and setup_indirect structs. */ .long SETUP_TYPE_MAX + /* Offset to the MLE header structure */ +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + .long rva(mle_header) +#else + .long 0 +#endif + kernel_info_var_len_data: /* Empty for time being... */ SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end) + +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + /* + * The MLE Header per the TXT Specification, section 2.1 + * MLE capabilities, see table 4. Capabilities set: + * bit 0: Support for GETSEC[WAKEUP] for RLP wakeup + * bit 1: Support for RLP wakeup using MONITOR address + * bit 2: The ECX register will contain the pointer to the MLE page table + * bit 5: TPM 1.2 family: Details/authorities PCR usage support + * bit 9: Supported format of TPM 2.0 event log - TCG compliant + */ +SYM_DATA_START(mle_header) + .long 0x9082ac5a /* UUID0 */ + .long 0x74a7476f /* UUID1 */ + .long 0xa2555c0f /* UUID2 */ + .long 0x42b651cb /* UUID3 */ + .long 0x00000034 /* MLE header size */ + .long 0x00020002 /* MLE version 2.2 */ + .long rva(sl_stub_entry) /* Linear entry point of MLE (virt. address) */ + .long 0x00000000 /* First valid page of MLE */ + .long 0x00000000 /* Offset within binary of first byte of MLE */ + .long rva(_edata) /* Offset within binary of last byte + 1 of MLE */ + .long 0x00000227 /* Bit vector of MLE-supported capabilities */ + .long 0x00000000 /* Starting linear address of command line (unused) */ + .long 0x00000000 /* Ending linear address of command line (unused) */ +SYM_DATA_END(mle_header) +#endif diff --git a/arch/x86/boot/compressed/sl_main.c b/arch/x86/boot/compressed/sl_main.c new file mode 100644 index 0000000..6ba59e7 --- /dev/null +++ b/arch/x86/boot/compressed/sl_main.c @@ -0,0 +1,549 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Secure Launch early measurement and validation routines. + * + * Copyright (c) 2021, Oracle and/or its affiliates. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "misc.h" +#include "early_sha1.h" + +#define CAPS_VARIABLE_MTRR_COUNT_MASK 0xff + +#define SL_TPM12_LOG 1 +#define SL_TPM20_LOG 2 + +#define SL_TPM20_MAX_ALGS 2 + +#define SL_MAX_EVENT_DATA 64 +#define SL_TPM12_LOG_SIZE (sizeof(struct tcg_pcr_event) + \ + SL_MAX_EVENT_DATA) +#define SL_TPM20_LOG_SIZE (sizeof(struct tcg_pcr_event2_head) + \ + SHA1_DIGEST_SIZE + SHA256_DIGEST_SIZE + \ + sizeof(struct tcg_event_field) + \ + SL_MAX_EVENT_DATA) + +static void *evtlog_base; +static u32 evtlog_size; +static struct txt_heap_event_log_pointer2_1_element *log20_elem; +static u32 tpm_log_ver = SL_TPM12_LOG; +struct tcg_efi_specid_event_algs tpm_algs[SL_TPM20_MAX_ALGS] = {0}; + +#if !IS_ENABLED(CONFIG_SECURE_LAUNCH_ALT_PCR19) +static u32 pcr_config = SL_DEF_CONFIG_PCR18; +#else +static u32 pcr_config = SL_ALT_CONFIG_PCR19; +#endif + +#if !IS_ENABLED(CONFIG_SECURE_LAUNCH_ALT_PCR20) +static u32 pcr_image = SL_DEF_IMAGE_PCR17; +#else +static u32 pcr_image = SL_ALT_IMAGE_PCR20; +#endif + +extern u32 sl_cpu_type; +extern u32 sl_mle_start; + +u32 slaunch_get_cpu_type(void) +{ + return sl_cpu_type; +} + +static u64 sl_txt_read(u32 reg) +{ + return readq((void *)(u64)(TXT_PRIV_CONFIG_REGS_BASE + reg)); +} + +static void sl_txt_write(u32 reg, u64 val) +{ + writeq(val, (void *)(u64)(TXT_PRIV_CONFIG_REGS_BASE + reg)); +} + +static void __noreturn sl_txt_reset(u64 error) +{ + /* Reading the E2STS register acts as a barrier for TXT registers */ + sl_txt_write(TXT_CR_ERRORCODE, error); + sl_txt_read(TXT_CR_E2STS); + sl_txt_write(TXT_CR_CMD_UNLOCK_MEM_CONFIG, 1); + sl_txt_read(TXT_CR_E2STS); + sl_txt_write(TXT_CR_CMD_RESET, 1); + + for ( ; ; ) + asm volatile ("hlt"); + + unreachable(); +} + +static u64 sl_rdmsr(u32 reg) +{ + u64 lo, hi; + + asm volatile ("rdmsr" : "=a" (lo), "=d" (hi) : "c" (reg)); + + return (hi << 32) | lo; +} + +static void sl_check_pmr_coverage(void *base, u32 size, bool allow_hi) +{ + void *end = base + size; + struct txt_os_sinit_data *os_sinit_data; + void *txt_heap; + + if (!(sl_cpu_type & SL_CPU_INTEL)) + return; + + txt_heap = (void *)sl_txt_read(TXT_CR_HEAP_BASE); + os_sinit_data = txt_os_sinit_data_start(txt_heap); + + if ((end >= (void *)0x100000000ULL) && + (base < (void *)0x100000000ULL)) + sl_txt_reset(SL_ERROR_REGION_STRADDLE_4GB); + + /* + * Note that the late stub code validates that the hi PMR covers + * all memory above 4G. At this point the code can only check that + * regions are within the hi PMR but that is sufficient. + */ + if ((end > (void *)0x100000000ULL) && + (base >= (void *)0x100000000ULL)) { + if (allow_hi) { + if (end >= (void *)(os_sinit_data->vtd_pmr_hi_base + + os_sinit_data->vtd_pmr_hi_size)) + sl_txt_reset(SL_ERROR_BUFFER_BEYOND_PMR); + } else + sl_txt_reset(SL_ERROR_REGION_ABOVE_4GB); + } + + if (end >= (void *)os_sinit_data->vtd_pmr_lo_size) + sl_txt_reset(SL_ERROR_BUFFER_BEYOND_PMR); +} + +/* + * Some MSRs are modified by the pre-launch code including the MTRRs. + * The early MLE code has to restore these values. This code validates + * the values after they are measured. + */ +static void sl_txt_validate_msrs(struct txt_os_mle_data *os_mle_data) +{ + u64 mtrr_caps, mtrr_def_type, mtrr_var, misc_en_msr; + u32 vcnt, i; + struct txt_mtrr_state *saved_bsp_mtrrs = + &(os_mle_data->saved_bsp_mtrrs); + + mtrr_caps = sl_rdmsr(MSR_MTRRcap); + vcnt = (u32)(mtrr_caps & CAPS_VARIABLE_MTRR_COUNT_MASK); + + if (saved_bsp_mtrrs->mtrr_vcnt > vcnt) + sl_txt_reset(SL_ERROR_MTRR_INV_VCNT); + if (saved_bsp_mtrrs->mtrr_vcnt > TXT_OS_MLE_MAX_VARIABLE_MTRRS) + sl_txt_reset(SL_ERROR_MTRR_INV_VCNT); + + mtrr_def_type = sl_rdmsr(MSR_MTRRdefType); + if (saved_bsp_mtrrs->default_mem_type != mtrr_def_type) + sl_txt_reset(SL_ERROR_MTRR_INV_DEF_TYPE); + + for (i = 0; i < saved_bsp_mtrrs->mtrr_vcnt; i++) { + mtrr_var = sl_rdmsr(MTRRphysBase_MSR(i)); + if (saved_bsp_mtrrs->mtrr_pair[i].mtrr_physbase != mtrr_var) + sl_txt_reset(SL_ERROR_MTRR_INV_BASE); + mtrr_var = sl_rdmsr(MTRRphysMask_MSR(i)); + if (saved_bsp_mtrrs->mtrr_pair[i].mtrr_physmask != mtrr_var) + sl_txt_reset(SL_ERROR_MTRR_INV_MASK); + } + + misc_en_msr = sl_rdmsr(MSR_IA32_MISC_ENABLE); + if (os_mle_data->saved_misc_enable_msr != misc_en_msr) + sl_txt_reset(SL_ERROR_MSR_INV_MISC_EN); +} + +static void sl_find_event_log(void) +{ + struct txt_os_mle_data *os_mle_data; + struct txt_os_sinit_data *os_sinit_data; + void *txt_heap; + + txt_heap = (void *)sl_txt_read(TXT_CR_HEAP_BASE); + + os_mle_data = txt_os_mle_data_start(txt_heap); + evtlog_base = (void *)os_mle_data->evtlog_addr; + evtlog_size = os_mle_data->evtlog_size; + + /* + * For TPM 2.0, the event log 2.1 extended data structure has to also + * be located and fixed up. + */ + os_sinit_data = txt_os_sinit_data_start(txt_heap); + + /* + * Only support version 6 and later that properly handle the + * list of ExtDataElements in the OS-SINIT structure. + */ + if (os_sinit_data->version < 6) + sl_txt_reset(SL_ERROR_OS_SINIT_BAD_VERSION); + + /* Find the TPM2.0 logging extended heap element */ + log20_elem = tpm20_find_log2_1_element(os_sinit_data); + + /* If found, this implies TPM20 log and family */ + if (log20_elem) + tpm_log_ver = SL_TPM20_LOG; +} + +static void sl_validate_event_log_buffer(void) +{ + void *mle_base = (void *)(u64)sl_mle_start; + void *mle_end; + struct txt_os_sinit_data *os_sinit_data; + void *txt_heap; + void *txt_heap_end; + void *evtlog_end; + + if ((u64)evtlog_size > (LLONG_MAX - (u64)evtlog_base)) + sl_txt_reset(SL_ERROR_INTEGER_OVERFLOW); + evtlog_end = evtlog_base + evtlog_size; + + txt_heap = (void *)sl_txt_read(TXT_CR_HEAP_BASE); + txt_heap_end = txt_heap + sl_txt_read(TXT_CR_HEAP_SIZE); + os_sinit_data = txt_os_sinit_data_start(txt_heap); + + mle_end = mle_base + os_sinit_data->mle_size; + + /* + * This check is to ensure the event log buffer does not overlap with + * the MLE image. + */ + if ((evtlog_base >= mle_end) && + (evtlog_end > mle_end)) + goto pmr_check; /* above */ + + if ((evtlog_end <= mle_base) && + (evtlog_base < mle_base)) + goto pmr_check; /* below */ + + sl_txt_reset(SL_ERROR_MLE_BUFFER_OVERLAP); + +pmr_check: + /* + * The TXT heap is protected by the DPR. If the TPM event log is + * inside the TXT heap, there is no need for a PMR check. + */ + if ((evtlog_base > txt_heap) && + (evtlog_end < txt_heap_end)) + return; + + sl_check_pmr_coverage(evtlog_base, evtlog_size, true); +} + +static void sl_find_event_log_algorithms(void) +{ + struct tcg_efi_specid_event_head *efi_head = + (struct tcg_efi_specid_event_head *)(evtlog_base + + log20_elem->first_record_offset + + sizeof(struct tcg_pcr_event)); + + if (efi_head->num_algs == 0 || efi_head->num_algs > 2) + sl_txt_reset(SL_ERROR_TPM_NUMBER_ALGS); + + memcpy(&tpm_algs[0], &efi_head->digest_sizes[0], + sizeof(struct tcg_efi_specid_event_algs) * efi_head->num_algs); +} + +static void sl_tpm12_log_event(u32 pcr, u32 event_type, + const u8 *data, u32 length, + const u8 *event_data, u32 event_size) +{ + struct tcg_pcr_event *pcr_event; + struct sha1_state sctx = {0}; + u32 total_size; + u8 log_buf[SL_TPM12_LOG_SIZE] = {0}; + u8 sha1_hash[SHA1_DIGEST_SIZE] = {0}; + + pcr_event = (struct tcg_pcr_event *)log_buf; + pcr_event->pcr_idx = pcr; + pcr_event->event_type = event_type; + if (length > 0) { + early_sha1_init(&sctx); + early_sha1_update(&sctx, data, length); + early_sha1_final(&sctx, &sha1_hash[0]); + memcpy(&pcr_event->digest[0], &sha1_hash[0], SHA1_DIGEST_SIZE); + } + pcr_event->event_size = event_size; + if (event_size > 0) + memcpy((u8 *)pcr_event + sizeof(struct tcg_pcr_event), + event_data, event_size); + + total_size = sizeof(struct tcg_pcr_event) + event_size; + + if (tpm12_log_event(evtlog_base, evtlog_size, total_size, pcr_event)) + sl_txt_reset(SL_ERROR_TPM_LOGGING_FAILED); +} + +static void sl_tpm20_log_event(u32 pcr, u32 event_type, + const u8 *data, u32 length, + const u8 *event_data, u32 event_size) +{ + struct tcg_pcr_event2_head *head; + struct tcg_event_field *event; + struct sha1_state sctx1 = {0}; + struct sha256_state sctx256 = {0}; + u32 total_size; + u16 *alg_ptr; + u8 *dgst_ptr; + u8 log_buf[SL_TPM20_LOG_SIZE] = {0}; + u8 sha1_hash[SHA1_DIGEST_SIZE] = {0}; + u8 sha256_hash[SHA256_DIGEST_SIZE] = {0}; + + head = (struct tcg_pcr_event2_head *)log_buf; + head->pcr_idx = pcr; + head->event_type = event_type; + total_size = sizeof(struct tcg_pcr_event2_head); + alg_ptr = (u16 *)(log_buf + sizeof(struct tcg_pcr_event2_head)); + + for ( ; head->count < 2; head->count++) { + if (!tpm_algs[head->count].alg_id) + break; + + *alg_ptr = tpm_algs[head->count].alg_id; + dgst_ptr = (u8 *)alg_ptr + sizeof(u16); + + if (tpm_algs[head->count].alg_id == TPM_ALG_SHA256 && + length) { + sha256_init(&sctx256); + sha256_update(&sctx256, data, length); + sha256_final(&sctx256, &sha256_hash[0]); + } else if (tpm_algs[head->count].alg_id == TPM_ALG_SHA1 && + length) { + early_sha1_init(&sctx1); + early_sha1_update(&sctx1, data, length); + early_sha1_final(&sctx1, &sha1_hash[0]); + } + + if (tpm_algs[head->count].alg_id == TPM_ALG_SHA256) { + memcpy(dgst_ptr, &sha256_hash[0], SHA256_DIGEST_SIZE); + total_size += SHA256_DIGEST_SIZE + sizeof(u16); + alg_ptr = (u16 *)((u8 *)alg_ptr + SHA256_DIGEST_SIZE + sizeof(u16)); + } else if (tpm_algs[head->count].alg_id == TPM_ALG_SHA1) { + memcpy(dgst_ptr, &sha1_hash[0], SHA1_DIGEST_SIZE); + total_size += SHA1_DIGEST_SIZE + sizeof(u16); + alg_ptr = (u16 *)((u8 *)alg_ptr + SHA1_DIGEST_SIZE + sizeof(u16)); + } else + sl_txt_reset(SL_ERROR_TPM_UNKNOWN_DIGEST); + } + + event = (struct tcg_event_field *)(log_buf + total_size); + event->event_size = event_size; + if (event_size > 0) + memcpy((u8 *)event + sizeof(struct tcg_event_field), + event_data, event_size); + total_size += sizeof(struct tcg_event_field) + event_size; + + if (tpm20_log_event(log20_elem, evtlog_base, evtlog_size, + total_size, &log_buf[0])) + sl_txt_reset(SL_ERROR_TPM_LOGGING_FAILED); +} + +static void sl_tpm_extend_evtlog(u32 pcr, u32 type, + const u8 *data, u32 length, const char *desc) +{ + if (tpm_log_ver == SL_TPM20_LOG) + sl_tpm20_log_event(pcr, type, data, length, + (const u8 *)desc, strlen(desc)); + else + sl_tpm12_log_event(pcr, type, data, length, + (const u8 *)desc, strlen(desc)); +} + +static struct setup_data *sl_handle_setup_data(struct setup_data *curr) +{ + struct setup_data *next; + struct setup_indirect *ind; + + if (!curr) + return NULL; + + next = (struct setup_data *)(unsigned long)curr->next; + + /* SETUP_INDIRECT instances have to be handled differently */ + if (curr->type == SETUP_INDIRECT) { + ind = (struct setup_indirect *) + ((u8 *)curr + offsetof(struct setup_data, data)); + + sl_check_pmr_coverage((void *)ind->addr, ind->len, true); + + sl_tpm_extend_evtlog(pcr_config, TXT_EVTYPE_SLAUNCH, + (void *)ind->addr, ind->len, + "Measured Kernel setup_indirect"); + + return next; + } + + sl_check_pmr_coverage(((u8 *)curr) + sizeof(struct setup_data), + curr->len, true); + + sl_tpm_extend_evtlog(pcr_config, TXT_EVTYPE_SLAUNCH, + ((u8 *)curr) + sizeof(struct setup_data), + curr->len, + "Measured Kernel setup_data"); + + return next; +} + +asmlinkage __visible void sl_check_region(void *base, u32 size) +{ + sl_check_pmr_coverage(base, size, false); +} + +asmlinkage __visible void sl_main(void *bootparams) +{ + struct boot_params *bp; + struct setup_data *data; + struct txt_os_mle_data *os_mle_data; + struct txt_os_mle_data os_mle_tmp = {0}; + const char *signature; + unsigned long mmap = 0; + void *txt_heap; + u32 data_count; + + /* + * Currently only Intel TXT is supported for Secure Launch. Testing + * this value also indicates that the kernel was booted successfully + * through the Secure Launch entry point and is in SMX mode. + */ + if (!(sl_cpu_type & SL_CPU_INTEL)) + return; + + /* Locate the TPM event log. */ + sl_find_event_log(); + + /* Validate the location of the event log buffer before using it */ + sl_validate_event_log_buffer(); + + /* + * Find the TPM hash algorithms used by the ACM and recorded in the + * event log. + */ + if (tpm_log_ver == SL_TPM20_LOG) + sl_find_event_log_algorithms(); + + /* Sanitize them before measuring */ + boot_params = (struct boot_params *)bootparams; + sanitize_boot_params(boot_params); + + /* Place event log NO_ACTION tags before and after measurements */ + sl_tpm_extend_evtlog(17, TXT_EVTYPE_SLAUNCH_START, NULL, 0, ""); + + sl_check_pmr_coverage(bootparams, PAGE_SIZE, false); + + /* Measure the zero page/boot params */ + sl_tpm_extend_evtlog(pcr_config, TXT_EVTYPE_SLAUNCH, + bootparams, PAGE_SIZE, + "Measured boot parameters"); + + /* Now safe to use boot params */ + bp = (struct boot_params *)bootparams; + + /* Measure the command line */ + if (bp->hdr.cmdline_size > 0) { + u64 cmdline = (u64)bp->hdr.cmd_line_ptr; + + if (bp->ext_cmd_line_ptr > 0) + cmdline = cmdline | ((u64)bp->ext_cmd_line_ptr << 32); + + sl_check_pmr_coverage((void *)cmdline, + bp->hdr.cmdline_size, true); + + sl_tpm_extend_evtlog(pcr_config, TXT_EVTYPE_SLAUNCH, + (u8 *)cmdline, + bp->hdr.cmdline_size, + "Measured Kernel command line"); + } + + /* + * Measuring the boot params measured the fixed e820 memory map. + * Measure any setup_data entries including e820 extended entries. + */ + data = (struct setup_data *)(unsigned long)bp->hdr.setup_data; + while (data) + data = sl_handle_setup_data(data); + + /* If bootloader was EFI, measure the memory map passed across */ + signature = + (const char *)&bp->efi_info.efi_loader_signature; + + if (!strncmp(signature, EFI32_LOADER_SIGNATURE, 4)) + mmap = bp->efi_info.efi_memmap; + else if (!strncmp(signature, EFI64_LOADER_SIGNATURE, 4)) + mmap = (bp->efi_info.efi_memmap | + ((u64)bp->efi_info.efi_memmap_hi << 32)); + + if (mmap) + sl_tpm_extend_evtlog(pcr_config, TXT_EVTYPE_SLAUNCH, + (void *)mmap, + bp->efi_info.efi_memmap_size, + "Measured EFI memory map"); + + /* Measure any external initrd */ + if (bp->hdr.ramdisk_image != 0 && bp->hdr.ramdisk_size != 0) { + u64 ramdisk = (u64)bp->hdr.ramdisk_image; + + if (bp->ext_ramdisk_size > 0) + sl_txt_reset(SL_ERROR_INITRD_TOO_BIG); + + if (bp->ext_ramdisk_image > 0) + ramdisk = ramdisk | + ((u64)bp->ext_ramdisk_image << 32); + + sl_check_pmr_coverage((void *)ramdisk, + bp->hdr.ramdisk_size, true); + + sl_tpm_extend_evtlog(pcr_image, TXT_EVTYPE_SLAUNCH, + (u8 *)(ramdisk), + bp->hdr.ramdisk_size, + "Measured initramfs"); + } + + /* + * Some extra work to do on Intel, have to measure the OS-MLE + * heap area. + */ + txt_heap = (void *)sl_txt_read(TXT_CR_HEAP_BASE); + os_mle_data = txt_os_mle_data_start(txt_heap); + + /* Measure only portions of OS-MLE data, not addresses/sizes etc. */ + os_mle_tmp.version = os_mle_data->version; + os_mle_tmp.saved_misc_enable_msr = os_mle_data->saved_misc_enable_msr; + os_mle_tmp.saved_bsp_mtrrs = os_mle_data->saved_bsp_mtrrs; + + /* No PMR check is needed, the TXT heap is covered by the DPR */ + + sl_tpm_extend_evtlog(pcr_config, TXT_EVTYPE_SLAUNCH, + (u8 *)&os_mle_tmp, + sizeof(struct txt_os_mle_data), + "Measured TXT OS-MLE data"); + + sl_tpm_extend_evtlog(17, TXT_EVTYPE_SLAUNCH_END, NULL, 0, ""); + + /* + * Now that the OS-MLE data is measured, ensure the MTRR and + * misc enable MSRs are what we expect. + */ + sl_txt_validate_msrs(os_mle_data); +} diff --git a/arch/x86/boot/compressed/sl_stub.S b/arch/x86/boot/compressed/sl_stub.S new file mode 100644 index 0000000..e36ef62 --- /dev/null +++ b/arch/x86/boot/compressed/sl_stub.S @@ -0,0 +1,685 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Secure Launch protected mode entry point. + * + * Copyright (c) 2021, Oracle and/or its affiliates. + */ + .code32 + .text +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* CPUID: leaf 1, ECX, SMX feature bit */ +#define X86_FEATURE_BIT_SMX 6 + +/* Can't include apiddef.h in asm */ +#define XAPIC_ENABLE (1 << 11) +#define X2APIC_ENABLE (1 << 10) + +/* Can't include traps.h in asm */ +#define X86_TRAP_NMI 2 + +/* Can't include mtrr.h in asm */ +#define MTRRphysBase0 0x200 + +#define IDT_VECTOR_LO_BITS 0 +#define IDT_VECTOR_HI_BITS 6 + +/* + * See the comment in head_64.S for detailed informatoin on what this macro + * is used for. + */ +#define rva(X) ((X) - sl_stub_entry) + +/* + * The GETSEC op code is open coded because older versions of + * GCC do not support the getsec mnemonic. + */ +.macro GETSEC leaf + pushl %ebx + xorl %ebx, %ebx /* Must be zero for SMCTRL */ + movl \leaf, %eax /* Leaf function */ + .byte 0x0f, 0x37 /* GETSEC opcode */ + popl %ebx +.endm + +.macro TXT_RESET error + /* + * Set a sticky error value and reset. Note the movs to %eax act as + * TXT register barriers. + */ + movl \error, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ERRORCODE) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_NO_SECRETS) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_UNLOCK_MEM_CONFIG) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_RESET) +1: + hlt + jmp 1b +.endm + + .code32 +SYM_FUNC_START(sl_stub_entry) + cli + cld + + /* + * On entry, %ebx has the entry abs offset to sl_stub_entry. This + * will be correctly scaled using the rva macro and avoid causing + * relocations. Only %cs and %ds segments are known good. + */ + + /* Load GDT, set segment regs and lret to __SL32_CS */ + leal rva(sl_gdt_desc)(%ebx), %eax + addl %eax, 2(%eax) + lgdt (%eax) + + movl $(__SL32_DS), %eax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + + /* + * Now that %ss is known good, take the first stack for the BSP. The + * AP stacks are only used on Intel. + */ + leal rva(sl_stacks_end)(%ebx), %esp + + leal rva(.Lsl_cs)(%ebx), %eax + pushl $(__SL32_CS) + pushl %eax + lret + +.Lsl_cs: + /* Save our base pointer reg and page table for MLE */ + pushl %ebx + pushl %ecx + + /* See if SMX feature is supported. */ + movl $1, %eax + cpuid + testl $(X86_FEATURE_BIT_SMX), %ecx + jz .Ldo_unknown_cpu + + popl %ecx + popl %ebx + + /* Know it is Intel */ + movl $(SL_CPU_INTEL), rva(sl_cpu_type)(%ebx) + + /* Locate the base of the MLE using the page tables in %ecx */ + call sl_find_mle_base + + /* Increment CPU count for BSP */ + incl rva(sl_txt_cpu_count)(%ebx) + + /* + * Enable SMI with GETSEC[SMCTRL] which were disabled by SENTER. + * NMIs were also disabled by SENTER. Since there is no IDT for the BSP, + * allow the mainline kernel re-enable them in the normal course of + * booting. + */ + GETSEC $(SMX_X86_GETSEC_SMCTRL) + + /* Clear the TXT error registers for a clean start of day */ + movl $0, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ERRORCODE) + movl $0xffffffff, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ESTS) + + /* On Intel, the zero page address is passed in the TXT heap */ + /* Read physical base of heap into EAX */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* Read the size of the BIOS data into ECX (first 8 bytes) */ + movl (%eax), %ecx + /* Skip over BIOS data and size of OS to MLE data section */ + leal 8(%eax, %ecx), %eax + + /* Need to verify the values in the OS-MLE struct passed in */ + call sl_txt_verify_os_mle_struct + + /* + * Get the boot params address from the heap. Note %esi and %ebx MUST + * be preserved across calls and operations. + */ + movl SL_boot_params_addr(%eax), %esi + + /* Save %ebx so the APs can find their way home */ + movl %ebx, (SL_mle_scratch + SL_SCRATCH_AP_EBX)(%eax) + + /* Fetch the AP wake code block address from the heap */ + movl SL_ap_wake_block(%eax), %edi + movl %edi, rva(sl_txt_ap_wake_block)(%ebx) + + /* Store the offset in the AP wake block to the jmp address */ + movl $(sl_ap_jmp_offset - sl_txt_ap_wake_begin), \ + (SL_mle_scratch + SL_SCRATCH_AP_JMP_OFFSET)(%eax) + + /* %eax still is the base of the OS-MLE block, save it */ + pushl %eax + + /* Relocate the AP wake code to the safe block */ + call sl_txt_reloc_ap_wake + + /* + * Wake up all APs that are blocked in the ACM and wait for them to + * halt. This should be done before restoring the MTRRs so the ACM is + * still properly in WB memory. + */ + call sl_txt_wake_aps + + /* + * Pop OS-MLE base address (was in %eax above) for call to load + * MTRRs/MISC MSR + */ + popl %edi + call sl_txt_load_regs + + jmp .Lcpu_setup_done + +.Ldo_unknown_cpu: + /* Non-Intel CPUs are not yet supported */ + ud2 + +.Lcpu_setup_done: + /* + * Don't enable MCE at this point. The kernel will enable + * it on the BSP later when it is ready. + */ + + /* Done, jump to normal 32b pm entry */ + jmp startup_32 +SYM_FUNC_END(sl_stub_entry) + +SYM_FUNC_START(sl_find_mle_base) + /* %ecx has PDPT, get first PD */ + movl (%ecx), %eax + andl $(PAGE_MASK), %eax + /* Get first PT from first PDE */ + movl (%eax), %eax + andl $(PAGE_MASK), %eax + /* Get MLE base from first PTE */ + movl (%eax), %eax + andl $(PAGE_MASK), %eax + + movl %eax, rva(sl_mle_start)(%ebx) + ret +SYM_FUNC_END(sl_find_mle_base) + +SYM_FUNC_START(sl_check_buffer_mle_overlap) + /* %ecx: buffer begin %edx: buffer end */ + /* %ebx: MLE begin %edi: MLE end */ + + cmpl %edi, %ecx + jb .Lnext_check + cmpl %edi, %edx + jbe .Lnext_check + jmp .Lvalid /* Buffer above MLE */ + +.Lnext_check: + cmpl %ebx, %edx + ja .Linvalid + cmpl %ebx, %ecx + jae .Linvalid + jmp .Lvalid /* Buffer below MLE */ + +.Linvalid: + TXT_RESET $(SL_ERROR_MLE_BUFFER_OVERLAP) + +.Lvalid: + ret +SYM_FUNC_END(sl_check_buffer_mle_overlap) + +SYM_FUNC_START(sl_txt_verify_os_mle_struct) + pushl %ebx + /* + * %eax points to the base of the OS-MLE struct. Need to also + * read some values from the OS-SINIT struct too. + */ + movl -8(%eax), %ecx + /* Skip over OS to MLE data section and size of OS-SINIT structure */ + leal (%eax, %ecx), %edx + + /* Load MLE image base absolute offset */ + movl rva(sl_mle_start)(%ebx), %ebx + + /* Verify the value of the low PMR base. It should always be 0. */ + movl SL_vtd_pmr_lo_base(%edx), %esi + cmpl $0, %esi + jz .Lvalid_pmr_base + TXT_RESET $(SL_ERROR_LO_PMR_BASE) + +.Lvalid_pmr_base: + /* Grab some values from OS-SINIT structure */ + movl SL_mle_size(%edx), %edi + addl %ebx, %edi + jc .Loverflow_detected + movl SL_vtd_pmr_lo_size(%edx), %esi + + /* Check the AP wake block */ + movl SL_ap_wake_block(%eax), %ecx + movl SL_ap_wake_block_size(%eax), %edx + addl %ecx, %edx + jc .Loverflow_detected + call sl_check_buffer_mle_overlap + cmpl %esi, %edx + ja .Lbuffer_beyond_pmr + + /* Check the boot params */ + movl SL_boot_params_addr(%eax), %ecx + movl $(PAGE_SIZE), %edx + addl %ecx, %edx + jc .Loverflow_detected + call sl_check_buffer_mle_overlap + cmpl %esi, %edx + ja .Lbuffer_beyond_pmr + + /* Check that the AP wake block is big enough */ + cmpl $(sl_txt_ap_wake_end - sl_txt_ap_wake_begin), \ + SL_ap_wake_block_size(%eax) + jae .Lwake_block_ok + TXT_RESET $(SL_ERROR_WAKE_BLOCK_TOO_SMALL) + +.Lwake_block_ok: + popl %ebx + ret + +.Loverflow_detected: + TXT_RESET $(SL_ERROR_INTEGER_OVERFLOW) + +.Lbuffer_beyond_pmr: + TXT_RESET $(SL_ERROR_BUFFER_BEYOND_PMR) +SYM_FUNC_END(sl_txt_verify_os_mle_struct) + +SYM_FUNC_START(sl_txt_ap_entry) + cli + cld + /* + * The %cs and %ds segments are known good after waking the AP. + * First order of business is to find where we are and + * save it in %ebx. + */ + + /* Read physical base of heap into EAX */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* Read the size of the BIOS data into ECX (first 8 bytes) */ + movl (%eax), %ecx + /* Skip over BIOS data and size of OS to MLE data section */ + leal 8(%eax, %ecx), %eax + + /* Saved %ebx from the BSP and stash OS-MLE pointer */ + movl (SL_mle_scratch + SL_SCRATCH_AP_EBX)(%eax), %ebx + /* Save OS-MLE base in %edi for call to sl_txt_load_regs */ + movl %eax, %edi + + /* Lock and get our stack index */ + movl $1, %ecx +.Lspin: + xorl %eax, %eax + lock cmpxchgl %ecx, rva(sl_txt_spin_lock)(%ebx) + pause + jnz .Lspin + + /* Increment the stack index and use the next value inside lock */ + incl rva(sl_txt_stack_index)(%ebx) + movl rva(sl_txt_stack_index)(%ebx), %eax + + /* Unlock */ + movl $0, rva(sl_txt_spin_lock)(%ebx) + + /* Location of the relocated AP wake block */ + movl rva(sl_txt_ap_wake_block)(%ebx), %ecx + + /* Load reloc GDT, set segment regs and lret to __SL32_CS */ + lgdt (sl_ap_gdt_desc - sl_txt_ap_wake_begin)(%ecx) + + movl $(__SL32_DS), %edx + movw %dx, %ds + movw %dx, %es + movw %dx, %fs + movw %dx, %gs + movw %dx, %ss + + /* Load our reloc AP stack */ + movl $(TXT_BOOT_STACK_SIZE), %edx + mull %edx + leal (sl_stacks_end - sl_txt_ap_wake_begin)(%ecx), %esp + subl %eax, %esp + + /* Switch to AP code segment */ + leal rva(.Lsl_ap_cs)(%ebx), %eax + pushl $(__SL32_CS) + pushl %eax + lret + +.Lsl_ap_cs: + /* Load the relocated AP IDT */ + lidt (sl_ap_idt_desc - sl_txt_ap_wake_begin)(%ecx) + + /* Fixup MTRRs and misc enable MSR on APs too */ + call sl_txt_load_regs + + /* Enable SMI with GETSEC[SMCTRL] */ + GETSEC $(SMX_X86_GETSEC_SMCTRL) + + /* IRET-to-self can be used to enable NMIs which SENTER disabled */ + leal rva(.Lnmi_enabled_ap)(%ebx), %eax + pushfl + pushl $(__SL32_CS) + pushl %eax + iret + +.Lnmi_enabled_ap: + /* Put APs in X2APIC mode like the BSP */ + movl $(MSR_IA32_APICBASE), %ecx + rdmsr + orl $(XAPIC_ENABLE | X2APIC_ENABLE), %eax + wrmsr + + /* + * Basically done, increment the CPU count and jump off to the AP + * wake block to wait. + */ + lock incl rva(sl_txt_cpu_count)(%ebx) + + movl rva(sl_txt_ap_wake_block)(%ebx), %eax + jmp *%eax +SYM_FUNC_END(sl_txt_ap_entry) + +SYM_FUNC_START(sl_txt_reloc_ap_wake) + /* Save boot params register */ + pushl %esi + + movl rva(sl_txt_ap_wake_block)(%ebx), %edi + + /* Fixup AP IDT and GDT descriptor before relocating */ + leal rva(sl_ap_idt_desc)(%ebx), %eax + addl %edi, 2(%eax) + leal rva(sl_ap_gdt_desc)(%ebx), %eax + addl %edi, 2(%eax) + + /* + * Copy the AP wake code and AP GDT/IDT to the protected wake block + * provided by the loader. Destination already in %edi. + */ + movl $(sl_txt_ap_wake_end - sl_txt_ap_wake_begin), %ecx + leal rva(sl_txt_ap_wake_begin)(%ebx), %esi + rep movsb + + /* Setup the IDT for the APs to use in the relocation block */ + movl rva(sl_txt_ap_wake_block)(%ebx), %ecx + addl $(sl_ap_idt - sl_txt_ap_wake_begin), %ecx + xorl %edx, %edx + + /* Form the default reset vector relocation address */ + movl rva(sl_txt_ap_wake_block)(%ebx), %esi + addl $(sl_txt_int_reset - sl_txt_ap_wake_begin), %esi + +1: + cmpw $(NR_VECTORS), %dx + jz .Lap_idt_done + + cmpw $(X86_TRAP_NMI), %dx + jz 2f + + /* Load all other fixed vectors with reset handler */ + movl %esi, %eax + movw %ax, (IDT_VECTOR_LO_BITS)(%ecx) + shrl $16, %eax + movw %ax, (IDT_VECTOR_HI_BITS)(%ecx) + jmp 3f + +2: + /* Load single wake NMI IPI vector at the relocation address */ + movl rva(sl_txt_ap_wake_block)(%ebx), %eax + addl $(sl_txt_int_ipi_wake - sl_txt_ap_wake_begin), %eax + movw %ax, (IDT_VECTOR_LO_BITS)(%ecx) + shrl $16, %eax + movw %ax, (IDT_VECTOR_HI_BITS)(%ecx) + +3: + incw %dx + addl $8, %ecx + jmp 1b + +.Lap_idt_done: + popl %esi + ret +SYM_FUNC_END(sl_txt_reloc_ap_wake) + +SYM_FUNC_START(sl_txt_load_regs) + /* Save base pointer register */ + pushl %ebx + + /* + * On Intel, the original variable MTRRs and Misc Enable MSR are + * restored on the BSP at early boot. Each AP will also restore + * its MTRRs and Misc Enable MSR. + */ + pushl %edi + addl $(SL_saved_bsp_mtrrs), %edi + movl (%edi), %ebx + pushl %ebx /* default_mem_type lo */ + addl $4, %edi + movl (%edi), %ebx + pushl %ebx /* default_mem_type hi */ + addl $4, %edi + movl (%edi), %ebx /* mtrr_vcnt lo, don't care about hi part */ + addl $8, %edi /* now at MTRR pair array */ + /* Write the variable MTRRs */ + movl $(MTRRphysBase0), %ecx +1: + cmpl $0, %ebx + jz 2f + + movl (%edi), %eax /* MTRRphysBaseX lo */ + addl $4, %edi + movl (%edi), %edx /* MTRRphysBaseX hi */ + wrmsr + addl $4, %edi + incl %ecx + movl (%edi), %eax /* MTRRphysMaskX lo */ + addl $4, %edi + movl (%edi), %edx /* MTRRphysMaskX hi */ + wrmsr + addl $4, %edi + incl %ecx + + decl %ebx + jmp 1b +2: + /* Write the default MTRR register */ + popl %edx + popl %eax + movl $(MSR_MTRRdefType), %ecx + wrmsr + + /* Return to beginning and write the misc enable msr */ + popl %edi + addl $(SL_saved_misc_enable_msr), %edi + movl (%edi), %eax /* saved_misc_enable_msr lo */ + addl $4, %edi + movl (%edi), %edx /* saved_misc_enable_msr hi */ + movl $(MSR_IA32_MISC_ENABLE), %ecx + wrmsr + + popl %ebx + ret +SYM_FUNC_END(sl_txt_load_regs) + +SYM_FUNC_START(sl_txt_wake_aps) + /* Save boot params register */ + pushl %esi + + /* First setup the MLE join structure and load it into TXT reg */ + leal rva(sl_gdt)(%ebx), %eax + leal rva(sl_txt_ap_entry)(%ebx), %ecx + leal rva(sl_smx_rlp_mle_join)(%ebx), %edx + movl %eax, SL_rlp_gdt_base(%edx) + movl %ecx, SL_rlp_entry_point(%edx) + movl %edx, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_MLE_JOIN) + + /* Another TXT heap walk to find various values needed to wake APs */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* At BIOS data size, find the number of logical processors */ + movl (SL_num_logical_procs + 8)(%eax), %edx + /* Skip over BIOS data */ + movl (%eax), %ecx + addl %ecx, %eax + /* Skip over OS to MLE */ + movl (%eax), %ecx + addl %ecx, %eax + /* At OS-SNIT size, get capabilities to know how to wake up the APs */ + movl (SL_capabilities + 8)(%eax), %esi + /* Skip over OS to SNIT */ + movl (%eax), %ecx + addl %ecx, %eax + /* At SINIT-MLE size, get the AP wake MONITOR address */ + movl (SL_rlp_wakeup_addr + 8)(%eax), %edi + + /* Determine how to wake up the APs */ + testl $(1 << TXT_SINIT_MLE_CAP_WAKE_MONITOR), %esi + jz .Lwake_getsec + + /* Wake using MWAIT MONITOR */ + movl $1, (%edi) + jmp .Laps_awake + +.Lwake_getsec: + /* Wake using GETSEC(WAKEUP) */ + GETSEC $(SMX_X86_GETSEC_WAKEUP) + +.Laps_awake: + /* + * All of the APs are woken up and rendesvous in the relocated wake + * block starting at sl_txt_ap_wake_begin. Wait for all of them to + * halt. + */ + pause + cmpl rva(sl_txt_cpu_count)(%ebx), %edx + jne .Laps_awake + + popl %esi + ret +SYM_FUNC_END(sl_txt_wake_aps) + +/* This is the beginning of the relocated AP wake code block */ + .global sl_txt_ap_wake_begin +sl_txt_ap_wake_begin: + + /* + * Wait for NMI IPI in the relocated AP wake block which was provided + * and protected in the memory map by the prelaunch code. Leave all + * other interrupts masked since we do not expect anything but an NMI. + */ + xorl %edx, %edx + +1: + hlt + testl %edx, %edx + jz 1b + + /* + * This is the long absolute jump to the 32b Secure Launch protected + * mode stub code in the rmpiggy. The jump address will be fixed in + * the SMP boot code when the first AP is brought up. This whole area + * is provided and protected in the memory map by the prelaunch code. + */ + .byte 0xea +sl_ap_jmp_offset: + .long 0x00000000 + .word __SL32_CS + +SYM_FUNC_START(sl_txt_int_ipi_wake) + movl $1, %edx + + /* NMI context, just IRET */ + iret +SYM_FUNC_END(sl_txt_int_ipi_wake) + +SYM_FUNC_START(sl_txt_int_reset) + TXT_RESET $(SL_ERROR_INV_AP_INTERRUPT) +SYM_FUNC_END(sl_txt_int_reset) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_idt_desc) + .word sl_ap_idt_end - sl_ap_idt - 1 /* Limit */ + .long sl_ap_idt - sl_txt_ap_wake_begin /* Base */ +SYM_DATA_END_LABEL(sl_ap_idt_desc, SYM_L_LOCAL, sl_ap_idt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_idt) + .rept NR_VECTORS + .word 0x0000 /* Offset 15 to 0 */ + .word __SL32_CS /* Segment selector */ + .word 0x8e00 /* Present, DPL=0, 32b Vector, Interrupt */ + .word 0x0000 /* Offset 31 to 16 */ + .endr +SYM_DATA_END_LABEL(sl_ap_idt, SYM_L_LOCAL, sl_ap_idt_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_gdt_desc) + .word sl_ap_gdt_end - sl_ap_gdt - 1 + .long sl_ap_gdt - sl_txt_ap_wake_begin +SYM_DATA_END_LABEL(sl_ap_gdt_desc, SYM_L_LOCAL, sl_ap_gdt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_gdt) + .quad 0x0000000000000000 /* NULL */ + .quad 0x00cf9a000000ffff /* __SL32_CS */ + .quad 0x00cf92000000ffff /* __SL32_DS */ +SYM_DATA_END_LABEL(sl_ap_gdt, SYM_L_LOCAL, sl_ap_gdt_end) + + /* Small stacks for BSP and APs to work with */ + .balign 4 +SYM_DATA_START_LOCAL(sl_stacks) + .fill (TXT_MAX_CPUS * TXT_BOOT_STACK_SIZE), 1, 0 +SYM_DATA_END_LABEL(sl_stacks, SYM_L_LOCAL, sl_stacks_end) + +/* This is the end of the relocated AP wake code block */ + .global sl_txt_ap_wake_end +sl_txt_ap_wake_end: + + .data + .balign 8 +SYM_DATA_START_LOCAL(sl_gdt_desc) + .word sl_gdt_end - sl_gdt - 1 + .long sl_gdt - sl_gdt_desc +SYM_DATA_END_LABEL(sl_gdt_desc, SYM_L_LOCAL, sl_gdt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_gdt) + .quad 0x0000000000000000 /* NULL */ + .quad 0x00cf9a000000ffff /* __SL32_CS */ + .quad 0x00cf92000000ffff /* __SL32_DS */ +SYM_DATA_END_LABEL(sl_gdt, SYM_L_LOCAL, sl_gdt_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_smx_rlp_mle_join) + .long sl_gdt_end - sl_gdt - 1 /* GDT limit */ + .long 0x00000000 /* GDT base */ + .long __SL32_CS /* Seg Sel - CS (DS, ES, SS = seg_sel+8) */ + .long 0x00000000 /* Entry point physical address */ +SYM_DATA_END(sl_smx_rlp_mle_join) + +SYM_DATA(sl_cpu_type, .long 0x00000000) + +SYM_DATA(sl_mle_start, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_spin_lock, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_stack_index, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_cpu_count, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_ap_wake_block, .long 0x00000000) diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c index ecd3fd6..b665c51 100644 --- a/arch/x86/kernel/asm-offsets.c +++ b/arch/x86/kernel/asm-offsets.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -93,4 +94,22 @@ static void __used common(void) OFFSET(TSS_sp0, tss_struct, x86_tss.sp0); OFFSET(TSS_sp1, tss_struct, x86_tss.sp1); OFFSET(TSS_sp2, tss_struct, x86_tss.sp2); + +#ifdef CONFIG_SECURE_LAUNCH + BLANK(); + OFFSET(SL_boot_params_addr, txt_os_mle_data, boot_params_addr); + OFFSET(SL_saved_misc_enable_msr, txt_os_mle_data, saved_misc_enable_msr); + OFFSET(SL_saved_bsp_mtrrs, txt_os_mle_data, saved_bsp_mtrrs); + OFFSET(SL_ap_wake_block, txt_os_mle_data, ap_wake_block); + OFFSET(SL_ap_wake_block_size, txt_os_mle_data, ap_wake_block_size); + OFFSET(SL_mle_scratch, txt_os_mle_data, mle_scratch); + OFFSET(SL_num_logical_procs, txt_bios_data, num_logical_procs); + OFFSET(SL_capabilities, txt_os_sinit_data, capabilities); + OFFSET(SL_mle_size, txt_os_sinit_data, mle_size); + OFFSET(SL_vtd_pmr_lo_base, txt_os_sinit_data, vtd_pmr_lo_base); + OFFSET(SL_vtd_pmr_lo_size, txt_os_sinit_data, vtd_pmr_lo_size); + OFFSET(SL_rlp_wakeup_addr, txt_sinit_mle_data, rlp_wakeup_addr); + OFFSET(SL_rlp_gdt_base, smx_rlp_mle_join, rlp_gdt_base); + OFFSET(SL_rlp_entry_point, smx_rlp_mle_join, rlp_entry_point); +#endif } From patchwork Fri Aug 27 13:28:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 480DFC25AEE for ; Fri, 27 Aug 2021 13:21:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 297A360FF2 for ; Fri, 27 Aug 2021 13:21:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245280AbhH0NWT (ORCPT ); Fri, 27 Aug 2021 09:22:19 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:31276 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245212AbhH0NWF (ORCPT ); Fri, 27 Aug 2021 09:22:05 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RA7sZ1024207; Fri, 27 Aug 2021 13:20:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=i4xQmbvI4G/h2NIs8DYNtjtoMidMR3X2fKkOhOoUOS8=; b=zlhPJQvIt8bun2SFQ70uLFXjvSadVmCtPZZgbrgTt4YAI41iKOr8oiRKxFLcP55nfMd+ Cnv+z5BFs32eDY16eL2EuZ78iyeMVZWCT+akam2AZbyxYg637SPOHxE6sgMGIaMCSrbb 7T/IXtWWOxf80MIfyRzdNJNJ7RhXG5I4eaTnSFGwmV+lcqG2AKIY5BpwBazL9aVKPmKL jXRrJyC0kjv16kgI4oW4ZYWyirD/SI3lV8ptPBTqRCLOifFFKGf/a2d00YxTJ2/OOsUN WNOcQ7Q6LTK/AC42I1rnx1S4LkBwnCOZx0jWs9HDDu/0H/rBBHSQBEjAp3T4dOcFiltM SQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=i4xQmbvI4G/h2NIs8DYNtjtoMidMR3X2fKkOhOoUOS8=; b=tLbrpyXqDApvTIXKbh/kQFZ5ExgF0yII48SKSxIgy/d+bmC/i+LJE0k+m1pln6HN3d3N eqop309HOKJEfBtYcVJ7lIQih85IZDIvsDNfKyRca02g3HhF3oILeAajb+kWR1KTpaMS vfwK09t3dRjjbC0neEhjJpwoEsIq/kWRZivRtFmiJvjJmaYVn4xwWJPFKOTmFqVkqXtU Sm1F8RTSZQa7Vnk9LWwOkLrzEFWEnhWE1IduskFN/afzEmUlG7tqMeWFlONw2mOadt9T oNsaVttp5E0blEj6foSxM8NUIrs0Ur11QxfJXeqwYdsh3eni/9I5LCLVEaSAf3OiORef Rw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap0xpbyx4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:55 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RDBXLM007403; Fri, 27 Aug 2021 13:20:54 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2043.outbound.protection.outlook.com [104.47.51.43]) by aserp3030.oracle.com with ESMTP id 3ajqhmjmbs-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WGveCsFd6yIUPAMR3nOhgK7P/zUYoTGpxjtE3Bh+vhZ45ilDSy85omix5GzkolsXb1fiN8YjMGrtRAi0fpFaR31KC+6bG6xmsGklgaQbXTPZzpmE6pSLBFFRtef2kF4nL4BQWmQvMcP/KRQgULRSb8gPA+Q5sZ1YkdoYAdvoCjcgsmhj5Gd+bhLH57Mg2DOO+0C7E7QVoaiiptfqCuOoeABv230eHHRxzjjFwRu1oNmSQih3g3WLQFAZQQE9zlVnd9ZXc1QwFFE1s1bAG8SrD8rOA14Vny2mpm34/+waiS1yMIUW1mTLKle8XgAI+3c7ae8+vdUppB9tTzXsrvAVnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=i4xQmbvI4G/h2NIs8DYNtjtoMidMR3X2fKkOhOoUOS8=; b=hFy0SvULxGr91A+S7cRtaniXfZCMCwHXf+YhD+lsdPpjZwwgoSIW/+ngYasxu3rHwzbON4idj2eBDkrvLJzw824gOWrohWsTWKpiVWNLvIJSxsPvaP2LD/e9Y5Z7x25wbUbTSGCaonZ3gAmtA+0y39M3xHpKyU1mjphU9qOiRPV/bv4NaoVXd0X39zei2zzzHzZyExgoVJ4iGQeWgur2MumokMTpXKbKlF/+hy507knAKkEQ0Ch7ik8X6UX57YRDovFUHEkz7liZeWPfX4e0Pp5ioEeLYD3QBF6aKHl+T++jOTi0Sh3SUTkVAzTLGCEADY+UKVNIdfgeuyHe4zOrNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=i4xQmbvI4G/h2NIs8DYNtjtoMidMR3X2fKkOhOoUOS8=; b=Qm9LjrsbuDFAHc51oGCp6Zi695HZXwnC0ivLu1Cc/devX/Kgm3GB5nLpSd7E01Omr7OuAOVF/wg/MoPwyZ81WUHHoLc3rfRQCuLkAq0EMtaFTCJ1IxMkHJI/8HWTLjBpfRXidFGYUkw+SkepYw+8NkvuoD33nmRvp0RN+g0mTPU= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:52 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:52 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 09/14] x86: Secure Launch kernel late boot stub Date: Fri, 27 Aug 2021 09:28:32 -0400 Message-Id: <1630070917-9896-10-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 017dce5b-e83f-4def-e4f3-08d9695d7e2c X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BaToLpkIEtBm+IbpHgPRIHg5tJux2GZDEi2WSk8/qF+CLTj8izjrh8Cgq1TKH3nV3tmdf8DHcjmUwEXyns1hor1bt7WaORCKiKpZXhDVWBUeThiOHzbsj8OVz95MGh5frlsgL67r2aeLINyvohk5A6HWaHedHa55rKNh6z0Yp/hS0cxD9ubi7vytxOmZWMUd8HgTeqUUkcqceoLTyjGW21VrXI2KL+ljCfCRqYpqjCfPpsjEMLlAGQxvIQtgVk1f39MG59CjPYNJsQnlFKoKYycbNtz8JFkesRI0dlMB0tMk0bf9cK+rx8irQx8fKtjNBzok8lCFvbfMnS/ocpa9C9sDoyGbxIarrCGEaDVnFeYVaAAkKe83six7PxeXe1HPv29ZUUACeazKZy9dJGSACdiEwGwGpHCKTyO4DGFRjw4aCKLfDdOltZczvi+du1uAzbX7BxkCdc2hAtKo9x5HqAMeEU6OitUQTx6aymtMI5UiWYbiyscC7QLjIzFr9eZ3i5fGYVHCYWWzTM+b315CimBlhK19tu4GmQKQGB7tixYu30gs+kxcIi0CuxKzfdhdSPFNMKyPug4dnaei/g28PX0TSDorlLPZNEzxJWGq1/YSTpSVXK+r/FRlyVr41vCJl7FrHQlWDRpcoZ7U2nPoLOdYzy1U760M1ubcduCREPiou64qdF7ZfvC0EzKdWC1g3BLhL2fw3i7BIdzm2urPeg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(30864003)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +8AqBj5TyNxXBoPG0D5jfEu2uLJy/RUlRIgS8aFkO0NxiDxk16Kv7e2Xp767lzFludkebeNPOUzKWmdUHJusl8AG14KJFAlNxoMiYuyUOBXfwOskIhLDvV2OfLN1Em+fHI/81n9pTzRIN8sm6umw5s2yGOnE5G6Nmi+aMzo78GOhKBjW4fsOTmD2bJG8ZYQ5u4wtWqUSiS6IItEw6PThtWcMCmNhGC+UJWUbYjmXk9mPYQOhEaMjN+9psDL43sSmsrg7d2OGSg9xnCDhQYcBj8SV2fqhBsX5cBLynrigI59xazJevL0YKFHpYlEJ1TK1fRiafk91pJ8uHAKLQ8cpI4EEG19c45gSey/iGabjJkmb9sKgte+2JYRWO5nJmgSmTdda/H4xf+hZ7cN7pv5EsxvnPL+W5P0jxFaYFHt030g8yyo/RIOBYUWkqOblCY+BBHHSYD+12S8CXpRnM9ETkffoba0bnmY4cte2vl4xGnY6uUvEzpewpQbajywh3WiyI0s0lzG4pG4vl4XZgLR1EIS6R8tTrD4ge+MOyo67ICIPh/JOUqI8pRE6rhKd5ZbBD/FL2TlrBvjxuV2SqafCnIpEaFUm1jfdcnAfQZ4v1Tu59MnBpMb7jDyE/eTB/yP0TswxVth/nJG9jsDKC9kOMLEqW1n5q/HUhUwDUYDd3WNSROVcUApO8l67fKoruL0FTdCgmQV/Xnx6tc4epHghlPxjG6MvNo+EqjdKanEytFL7zFSDp3JeR8O1MoY5PJDx5g0owz/jVC47MoiltrT6MX4NW7/gPW0VCvJFlyDckL86F+3t5Aw0rdkFvq3CRTn7PBEmilBIXN2tD6wXNajaTJl7LHPwRYaRFMBOiReU7zF2fBiPMwEALOWjGobPUUqwTRnzLlqaHqnyYbrez+64ogERJavFmzPUWeHPCMr4oHNvFVtvofijRjPqULsTTKsE2MA4qL2r4nJJV1tX360vQH6zQzHZDItCQwajEmeoVWkN4AcqCCd0hOfwh6LVSU9IjiQOkNYnefhUiiaI6i0kZFE70R975k0fXa5UebP0moGnMMW+Rxdbr29iCFqGiowaaAsTB8GPaSa/JJO7j1A6r5+0QGKZMEQwYxm3SUBzEtDKoIUXXGrHu5IaPnLRjox/r08W7mgj/ZcaKwVGtob1TApdT9ATHYfUlC/cRIgzZP/xXkC8kGBUR6H8c1Fo/XPQaD3NToUzwEC5PztcziXJa7/CeR3+8qjFEdxwuFhwlq5O75Ux3uL6kEF/fF+hgZBzZYBISDuLfrUoNHrFGr60bXGzp/+7CTeixWVqzi2UvmdDrW14sCyy+riGkMWuAZiW X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 017dce5b-e83f-4def-e4f3-08d9695d7e2c X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:52.1131 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sWCubs3nC0ahkGaZ+RSyjIEpyi5roDB6XFGQIrBmSn5kUnAhEAG3rItnp5a9gG6fjKT1mtwZYGfFk1je0gE7Al6ZA2/thSLHv5UdCiXZ1uw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: YPnD9WqctYBD3WRfXQIXA3HUDN_wfVoK X-Proofpoint-ORIG-GUID: YPnD9WqctYBD3WRfXQIXA3HUDN_wfVoK Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org The routine slaunch_setup is called out of the x86 specific setup_arch routine during early kernel boot. After determining what platform is present, various operations specific to that platform occur. This includes finalizing setting for the platform late launch and verifying that memory protections are in place. For TXT, this code also reserves the original compressed kernel setup area where the APs were left looping so that this memory cannot be used. Signed-off-by: Ross Philipson --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/setup.c | 3 + arch/x86/kernel/slaunch.c | 460 +++++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/intel/dmar.c | 4 + 4 files changed, 468 insertions(+) create mode 100644 arch/x86/kernel/slaunch.c diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 3e625c6..d6ee904 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -80,6 +80,7 @@ obj-$(CONFIG_X86_32) += tls.o obj-$(CONFIG_IA32_EMULATION) += tls.o obj-y += step.o obj-$(CONFIG_INTEL_TXT) += tboot.o +obj-$(CONFIG_SECURE_LAUNCH) += slaunch.o obj-$(CONFIG_ISA_DMA_API) += i8237.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-y += cpu/ diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 055a834..482bd76 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -976,6 +977,8 @@ void __init setup_arch(char **cmdline_p) early_gart_iommu_check(); #endif + slaunch_setup_txt(); + /* * partially used pages are not usable - thus * we are rounding upwards: diff --git a/arch/x86/kernel/slaunch.c b/arch/x86/kernel/slaunch.c new file mode 100644 index 0000000..f91f0b5 --- /dev/null +++ b/arch/x86/kernel/slaunch.c @@ -0,0 +1,460 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Secure Launch late validation/setup and finalization support. + * + * Copyright (c) 2021, Oracle and/or its affiliates. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static u32 sl_flags; +static struct sl_ap_wake_info ap_wake_info; +static u64 evtlog_addr; +static u32 evtlog_size; +static u64 vtd_pmr_lo_size; + +/* This should be plenty of room */ +static u8 txt_dmar[PAGE_SIZE] __aligned(16); + +u32 slaunch_get_flags(void) +{ + return sl_flags; +} +EXPORT_SYMBOL(slaunch_get_flags); + +struct sl_ap_wake_info *slaunch_get_ap_wake_info(void) +{ + return &ap_wake_info; +} + +struct acpi_table_header *slaunch_get_dmar_table(struct acpi_table_header *dmar) +{ + /* The DMAR is only stashed and provided via TXT on Intel systems */ + if (memcmp(txt_dmar, "DMAR", 4)) + return dmar; + + return (struct acpi_table_header *)(&txt_dmar[0]); +} + +void __noreturn slaunch_txt_reset(void __iomem *txt, + const char *msg, u64 error) +{ + u64 one = 1, val; + + pr_err("%s", msg); + + /* + * This performs a TXT reset with a sticky error code. The reads of + * TXT_CR_E2STS act as barriers. + */ + memcpy_toio(txt + TXT_CR_ERRORCODE, &error, sizeof(error)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + memcpy_toio(txt + TXT_CR_CMD_NO_SECRETS, &one, sizeof(one)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + memcpy_toio(txt + TXT_CR_CMD_UNLOCK_MEM_CONFIG, &one, sizeof(one)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + memcpy_toio(txt + TXT_CR_CMD_RESET, &one, sizeof(one)); + + for ( ; ; ) + asm volatile ("hlt"); + + unreachable(); +} + +/* + * The TXT heap is too big to map all at once with early_ioremap + * so it is done a table at a time. + */ +static void __init *txt_early_get_heap_table(void __iomem *txt, u32 type, + u32 bytes) +{ + void *heap; + u64 base, size, offset = 0; + int i; + + if (type > TXT_SINIT_TABLE_MAX) + slaunch_txt_reset(txt, + "Error invalid table type for early heap walk\n", + SL_ERROR_HEAP_WALK); + + memcpy_fromio(&base, txt + TXT_CR_HEAP_BASE, sizeof(base)); + memcpy_fromio(&size, txt + TXT_CR_HEAP_SIZE, sizeof(size)); + + /* Iterate over heap tables looking for table of "type" */ + for (i = 0; i < type; i++) { + base += offset; + heap = early_memremap(base, sizeof(u64)); + if (!heap) + slaunch_txt_reset(txt, + "Error early_memremap of heap for heap walk\n", + SL_ERROR_HEAP_MAP); + + offset = *((u64 *)heap); + + /* + * After the first iteration, any offset of zero is invalid and + * implies the TXT heap is corrupted. + */ + if (!offset) + slaunch_txt_reset(txt, + "Error invalid 0 offset in heap walk\n", + SL_ERROR_HEAP_ZERO_OFFSET); + + early_memunmap(heap, sizeof(u64)); + } + + /* Skip the size field at the head of each table */ + base += sizeof(u64); + heap = early_memremap(base, bytes); + if (!heap) + slaunch_txt_reset(txt, + "Error early_memremap of heap section\n", + SL_ERROR_HEAP_MAP); + + return heap; +} + +static void __init txt_early_put_heap_table(void *addr, unsigned long size) +{ + early_memunmap(addr, size); +} + +/* + * TXT uses a special set of VTd registers to protect all of memory from DMA + * until the IOMMU can be programmed to protect memory. There is the low + * memory PMR that can protect all memory up to 4G. The high memory PRM can + * be setup to protect all memory beyond 4Gb. Validate that these values cover + * what is expected. + */ +static void __init slaunch_verify_pmrs(void __iomem *txt) +{ + struct txt_os_sinit_data *os_sinit_data; + unsigned long last_pfn; + u32 field_offset, err = 0; + const char *errmsg = ""; + + field_offset = offsetof(struct txt_os_sinit_data, lcp_po_base); + os_sinit_data = txt_early_get_heap_table(txt, TXT_OS_SINIT_DATA_TABLE, + field_offset); + + /* Save a copy */ + vtd_pmr_lo_size = os_sinit_data->vtd_pmr_lo_size; + + last_pfn = e820__end_of_ram_pfn(); + + /* + * First make sure the hi PMR covers all memory above 4G. In the + * unlikely case where there is < 4G on the system, the hi PMR will + * not be set. + */ + if (os_sinit_data->vtd_pmr_hi_base != 0x0ULL) { + if (os_sinit_data->vtd_pmr_hi_base != 0x100000000ULL) { + err = SL_ERROR_HI_PMR_BASE; + errmsg = "Error hi PMR base\n"; + goto out; + } + + if (PFN_PHYS(last_pfn) > os_sinit_data->vtd_pmr_hi_base + + os_sinit_data->vtd_pmr_hi_size) { + err = SL_ERROR_HI_PMR_SIZE; + errmsg = "Error hi PMR size\n"; + goto out; + } + } + + /* + * Lo PMR base should always be 0. This was already checked in + * early stub. + */ + + /* + * Check that if the kernel was loaded below 4G, that it is protected + * by the lo PMR. Note this is the decompressed kernel. The ACM would + * have ensured the compressed kernel (the MLE image) was protected. + */ + if ((__pa_symbol(_end) < 0x100000000ULL) && + (__pa_symbol(_end) > os_sinit_data->vtd_pmr_lo_size)) { + err = SL_ERROR_LO_PMR_MLE; + errmsg = "Error lo PMR does not cover MLE kernel\n"; + } + + /* + * Other regions of interest like boot param, AP wake block, cmdline + * already checked for PMR coverage in the early stub code. + */ + +out: + txt_early_put_heap_table(os_sinit_data, field_offset); + + if (err) + slaunch_txt_reset(txt, errmsg, err); +} + +static void __init slaunch_txt_reserve_range(u64 base, u64 size) +{ + int type; + + type = e820__get_entry_type(base, base + size - 1); + if (type == E820_TYPE_RAM) { + pr_info("memblock reserve base: %llx size: %llx\n", base, size); + memblock_reserve(base, size); + } +} + +/* + * For Intel, certain regions of memory must be marked as reserved by putting + * them on the memblock reserved list if they are not already e820 reserved. + * This includes: + * - The TXT HEAP + * - The ACM area + * - The TXT private register bank + * - The MDR list sent to the MLE by the ACM (see TXT specification) + * (Normally the above are properly reserved by firmware but if it was not + * done, reserve them now) + * - The AP wake block + * - TPM log external to the TXT heap + * + * Also if the low PMR doesn't cover all memory < 4G, any RAM regions above + * the low PMR must be reservered too. + */ +static void __init slaunch_txt_reserve(void __iomem *txt) +{ + struct txt_sinit_memory_descriptor_record *mdr; + struct txt_sinit_mle_data *sinit_mle_data; + void *mdrs; + u64 base, size, heap_base, heap_size; + u32 field_offset, mdrnum, mdroffset, mdrslen, i; + + base = TXT_PRIV_CONFIG_REGS_BASE; + size = TXT_PUB_CONFIG_REGS_BASE - TXT_PRIV_CONFIG_REGS_BASE; + slaunch_txt_reserve_range(base, size); + + memcpy_fromio(&heap_base, txt + TXT_CR_HEAP_BASE, sizeof(heap_base)); + memcpy_fromio(&heap_size, txt + TXT_CR_HEAP_SIZE, sizeof(heap_size)); + slaunch_txt_reserve_range(heap_base, heap_size); + + memcpy_fromio(&base, txt + TXT_CR_SINIT_BASE, sizeof(base)); + memcpy_fromio(&size, txt + TXT_CR_SINIT_SIZE, sizeof(size)); + slaunch_txt_reserve_range(base, size); + + field_offset = offsetof(struct txt_sinit_mle_data, + sinit_vtd_dmar_table_size); + sinit_mle_data = txt_early_get_heap_table(txt, TXT_SINIT_MLE_DATA_TABLE, + field_offset); + + mdrnum = sinit_mle_data->num_of_sinit_mdrs; + mdroffset = sinit_mle_data->sinit_mdrs_table_offset; + + txt_early_put_heap_table(sinit_mle_data, field_offset); + + if (!mdrnum) + goto nomdr; + + mdrslen = (mdrnum * sizeof(struct txt_sinit_memory_descriptor_record)); + + mdrs = txt_early_get_heap_table(txt, TXT_SINIT_MLE_DATA_TABLE, + mdroffset + mdrslen - 8); + + mdr = (struct txt_sinit_memory_descriptor_record *) + (mdrs + mdroffset - 8); + + for (i = 0; i < mdrnum; i++, mdr++) { + /* Spec says some entries can have length 0, ignore them */ + if (mdr->type > 0 && mdr->length > 0) + slaunch_txt_reserve_range(mdr->address, mdr->length); + } + + txt_early_put_heap_table(mdrs, mdroffset + mdrslen - 8); + +nomdr: + slaunch_txt_reserve_range(ap_wake_info.ap_wake_block, + ap_wake_info.ap_wake_block_size); + + /* + * Earlier checks ensured that the event log was properly situated + * either inside the TXT heap or outside. This is a check to see if the + * event log needs to be reserved. If it is in the TXT heap, it is + * already reserved. + */ + if (evtlog_addr < heap_base || evtlog_addr > (heap_base + heap_size)) + slaunch_txt_reserve_range(evtlog_addr, evtlog_size); + + for (i = 0; i < e820_table->nr_entries; i++) { + base = e820_table->entries[i].addr; + size = e820_table->entries[i].size; + if ((base >= vtd_pmr_lo_size) && (base < 0x100000000ULL)) + slaunch_txt_reserve_range(base, size); + else if ((base < vtd_pmr_lo_size) && + (base + size > vtd_pmr_lo_size)) + slaunch_txt_reserve_range(vtd_pmr_lo_size, + base + size - vtd_pmr_lo_size); + } +} + +/* + * TXT stashes a safe copy of the DMAR ACPI table to prevent tampering. + * It is stored in the TXT heap. Fetch it from there and make it available + * to the IOMMU driver. + */ +static void __init slaunch_copy_dmar_table(void __iomem *txt) +{ + struct txt_sinit_mle_data *sinit_mle_data; + void *dmar; + u32 field_offset, dmar_size, dmar_offset; + + memset(&txt_dmar, 0, PAGE_SIZE); + + field_offset = offsetof(struct txt_sinit_mle_data, + processor_scrtm_status); + sinit_mle_data = txt_early_get_heap_table(txt, TXT_SINIT_MLE_DATA_TABLE, + field_offset); + + dmar_size = sinit_mle_data->sinit_vtd_dmar_table_size; + dmar_offset = sinit_mle_data->sinit_vtd_dmar_table_offset; + + txt_early_put_heap_table(sinit_mle_data, field_offset); + + if (!dmar_size || !dmar_offset) + slaunch_txt_reset(txt, + "Error invalid DMAR table values\n", + SL_ERROR_HEAP_INVALID_DMAR); + + if (unlikely(dmar_size > PAGE_SIZE)) + slaunch_txt_reset(txt, + "Error DMAR too big to store\n", + SL_ERROR_HEAP_DMAR_SIZE); + + + dmar = txt_early_get_heap_table(txt, TXT_SINIT_MLE_DATA_TABLE, + dmar_offset + dmar_size - 8); + if (!dmar) + slaunch_txt_reset(txt, + "Error early_ioremap of DMAR\n", + SL_ERROR_HEAP_DMAR_MAP); + + memcpy(&txt_dmar[0], dmar + dmar_offset - 8, dmar_size); + + txt_early_put_heap_table(dmar, dmar_offset + dmar_size - 8); +} + +/* + * The location of the safe AP wake code block is stored in the TXT heap. + * Fetch it here in the early init code for later use in SMP startup. + * + * Also get the TPM event log values that may have to be put on the + * memblock reserve list later. + */ +static void __init slaunch_fetch_os_mle_fields(void __iomem *txt) +{ + struct txt_os_mle_data *os_mle_data; + u8 *jmp_offset; + + os_mle_data = txt_early_get_heap_table(txt, TXT_OS_MLE_DATA_TABLE, + sizeof(*os_mle_data)); + + ap_wake_info.ap_wake_block = os_mle_data->ap_wake_block; + ap_wake_info.ap_wake_block_size = os_mle_data->ap_wake_block_size; + + jmp_offset = os_mle_data->mle_scratch + SL_SCRATCH_AP_JMP_OFFSET; + ap_wake_info.ap_jmp_offset = *((u32 *)jmp_offset); + + evtlog_addr = os_mle_data->evtlog_addr; + evtlog_size = os_mle_data->evtlog_size; + + txt_early_put_heap_table(os_mle_data, sizeof(*os_mle_data)); +} + +/* + * Intel TXT specific late stub setup and validation. + */ +void __init slaunch_setup_txt(void) +{ + void __iomem *txt; + u64 one = TXT_REGVALUE_ONE, val; + + if (!boot_cpu_has(X86_FEATURE_SMX)) + return; + + /* + * First see if SENTER was done and not by TBOOT by reading the status + * register in the public space. If the public register space cannot + * be read, TXT is disabled. + */ + txt = early_ioremap(TXT_PUB_CONFIG_REGS_BASE, + TXT_NR_CONFIG_PAGES * PAGE_SIZE); + if (!txt) + return; + + memcpy_fromio(&val, txt + TXT_CR_STS, sizeof(val)); + early_iounmap(txt, TXT_NR_CONFIG_PAGES * PAGE_SIZE); + + /* Was SENTER done? */ + if (!(val & TXT_SENTER_DONE_STS)) + return; + + /* Was it done by TBOOT? */ + if (boot_params.tboot_addr) + return; + + /* Now we want to use the private register space */ + txt = early_ioremap(TXT_PRIV_CONFIG_REGS_BASE, + TXT_NR_CONFIG_PAGES * PAGE_SIZE); + if (!txt) { + /* This is really bad, no where to go from here */ + panic("Error early_ioremap of TXT priv registers\n"); + } + + /* + * Try to read the Intel VID from the TXT private registers to see if + * TXT measured launch happened properly and the private space is + * available. + */ + memcpy_fromio(&val, txt + TXT_CR_DIDVID, sizeof(val)); + if ((u16)(val & 0xffff) != 0x8086) { + /* + * Can't do a proper TXT reset since it appears something is + * wrong even though SENTER happened and it should be in SMX + * mode. + */ + panic("Invalid TXT vendor ID, not in SMX mode\n"); + } + + /* Set flags so subsequent code knows the status of the launch */ + sl_flags |= (SL_FLAG_ACTIVE|SL_FLAG_ARCH_TXT); + + /* + * Reading the proper DIDVID from the private register space means we + * are in SMX mode and private registers are open for read/write. + */ + + /* On Intel, have to handle TPM localities via TXT */ + memcpy_toio(txt + TXT_CR_CMD_SECRETS, &one, sizeof(one)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + memcpy_toio(txt + TXT_CR_CMD_OPEN_LOCALITY1, &one, sizeof(one)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + + slaunch_fetch_os_mle_fields(txt); + + slaunch_verify_pmrs(txt); + + slaunch_txt_reserve(txt); + + slaunch_copy_dmar_table(txt); + + early_iounmap(txt, TXT_NR_CONFIG_PAGES * PAGE_SIZE); + + pr_info("Intel TXT setup complete\n"); +} diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index d66f79a..d167e5d 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -663,6 +664,9 @@ static inline int dmar_walk_dmar_table(struct acpi_table_dmar *dmar, */ dmar_tbl = tboot_get_dmar_table(dmar_tbl); + /* If Secure Launch is active, it has similar logic */ + dmar_tbl = slaunch_get_dmar_table(dmar_tbl); + dmar = (struct acpi_table_dmar *)dmar_tbl; if (!dmar) return -ENODEV; From patchwork Fri Aug 27 13:28:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6002C432BE for ; Fri, 27 Aug 2021 13:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A809961027 for ; Fri, 27 Aug 2021 13:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245191AbhH0NWC (ORCPT ); Fri, 27 Aug 2021 09:22:02 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:24184 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232220AbhH0NV6 (ORCPT ); Fri, 27 Aug 2021 09:21:58 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RAFI2e015048; Fri, 27 Aug 2021 13:20:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=3mdbDIv/S/lggxNYRfzq4aRZ4D5Sk/xd9kkDvIMPGfM=; b=Y7b2fw0ClhgxXcmvQ8h0dayz2aqc9XPQpGAZmftbrHAyByoIlGOnz6Z5SmYt0vtiCX3a VJINjrBbsZ8npRnxxce+M0W7cBP31aUrILM8u8x0dVLzXBh2GBiNJtT1xAcjLuqdwuHU ZjZmrcojAkvgXXSH4/X0OHVyPT8doKo2FNiOsmn07XZmI1xWyVOcDbvENkqcMdfeU6ln M8QHVfmu8ID/luzwoIC5iHzKE+9Xn8oPZLG9SUd3cA6alqak21jxFLTrVyawZ9pnE5i7 5A3cLHNUfYMqlVeLlO7Uv8t2HMREC6dH2Y5iAdtUzqXN/Q5yQB4ojp/xbbguxozINET5 kw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=3mdbDIv/S/lggxNYRfzq4aRZ4D5Sk/xd9kkDvIMPGfM=; b=CKvss5LwyT5N9SrHEQIWm9FNIKY+/qRciGMCDm/k7Yhc/ZbX2Bb9C5MPfPrBma20p5yI T4U2HCZNoy0L9BfetpIFF6cAe8wkaUFD9on0WBLvq+cUubk/jLuOJY80x/IrgE32cFQQ mrh1TQx8tOcf1tTJiv6CJ6CDhA3Edi8sSwjJ9EcbfocngTD0lhR/cMOw0O+x/6qmHlEH CKqKRPL/fiNLaQ0KWm+/FLF8EoCcA/+xwCmpb61Uuiij3+x2aouN6KZZ+GRB9x1Eqqgw QPntTr6D8FNWl24wUFY8+S4fEq5EP2OQpHN08WG6VpipKTqTroH8j/xsf7Za3mEONz9g tA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap4xv3gy0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:57 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RD9nxI076969; Fri, 27 Aug 2021 13:20:56 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2044.outbound.protection.outlook.com [104.47.51.44]) by userp3030.oracle.com with ESMTP id 3ajpm4pqdq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VXXRoHhiFjJzrVS0jy7ldSWiAcibiAOXr+Jl7KAjeNgoZNSweQbyMiPcA0Z57PSnLN+6e3bx+Bc6p/1gRGUKamhOW+Qsop48I2FRZrLamBjnXjPdPrkBAmZsBMsiuxbk8uS5EIXAuxCiGiLZW+ollW+3upOsoQKgtl0Fk4sFaRSsnjQGfyMI9XeetKmdZjnTZZay+3cs/pFLJ+efg+Ths9gnYekjW3f0hZyW6pmEM5Z/F8HlJaODWhU2tC6Esj5vaTUhBB9yA4znLTPM7vgan7+jzbcLxhwinhYdNpzAw0yq9twraJPZ2fsy+5TKbLGAO73mJkpXdfce9wap4gA6cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3mdbDIv/S/lggxNYRfzq4aRZ4D5Sk/xd9kkDvIMPGfM=; b=ZrYsptW97TUS52j3jndTIK6s8FUP1AGq82eJMD128+ZMTm4AF0EK3Bastd0X6VlTmF4rM1RxMQvjen+SPQ9xIxZg8asRbfWL74AZB+NLWN8XE4cJR84FZl5sJ0M/mhSwkf8ICLMrtZ9rbecK6eeumMFrJPt3IjdfqD/GDFow0h8ejBh6TNeM4O5TEomdxunIyzspJONOauKPn5KfrKFYFEcqISYBgc/HJ8OfS0zkgUhcxTyPeGJBBwqIMbI/CYOSopyvwEWRJCjM7Pt3HnqWhFzIQtcilVHmaLAQ7BDwaa2b/0DZGrYNaGjlP5Ow+jXd2QouJPAuO7rrEZ4Jlm1Gpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3mdbDIv/S/lggxNYRfzq4aRZ4D5Sk/xd9kkDvIMPGfM=; b=RTh5ieozoT66RDDMQUakKFnYvZpCD6GM4Hc3MOnQVggnNx11SE4AfJCXNNCZiCamN0L2rGn7RWHisrs8lmqxGjBJVtP+0rtNa5NJJcf8p0C9W/7foqsgzDT7JqzAmiWpAVDtv8TXqB0TKH5zhbE5M8Zemkl4JCFv1TWBaZJXykQ= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:53 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:53 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 10/14] x86: Secure Launch SMP bringup support Date: Fri, 27 Aug 2021 09:28:33 -0400 Message-Id: <1630070917-9896-11-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30344e5e-0645-4f3c-3aca-08d9695d7f2f X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wSlf+AwXNdZ3BOAIKX2C48GHe33DwqC70wgwJIn230r0IuMVM84aSaqb3b64A9gicBZgAYgy9ZSpaQF/rObTpgUYfyN0FS5POu++9w+tqOrKTeOwvCxjHA2KuQsPQbcsMH/5LKO9meV67FqyWXtYl08s/DiC8yGG1J/po0rWehnTC7DUm01YKROAJ1t6jfyVElnP2RulXA946LrUZjoUuVVkJPyhOM1XdeDbQK+FQLZLoahOPkkjgEzNwVMXb0wn9dS9++cRvIJ0JuLGNmPkZyWnTdHnpp+UXRXHLAFmJRtxpfcie3yh8CBCcLwPCe0kJVNtmE5vE4xvWVPfXjuf6q40qzm40DCVZyQtnJZ+AKwxBEpY90biBcrLvKOR5bd80f90uNAejDr/SbNhGXZGFap/dB34bApRpdbxLP0yQNQhyg6hLSDV/R//wLOBwhbaYDv18X7L3a2RpK1WVap6rA1VUNGRKbQLfo6vKBHVllMbAt87YImdyti1KXSHvPDpqLpQQVyiNxsUCxMKzFowpYgdFM26cG/xSCnZU+44JODagiQNKlceo10dQXfgEiQvWDVGvfDSYAdPvSDP5642SAJ9dM3CcgZGQl1+WBSBmht/Gwm5f00HuXEHsBRs3/rnxLvSTHex0n7OX9TKI+lVmHqJEttvYtnEx26NLCgAAumZ51Ca6yOcEZ0lVyeNA4rVCZuNajoIQpwsKa0X1oTFPQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PI210alAE6hhx5BSVADkeg6UMDw6eRId92rWG4bhFAUt6MJrmuyAAPAKL8B8bHNb0uWJ3doYY100jkRdFO47bLQbzhom46qau9T2+JrVNexiXBqdCjrjlW6wUIP2oHS0nFrRLchdiREE3eSklYX+cdYgLh+w9M1rd9R7eBO8mi7XJlNhUlAW5yhncmXskfiIhWK3w24/pEM3GWsZdTocgmvPaAx+fJnaQfWzqvgMcu9qC8mkZGmvyLZTa3MVE9gUazNv46WuZYV9xTRvTsPME27rT74ctsu33AT5G92+NV7nAXZO53BVKtFBNpEVHSfydvbS/rt5M0BPqQpxnFkWv9FmZFkiGuVcaJScA2W43Us8cE80tsYnxfCnPJnSjSNblDqpNcqOwZGGTwH4lEzGvw0v4JAmf9h95VekDH2WKyAVVyMhExMfyBBgvSq9Qlw5vt4TEpYKzN5gLGVZqzN/+ukC33MyQcrZ/Xqcg8KjEimZmYX4hBxUWWgE3VmtaIxDfcDBbapRdpMJR68whIo5iIpNm0TVZFp6eGxHFjzQsQnV7cCvNnflz7kOEEXU6pU+sRMuSu3bPC0fSaOfEE6Is2efcEt+dJzrbYvBPWwmSmvRF28/uc6rdqj4vuIt3n2nMDn0queDbvmB+GRj5zJX1fdUJv/87ozdz8wHOEJu9EDh+lFGXXSi05zE/al5elWl7yv0LSjaSVtHkwg0mDT9CU3o4Z5pkP83EaU/exR0tUEwFLej0tUfV/eu50Gc236XR0tXTl17ItdjJP5TT71grsu95rmQtHqhrtT62aiz60GPpqe8CmG3FgLPdDCt8yiSRauD6MvSS/SeAQRYAy8x8blIPPswGdIQvqUSnMsOhcQvVWJvyLVshyPt9/Lu5lSOxby2U8GN7B6/JhdMvZ5CdDbaXL7dbB9ECJvrGmZnNizUnQZSRvc6pKENi2JjzxNBDZFWvQes2aMiXgnKfI0omsloSnd9CXAaP+bIdIJhCbaHdmim0QYvBdvBEBnUCRb9gDbNEfqt7JpbN/ejYPc6o3mQ+ApXK/9Xj80C6N54ZoMOFMLtnYCJYdO1fP1zNwrFDNxJ90vPlvmhCn6D7qsRhtRRVLf1M4ulZ2OUQwVZU1Jx2rghqme1WIuLga2BgIRPHArcxyGBKvzb5Mx8jFFjK7HiAZF7HGnZMAr8Bb0tvzaJijf3wp3aqiqrWQhx8SLJHGy9FL44St+V/8/Fpiosqad9BOUdDITTthQDhqfrzhAwhmO1Hl/7FsY4/hjBRXvB4r+1poUX5Q1RNyAQ1rwvP/pAoMOyU7BFeN4RFr/KBzFZ0zSnPYi1EyzJ217RjDQW X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30344e5e-0645-4f3c-3aca-08d9695d7f2f X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:53.7641 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vV/zrwafi2I1ehU/MCVRcNXnvztVkWFqdL0VGDOLYY89sgsQSnr9c6bFV7QEHNXIgmfk9mtD/pqvC9myYtWsRSDd9WOJVMVnJ4/z37O6kwQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-ORIG-GUID: JHwHtlovlIysZaQk4R5kZXmJwe-6siw9 X-Proofpoint-GUID: JHwHtlovlIysZaQk4R5kZXmJwe-6siw9 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org On Intel, the APs are left in a well documented state after TXT performs the late launch. Specifically they cannot have #INIT asserted on them so a standard startup via INIT/SIPI/SIPI cannot be performed. Instead the early SL stub code parked the APs in a pause/jmp loop waiting for an NMI. The modified SMP boot code is called for the Secure Launch case. The jump address for the RM piggy entry point is fixed up in the jump where the APs are waiting and an NMI IPI is sent to the AP. The AP vectors to the Secure Launch entry point in the RM piggy which mimics what the real mode code would do then jumps the the standard RM piggy protected mode entry point. Signed-off-by: Ross Philipson --- arch/x86/include/asm/realmode.h | 3 ++ arch/x86/kernel/smpboot.c | 86 ++++++++++++++++++++++++++++++++++++ arch/x86/realmode/rm/header.S | 3 ++ arch/x86/realmode/rm/trampoline_64.S | 37 ++++++++++++++++ 4 files changed, 129 insertions(+) diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h index 5db5d08..ef37bf1 100644 --- a/arch/x86/include/asm/realmode.h +++ b/arch/x86/include/asm/realmode.h @@ -37,6 +37,9 @@ struct real_mode_header { #ifdef CONFIG_X86_64 u32 machine_real_restart_seg; #endif +#ifdef CONFIG_SECURE_LAUNCH + u32 sl_trampoline_start32; +#endif }; /* This must match data at realmode/rm/trampoline_{32,64}.S */ diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 9320285..aafe627 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -1021,6 +1022,83 @@ int common_cpu_up(unsigned int cpu, struct task_struct *idle) return 0; } +#ifdef CONFIG_SECURE_LAUNCH + +static atomic_t first_ap_only = {1}; + +/* + * Called to fix the long jump address for the waiting APs to vector to + * the correct startup location in the Secure Launch stub in the rmpiggy. + */ +static int +slaunch_fixup_jump_vector(void) +{ + struct sl_ap_wake_info *ap_wake_info; + u32 *ap_jmp_ptr = NULL; + + if (!atomic_dec_and_test(&first_ap_only)) + return 0; + + ap_wake_info = slaunch_get_ap_wake_info(); + + ap_jmp_ptr = (u32 *)__va(ap_wake_info->ap_wake_block + + ap_wake_info->ap_jmp_offset); + + *ap_jmp_ptr = real_mode_header->sl_trampoline_start32; + + pr_info("TXT AP long jump address updated\n"); + + return 0; +} + +/* + * TXT AP startup is quite different than normal. The APs cannot have #INIT + * asserted on them or receive SIPIs. The early Secure Launch code has parked + * the APs in a pause loop waiting to receive an NMI. This will wake the APs + * and have them jump to the protected mode code in the rmpiggy where the rest + * of the SMP boot of the AP will proceed normally. + */ +static int +slaunch_wakeup_cpu_from_txt(int cpu, int apicid) +{ + unsigned long send_status = 0, accept_status = 0; + + /* Only done once */ + if (slaunch_fixup_jump_vector()) + return -1; + + /* Send NMI IPI to idling AP and wake it up */ + apic_icr_write(APIC_DM_NMI, apicid); + + if (init_udelay == 0) + udelay(10); + else + udelay(300); + + send_status = safe_apic_wait_icr_idle(); + + if (init_udelay == 0) + udelay(10); + else + udelay(300); + + accept_status = (apic_read(APIC_ESR) & 0xEF); + + if (send_status) + pr_err("Secure Launch IPI never delivered???\n"); + if (accept_status) + pr_err("Secure Launch IPI delivery error (%lx)\n", + accept_status); + + return (send_status | accept_status); +} + +#else + +#define slaunch_wakeup_cpu_from_txt(cpu, apicid) 0 + +#endif /* !CONFIG_SECURE_LAUNCH */ + /* * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad * (ie clustered apic addressing mode), this is a LOGICAL apic ID. @@ -1075,6 +1153,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle, cpumask_clear_cpu(cpu, cpu_initialized_mask); smp_mb(); + /* With Intel TXT, the AP startup is totally different */ + if ((slaunch_get_flags() & (SL_FLAG_ACTIVE|SL_FLAG_ARCH_TXT)) == + (SL_FLAG_ACTIVE|SL_FLAG_ARCH_TXT)) { + boot_error = slaunch_wakeup_cpu_from_txt(cpu, apicid); + goto txt_wake; + } + /* * Wake up a CPU in difference cases: * - Use the method in the APIC driver if it's defined @@ -1087,6 +1172,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle, boot_error = wakeup_cpu_via_init_nmi(cpu, start_ip, apicid, cpu0_nmi_registered); +txt_wake: if (!boot_error) { /* * Wait 10s total for first sign of life from AP diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S index 8c1db5b..9136bd5 100644 --- a/arch/x86/realmode/rm/header.S +++ b/arch/x86/realmode/rm/header.S @@ -36,6 +36,9 @@ SYM_DATA_START(real_mode_header) #ifdef CONFIG_X86_64 .long __KERNEL32_CS #endif +#ifdef CONFIG_SECURE_LAUNCH + .long pa_sl_trampoline_start32 +#endif SYM_DATA_END(real_mode_header) /* End signature, used to verify integrity */ diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S index cc8391f..cdfc2c2 100644 --- a/arch/x86/realmode/rm/trampoline_64.S +++ b/arch/x86/realmode/rm/trampoline_64.S @@ -104,6 +104,43 @@ SYM_CODE_END(sev_es_trampoline_start) .section ".text32","ax" .code32 +#ifdef CONFIG_SECURE_LAUNCH + .balign 4 +SYM_CODE_START(sl_trampoline_start32) + /* + * The early secure launch stub AP wakeup code has taken care of all + * the vagaries of launching out of TXT. This bit just mimics what the + * 16b entry code does and jumps off to the real startup_32. + */ + cli + wbinvd + + /* + * The %ebx provided is not terribly useful since it is the physical + * address of tb_trampoline_start and not the base of the image. + * Use pa_real_mode_base, which is fixed up, to get a run time + * base register to use for offsets to location that do not have + * pa_ symbols. + */ + movl $pa_real_mode_base, %ebx + + /* + * This may seem a little odd but this is what %esp would have had in + * it on the jmp from real mode because all real mode fixups were done + * via the code segment. The base is added at the 32b entry. + */ + movl rm_stack_end, %esp + + lgdt tr_gdt(%ebx) + lidt tr_idt(%ebx) + + movw $__KERNEL_DS, %dx # Data segment descriptor + + /* Jump to where the 16b code would have jumped */ + ljmpl $__KERNEL32_CS, $pa_startup_32 +SYM_CODE_END(sl_trampoline_start32) +#endif + .balign 4 SYM_CODE_START(startup_32) movl %edx, %ss From patchwork Fri Aug 27 13:28:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E4D0C25AE9 for ; Fri, 27 Aug 2021 13:21:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C9266103A for ; Fri, 27 Aug 2021 13:21:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245201AbhH0NWD (ORCPT ); Fri, 27 Aug 2021 09:22:03 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:25944 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245082AbhH0NV7 (ORCPT ); Fri, 27 Aug 2021 09:21:59 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RA2VEc020754; Fri, 27 Aug 2021 13:20:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=3y2hwlVXyCwkUCsu64t+jatx24TvUnXBKSvm68yyz4k=; b=Mj6SLaZPAgqpMluo90txSCcgpF/4KK4zRwpcgPjOVD/WlsZbRtklZmQYqhCWwa/hqd94 gQp2croIQ27OWzFutem8citUhTnfIXs2WO8TeKjPvs2IMCcOvOcpRt+KRYnWtr4npYs4 HsilsCwB4OureOHK70674fFPpAnfu1pdae1yLhx3yYayCpicKqR8K4zjCJ1mEyMDT2LM QMlJaM02x4mf3bMnycwiv9KfNuih+LLUjLssmgoRqbMiYx40QnqdGxrSjFUoQgKms5Sz L8e32cxlMunAODLywQxWbBIK9bQbcvrIHkUyQ1tgB/K6xDt6geJHevhhsiHPk5gWJQok nw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=3y2hwlVXyCwkUCsu64t+jatx24TvUnXBKSvm68yyz4k=; b=seAmAU3zqOE0FzzftJyCM2ZtOmJ/Sl7rcKdl7WN3g9pezUkuYLt0jIRz9dkmKcTxVvz+ fMvvV/dqzNtn1Egej+UNKZTQKSFstovDdQOZI2M1VK2IkVx/fzknjblADvH885e8rYzc aoSI9wMo0LfAgzQ5NurWwJGhoVvRLqHfTI6abLrBbhtKdp/Z6havmn0j8Nz3NAXgwJh6 LW1hifeRyZ9pcORFGX1QaT1/ih6L5qwIUCPbesbpa3wuthYPfdZEtwpOFn5hpmNWIHnH inFk7UzTSKPi8dm+oPBD4xnHic7XwdZa3BoWHFbeBsbCsJ1Wz4MY6NjeYFIEiNPjZYQV SQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap4ekunce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:58 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RD9nxJ076969; Fri, 27 Aug 2021 13:20:57 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2044.outbound.protection.outlook.com [104.47.51.44]) by userp3030.oracle.com with ESMTP id 3ajpm4pqdq-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=embcUBvqJQGAmF2rLLb2Vm0kMfVD/tTV285kLpofJrVuppzSxx5H+oWSp68whj25xVRf5mOsoPnurM4v/ZOAmywDBPUo1vfC6dNGPIspMXSbEKxIuX07V2D5PxnnW0vIfgKFWBE7Bhp8O9vlZDIr5AyfBiV8a4i9XECIouA+qO+WhhFu4onjjw34+1DQRU91V8DfkmG0VCplS+8F/Yn2jiNPkB5ozeddyUyW4tyn/OZ9MGOcmGDu7+yQW1CVHjZzMI0eErt200CYOCc5GN9a/kmC0qAZ0uo/jVf6Qy2nLZ0FDYH0cG3e7qsKZKiWpztQzmKfLoipJbDDd8730w0CXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3y2hwlVXyCwkUCsu64t+jatx24TvUnXBKSvm68yyz4k=; b=hopiV64nDMcJYhvhE5QZAxx2AMhjPQZZt7AIeoIF8HymcXixENkddxhufs1tDwhZhkkg5izOO4liuVF/1XadwIUe8cQ2xgkCAxKWlg2uQl5x1bP1334OrQY0m249yOLiAeUw92GPEk5MEO1mGUTkxcMqbWi9EKSbyBH/+a/YTnb4cHokKexioNcI2UkqW6mKZ6U9o+kQ5BOLtIgU+gq8bo+DuV2OYzKRxQA8Hpa0hOXiGD9PrkaR5PmfmJGKiPGkhfsTs5wQkZWUDu/qNd3oEvlW414RpV3k8nRcgneQF7JA1Vwq+vwlfzwbCkv6vl+aUfEEckSqyJh/huQFwbR1lQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3y2hwlVXyCwkUCsu64t+jatx24TvUnXBKSvm68yyz4k=; b=w8ueBO8jVVpkI2HEq7sGCaItu9SdpgMldU5mpHdIgtKPELq8KajA+Aj1ycyP6mxuQgM19ek7v/vDHKGQSYy0conY+YhCHZXbA9hz2AsTGlflRn23hDfHRKJSH+G/G9BEdaReIoeqeYfhDrBA/fAdmwwzX47xc14VF5uV155ZH1g= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:55 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:55 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 11/14] kexec: Secure Launch kexec SEXIT support Date: Fri, 27 Aug 2021 09:28:34 -0400 Message-Id: <1630070917-9896-12-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9b763bbd-5f22-4c64-7701-08d9695d802b X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KADy/+0lObOIhxu6H49w4+eeyBMiq8VxtVxsV/r/WgStdrFLJwEKMnuofY9Fb8Eea7Gmvf7wJXqiMV3siT2UIZVOBkgzlxf7NbjfzXKjZayWQsP0c3VOTBfJfxAr8x0z9OuQr4hxtjXIz+DdmNLexlCAr5CziYGnZbg5Gi0lr/nWH0IRiEzF9HN/s/PqC5ktwfxjF+PlUgTXBO/D9pdRVSlpboFnBPo2wXp08YbCDvX6WXaln9GyXOdWpLZQWBJnSsys9dO698o7j8M2JWrRgDAxM8jAbRzkHwT//ZWH2Q5/Azs2rHLlMEdLSq5j1BS21QdjLM1D5Jg8ikfldMi5AmWmrzIwB1lSqEiFwVx4f5FzueKnft7fQp//iDdOKMt2I8gjAzkfuu6V4h0r6Y5jYpderktQToMVNg4PlkG4x90hHHgWsHmt69riMRlG9YZZPcrh65REJLw7bojGgo/1pMW+N5FVSZgSlY3ibJGBiMM+hwjI6tYyJ0hq+76y2EKyJDuY1rhx0m/GSOd1ujFLG/PKnw/qBt/nGVhv7sW4Wv7TlGHd3bhl7wM2Pum6cw90EHjWJZjF0HKQ138EZxgJzGJC3dFnJwREqLZrlMaXavkKJu+8hKZiN68WeZD+vhAs0Dffc8P9ifC2YVscR02YHrSDnJrfK75n/NPpLFc6p8XsllOELdQhdqazNpmoqHS01NClA5wAgk9160UXkdJguQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PDlEbimDgYiBNAGNoW6Gr5mRh/Ex/9v8XflNEA2Tq9DWeRYZfq+/Y84N8tnY9EYy/zGggdu8epPez0NDpQ48MrUKEqfMpGioCcHh9SrsGA14KQMsGmC6hLgmDteykmBzF6pyTeYPTjO6GxW5Z1tktrzsQmacbweUiDeL3Dqoo2QrIC0tCGxXnvB72HGuu8tXx5WJWiCWB705Auvd0L4yiIFWkVc1pfb5pmtKie1cB7k898SvpqXEgaBA3Bo2WwyHAyuyN7B1JzCp8APirIAGrEdN5mVzsE3ds+R+rv8+U2vozvT+MyxN0jFOquiMkKXNkSBGekoy5mYkx0FpRYLpVxUtTo8X8EUH5kKL3lLZ5GqGYJuoHnshwzfcRXqupioR+7d08GCfeU29qvFw6jzolzNk3MQzVtSiSIiXpf3buX5vAf95jKlgLW18iRXISuchoiv2nBzXgo1z8/MhGyuOu8tPCdK+nuGpiemgQPNKr2R4QVcOExxOqeNpO/tRAgVKENL8y1a0oEdkr0I3RDvflPQztf1gIRohW53TIW4FkWlEhT0Je43sMw7NQcNdmd91mIXToMoGPPBCfjhP2VYcjtKyDlVTB+dp5PqV1XZZ5PRw5CR+o2ijC9nOpmlR7u5NPpDbgwOQu/9EWNsPtn+hojS5XBKQQ2zNx83FASH42SQs+GJOD9DEf7V64glie9skFsueTVKLad2Nd312bDHu2F1gDqXtsfBQh8hQ/So/ENRga1fMuaZMWyYnpwsfR0idiiGB3do0wTnCVEcajSRmrai9UL2BX83SzmrOCECFXgoMQzSWpSuWgqP6hQ3jn1V/+6oUa9/nyUtj9Jk6Ea1obSzPGWAsNr0oW3ZRaQehqPumqO3/JFxou8gjoxjE4h5NSnCc7JgTBFsW4bYyDldx3ugWVsD0xGQ0CpZ0kq1gTGYd5ECuPJQJziofDuhGdtQpgOhOifC7RKfvhLgoCkEte5wxSOFv8R1oYEeEvmxWsu8PMrTpi/81gS3tTVF2MPlW0cDF7QuxO0T2FAAmFb0hXK94SxduqMBW5Kir6DgVISSWkjhK8Dmcfjt4KRRcnp5aotjOD8PmaaaohozS1iM13TQpDCJUZ6lO2xalaO9OyIQkK7BFNFaDYLWk9kFKQq8fdFvjPzJwimKs/VFr6hVjPeINhNtu7e/yQMtQh/6MbVXUghUKfYMCsgWlCtgjbtCR7rsWH62SzMZ50t05A3JW8FMx86xMnNO25LFJ+7OGCbImFf8yUWiERWws6Kwq249/PGTl+OxmtBGOhxJUbdu2LapetCEokdz1Ti5yZ1o5B8eor7b00ihQOH7Eqv31dRJP X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b763bbd-5f22-4c64-7701-08d9695d802b X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:55.4641 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yEW8RnwzChflC1br30dcnn3MZKQlkKSRfxaaF2NHO0MbxHDjvFtpj20oSw3yEQYHfE3q7pUYgJMxRp5LyW7vIuvvFPCJIJgrL2M7O0GQ9DY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: hUd0dv83F_AmsnfDGA1yGWht2-UMLYbx X-Proofpoint-ORIG-GUID: hUd0dv83F_AmsnfDGA1yGWht2-UMLYbx Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Prior to running the next kernel via kexec, the Secure Launch code closes down private SMX resources and does an SEXIT. This allows the next kernel to start normally without any issues starting the APs etc. Signed-off-by: Ross Philipson --- arch/x86/kernel/slaunch.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ kernel/kexec_core.c | 4 +++ 2 files changed, 75 insertions(+) diff --git a/arch/x86/kernel/slaunch.c b/arch/x86/kernel/slaunch.c index f91f0b5..60a193a 100644 --- a/arch/x86/kernel/slaunch.c +++ b/arch/x86/kernel/slaunch.c @@ -458,3 +458,74 @@ void __init slaunch_setup_txt(void) pr_info("Intel TXT setup complete\n"); } + +static inline void smx_getsec_sexit(void) +{ + asm volatile (".byte 0x0f,0x37\n" + : : "a" (SMX_X86_GETSEC_SEXIT)); +} + +void slaunch_finalize(int do_sexit) +{ + void __iomem *config; + u64 one = TXT_REGVALUE_ONE, val; + + if ((slaunch_get_flags() & (SL_FLAG_ACTIVE|SL_FLAG_ARCH_TXT)) != + (SL_FLAG_ACTIVE|SL_FLAG_ARCH_TXT)) + return; + + config = ioremap(TXT_PRIV_CONFIG_REGS_BASE, TXT_NR_CONFIG_PAGES * + PAGE_SIZE); + if (!config) { + pr_emerg("Error SEXIT failed to ioremap TXT private reqs\n"); + return; + } + + /* Clear secrets bit for SEXIT */ + memcpy_toio(config + TXT_CR_CMD_NO_SECRETS, &one, sizeof(one)); + memcpy_fromio(&val, config + TXT_CR_E2STS, sizeof(val)); + + /* Unlock memory configurations */ + memcpy_toio(config + TXT_CR_CMD_UNLOCK_MEM_CONFIG, &one, sizeof(one)); + memcpy_fromio(&val, config + TXT_CR_E2STS, sizeof(val)); + + /* Close the TXT private register space */ + memcpy_toio(config + TXT_CR_CMD_CLOSE_PRIVATE, &one, sizeof(one)); + memcpy_fromio(&val, config + TXT_CR_E2STS, sizeof(val)); + + /* + * Calls to iounmap are not being done because of the state of the + * system this late in the kexec process. Local IRQs are disabled and + * iounmap causes a TLB flush which in turn causes a warning. Leaving + * thse mappings is not an issue since the next kernel is going to + * completely re-setup memory management. + */ + + /* Map public registers and do a final read fence */ + config = ioremap(TXT_PUB_CONFIG_REGS_BASE, TXT_NR_CONFIG_PAGES * + PAGE_SIZE); + if (!config) { + pr_emerg("Error SEXIT failed to ioremap TXT public reqs\n"); + return; + } + + memcpy_fromio(&val, config + TXT_CR_E2STS, sizeof(val)); + + pr_emerg("TXT clear secrets bit and unlock memory complete."); + + if (!do_sexit) + return; + + if (smp_processor_id() != 0) { + pr_emerg("Error TXT SEXIT must be called on CPU 0\n"); + return; + } + + /* Disable SMX mode */ + cr4_set_bits(X86_CR4_SMXE); + + /* Do the SEXIT SMX operation */ + smx_getsec_sexit(); + + pr_emerg("TXT SEXIT complete."); +} diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 4b34a9a..fdf0a27 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -1179,6 +1180,9 @@ int kernel_kexec(void) cpu_hotplug_enable(); pr_notice("Starting new kernel\n"); machine_shutdown(); + + /* Finalize TXT registers and do SEXIT */ + slaunch_finalize(1); } kmsg_dump(KMSG_DUMP_SHUTDOWN); From patchwork Fri Aug 27 13:28:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9791FC25AEB for ; Fri, 27 Aug 2021 13:21:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8078260FE7 for ; Fri, 27 Aug 2021 13:21:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245215AbhH0NWG (ORCPT ); Fri, 27 Aug 2021 09:22:06 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:28646 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245167AbhH0NWB (ORCPT ); Fri, 27 Aug 2021 09:22:01 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RA60N9020751; Fri, 27 Aug 2021 13:20:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=JrmrYv+4itrNkuyJVx9owj6FchfSRMm8+sp7P2G5ya8=; b=PnIysyTZ+4Xg555PEAG5JcHegv4YxCUqFymU2MmB9obhWoarusQR7Zef1mWVaNsanrNk hJPi4BTgbxzOLOOtY+61LKPbo9mU4DNZl29Y9NzjS6532XlU6QY4hoBW59fuaaM56LII NOOFLfAFoI99ChNuAFxoIyJFP5tNkv9L9heFnVZg3c8G0u7Wjo6rJ/v5QTQaMoZZRoEM bIJm9GVJ+xYmAIwCJM8tXq3uxrts4R+0AjYNl5XRd18eCdJj+2NI3CDwbI0RM4F1gTmH 29tNcjEjN3j5jJgEh39KRbgDPGonkehAHQskneSDbHdEup10Q4yITFLLtZIhU2piTSo/ /A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=JrmrYv+4itrNkuyJVx9owj6FchfSRMm8+sp7P2G5ya8=; b=KKehDOrauj/UVs1h+DikboJFjeXa0+aIhqFxQioA4TfOYD6dlRP+V3u6y+S37tq09LUM rU8O+lKjPjmk4iOJVdugQdF++IQ6RrelPx46CdXoFMFcSFLDAM5wPXf1XYoaFWPX/D17 /9uirC8nOqOYHXlEaWWOOTKoELtYkeVCUk/uvminqqxkEq/2c6vLaOxXXDygXn6Vx+fC aWowyTJNYptqWCcAKfmA6Mk8fClJMOv+NfCh05czyppZ9jRFs6s4XLz9vETc2WXSotvD 6gRgGaOAqe4hMyAG9nPbnlf9VzMab2Gc8l+tsIOhvRfLb3CExazzgMGRehy2NgMUZ55N 4g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap4ekuncg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:59 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RD9nxL076969; Fri, 27 Aug 2021 13:20:58 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2044.outbound.protection.outlook.com [104.47.51.44]) by userp3030.oracle.com with ESMTP id 3ajpm4pqdq-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:20:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d9bd8SH8nNpzj/fS0T3MQ+grl16sG2PxBzhwHq4dOOKydy1jyChi9txvlH4QyEMwhCm7OSz7dh36RKFC4fSP0RcKYfVS+FZWIIVaJbIVKlB/D4+5W1Kl78ZHdDw8m9vDTnAzSMxmZR+a8kz18Tgyvbt2Wmy+wlxn3zVYIU+0x8ufXqMhAli66YOcnXrzMknbxHNcuT1o0bmnhM81CFivgNyLLRaHBJnQ0mbXRUxT0x+rNlnP9X9mMWy001K3IJzHIX+WfCje+LocQU0a5vHtNK+pF2MjpLu09iF0QkKAwMs7dtLsSBt7IsUTOALkvkOW1B4eDzsYlylNglBKbRoR5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JrmrYv+4itrNkuyJVx9owj6FchfSRMm8+sp7P2G5ya8=; b=L4mN3ToDGIo6NvYBpNPh2vQtYh2VXnVhGRTc3tdJqfQ4bow8puIyug6yqEZP6/Fr9Mfv84V+rjJPyy7da99afw/L0c0AN+w1gjfz7tUlHghKLMNbXrtWH32n1mIshx62oGiNp5Mo+vIgi0X2GuDbacvAwzHoaJ/pt6A+TYEqPPdGo8KX8DOUEV86cR2z7w3HT5T6G5hnS/v2QCAG7/fvwzue1RdGbD+EMHN2RUR62m07Wk/KSQbOQfVaIsddkMIz9WnTVn8f0h13olXVu16gw3XE4Sdho6eWrKtv15U/2ovGxvTFadMnd4gDJVIbk+T19TjrcMOt8r6u9RkL7S9OnQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JrmrYv+4itrNkuyJVx9owj6FchfSRMm8+sp7P2G5ya8=; b=xjOEwlUyI4dIvUNSpW0CQC3aerLlZGdlB4Kt0Krd2/2DOh//THxju41vNSPiEEgzReTlge0o2s65qCO+0jx3Ey92fboBlUAvrz3AlI+xQQNcJpNbKG3Dr0ceY542s3nqPen8ZcktUz3hlfp+V15cPRpCn2y1V2jRqtCHYFk+Wio= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:57 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:57 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 12/14] reboot: Secure Launch SEXIT support on reboot paths Date: Fri, 27 Aug 2021 09:28:35 -0400 Message-Id: <1630070917-9896-13-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2a51f7ad-7c76-459a-de1e-08d9695d812e X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DWDjBC/d5lyXaGq7h6lL0IEXULjSkeiKXYHoZQgFzxmmEAREoT3WvyLTsBWrQpGePiQKkuJ6e/iaOkDKrkAC4AfmvhacM81cxS0mqfQ3maQHqThK+pq7dPppDdXvKOhpKRT0efxYheLE1slr79aoRPOsTOzhh2qZsjGwJCvuXxu+veb4egMDKNnp0KIR1+NjVNBwQfJ4fTpvQJxIYnSKSCHc70bDMny76TZARj89QnDE3NmKigqSeYWmnDBtKobXu6rNIYvuBzuNsWW7IPAliHND+GSN6RgNcd3452XGyIuW6faB2/XBfBxCxwdqgtVjm+TLveePuCYMZJ73YUg3dd4JU4b6nLjfbhe8kRjEaSswVoznahSsOzYRTxhWY9mrnTkIfh7O5+AC3W7L1GYqJGugBANOBf12nuznwTUTawkaNji+hbWPHcAF3pIuuv09XBPcwLQym8gNzU4ho/U7BqU/rImjMK1xFskXOFOQ/G3bVBoBzba0mpq77Ym8bvh2j4UJaOeg/rrN5+02jUghe+qFI6A0YjFPaM0MFcZoKYEwgWOT+sslRXMAxdL34F7VEZ++jlhDgTqZtvKODrBEToLhMzVD388TDuYqvpxwa4n8jKumkGGNlG7FfTmNPcmbf0WXWkN8P+qSUmSLJKFQNjxM9vC3uY1bcpTydioMxiqcpjS+CfnGNy31j3nVxwy/wnNGBlGxg2R5aipm3BaiBA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TuDye1fP2a/25cQxBXbyjud3AozLHU6dgk8ZnRPM7SHwUXE19QW/W38a+y8Pr141dt0rUSVRyyB5jlZKPKYw1oSojWAOHMWBgwhPH5D57Bz03/NrnnKC3URHe9EcMhMH6Yoq+dkWtGTY9BqSRuhq9sEpP58hVeoG+u7L5sISe8+AsmzWGyLc4MwrCWToxc/CtQdJWO0o5QF4SugLziKIRKGtn0S0NehtTCXBAE3+F6M8jDr+FIiYJDPcCZDirQHUfaEL9rZNbisddWdwLuLLNv+cwx8Gi8kXlE0K+jG/J1uC2y4oC4uncbRiaHuqTIUrO2n7ei/0+zFQCpP/Bv6IcZUegtoa1ho2qE1+9ceNQnaSvf2P27a4W/MjCrMFkpUM1y/EjUgwuLg2POvSARN1bkZmCgzXMPnwn8VGQxk7OuN/Gp8A3MAUpOyZGljdE6qB++bUJyq6tN2e/VbFIZaMxOHo8pmZqse8lSPhLxblfSAXVTQGtNUsIr1X03foxMmdvamWdoWldAltvzyjprlMnu1NOgEib3R/cRv0gF7/hHyLlGF7DzfjvYhkMwpNysp1GDqH584OVnEQ9oxIJIKaXqkudQDUilUQUuYkVSGV5x6XDfDVrvDJoIfBZT136IRT7GKFHeeTj/wdkl5cMXPkFJh/z71r9R3ej7JmQuZ9fQ1jV8TbKJceDbJAqP6YiQh6qDpOE+qJ6KMcHvnS5xFWivhkz3+fS7R0tq/st6WsEhQk+x1YGTgn6XClgVgrWpZpeZOFBCXHmBnfwDlG1Madr2QSErBLIvDsIHO/xmi7VlwtzAf8PNsfMPtdNczBTShDpneOm85+TgGu7OQZISImOU1s3fuD7sE2pD+oE31GcIwvBhWwJ85HSnGWL9CRFzOKuGgn5R2eKCtCaIePwm8DFpE++a1Sin+AryS5dDf1Md2VGGrLb1is32jt6Wby5iG19SAZDuQhiC7urOi6LX9/fjcInkWuTo8fC37raVW0pQ77IQ836Xjbsi4iQWqhE/9bZjJyw7CI6E4pwYTOhYs5dw74yaBQEAYXjMXWDoZxBOn5Hmf1rddF7PpL/T1nKDn7huYqP6kH87GLEbQD5y5LeRHi9MCNMjcdkjP/nmJHI/rmqJ+HuyoPtPpXpIDwC/QY2nUhVzG8qq04TLwLh9OUFWOWHs5saV2gRDW9yLP5WwceV6wAf8Ha4jNaLKVTf8N43nZrsm5bcq4+rSSG18PIv1+wkJSvSPQLuF1uOY7D8QPsqGavZi36QNUzhne4qAAkW614wrk0Mf+X/im/x6sLMNGXQICTNOyTiLFHmjmA6NzdgV34KnPTCt0eQ5JjkdO/ X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a51f7ad-7c76-459a-de1e-08d9695d812e X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:57.1522 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bgmH8LzRW8OjJ/OL/sljIT0DRoqcjE5uu1KxpcEdXmw0N28FrGRXppB+NNDGzxMBkg5kv+Y9fDBCrL2wyAGvrCeooO2LiIqoLB3Y+rlf4So= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: XOFqQTLDcIwPfpSoPgy08_Ufy4FS9ETo X-Proofpoint-ORIG-GUID: XOFqQTLDcIwPfpSoPgy08_Ufy4FS9ETo Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org If the MLE kernel is being powered off, rebooted or halted, then SEXIT must be called. Note that the SEXIT GETSEC leaf can only be called after a machine_shutdown() has been done on these paths. The machine_shutdown() is not called on a few paths like when poweroff action does not have a poweroff callback (into ACPI code) or when an emergency reset is done. In these cases, just the TXT registers are finalized but SEXIT is skipped. Signed-off-by: Ross Philipson --- arch/x86/kernel/reboot.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index ebfb911..fe9d8cc 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -731,6 +732,7 @@ static void native_machine_restart(char *__unused) if (!reboot_force) machine_shutdown(); + slaunch_finalize(!reboot_force); __machine_emergency_restart(0); } @@ -741,6 +743,9 @@ static void native_machine_halt(void) tboot_shutdown(TB_SHUTDOWN_HALT); + /* SEXIT done after machine_shutdown() to meet TXT requirements */ + slaunch_finalize(1); + stop_this_cpu(NULL); } @@ -749,8 +754,12 @@ static void native_machine_power_off(void) if (pm_power_off) { if (!reboot_force) machine_shutdown(); + slaunch_finalize(!reboot_force); pm_power_off(); + } else { + slaunch_finalize(0); } + /* A fallback in case there is no PM info available */ tboot_shutdown(TB_SHUTDOWN_HALT); } @@ -778,6 +787,7 @@ void machine_shutdown(void) void machine_emergency_restart(void) { + slaunch_finalize(0); __machine_emergency_restart(1); } From patchwork Fri Aug 27 13:28:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5EADC4320A for ; Fri, 27 Aug 2021 13:21:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0F4C60E93 for ; Fri, 27 Aug 2021 13:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245279AbhH0NWU (ORCPT ); Fri, 27 Aug 2021 09:22:20 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:32776 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245220AbhH0NWG (ORCPT ); Fri, 27 Aug 2021 09:22:06 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RC80Kb015347; Fri, 27 Aug 2021 13:21:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=lFXvnaXAliVEKN00J6JGw6FZ2uC45ziffS62j09NnHA=; b=eybtURGTmBWV+Fuu3+soQtebWWwBy1wnvyzlqGzF9Cx5ICOXlRvJhiv1zOvvjJ5JCN1g +c1wKI0XhXb6CJs6kh6rvnvVEoQ2+wjd0NvfY3BjwIRGXZlh1TEr20xrHJB5MgRUc391 iAcf89U6MUR+qUvDHiJueyvqP4XpziWhkVvxmN0xypJv/XcATU0somsBdMdPZ/2Ai21e wc/1u3Py8qArJ4wDo/sbTcOOOCqlKMqA0Zi15m4JzL2KFHfjfDS4ok6uWJ1w2xdmVxbn TQXZP2oBFCJ8jVwG4vhzwZTPLJHGPCchx40TX10OHNjrOE7meMaGz9T2Tn98f6kbbUyA gQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=lFXvnaXAliVEKN00J6JGw6FZ2uC45ziffS62j09NnHA=; b=bNzk/CK7Y1r3qWO+Un5i9d6rjxCPE9HCRPTEMeQdGDBXKRHgQU+ZnQKQ0jxQsexUWqrw Qy03HsoOEp9DayzgrtoINAtUODRqjSeVrIvqTqGxop41JUSR5W2RcwTEpVbE307Ssp0L EDazArM48Pot37D1p6Pnn6T6JScpyvSilJG8Pj8A894Y+JQVQlb9kt1HYOzmdYWs+toS cT7xi7EhohpFR2GHMpWi4og3sAEsqgLfNRXkkD6C7ROj/2fAMdAbUGke3ZRUWLwdM6jW ov+Xzm8nfbeUuHKLEvBbvBd+Ef/L+svG6kxS2HSg3iTdkMiXNEzULFJ7U5JeDWE9KfD+ vw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3apvjr0kue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:21:03 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RDBeGT013130; Fri, 27 Aug 2021 13:21:01 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2040.outbound.protection.outlook.com [104.47.51.40]) by userp3020.oracle.com with ESMTP id 3akb924gn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:21:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C7lZepQVcRpXZa8Bk9qkcX9gXHeo9LoCZ6IZVmiGVzkX0gR0ZspZkd1jSnYLtYVKa4exDv1FTmkm9eqEIns64I2xyT70JJCpxWfzdc0/Z/Q12iKhKVoOpFcbr82YVOZ+MN8CPpXRcEm3CM2Ewy9FXJY8u0m4/9G1YS1Krv7jnyf1SnxR5JJJSyhFgNlFwinDTMNVrH6Lvy5f43I3r8cAbQFiwRCOmFDraf2uPNMNT/kcBHxrFI0Y/fuWQvbsRSxB7mUYwPq+5fnZAGxSHNqvP3BzbS0eoIp4hRoZ7o7c6CdQIVrNhCYlPtw1Kz76xlNu+XAOq0uMCqX7XK98FoZcZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lFXvnaXAliVEKN00J6JGw6FZ2uC45ziffS62j09NnHA=; b=e05sMUC43/7E10VKPj2TeC17MZk/acvyzJP0v/YftlGFGAVi2NyH2s5Lt9VgWgj/GyT9k3Qu7O+aSEy1186Bu3cTtW7lxAoKA7jtKBVoCuUrojDxpiqeJNVhy6jmAz+OF+T9oU/XNYvZLU65fIg1HCCfqzHowjeGeoKdcE7YB7KS6CzjiKG+oRPNTpPjT3VsOavkUdGgPaUdHvdwAbA2l08umEDtkcIOq5VGcrcW2bQRax0pwLFxUSPdKynHK3fSnlu2nhtXoyOGsYn8ioQxjvOcBwmjWLxOjFBR37z1mSNDhmy3A8hn1TiX31kWZA3omsDBqG6SIUbOaTsdhg2KZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lFXvnaXAliVEKN00J6JGw6FZ2uC45ziffS62j09NnHA=; b=ewc9LLRNZMBENnXbFszpxa7/0BJ68dVbf5MvKBJAQPV8goKLQqBpxPhUXEAYLb0Mm79aqCTD6GRLMmTITdB5hKHzrQXEZ5D0LC8iBOvsmOfioqCpraTkdlAOgdTUFzxydsp0RebheAU9be6F5aPSRfuFc5j5v/DOtrvq0MIQ7wo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:20:59 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:20:59 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 13/14] x86: Secure Launch late initcall platform module Date: Fri, 27 Aug 2021 09:28:36 -0400 Message-Id: <1630070917-9896-14-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9afda798-cae3-4923-4495-08d9695d823b X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1227; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s0EY+afZOX/1DXZdOca+AWMA9w6DuD/9Gfu2kEiXzewOAdl5abmn9gr4hrQ4XbYYYE2Npm3FcthfcqVeXxvd1api5e33yIg+IDAUFI6YkTfOWnH0gFTdOpqa5kiu7LwdVnDfmcs+T9Jf0GMZo4NZgNMkBBeUISI8Y4ltwxj3UF0+irbKmphfACypxbngGMFBmphD7i7YXKr9REKZdKOtwzG63NcAHJ97gOTlPiepdrMNArba9etTQOPcROP+ZvsoAONb4uuVnFiAbb/GalqKy7yxmrqZeDDOwmCgWy7SDb4Teq/EYpvE+vQo7Qg0tpGavCXfqxyLm6ys2+l4zf3UYvG9SRPNeX+HetoYZNCLoVBv+CIptn3FyNOLPjheHDNnuLrXPGF2b9rn5MNDMA0TPFDs6FMHPilH6i2hTuxlPpGVfIWhRhjJKtxWwcBvE3VJBQ3QZXzwD9PabTkzdbgytduxmuQoXF4GKeT9X18fSQ7FGrkutsW/cg1Mlv3bl4qww4ejGZ63aQU2DApF6uD60sbHlTqcRsvzBym6Q/5y6MkuSzwiwxh11Jo2kVdKmIjiffe3pp6rMbGc9JbUT7W/bfiTAeBS5SulWyVb99zuTNOJ/agDsFizWhRTbHryfSbu1RKOu5XG4SjJW44LHRSp3TbwxFoiYZAxfT8UozN1syvTs2nyFzYFOcvQrD1XX7ExBd0HSzu65o/ILXzNpB//Wg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(30864003)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Yu4WRt8XumkJGWrF9sS3eB142Di1LJe0CxpY5j1D/YAxoQlUSs1DaY8Z6QcrgzJ21ROFDpNAnGZ0ukm+L1ZQyTFo+jKAzZETbaVrLtcvwrtcJC9gsBLAQtQtNyUMpY31cImGgJnZoNkRtXeSfhfYjIX7H0WL592wAVBnThdbNhHHQ6vqum8QnycIZ5KihPyLEKswV7wJvB1A8vkN2RcsjTVKOqALOMzR8ifGSPHq/0f+VPhlxvrT4esB9RYb1ezWZvOEQ6Mje8fkAoZN30RwNVpdFtsZlDes+J4O30+Slf1KwEXB64lFuRGgr9qsNwibSl4P9bHK61xt/Xi0Y8uBWldjnDlrDlKQRPpvo7zK+9suOdmeoqnh8zUKnn/3nTuIyCh/vrjraPh7ayR/tp+ESfhsiMr1DgyySPHrH89hmkwdP2PTgyv51efFVJB5RfsXQKdRE4wV0WfJsSw+V1IqzIRVlI+rDeHcVPe9NKXNmdrqvaTmAevikQ0Naim6eXA0NCszOhdzia7yh7XaKpC8YkPbXm1tbqnuoIjIsl9LoS/nsDtgJMPzZvzZHM2xJLOEXExdwYPNFFraAKWZyurycFG7CiPOttTSyqwYRlI31fnyg/GxBcA6C4XhbwdAX10FHGUkDqbxRhUIi8AHKUyILwyuQFIrQjEYqGg2wAItRVhWyUBdb3QXbJa/VAX9MpRYm1ID1qbotJVu1k2yr36NplAJ7BTXKmzdYW/FGV9K/Uqi1fVpzVNYYpfrDGNcLVyJO+sXf1bFeA/R4QQUeRr4w8wW5kX9MMrOTQnPVw5LLqNDXa2LOZki0pUVGWecjmaA1N7rrO62xfo8huwu633nmRkN5EM6JAR6SniMV+khX+5eVJvTG3ksa4jDoBqHWt8PLFEdONYLSmJ71uyTYpVySQ+bsQpXpiZEJh2dipOnPGejFB11PPfSmQOeND2D6kt34xXNxDINHi+8jAbsss7glSlr5TNWtQZJptnxOiOePSjEbSntbXpFG7FuLw1i62LDBJam7PvjC44GTx7AOfbeNdCXNfeqpCUZE2NzBv0eL5BLbQInMu5IC7VfDJ1V4JOnx48/0kaoG7vBGCa4YrewU6bLZ4SaAu0Lw4rQ7iqPxIEl4c1BF/UFv5vghANIRXfQ+sUSi4m3r0MuTfUWl1oflhdB39UpoNvMVGhgWCLNtk7+AKHdYv1g/flq3DbMJKgRBTmho8otUpAu6tMH6Y26y86vOyW55LXDVcYQhB/gw7+ml2TyD7TConN196IWQPwykBX7SJ5fOxrhfgc7hTFv0B/koX1E5ysXiOKs3rz1zVJm/DNgu/rKLBL9lk3n4o0A X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9afda798-cae3-4923-4495-08d9695d823b X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:20:58.8712 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AqoCfE6/sOJZ+OWTqdOo6amqIbUWi+BHAtTQeexIr2gBZ6Yh23YCcKB8gbmbdXoESPMQRtr91QT9iW4O/G8e6Nr3gGmSpQjgSc7QoDCqvE4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-GUID: vEG0ghAhCIDfoNNA2uDJ78B-8E1G0Ble X-Proofpoint-ORIG-GUID: vEG0ghAhCIDfoNNA2uDJ78B-8E1G0Ble Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: "Daniel P. Smith" The Secure Launch platform module is a late init module. During the init call, the TPM event log is read and measurements taken in the early boot stub code are located. These measurements are extended into the TPM PCRs using the mainline TPM kernel driver. The platform module also registers the securityfs nodes to allow access to TXT register fields on Intel along with the fetching of and writing events to the late launch TPM log. Signed-off-by: Daniel P. Smith Signed-off-by: garnetgrimm Signed-off-by: Ross Philipson --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/slmodule.c | 494 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 495 insertions(+) create mode 100644 arch/x86/kernel/slmodule.c diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index d6ee904..09b730a 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -81,6 +81,7 @@ obj-$(CONFIG_IA32_EMULATION) += tls.o obj-y += step.o obj-$(CONFIG_INTEL_TXT) += tboot.o obj-$(CONFIG_SECURE_LAUNCH) += slaunch.o +obj-$(CONFIG_SECURE_LAUNCH) += slmodule.o obj-$(CONFIG_ISA_DMA_API) += i8237.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-y += cpu/ diff --git a/arch/x86/kernel/slmodule.c b/arch/x86/kernel/slmodule.c new file mode 100644 index 0000000..bad50f0a --- /dev/null +++ b/arch/x86/kernel/slmodule.c @@ -0,0 +1,494 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Secure Launch late validation/setup, securityfs exposure and + * finalization support. + * + * Copyright (c) 2021 Apertus Solutions, LLC + * Copyright (c) 2021 Assured Information Security, Inc. + * Copyright (c) 2021, Oracle and/or its affiliates. + * + * Author(s): + * Daniel P. Smith + * Garnet T. Grimm + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SL_FS_ENTRIES 10 +/* root directory node must be last */ +#define SL_ROOT_DIR_ENTRY (SL_FS_ENTRIES - 1) +#define SL_TXT_DIR_ENTRY (SL_FS_ENTRIES - 2) +#define SL_TXT_FILE_FIRST (SL_TXT_DIR_ENTRY - 1) +#define SL_TXT_ENTRY_COUNT 7 + +#define DECLARE_TXT_PUB_READ_U(size, fmt, msg_size) \ +static ssize_t txt_pub_read_u##size(unsigned int offset, \ + loff_t *read_offset, \ + size_t read_len, \ + char __user *buf) \ +{ \ + void __iomem *txt; \ + char msg_buffer[msg_size]; \ + u##size reg_value = 0; \ + txt = ioremap(TXT_PUB_CONFIG_REGS_BASE, \ + TXT_NR_CONFIG_PAGES * PAGE_SIZE); \ + if (IS_ERR(txt)) \ + return PTR_ERR(txt); \ + memcpy_fromio(®_value, txt + offset, sizeof(u##size)); \ + iounmap(txt); \ + snprintf(msg_buffer, msg_size, fmt, reg_value); \ + return simple_read_from_buffer(buf, read_len, read_offset, \ + &msg_buffer, msg_size); \ +} + +DECLARE_TXT_PUB_READ_U(8, "%#04x\n", 6); +DECLARE_TXT_PUB_READ_U(32, "%#010x\n", 12); +DECLARE_TXT_PUB_READ_U(64, "%#018llx\n", 20); + +#define DECLARE_TXT_FOPS(reg_name, reg_offset, reg_size) \ +static ssize_t txt_##reg_name##_read(struct file *flip, \ + char __user *buf, size_t read_len, loff_t *read_offset) \ +{ \ + return txt_pub_read_u##reg_size(reg_offset, read_offset, \ + read_len, buf); \ +} \ +static const struct file_operations reg_name##_ops = { \ + .read = txt_##reg_name##_read, \ +} + +DECLARE_TXT_FOPS(sts, TXT_CR_STS, 64); +DECLARE_TXT_FOPS(ests, TXT_CR_ESTS, 8); +DECLARE_TXT_FOPS(errorcode, TXT_CR_ERRORCODE, 32); +DECLARE_TXT_FOPS(didvid, TXT_CR_DIDVID, 64); +DECLARE_TXT_FOPS(e2sts, TXT_CR_E2STS, 64); +DECLARE_TXT_FOPS(ver_emif, TXT_CR_VER_EMIF, 32); +DECLARE_TXT_FOPS(scratchpad, TXT_CR_SCRATCHPAD, 64); + +/* + * Securityfs exposure + */ +struct memfile { + char *name; + void *addr; + size_t size; +}; + +static struct memfile sl_evtlog = {"eventlog", 0, 0}; +static void *txt_heap; +static struct txt_heap_event_log_pointer2_1_element __iomem *evtlog20; +static DEFINE_MUTEX(sl_evt_log_mutex); + +static ssize_t sl_evtlog_read(struct file *file, char __user *buf, + size_t count, loff_t *pos) +{ + ssize_t size; + + if (!sl_evtlog.addr) + return 0; + + mutex_lock(&sl_evt_log_mutex); + size = simple_read_from_buffer(buf, count, pos, sl_evtlog.addr, + sl_evtlog.size); + mutex_unlock(&sl_evt_log_mutex); + + return size; +} + +static ssize_t sl_evtlog_write(struct file *file, const char __user *buf, + size_t datalen, loff_t *ppos) +{ + char *data; + ssize_t result; + + if (!sl_evtlog.addr) + return 0; + + /* No partial writes. */ + result = -EINVAL; + if (*ppos != 0) + goto out; + + data = memdup_user(buf, datalen); + if (IS_ERR(data)) { + result = PTR_ERR(data); + goto out; + } + + mutex_lock(&sl_evt_log_mutex); + if (evtlog20) + result = tpm20_log_event(evtlog20, sl_evtlog.addr, + sl_evtlog.size, datalen, data); + else + result = tpm12_log_event(sl_evtlog.addr, sl_evtlog.size, + datalen, data); + mutex_unlock(&sl_evt_log_mutex); + + kfree(data); +out: + return result; +} + +static const struct file_operations sl_evtlog_ops = { + .read = sl_evtlog_read, + .write = sl_evtlog_write, + .llseek = default_llseek, +}; + +static struct dentry *fs_entries[SL_FS_ENTRIES]; + +struct sfs_file { + int parent; + const char *name; + const struct file_operations *fops; +}; + +static const struct sfs_file sl_files[] = { + { SL_TXT_DIR_ENTRY, "sts", &sts_ops }, + { SL_TXT_DIR_ENTRY, "ests", &ests_ops }, + { SL_TXT_DIR_ENTRY, "errorcode", &errorcode_ops }, + { SL_TXT_DIR_ENTRY, "didvid", &didvid_ops }, + { SL_TXT_DIR_ENTRY, "ver_emif", &ver_emif_ops }, + { SL_TXT_DIR_ENTRY, "scratchpad", &scratchpad_ops }, + { SL_TXT_DIR_ENTRY, "e2sts", &e2sts_ops } +}; + +static int sl_create_file(int entry, int parent, const char *name, + const struct file_operations *ops) +{ + if (entry < 0 || entry > SL_TXT_DIR_ENTRY) + return -EINVAL; + fs_entries[entry] = + securityfs_create_file(name, 0440, + fs_entries[parent], NULL, ops); + if (IS_ERR(fs_entries[entry])) { + pr_err("Error creating securityfs %s file\n", name); + return PTR_ERR(fs_entries[entry]); + } + return 0; +} + +static long slaunch_expose_securityfs(void) +{ + long ret = 0; + int i = 0; + + fs_entries[SL_ROOT_DIR_ENTRY] = securityfs_create_dir("slaunch", NULL); + if (IS_ERR(fs_entries[SL_ROOT_DIR_ENTRY])) { + pr_err("Error creating securityfs slaunch root directory\n"); + ret = PTR_ERR(fs_entries[SL_ROOT_DIR_ENTRY]); + goto err; + } + + if (slaunch_get_flags() & SL_FLAG_ARCH_TXT) { + fs_entries[SL_TXT_DIR_ENTRY] = + securityfs_create_dir("txt", + fs_entries[SL_ROOT_DIR_ENTRY]); + if (IS_ERR(fs_entries[SL_TXT_DIR_ENTRY])) { + pr_err("Error creating securityfs txt directory\n"); + ret = PTR_ERR(fs_entries[SL_TXT_DIR_ENTRY]); + goto err_dir; + } + + for (i = 0; i < SL_TXT_ENTRY_COUNT; i++) { + ret = sl_create_file(SL_TXT_FILE_FIRST - i, + sl_files[i].parent, sl_files[i].name, + sl_files[i].fops); + if (ret) + goto err_dir; + } + } + + if (sl_evtlog.addr > 0) { + ret = sl_create_file(0, SL_ROOT_DIR_ENTRY, sl_evtlog.name, + &sl_evtlog_ops); + if (ret) + goto err_dir; + } + + return 0; + +err_dir: + for (i = 0; i <= SL_ROOT_DIR_ENTRY; i++) + securityfs_remove(fs_entries[i]); +err: + return ret; +} + +static void slaunch_teardown_securityfs(void) +{ + int i; + + for (i = 0; i < SL_FS_ENTRIES; i++) + securityfs_remove(fs_entries[i]); + + if (slaunch_get_flags() & SL_FLAG_ARCH_TXT) { + if (sl_evtlog.addr) { + memunmap(sl_evtlog.addr); + sl_evtlog.addr = NULL; + } + sl_evtlog.size = 0; + if (txt_heap) { + memunmap(txt_heap); + txt_heap = NULL; + } + } +} + +static void slaunch_intel_evtlog(void __iomem *txt) +{ + struct txt_os_mle_data *params; + void *os_sinit_data; + u64 base, size; + + memcpy_fromio(&base, txt + TXT_CR_HEAP_BASE, sizeof(base)); + memcpy_fromio(&size, txt + TXT_CR_HEAP_SIZE, sizeof(size)); + + /* now map TXT heap */ + txt_heap = memremap(base, size, MEMREMAP_WB); + if (!txt_heap) + slaunch_txt_reset(txt, + "Error failed to memremap TXT heap\n", + SL_ERROR_HEAP_MAP); + + params = (struct txt_os_mle_data *)txt_os_mle_data_start(txt_heap); + + sl_evtlog.size = params->evtlog_size; + sl_evtlog.addr = memremap(params->evtlog_addr, params->evtlog_size, + MEMREMAP_WB); + if (!sl_evtlog.addr) + slaunch_txt_reset(txt, + "Error failed to memremap TPM event log\n", + SL_ERROR_EVENTLOG_MAP); + + /* Determine if this is TPM 1.2 or 2.0 event log */ + if (memcmp(sl_evtlog.addr + sizeof(struct tcg_pcr_event), + TCG_SPECID_SIG, sizeof(TCG_SPECID_SIG))) + return; /* looks like it is not 2.0 */ + + /* For TPM 2.0 logs, the extended heap element must be located */ + os_sinit_data = txt_os_sinit_data_start(txt_heap); + + evtlog20 = tpm20_find_log2_1_element(os_sinit_data); + + /* + * If this fails, things are in really bad shape. Any attempt to write + * events to the log will fail. + */ + if (!evtlog20) + slaunch_txt_reset(txt, + "Error failed to find TPM20 event log element\n", + SL_ERROR_TPM_INVALID_LOG20); +} + +static void slaunch_tpm20_extend_event(struct tpm_chip *tpm, void __iomem *txt, + struct tcg_pcr_event2_head *event) +{ + struct tpm_digest *digests; + u16 *alg_id_field = (u16 *)((u8 *)event + + sizeof(struct tcg_pcr_event2_head)); + u8 *dptr; + int ret; + u32 i, j; + + digests = kcalloc(tpm->nr_allocated_banks, sizeof(*digests), + GFP_KERNEL); + if (!digests) + slaunch_txt_reset(txt, + "Failed to allocate array of digests\n", + SL_ERROR_GENERIC); + + for (i = 0; i < tpm->nr_allocated_banks; i++) + digests[i].alg_id = tpm->allocated_banks[i].alg_id; + + + /* Early SL code ensured there was a max count of 2 digests */ + for (i = 0; i < event->count; i++) { + dptr = (u8 *)alg_id_field + sizeof(u16); + + for (j = 0; j < tpm->nr_allocated_banks; j++) { + if (digests[j].alg_id != *alg_id_field) + continue; + + switch (digests[j].alg_id) { + case TPM_ALG_SHA256: + memcpy(&digests[j].digest[0], dptr, + SHA256_DIGEST_SIZE); + alg_id_field = (u16 *)((u8 *)alg_id_field + + SHA256_DIGEST_SIZE + sizeof(u16)); + break; + case TPM_ALG_SHA1: + memcpy(&digests[j].digest[0], dptr, + SHA1_DIGEST_SIZE); + alg_id_field = (u16 *)((u8 *)alg_id_field + + SHA1_DIGEST_SIZE + sizeof(u16)); + default: + break; + } + } + } + + ret = tpm_pcr_extend(tpm, event->pcr_idx, digests); + if (ret) { + pr_err("Error extending TPM20 PCR, result: %d\n", ret); + slaunch_txt_reset(txt, + "Failed to extend TPM20 PCR\n", + SL_ERROR_TPM_EXTEND); + } + + kfree(digests); +} + +static void slaunch_tpm20_extend(struct tpm_chip *tpm, void __iomem *txt) +{ + struct tcg_pcr_event *event_header = + (struct tcg_pcr_event *)(sl_evtlog.addr + + evtlog20->first_record_offset); + /* Skip first TPM 1.2 event to get to first TPM 2.0 event */ + struct tcg_pcr_event2_head *event = + (struct tcg_pcr_event2_head *)((u8 *)event_header + + sizeof(struct tcg_pcr_event) + + event_header->event_size); + int start = 0, end = 0, size; + + while ((void *)event < sl_evtlog.addr + evtlog20->next_record_offset) { + size = __calc_tpm2_event_size(event, event_header, false); + if (!size) + slaunch_txt_reset(txt, + "TPM20 invalid event in event log\n", + SL_ERROR_TPM_INVALID_EVENT); + + /* + * Marker events indicate where the Secure Launch early stub + * started and ended adding post launch events. + */ + if (event->event_type == TXT_EVTYPE_SLAUNCH_END) { + end = 1; + break; + } else if (event->event_type == TXT_EVTYPE_SLAUNCH_START) { + start = 1; + goto next; + } + + if (start) + slaunch_tpm20_extend_event(tpm, txt, event); + +next: + event = (struct tcg_pcr_event2_head *)((u8 *)event + size); + } + + if (!start || !end) + slaunch_txt_reset(txt, + "Missing start or end events for extending TPM20 PCRs\n", + SL_ERROR_TPM_EXTEND); +} + +static void slaunch_tpm12_extend(struct tpm_chip *tpm, void __iomem *txt) +{ + struct tpm12_event_log_header *event_header = + (struct tpm12_event_log_header *)sl_evtlog.addr; + struct tcg_pcr_event *event = + (struct tcg_pcr_event *)((u8 *)event_header + + sizeof(struct tpm12_event_log_header)); + struct tpm_digest digest; + int start = 0, end = 0, size, ret; + + while ((void *)event < sl_evtlog.addr + event_header->next_event_offset) { + size = sizeof(struct tcg_pcr_event) + event->event_size; + + /* + * Marker events indicate where the Secure Launch early stub + * started and ended adding post launch events. + */ + if (event->event_type == TXT_EVTYPE_SLAUNCH_END) { + end = 1; + break; + } else if (event->event_type == TXT_EVTYPE_SLAUNCH_START) { + start = 1; + goto next; + } + + if (start) { + memset(&digest.digest[0], 0, TPM_MAX_DIGEST_SIZE); + digest.alg_id = TPM_ALG_SHA1; + memcpy(&digest.digest[0], &event->digest[0], + SHA1_DIGEST_SIZE); + + ret = tpm_pcr_extend(tpm, event->pcr_idx, &digest); + if (ret) { + pr_err("Error extending TPM12 PCR, result: %d\n", ret); + slaunch_txt_reset(txt, + "Failed to extend TPM12 PCR\n", + SL_ERROR_TPM_EXTEND); + } + } + +next: + event = (struct tcg_pcr_event *)((u8 *)event + size); + } + + if (!start || !end) + slaunch_txt_reset(txt, + "Missing start or end events for extending TPM12 PCRs\n", + SL_ERROR_TPM_EXTEND); +} + +static void slaunch_pcr_extend(void __iomem *txt) +{ + struct tpm_chip *tpm; + + tpm = tpm_default_chip(); + if (!tpm) + slaunch_txt_reset(txt, + "Could not get default TPM chip\n", + SL_ERROR_TPM_INIT); + if (evtlog20) + slaunch_tpm20_extend(tpm, txt); + else + slaunch_tpm12_extend(tpm, txt); +} + +static int __init slaunch_module_init(void) +{ + void __iomem *txt; + + /* Check to see if Secure Launch happened */ + if ((slaunch_get_flags() & (SL_FLAG_ACTIVE|SL_FLAG_ARCH_TXT)) != + (SL_FLAG_ACTIVE|SL_FLAG_ARCH_TXT)) + return 0; + + txt = ioremap(TXT_PRIV_CONFIG_REGS_BASE, TXT_NR_CONFIG_PAGES * + PAGE_SIZE); + if (!txt) + panic("Error ioremap of TXT priv registers\n"); + + /* Only Intel TXT is supported at this point */ + slaunch_intel_evtlog(txt); + + slaunch_pcr_extend(txt); + + iounmap(txt); + + return slaunch_expose_securityfs(); +} + +static void __exit slaunch_module_exit(void) +{ + slaunch_teardown_securityfs(); +} + +late_initcall(slaunch_module_init); + +__exitcall(slaunch_module_exit); From patchwork Fri Aug 27 13:28:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 12462087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DEA5C2BB4C for ; Fri, 27 Aug 2021 13:21:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13FB460F91 for ; Fri, 27 Aug 2021 13:21:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245261AbhH0NWP (ORCPT ); Fri, 27 Aug 2021 09:22:15 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:37616 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245210AbhH0NWF (ORCPT ); Fri, 27 Aug 2021 09:22:05 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RANNPq015027; Fri, 27 Aug 2021 13:21:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=pCuiy1PYr8laUbnFWIkuUZhLNZc3nLFo89v5zj/FsI8=; b=BKuIOWfAvkziNmmjch2ns9pAeha4qVrq2kUrzdDPOSHtW3rKabPHtAiPKP9hTWYmi/KX PQv2+7N4GDP5O5T1bA+DwLaTzJJLLsq2ck7YclyNwSJs39ZJLRIctbeDiCa0niJb1cAH DnUo2J8tgoWCNqT6GwVOtfL/nRI8r27jrpHPZu8noms4pl84iWWhQR/50FmbwR/uNWSX aP/tGjfQRIPbkQKhnVCfMN1WXUxwallXfdkMW3jRUp8dAKLQyEnwq9Lx8how8LamH4Do Ue7C5LiZPZQ4kS/3H8yfzw7VmPOosoecy1U5U7XKVVSvKfS61D96u1bL+y/PIJnr4s3P yg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=pCuiy1PYr8laUbnFWIkuUZhLNZc3nLFo89v5zj/FsI8=; b=WI2lTnFb/MX6uktSpOJRR0W2Qd4Nrn2hh4nNHrAVqBBGVt72gubpOk+FrLeWMNztMlR7 WhrBJTTcp54iZ2GvAVV3ubwz7RhX+b2QiP3PLS4dOrKAYn24T7KRHykIUbEUdNrvTqd0 P72b28pwrpH9NHJM3YKaVBZPbhneN1/DgnmmHl0lasvpQpz42oB/N2T2opt6Xcl3wzSf Qmwe7MykKZ6sAtzv0hr1ey7AmrF+2kQMQtCZOC8afa+dDws93dt+guNhiivprpBouGkl 5P9K5pYnBhdERY2oc7YdLHLis3yU0OQsyHm6bMmx8OZkJ+QUk+vROhh+t00Q0scS9u4B lA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap4xv3gya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:21:04 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RDBeGU013130; Fri, 27 Aug 2021 13:21:02 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2040.outbound.protection.outlook.com [104.47.51.40]) by userp3020.oracle.com with ESMTP id 3akb924gn5-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 13:21:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AGEVyTL4IH63bFCZOMObMsxLLrFfqJPaBCXC94msnRLfOHJ6LRcjBRuSfr8eu4GcclPe4ESJVyPWnSxKQuYUBX1OSHSFfY3MxACN/E3ZEiHd3qKRYJOh7zkeyWmAgspfURqfnhsvoBPUenDPVGS7c5yk85TdDHKhW0q1q/le0D9Kd3SxEjedFXr6iFTWa0EYCQGtF8EKad3DE/EvqNdpdiPNj5oHpwQaOm3e6H2zhDDBGypRDIGPFB4s7XuQP+fls8UBZvg05GwN7dNcbpKI0C/Lee5cjbkvNY0ROFOEUv10W6mKCySonvrT2pvjdCIzEhySV+zIVgMjZs0bH2pq0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pCuiy1PYr8laUbnFWIkuUZhLNZc3nLFo89v5zj/FsI8=; b=TQJbsSGzTLt08GmvKO3uQIXDhAdZtlyX/7Ifm40liDgYRD88W3rFcv7EvRck+Vg6POtyNIEmFYhP5d37Zhl+JHE3r/jjFA1GRWp5dxMLscmRSsDvlFWN0mL1z6zjA3NZrgtWjgNAImug1kOqXnkQiSq0ooxvwMbxG4slHaanb1BoDwzAO7EV/qzmhc9HAi4f0xK4tnY6xsNNx5ZhWedhEgfHLM7+5ij1AUbw7oCL0tDF0bUc9JVF6+v8Q3AbWoQy5hhh9Fke+gBUbXCm3qmgHXo+fpvlFfU7sHIK4I4KkFa4Leui4Dblz5RQCmCSi5O88TtEBC8hH0DfDFHq4pQ7+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pCuiy1PYr8laUbnFWIkuUZhLNZc3nLFo89v5zj/FsI8=; b=pbX5awhGXAJiH5MlcTiBK1F+TuSzydubQtQbFqsWiGzintxO900yJbGqOIG2PTgn5wQlVJNNfB8Qlvj7a462xijuYRBMBhKq6StUzt35m7UQWH68YFdfDw2GZxhm6Xh3CARJ525phD8H7Z5K6mN61Tm7sE7bpVNUJLG/Cub+Tkw= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) by BYAPR10MB3237.namprd10.prod.outlook.com (2603:10b6:a03:153::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 13:21:00 +0000 Received: from BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3]) by BY5PR10MB3793.namprd10.prod.outlook.com ([fe80::e035:720f:86fd:bae3%4]) with mapi id 15.20.4457.020; Fri, 27 Aug 2021 13:21:00 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v4 14/14] tpm: Allow locality 2 to be set when initializing the TPM for Secure Launch Date: Fri, 27 Aug 2021 09:28:37 -0400 Message-Id: <1630070917-9896-15-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> References: <1630070917-9896-1-git-send-email-ross.philipson@oracle.com> X-ClientProxiedBy: SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) To BY5PR10MB3793.namprd10.prod.outlook.com (2603:10b6:a03:1f6::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lateralus.us.oracle.com (209.17.40.45) by SN6PR05CA0011.namprd05.prod.outlook.com (2603:10b6:805:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.8 via Frontend Transport; Fri, 27 Aug 2021 13:20:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9affd255-28df-48e2-3739-08d9695d8335 X-MS-TrafficTypeDiagnostic: BYAPR10MB3237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wWk1dIaP4EgnWLecjLk8Enf+4EDD9rHAMjdDgcHQoNuQ498EnvJrf3RuCGUeIwF9QO13VcKxcb7ZPPCa4/Moy3WMuzUAD8CqD2nw1lHQU+aEr3cwUn+jsqDXvS3Co8rRP5R74IiNm45Cp/9CftVHEns9wPGVTRGFxJxLzSchrljqfkhkbHjt2YbydZuQ/MD537Tk7Tpii4yLsQYtgjajmDdMDgbG+z565WU3X/8DEacKrrxurwEl5ERunY4U3NFuKqcPR8qFy79kaciXzTiIQakiA87hLDdFiBWvnbh2D46d/kyxeStTFwim8kx2FNk/ZPspnOUamuJD3R8aabWy+sdMvJo375+olDz24Py80pz8EB6OaTcp4wM88IXPRUliwfrWYqcMpMfEP8yQ5jleRO29v/iWRbBRR1+bPX/5Em92C7GLpejqv1r1/MFZeteMeurmEOIoHoJpYQdzA1SV6FA0ihfZmiH3TIVspKI9gHNDeM/TeGngoO08iPqd3TXMDz5Pa9VF/kXlRFyD7oadTAzgHEJNuJJEoeJS8K1xfXtLs6T4otMaZpTjaXi9/k06RMN8WxJoP41Rvldf40RtuofwFe5Q8HIsuAqW49xLwIzAQ3P9FAwBMH27ftW9cKP0hbg9UxmiBWF/MNXZmaX0d8F10zLY0U6lIdl6gGU/tA6nt958vz5j0DsQW38aJCyXkqi316zlbELKAFPo2C+ouQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB3793.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(366004)(346002)(376002)(396003)(956004)(44832011)(2616005)(2906002)(52116002)(26005)(7696005)(478600001)(38350700002)(38100700002)(6486002)(36756003)(186003)(83380400001)(6666004)(86362001)(8936002)(8676002)(316002)(66946007)(66556008)(4326008)(66476007)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bgEePlB8TwA0D7kqY1kYfhFcvNJHkn7qClYY922vM9bIdEHXrjp0sn/63JxAwA0brf1FlujLTg/8U+QhhABBJlkDdOvI59XrbCsx20f2oVb9h8vC0xahNKEeRC0auzH5yCvOKxbUWtRlaKMgBarEXJrE837DXnhv8CatUQXtIx6mmEb+vFIvZSaiIYfbbCGYum61ID212i8pcjXKXm3qk+ZNwoqSqPT2sSuEGHJkyk8HdcINWf8RhRFaLlHvU0zWavc5R5fk1nxFQZmOGWGYiSc9gPgOR61hVypSIJkRkaOTQl5weAmTFPAyhlThQ/s8TYnuDd97Jweau6rP5CwZ/p1Cb8uVpyDNKYoNNoX8XmTUarFaIUkwBW+VtGco+zU28vHx7bfQzfPO8pH4Jlx8NgRf/SOtXJjmHKvfLfvONTFxxRIDa/Fs2Ws7BicEHH2/8YkX/hCoJ2dND48HeuCSgL8oLG8u+v3Fflacm/wHQs8acSYpC3GWFOvpW2qUQj360Jq5Dreq2f8ZJyFzS4tambxhcmmy8ugpB2KS8faNcKXDiXDM7VjdcgAr4nUFW7v2dl4fzJYTxQRp3nvzM1HM4X7GLQazEewa/eFCab8LtSoyr5fqu2aQBniMwAbHhWxJ1EOKKQpd6GcldAalkop48nUkwksNDOLZ66S5gs7+inpidSnZQpAuYPRkgPCDd/WkBsPSJ/pbUfbKtgWjG/aBNF3su91tOzSciKD85PImZJouia7ZN8IKWUtHcCS73QcHQdM2md52f/cMrB4daUmDDB4h9VU8c8TlEtKwpNjnH7SsLYr6QRURDRjG/ux6qEzDBalV2veBEmNkn7/35ic4aYbkgNYs2Hmsh7BP3QGGuVckfSheHPYVkhSAjrgjYktfHn6nOtGR+I6cLnLK9uZ+hXszB8JVkPbSxnOS8GjMJzKdcsSNRiE1A2cyvxN8N5sr1Hne/ZsSlt12f8e0ZTcycJJlvrkUr7ZpQOfLcTFkulAKvieQF5KEf1MqlQMOr4exifJzWh+nZY9jlT6VPl9TzktEdPdoHNMYCm/G8YtVpFOqLdqKhFo0PNA2QZI2w32T8KozpLxKJqm1149qRz1lcRH7zLiEgA6W8BVdMbc4yyA0CFgfbqaHfeb05GK8GgCJ6B52HiAZ+U0W5CNnXz08D6XcN+nhhEgB2JvkwUSHUENMsax8oLY2yS4SWEHzy7vo7rTac7duaXy0AKjqoTuHGs2Ewj9YnSMBGNUSxXmZjcr5Lsxlp6f4e+Z1qhVbH83jD05AAE1S9B2rOXoI5r5eL1lnls5fzDWyCLBfsH99KLeYXjw/2/eOKSVmcyXH26UY X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9affd255-28df-48e2-3739-08d9695d8335 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB3793.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 13:21:00.5582 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8SuCnAQvlxFGTSndnYsNXq4rTZisW9uhAwAZkvP06/Ki3N+0QruppOQIjpUYxCNVCw9HlO/3GQ4klWluK0nbNePyqsxpo5EXrnK4J0zdQqU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3237 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10088 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270086 X-Proofpoint-ORIG-GUID: L20cHFe815oKpsfYh4aeMPg2ybvfuhYu X-Proofpoint-GUID: L20cHFe815oKpsfYh4aeMPg2ybvfuhYu Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org The Secure Launch MLE environment uses PCRs that are only accessible from the DRTM locality 2. By default the TPM drivers always initialize the locality to 0. When a Secure Launch is in progress, initialize the locality to 2. Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm-chip.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index ddaeceb..ce0a3b7 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "tpm.h" DEFINE_IDR(dev_nums_idr); @@ -34,12 +35,18 @@ static int tpm_request_locality(struct tpm_chip *chip) { + int locality; int rc; if (!chip->ops->request_locality) return 0; - rc = chip->ops->request_locality(chip, 0); + if (slaunch_get_flags() & SL_FLAG_ACTIVE) + locality = 2; + else + locality = 0; + + rc = chip->ops->request_locality(chip, locality); if (rc < 0) return rc;