From patchwork Sun Apr 10 10:49:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 12808110 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6282C433EF for ; Sun, 10 Apr 2022 10:49:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237442AbiDJKwC (ORCPT ); Sun, 10 Apr 2022 06:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbiDJKwA (ORCPT ); Sun, 10 Apr 2022 06:52:00 -0400 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2109.outbound.protection.outlook.com [40.92.103.109]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1476652E4D; Sun, 10 Apr 2022 03:49:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EL/jjQKXWGEg9WCgWwDwTqCOIOrKCHVFCkWjrupUhdKR3nZqYqqJUeL8MTh0/9DL8hkxCor+KDGNBIp9GCzYt599fhr87SRjgRiqumjkVFwppDWKQJZrAZkvJw66nF8chp4LZEKD9odY0Jx3QH/k4xojJBssvYy9+MDEcGghPXib+7DIsR94dcjj/Y24P0KEpqyI+dHJipqAtVeAPyTTT9mb6NmiUBR70mUvZw9fW/Z/cQtMsWiGLLD5ZJ9wR7TDZSEpGRWdZdHzfjFtmTaOETqjraBs3AFrEQtB6lYScaAcUG5zNHYAk8fExT0Ikgcpz7YMbdBkRXJZEBKy841OvA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HRYT9HIVLI3JsGOF2U/SbYZObbuVI/T8O37W1Car8WE=; b=fOBK8mGfaAVd2CmxnaAFAYY/YSbmGW6nuE+Ll49qWAIHRnHjxZc8NTUP7j+Wkx6eGXBOHtPYQtYoRMvjE/MRhVgsBpxbvUgvVilkNDKBoYDfGmFmR/FoLSgLJCdSGxnjXVBnOy9CTu6L5nEG3JUUtRj4kttph3yfsJS6237rJjAPRm7x4FssEqSmtnT46fwrPUZGRI+u0wXtHjvw65t8wcFxCCmmZNVnpuY0ZEiPeqNwvAzaPsNX/YbnfMYifcvLVwIjLkQx3ulSfABYCYjshsWluFSR69UGBVjJvPkM7sxwf1f8qalr3xFsnxxtMGOL0ucbYrhTRpZ2AqKYIb0xIQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HRYT9HIVLI3JsGOF2U/SbYZObbuVI/T8O37W1Car8WE=; b=Nq9co3KHin5PJ0GpCVJVUIcrfD559PS+EzHaIrp5d9DQtDAVj7clUDeFmZ5V9m1Y7075uXzb48c4fbBjnMqs26Q4NsW8w99a+c1a9q+HpDnaPKfsNNrzXZkgktbVv4YVG9pUmKa4FiIHbVQpQaOLgXhGAhTNUrtEqRSXVpFuKooZmrKQclY/90UuV023HyjdB5Cb3+NYDQ9fxEBeffikonEjNT1D0TF95K60puro2mhCicLP/0+1HEoTEDPuIdYS9dtPJzTTSHq9sFN3x+DhPGUAfTmYqqRoBHY8ez7Zb0wJ89rVypwa1CL8rX9R4ruAardWEP5rGCXDsRcGpWsG4A== Received: from PNZPR01MB4415.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:1b::13) by PNXPR01MB6803.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:a4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Sun, 10 Apr 2022 10:49:40 +0000 Received: from PNZPR01MB4415.INDPRD01.PROD.OUTLOOK.COM ([fe80::dc4b:b757:214c:22cd]) by PNZPR01MB4415.INDPRD01.PROD.OUTLOOK.COM ([fe80::dc4b:b757:214c:22cd%7]) with mapi id 15.20.5144.029; Sun, 10 Apr 2022 10:49:40 +0000 From: Aditya Garg To: "jarkko@kernel.org" , "zohar@linux.ibm.com" , "dmitry.kasatkin@gmail.com" , "jmorris@namei.org" , "serge@hallyn.com" , "ast@kernel.org" , "daniel@iogearbox.net" , "andrii@kernel.org" , "kafai@fb.com" , "songliubraving@fb.com" , "yhs@fb.com" , "john.fastabend@gmail.com" , "kpsingh@kernel.org" CC: "linux-integrity@vger.kernel.org" , "keyrings@vger.kernel.org" , "linux-security-module@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "bpf@vger.kernel.org" , Orlando Chamberlain , "admin@kodeit.net" Subject: [PATCH v3 RESEND] efi: Do not import certificates from UEFI Secure Boot for T2 Macs Thread-Topic: [PATCH v3 RESEND] efi: Do not import certificates from UEFI Secure Boot for T2 Macs Thread-Index: AQHYTMiu7fv9f4beLU+/MNIc0GPCKQ== Date: Sun, 10 Apr 2022 10:49:40 +0000 Message-ID: <652C3E9E-CB97-4C70-A961-74AF8AEF9E39@live.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Dk+Bk30Vq8pr0Mf13vFncptVWdm2hXtW] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7a20533a-22d9-416d-ec26-08da1adfd0aa x-ms-traffictypediagnostic: PNXPR01MB6803:EE_ x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: mYd/zd2ozv+maSKzZYzunUD8kQHUF4ywu1rIOz7DuAMdtV8JGR2YiCfInTtNbH0m1ZESCJmL0n1FBNHR9jloe8KVZUiIgJIWjyWXBnFeRhxxftgFqUIVNQJO/pqt8U6jpUpGsC2UBZDxhqhvdBpygm5FH9DLvqNbA3H2uJg1rnnm0sWADDS+e/i+d217PBYlmkmQNH0jqGtVbfzs3Eb7ZgjYi7FNBPj3Pirdd+DNJSJctkVPy3Yj+3rNusVA2TmIKaN0nYh8LeGcL8hDntW1btetbJWYZnbTOAjKcR5LUWuBmyIhb9+GP+uhmdOiJZ59FBrpk/BLYlFcORehS8HLUpFCkXWh+EVDHumEXzinpnQU5AW76rj5Yz42FprW1cpa9TkdF1DqOKzJcVJPwMIjeEPd/fWTMlM0OVIhmCCOHqR6QE5obDmPHzmbFLd4x4yAM8wFCoF38B7xngGuR9gibtgVaVCk4rjb/3VinadJfSNdF1VDWkdimg3sylZgKrfiTjBt5VQvJR5M9Vf4ikUEQjlWC4HavoBdkWcxIFaATfTbAUlt2EwT1A438hYPwtJmZSv6NeYUwARKlQGDEwnhQA== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: d/aGMdBH4KnXkB5maKcP/vhWRHmO+fxg/QzXTX3J2fl54sHWZhLcNKswh6lQyNUgn6WIW/YSpc8GvIFOUcmdML41VwMnrk9gR90iCZUeQ+IknOWaZldMuHRhbqC/xSRlQbBsFxZdyEYxPIaTIazeBxe6cyOk/6HojGyFUvEFrSrymeU67RRDon8o+zyfsXK1Ce1vkGrH8aHnkIikcNaSUkTg4wTdFqlqktw7qNTTuwY1BpFgNCcjLHXHTsy95h6yZZKr+gfNtkBSWxKP+nQJ8AQxP8jshwAdfzWVB6cfHuVsrVLaJaDe7IX5b0SUamdqAaDlbip9W/APDpquVn7s+Rnyr4RByobnsYLZuJ3egJg35sBGz2oEoXb3zes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ID: <19A300E8C6374B4A9B52EF1D3E2EA82F@INDPRD01.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-42ed3.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PNZPR01MB4415.INDPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 7a20533a-22d9-416d-ec26-08da1adfd0aa X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Apr 2022 10:49:40.6769 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PNXPR01MB6803 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Aditya Garg On T2 Macs, the secure boot is handled by the T2 Chip. If enabled, only macOS and Windows are allowed to boot on these machines. Thus we need to disable secure boot for Linux. If we boot into Linux after disabling secure boot, if CONFIG_LOAD_UEFI_KEYS is enabled, EFI Runtime services fail to start, with the following logs in dmesg Call Trace: page_fault_oops+0x4f/0x2c0 ? search_bpf_extables+0x6b/0x80 ? search_module_extables+0x50/0x80 ? search_exception_tables+0x5b/0x60 kernelmode_fixup_or_oops+0x9e/0x110 __bad_area_nosemaphore+0x155/0x190 bad_area_nosemaphore+0x16/0x20 do_kern_addr_fault+0x8c/0xa0 exc_page_fault+0xd8/0x180 asm_exc_page_fault+0x1e/0x30 (Removed some logs from here) ? __efi_call+0x28/0x30 ? switch_mm+0x20/0x30 ? efi_call_rts+0x19a/0x8e0 ? process_one_work+0x222/0x3f0 ? worker_thread+0x4a/0x3d0 ? kthread+0x17a/0x1a0 ? process_one_work+0x3f0/0x3f0 ? set_kthread_struct+0x40/0x40 ? ret_from_fork+0x22/0x30 ---[ end trace 1f82023595a5927f ]--- efi: Froze efi_rts_wq and disabled EFI Runtime Services integrity: Couldn't get size: 0x8000000000000015 integrity: MODSIGN: Couldn't get UEFI db list efi: EFI Runtime Services are disabled! integrity: Couldn't get size: 0x8000000000000015 integrity: Couldn't get UEFI dbx list integrity: Couldn't get size: 0x8000000000000015 integrity: Couldn't get mokx list integrity: Couldn't get size: 0x80000000 This patch prevents querying of these UEFI variables, since these Macs seem to use a non-standard EFI hardware Cc: stable@vger.kernel.org Signed-off-by: Aditya Garg --- v2 :- Reduce code size of the table. V3 :- Close the brackets which were left open by mistake. .../platform_certs/keyring_handler.h | 8 ++++ security/integrity/platform_certs/load_uefi.c | 48 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/security/integrity/platform_certs/keyring_handler.h b/security/integrity/platform_certs/keyring_handler.h index 2462bfa08..cd06bd607 100644 --- a/security/integrity/platform_certs/keyring_handler.h +++ b/security/integrity/platform_certs/keyring_handler.h @@ -30,3 +30,11 @@ efi_element_handler_t get_handler_for_db(const efi_guid_t *sig_type); efi_element_handler_t get_handler_for_dbx(const efi_guid_t *sig_type); #endif + +#ifndef UEFI_QUIRK_SKIP_CERT +#define UEFI_QUIRK_SKIP_CERT(vendor, product) \ + .matches = { \ + DMI_MATCH(DMI_BOARD_VENDOR, vendor), \ + DMI_MATCH(DMI_PRODUCT_NAME, product), \ + }, +#endif diff --git a/security/integrity/platform_certs/load_uefi.c b/security/integrity/platform_certs/load_uefi.c index 08b6d12f9..f246c8732 100644 --- a/security/integrity/platform_certs/load_uefi.c +++ b/security/integrity/platform_certs/load_uefi.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -12,6 +13,32 @@ #include "../integrity.h" #include "keyring_handler.h" +/* Apple Macs with T2 Security chip don't support these UEFI variables. + * The T2 chip manages the Secure Boot and does not allow Linux to boot + * if it is turned on. If turned off, an attempt to get certificates + * causes a crash, so we simply return 0 for them in each function. + */ + +static const struct dmi_system_id uefi_skip_cert[] = { + + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro15,1") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro15,2") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro15,3") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro15,4") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro16,1") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro16,2") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro16,3") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro16,4") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookAir8,1") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookAir8,2") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookAir9,1") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacMini8,1") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacPro7,1") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMac20,1") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMac20,2") }, + { } +}; + /* * Look to see if a UEFI variable called MokIgnoreDB exists and return true if * it does. @@ -21,12 +48,18 @@ * is set, we should ignore the db variable also and the true return indicates * this. */ + static __init bool uefi_check_ignore_db(void) { efi_status_t status; unsigned int db = 0; unsigned long size = sizeof(db); efi_guid_t guid = EFI_SHIM_LOCK_GUID; + const struct dmi_system_id *dmi_id; + + dmi_id = dmi_first_match(uefi_skip_cert); + if (dmi_id) + return 0; status = efi.get_variable(L"MokIgnoreDB", &guid, NULL, &size, &db); return status == EFI_SUCCESS; @@ -41,6 +74,11 @@ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid, unsigned long lsize = 4; unsigned long tmpdb[4]; void *db; + const struct dmi_system_id *dmi_id; + + dmi_id = dmi_first_match(uefi_skip_cert); + if (dmi_id) + return 0; *status = efi.get_variable(name, guid, NULL, &lsize, &tmpdb); if (*status == EFI_NOT_FOUND) @@ -85,6 +123,11 @@ static int __init load_moklist_certs(void) unsigned long moksize; efi_status_t status; int rc; + const struct dmi_system_id *dmi_id; + + dmi_id = dmi_first_match(uefi_skip_cert); + if (dmi_id) + return 0; /* First try to load certs from the EFI MOKvar config table. * It's not an error if the MOKvar config table doesn't exist @@ -138,6 +181,11 @@ static int __init load_uefi_certs(void) unsigned long dbsize = 0, dbxsize = 0, mokxsize = 0; efi_status_t status; int rc = 0; + const struct dmi_system_id *dmi_id; + + dmi_id = dmi_first_match(uefi_skip_cert); + if (dmi_id) + return 0; if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) return false;