From patchwork Fri Oct 30 06:08:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 11868557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82B1615E6 for ; Fri, 30 Oct 2020 06:09:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EF1A221F8 for ; Fri, 30 Oct 2020 06:09:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="MUUSBs7g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725850AbgJ3GJY (ORCPT ); Fri, 30 Oct 2020 02:09:24 -0400 Received: from de-smtp-delivery-102.mimecast.com ([51.163.158.102]:46149 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgJ3GJY (ORCPT ); Fri, 30 Oct 2020 02:09:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1604038159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tUKxGzan5uWFtK6gBoKg+rjV3lc0R7rkT0PZnUKnzSw=; b=MUUSBs7gPBRJGbYrR0m8z+P5ReIci+0OAv5pIwdZR0yWTauFZYmBpWssmf67LjJaydJ6eX nr6MqWJ17i0ElFhgB70K69W384hE9yvaJG6SNBU6yoOjRPZI59a3/EY882Qdc+PjUdzLHe D8YAbB91cJW8HYRMbg8XHDtWmpEIq8I= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2176.outbound.protection.outlook.com [104.47.17.176]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-17-8t0A9jXjM_i1sZG_HSWBpQ-1; Fri, 30 Oct 2020 07:09:18 +0100 X-MC-Unique: 8t0A9jXjM_i1sZG_HSWBpQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DddbCW51XkDD20IkTA6tvaSWeEt6XK+foSYrYd0fjkfdm/BS7zCByXjy4pQMBKf4wgzvlPYmZ+JlIw1nTmwUd9SJf61uEgRthBMsh+f6JiQR/36EevOjz5z1lDcN+Tz3FjS236ILIuVthCda+zVzJaHz4mm8SfPMpNt9lfvg98Mwl0M0Fz7h9erd5Q6yWD+YNUdt9vORaEMpqG6JOJKoV6iVSSzQA58V9I8G/0sQ/5vDT+/ThbgCFLfHPNSVqVaDyff77MEGefVJPsocPTpefhNDpOx2asb48/G8/FhoAqlqPLX+yuV7JQFfJODZVNvRN6mrRNbdgZot4VaK+JZ0dg== 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=gepDNqtt+cyRoPs2yyuC7yQGbTAgPkdpD5ThQ+4scD4=; b=TGtGMfXu9msZgbAmZifZV8iUYaSAJkr6idI3RYrDZ4KY1M4IVdTuwUXB/BPBnRa+ZHpV0r43k0ZMgngk+cB5/Nm37jktwE8Egt/+rsf67Kb0dOLdfVp55WqhChAaicVFw6Q7IbRRb2+9Si4yDXicVOdEUaxmY6zdlvHO/PsKmBgc1i/qn3MDUpQH7djkfhUbxWSLxpH34iFjU+xakbMFkzxloNHl8yfe4OY0QHzu1p81C4RodzKm/70E7RGlLcmSHO5vKaD3VUYxVD/cOpblZkLghd7oTl4R0Rjiaf14VBFT/Q3QnLGma/G3dpptKUP+dUKGI73Ez8fjojxryigZNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM6PR04MB4919.eurprd04.prod.outlook.com (2603:10a6:20b:c::23) by AS8PR04MB7943.eurprd04.prod.outlook.com (2603:10a6:20b:2a1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Fri, 30 Oct 2020 06:09:16 +0000 Received: from AM6PR04MB4919.eurprd04.prod.outlook.com ([fe80::f063:76fc:db1a:905b]) by AM6PR04MB4919.eurprd04.prod.outlook.com ([fe80::f063:76fc:db1a:905b%6]) with mapi id 15.20.3477.035; Fri, 30 Oct 2020 06:09:16 +0000 From: Chester Lin To: ardb@kernel.org, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, dmitry.kasatkin@gmail.com, catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com CC: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, x86@kernel.org, jlee@suse.com, clin@suse.com Subject: [PATCH v3 1/3] efi: generalize efi_get_secureboot Date: Fri, 30 Oct 2020 14:08:38 +0800 Message-ID: <20201030060840.1810-2-clin@suse.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201030060840.1810-1-clin@suse.com> References: <20201030060840.1810-1-clin@suse.com> X-Originating-IP: [36.225.26.227] X-ClientProxiedBy: HK0PR01CA0049.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::13) To AM6PR04MB4919.eurprd04.prod.outlook.com (2603:10a6:20b:c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (36.225.26.227) by HK0PR01CA0049.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Fri, 30 Oct 2020 06:09:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 720f2a6b-9976-4b7f-2ac4-08d87c9a54e9 X-MS-TrafficTypeDiagnostic: AS8PR04MB7943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4PZxF4wZ1A8OoJT3B1AKnUSbgziNEBpuLK0/i2qa1ywDHes2qqax3pT9NxjcwyUy3XUUPMiy9BFIqU3PUVNwZJddRorDtxLTH7inxmiG2H4AqrpNSj+neYcXk+zp/aVcAAbzVsxDxnQ2klyvKpcX3pYPMqHJ6EB31emt9Rg1WQTCJkcvlzcb0usjuZein1ioRnRtWN7zK5y4cr/xwCmp1MV8GMHnIWfm1zE2aql56gtwGjTuGSVbWdigPiaI4jG7XOUGy0lzRJ6uy+QhmAtZ8MnH5tQ8azMRgTkS0V4G7D2u9sFbO6WxJnNiWQ1emx8gc48qikw1hDqdjKDRJmvtmK+fVbOqznqaf2bU2pV58Y4p24iChdI/++q7Uy+PohKLatcw8Bo1n6kMUGMl6JT6gQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4919.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(346002)(376002)(366004)(396003)(4326008)(186003)(2906002)(7416002)(36756003)(2616005)(16526019)(1076003)(956004)(5660300002)(52116002)(6486002)(8676002)(6512007)(66556008)(66476007)(66946007)(86362001)(6506007)(26005)(69590400008)(8936002)(316002)(83380400001)(478600001)(107886003)(45080400002)(6666004)(921003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Yh1hF//+NqiKTN6lLqDlF0ZmVAPXf6x8AxHxhCHLRTmitg8R3V4xMnDwH9qxUszQs8jH2IaP2vAtc8CdbNSGJ2jvjMs1mX3yyPOvNOhT6kUpEFZFdiKqL+uAoEafrurQc853jJMHQ/iWaxgqk9l85qrAuFsh4yqBcDEU+qufhmgZCMuKxbeilLW1/JwoTwQEEWHBmAqBC4RBBP+hSuaHrPu4IbMEusHFne9Ao0AdTg1Ad8NU72R8wGZ2pqniCKe0d7aCK1yDPUj9liHFCOOyeFVxHweV9pBwSX0jIq82okHPLkELikfpg2p/IQUqgG7s/+BncN1PLDog44XgpRQ2wIHAUZaNtz3l+blQSgrTOaE6CdFB7UkJ3GuJsnNGIe+iYzRgrZMyhq13dSY2PmBDdNb+y2dsNTaW6bZDKwhY4DaSbllNq1l1ECPERUhq0TUt6s9/ClJCdg/rGs2iE9blmDSFGc9inBcQpZ9EA4hDTQ9uYTsNoNEwhGU9wWQtRP1UMHMtcyS0PA+/DbO9rYsobjXApWsk1ZMCiTUyvptJj9wCqXCiLpIMLNuFOMF9emtua94Wrgpl0yx8f/m/R8iDd8pKHECoa+k4nAfaREqw4OQmAyA60xy6i+7lPn0Cnv/doL3O2l7Bwe46ljAmUJcGcg== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 720f2a6b-9976-4b7f-2ac4-08d87c9a54e9 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4919.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2020 06:09:16.5689 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: So4VeEc5gSCbSBAeT9lKS0NvaqvY+K86q6FZUelxKUW0FQvJ5sbi7MFipnQQNPCd X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7943 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Generalize the efi_get_secureboot() function so not only efistub but also other subsystems can use it. Signed-off-by: Chester Lin --- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/firmware/efi/libstub/efi-stub.c | 2 +- drivers/firmware/efi/libstub/efistub.h | 22 ++++--- drivers/firmware/efi/libstub/secureboot.c | 76 ----------------------- drivers/firmware/efi/libstub/x86-stub.c | 2 +- include/linux/efi.h | 41 +++++++++++- 6 files changed, 57 insertions(+), 88 deletions(-) delete mode 100644 drivers/firmware/efi/libstub/secureboot.c diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 8a94388e38b3..88e47b0ca09d 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -49,7 +49,7 @@ OBJECT_FILES_NON_STANDARD := y # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. KCOV_INSTRUMENT := n -lib-y := efi-stub-helper.o gop.o secureboot.o tpm.o \ +lib-y := efi-stub-helper.o gop.o tpm.o \ file.o mem.o random.o randomalloc.o pci.o \ skip_spaces.o lib-cmdline.o lib-ctype.o \ alignedmem.o relocate.o vsprintf.o diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 914a343c7785..ad96f1d786a9 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -196,7 +196,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, /* Ask the firmware to clear memory on unclean shutdown */ efi_enable_reset_attack_mitigation(); - secure_boot = efi_get_secureboot(); + secure_boot = efi_get_secureboot(get_efi_var); /* * Unauthenticated device tree data is a security hazard, so ignore diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 2d7abcd99de9..b1833b51e6d6 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -91,14 +91,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var)) #endif -#define get_efi_var(name, vendor, ...) \ - efi_rt_call(get_variable, (efi_char16_t *)(name), \ - (efi_guid_t *)(vendor), __VA_ARGS__) - -#define set_efi_var(name, vendor, ...) \ - efi_rt_call(set_variable, (efi_char16_t *)(name), \ - (efi_guid_t *)(vendor), __VA_ARGS__) - #define efi_get_handle_at(array, idx) \ (efi_is_native() ? (array)[idx] \ : (efi_handle_t)(unsigned long)((u32 *)(array))[idx]) @@ -112,6 +104,20 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, ((handle = efi_get_handle_at((array), i)) || true); \ i++) +static inline +efi_status_t get_efi_var(efi_char16_t *name, efi_guid_t *vendor, u32 *attr, + unsigned long *size, void *data) +{ + return efi_rt_call(get_variable, name, vendor, attr, size, data); +} + +static inline +efi_status_t set_efi_var(efi_char16_t *name, efi_guid_t *vendor, u32 attr, + unsigned long size, void *data) +{ + return efi_rt_call(set_variable, name, vendor, attr, size, data); +} + static inline void efi_set_u64_split(u64 data, u32 *lo, u32 *hi) { diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c deleted file mode 100644 index 5efc524b14be..000000000000 --- a/drivers/firmware/efi/libstub/secureboot.c +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Secure boot handling. - * - * Copyright (C) 2013,2014 Linaro Limited - * Roy Franz - */ -#include -#include - -#include "efistub.h" - -/* BIOS variables */ -static const efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID; -static const efi_char16_t efi_SecureBoot_name[] = L"SecureBoot"; -static const efi_char16_t efi_SetupMode_name[] = L"SetupMode"; - -/* SHIM variables */ -static const efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID; -static const efi_char16_t shim_MokSBState_name[] = L"MokSBState"; - -/* - * Determine whether we're in secure boot mode. - * - * Please keep the logic in sync with - * arch/x86/xen/efi.c:xen_efi_get_secureboot(). - */ -enum efi_secureboot_mode efi_get_secureboot(void) -{ - u32 attr; - u8 secboot, setupmode, moksbstate; - unsigned long size; - efi_status_t status; - - size = sizeof(secboot); - status = get_efi_var(efi_SecureBoot_name, &efi_variable_guid, - NULL, &size, &secboot); - if (status == EFI_NOT_FOUND) - return efi_secureboot_mode_disabled; - if (status != EFI_SUCCESS) - goto out_efi_err; - - size = sizeof(setupmode); - status = get_efi_var(efi_SetupMode_name, &efi_variable_guid, - NULL, &size, &setupmode); - if (status != EFI_SUCCESS) - goto out_efi_err; - - if (secboot == 0 || setupmode == 1) - return efi_secureboot_mode_disabled; - - /* - * See if a user has put the shim into insecure mode. If so, and if the - * variable doesn't have the runtime attribute set, we might as well - * honor that. - */ - size = sizeof(moksbstate); - status = get_efi_var(shim_MokSBState_name, &shim_guid, - &attr, &size, &moksbstate); - - /* If it fails, we don't care why. Default to secure */ - if (status != EFI_SUCCESS) - goto secure_boot_enabled; - if (!(attr & EFI_VARIABLE_RUNTIME_ACCESS) && moksbstate == 1) - return efi_secureboot_mode_disabled; - -secure_boot_enabled: - efi_info("UEFI Secure Boot is enabled.\n"); - return efi_secureboot_mode_enabled; - -out_efi_err: - efi_err("Could not determine UEFI Secure Boot status.\n"); - return efi_secureboot_mode_unknown; -} diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 3672539cb96e..3f9b492c566b 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -781,7 +781,7 @@ unsigned long efi_main(efi_handle_t handle, * otherwise we ask the BIOS. */ if (boot_params->secure_boot == efi_secureboot_mode_unset) - boot_params->secure_boot = efi_get_secureboot(); + boot_params->secure_boot = efi_get_secureboot(get_efi_var); /* Ask the firmware to clear memory on unclean shutdown */ efi_enable_reset_attack_mitigation(); diff --git a/include/linux/efi.h b/include/linux/efi.h index d7c0e73af2b9..cc2d3de39031 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1089,7 +1089,46 @@ enum efi_secureboot_mode { efi_secureboot_mode_disabled, efi_secureboot_mode_enabled, }; -enum efi_secureboot_mode efi_get_secureboot(void); + +static inline enum efi_secureboot_mode efi_get_secureboot(efi_get_variable_t *get_var) +{ + efi_guid_t var_guid = EFI_GLOBAL_VARIABLE_GUID; + efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID; + efi_status_t status; + unsigned long size; + u8 secboot, setupmode, moksbstate; + u32 attr; + + size = sizeof(secboot); + status = get_var(L"SecureBoot", &var_guid, NULL, &size, &secboot); + + if (status == EFI_NOT_FOUND) + return efi_secureboot_mode_disabled; + if (status != EFI_SUCCESS) + return efi_secureboot_mode_unknown; + + size = sizeof(setupmode); + status = get_var(L"SetupMode", &var_guid, NULL, &size, &setupmode); + + if (status != EFI_SUCCESS) + return efi_secureboot_mode_unknown; + if (secboot == 0 || setupmode == 1) + return efi_secureboot_mode_disabled; + + /* + * See if a user has put the shim into insecure mode. If so, and if the + * variable doesn't have the runtime attribute set, we might as well + * honor that. + */ + size = sizeof(moksbstate); + status = get_var(L"MokSBState", &shim_guid, &attr, &size, &moksbstate); + /* If it fails, we don't care why. Default to secure */ + if (status == EFI_SUCCESS && moksbstate == 1 + && !(attr & EFI_VARIABLE_RUNTIME_ACCESS)) + return efi_secureboot_mode_disabled; + + return efi_secureboot_mode_enabled; +} #ifdef CONFIG_RESET_ATTACK_MITIGATION void efi_enable_reset_attack_mitigation(void); From patchwork Fri Oct 30 06:08:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 11868561 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BB5B1592 for ; Fri, 30 Oct 2020 06:09:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D689822206 for ; Fri, 30 Oct 2020 06:09:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="O5TZNfmh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725875AbgJ3GJ3 (ORCPT ); Fri, 30 Oct 2020 02:09:29 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:32235 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbgJ3GJ2 (ORCPT ); Fri, 30 Oct 2020 02:09:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1604038164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oQvM2JE+j7/DleT37T611kucF8NlR4G9Y59/gRb7JBk=; b=O5TZNfmhK8YQXYQnaAaOLyxSgR6COnZQbQIGBQRXHthd2YQKk2OQPjOy8ZOYknyiAzqia6 +yEcsaXwL8gkGV8QHiJGzbp44Eh+8+Ps9KW9fMnZsVQZtU9GYpW9/k/GRo40uBP3mB+E1m bV5Og9gTXXdpmp0CX2PsczeCyUXXPx8= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2177.outbound.protection.outlook.com [104.47.17.177]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-32-MDnEefD4MIGO8vQAJeivZw-1; Fri, 30 Oct 2020 07:09:23 +0100 X-MC-Unique: MDnEefD4MIGO8vQAJeivZw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eEOP2Z2lkrUTUVrqLUrWSaFji1eA/tmNtxXPu5zellU/k47Aq/UVi9oQ14mCcVKV9APiJC1iHk/oDp7B34bnsILomEkkrg3Oaokgm5j+T+8NJ4kXA7i9ghz4qAQmcN5IqynmB0wPwhUn8fIPMCss3wxa/FD1SHfjS3bDLRKl4wc62AFkpSadx9SW7t3fod1z91vsnk/epFOqzPvuC5X9xO86UTeadZQcFkN7ntUDwypalWteiYdfSjK77CyjtNu/Yf3JwdsPSOuWYbhEuU0FuPdLQr5/PT4+wCi6O/yeLeVbV56YGmb2gmPaEkgpBqEe82Oz83+uwV4MC0kcxGb3lA== 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=J4iAAMV7x59qmnQJ5iU4xhe/FTnFqg0ZYqSlBHXpBVY=; b=BrbE36m1SSapLE5eZy0ey4yZsxPXBDOOd4AIssD5MuTw5SIxYENPgz/RwkLJwikuaoVZ4FBhE74VGI102GvGTHjVXD8nRdhKxkYxEBePGBbzqbUv6iGc0INHYOaEj4rAY1TOyGN4N9Qrv4MjADMQMzjcEoGqbzl8ec5hupCW91/lBSVMOnCsin6dJMJjeETNEdyqeTk/PVXxrdoXWStQB6gd7vsHxQHm89wEfh6NvTdqEbliH9x7bVh80FOCARPwLzizq4aVcgYvByTrk9mYfZzYXagWluT81ogN5syP/sdOaozW7xOM/hYbbzfz4hxMbr+SxvIHx9z/KGwpEglfbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM6PR04MB4919.eurprd04.prod.outlook.com (2603:10a6:20b:c::23) by AS8PR04MB7943.eurprd04.prod.outlook.com (2603:10a6:20b:2a1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Fri, 30 Oct 2020 06:09:21 +0000 Received: from AM6PR04MB4919.eurprd04.prod.outlook.com ([fe80::f063:76fc:db1a:905b]) by AM6PR04MB4919.eurprd04.prod.outlook.com ([fe80::f063:76fc:db1a:905b%6]) with mapi id 15.20.3477.035; Fri, 30 Oct 2020 06:09:21 +0000 From: Chester Lin To: ardb@kernel.org, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, dmitry.kasatkin@gmail.com, catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com CC: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, x86@kernel.org, jlee@suse.com, clin@suse.com Subject: [PATCH v3 2/3] ima: replace arch-specific get_sb_mode() with a common helper ima_get_efi_secureboot() Date: Fri, 30 Oct 2020 14:08:39 +0800 Message-ID: <20201030060840.1810-3-clin@suse.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201030060840.1810-1-clin@suse.com> References: <20201030060840.1810-1-clin@suse.com> X-Originating-IP: [36.225.26.227] X-ClientProxiedBy: HK0PR01CA0049.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::13) To AM6PR04MB4919.eurprd04.prod.outlook.com (2603:10a6:20b:c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (36.225.26.227) by HK0PR01CA0049.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Fri, 30 Oct 2020 06:09:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 421955fd-abee-4680-c635-08d87c9a57e9 X-MS-TrafficTypeDiagnostic: AS8PR04MB7943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:525; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZBLF86StWzcOkwgNzHklYX+4S+xJ8XGNdHcfJxVRNByNjZh/AtUWZm7ynoK+GmiAOFmJGmyAciVJPVYmaySVWkAZIGV2m4m0W4BD/SVOyn83V+eZtma6sqMrqoUInPUt25ZMzc8SajlYRg4OKQDuuRSyE0K9rrXiBPNhbEoJh9B0MoB4SRbZNrLGwFpZO+T05kJc2wx4dd4YOcoxrVuKSqYKGvGXnTNgHze7LnAc5LWMgzLQJVdJsvodcgQozi+9u8tJo11oSFVvrOdCO7sa4Pd0nHlnrDBcfKPEjkUUo0AvR0WTE9n6Clz2VqDSOOv1GUki4zNJoNk2rff9xDQDO68QWzvsV/+MP5mQv4IyViUfl2YNQH/27mynSppziMjVz1UMiNJ9VRD+boDhUIyCww== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4919.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(346002)(376002)(366004)(396003)(4326008)(186003)(2906002)(7416002)(36756003)(2616005)(16526019)(1076003)(956004)(5660300002)(52116002)(6486002)(8676002)(6512007)(66556008)(66476007)(66946007)(86362001)(6506007)(26005)(69590400008)(8936002)(316002)(83380400001)(478600001)(107886003)(6666004)(921003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: caMxZmqnK4pZcjkhqeJsVc7YG1rZpMio+ePPac97FeEvwKD43kBhqoZToH0eber3fuausLBpy5kBRuCdjwgDsYJQrc95cdiNvqlv+Z/Mkzdb4eqrtJHgd9feTE7hM5J57m6QnRfgF9xctm4OpHdhvB6zDZ+QQrvB3vN2AXFCJV5OSqjOfrSS4YBn40Q52+vKeZD0w7sA2RJ+60NvLH0pFu41BhYDu0A4Fx7ou43G1sFnQDbygmlj0cjB7EVIbjcuPi8fY85eK9g48r61f221Cm49QLJgM55mSBczN5V4wNsUqxJYamKkEreY0As2Owe7HPb2/snRbbRwFg1GKIIBdmQYKFuSLO/7x7/UkbsKgeyEKAsvflulq/mDnbuuhq5bMO9MY7cV+HFVLrQimZxKRFJix2OMhbrU7T8mFF8vBzWUyqzxBFdidccf23HQI5jmI8T3erTWtyAYDrbgS7PCgqQgivSFXmYuBD2IV0+AtSW5qlhHtSJ/5Wh3DwLxHfVO6nMLKzN40GTM8lnv7Sas8C7bhGQa8E7S9mt5LQXXvVRfMKI7UlKArOSwwiaGXzijdzoZsqU5g4uuzPvPOSWHBGFsQgTQAVeJ1wl8vHqOYwxkOAJOckEUoJxC/t5B9orJOW+vW2iStvDbxL5lZMK6qw== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 421955fd-abee-4680-c635-08d87c9a57e9 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4919.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2020 06:09:21.6060 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kiWL43G8d249K9vjR86wwFas52E+6S1o+sN/yXpD9qPsyiWsydaO0/JS5vh1tW9R X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7943 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org remove the get_sb_mode() from x86/kernel/ima_arch.c and create a common helper ima_get_efi_secureboot() in IMA so that all EFI-based architectures can refer to the same procedure. Signed-off-by: Chester Lin --- arch/x86/kernel/ima_arch.c | 69 +++++++------------------------- include/linux/ima.h | 10 +++++ security/integrity/ima/Makefile | 1 + security/integrity/ima/ima_efi.c | 26 ++++++++++++ 4 files changed, 51 insertions(+), 55 deletions(-) create mode 100644 security/integrity/ima/ima_efi.c diff --git a/arch/x86/kernel/ima_arch.c b/arch/x86/kernel/ima_arch.c index 7dfb1e808928..2c773532ff0a 100644 --- a/arch/x86/kernel/ima_arch.c +++ b/arch/x86/kernel/ima_arch.c @@ -8,69 +8,28 @@ extern struct boot_params boot_params; -static enum efi_secureboot_mode get_sb_mode(void) -{ - efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID; - efi_status_t status; - unsigned long size; - u8 secboot, setupmode; - - size = sizeof(secboot); - - if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) { - pr_info("ima: secureboot mode unknown, no efi\n"); - return efi_secureboot_mode_unknown; - } - - /* Get variable contents into buffer */ - status = efi.get_variable(L"SecureBoot", &efi_variable_guid, - NULL, &size, &secboot); - if (status == EFI_NOT_FOUND) { - pr_info("ima: secureboot mode disabled\n"); - return efi_secureboot_mode_disabled; - } - - if (status != EFI_SUCCESS) { - pr_info("ima: secureboot mode unknown\n"); - return efi_secureboot_mode_unknown; - } - - size = sizeof(setupmode); - status = efi.get_variable(L"SetupMode", &efi_variable_guid, - NULL, &size, &setupmode); - - if (status != EFI_SUCCESS) /* ignore unknown SetupMode */ - setupmode = 0; - - if (secboot == 0 || setupmode == 1) { - pr_info("ima: secureboot mode disabled\n"); - return efi_secureboot_mode_disabled; - } - - pr_info("ima: secureboot mode enabled\n"); - return efi_secureboot_mode_enabled; -} - bool arch_ima_get_secureboot(void) { - static enum efi_secureboot_mode sb_mode; - static bool initialized; - - if (!initialized && efi_enabled(EFI_BOOT)) { - sb_mode = boot_params.secure_boot; + static bool sb_enabled, initialized; - if (sb_mode == efi_secureboot_mode_unset) - sb_mode = get_sb_mode(); + if (initialized) { + return sb_enabled; + } else if (efi_enabled(EFI_BOOT)) { initialized = true; + + if (boot_params.secure_boot == efi_secureboot_mode_unset) { + sb_enabled = ima_get_efi_secureboot(); + return sb_enabled; + } } - if (sb_mode == efi_secureboot_mode_enabled) - return true; - else - return false; + if (boot_params.secure_boot == efi_secureboot_mode_enabled) + sb_enabled = true; + + return sb_enabled; } -/* secureboot arch rules */ +/* secure and trusted boot arch rules */ static const char * const sb_arch_rules[] = { #if !IS_ENABLED(CONFIG_KEXEC_SIG) "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig", diff --git a/include/linux/ima.h b/include/linux/ima.h index 8fa7bcfb2da2..9f9699f017be 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -50,6 +50,16 @@ static inline const char * const *arch_get_ima_policy(void) } #endif +#if defined(CONFIG_EFI) && defined(CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT) +extern bool ima_get_efi_secureboot(void); +#else +static inline bool ima_get_efi_secureboot(void) +{ + return false; +} +#endif + + #else static inline int ima_bprm_check(struct linux_binprm *bprm) { diff --git a/security/integrity/ima/Makefile b/security/integrity/ima/Makefile index 67dabca670e2..32076b3fd292 100644 --- a/security/integrity/ima/Makefile +++ b/security/integrity/ima/Makefile @@ -14,3 +14,4 @@ ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o ima-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o ima-$(CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS) += ima_asymmetric_keys.o ima-$(CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS) += ima_queue_keys.o +ima-$(CONFIG_EFI) += ima_efi.o diff --git a/security/integrity/ima/ima_efi.c b/security/integrity/ima/ima_efi.c new file mode 100644 index 000000000000..a78f66e19689 --- /dev/null +++ b/security/integrity/ima/ima_efi.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2020 SUSE LLC + * + * Author: + * Chester Lin + */ + +#include +#include + +#ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT +bool ima_get_efi_secureboot(void) +{ + enum efi_secureboot_mode sb_mode; + + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) { + pr_info("ima: secureboot mode unknown, no efi\n"); + return false; + } + + sb_mode = efi_get_secureboot(efi.get_variable); + + return (sb_mode == efi_secureboot_mode_enabled) ? true : false; +} +#endif From patchwork Fri Oct 30 06:08:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 11868563 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 004E2157C for ; Fri, 30 Oct 2020 06:09:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C387F22202 for ; Fri, 30 Oct 2020 06:09:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="lXeqEBqw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725863AbgJ3GJh (ORCPT ); Fri, 30 Oct 2020 02:09:37 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:28804 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725885AbgJ3GJe (ORCPT ); Fri, 30 Oct 2020 02:09:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1604038170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/Fv7kjlLaE1ID8TqNkNRfCKTkbSAy2dUe8mwvzgGWgs=; b=lXeqEBqwrY8YDUhL1gP6ca75NUxsiSwPgYCcdto2H6rZliAb/Tbrv0f/rpPT21xp1nTQqR tu2tnqwDLu0WluDuT5q/f3V85VJtcp/VUsobRKKQz3iYoHKv4nPYcBdr5bE46pAiqN/j8r X8spa+IoPu1tD9UeFrdlbH89gXGSQvQ= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2172.outbound.protection.outlook.com [104.47.17.172]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-34-s8cP6mGeMzS4MQlBZgTtUw-1; Fri, 30 Oct 2020 07:09:28 +0100 X-MC-Unique: s8cP6mGeMzS4MQlBZgTtUw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BaUdWbfMtI0P+LNjGpNyKbSFWOxhjFUs0zOYhL1r78xsehC8Sa9qV2yzf33FZ/kGZ9g8v3sr4lxfDo4XZHAedqmhhirc/bx4OzkjYXtU8BIQCrrTzUe1CywaNH5dhaklj1O5LCyPmTWoGSgtjs+kAPPb0l64eXW7U0D2rS/MnhC8u5QlE5MG8E1hYjEctL36xoaCcZgAXHX1ThSq0jHf5Cd7217jLPMhG0edrx4kE9KKYE34ut/MOchFM+OMT12jJHY33zCdmAm5fe9k7K4e7i3WoseOSk3teXUwDWrna5CL4FJv4iAS/465zt63c4LI+JH4/vcyWyIZDhql7dZcpA== 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=i2s5pNb2jKUMdl7cEgIOLMyVaU6avnr8VXDXLQN1KI8=; b=ZV/1Llj6A62mR62tnXdZt50vMQhJzbQ8TEBhQ5X06Gzb/OLfViQy9Lrnyxw6uL7AyOE+RLRcRcNElmEzoi14AA4DBUhmNwDm+M9jwZuV41yqo8TPWzqH2sQ1D+oKTT3xgfL1bflQXPmRIkdrDmmSK93jsWfBLEf2GN6sXvcbEzda1cARB5MyceCFFuZkOwObjmLNa+RYc+vYkGu/NPIsno6wqQoa73sQhp14eFraITKEgKGYTarQ/Cu2qgg9u1b3Dzpsv1KaCvGRUdM/hPITY1CMnttihEZHQ/XTr1QJpnRwuZLWgyx9MBjQve1oOOR45gYDxV04TPWYiyP+5X1Juw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=suse.com; Received: from AM6PR04MB4919.eurprd04.prod.outlook.com (2603:10a6:20b:c::23) by AS8PR04MB7943.eurprd04.prod.outlook.com (2603:10a6:20b:2a1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Fri, 30 Oct 2020 06:09:26 +0000 Received: from AM6PR04MB4919.eurprd04.prod.outlook.com ([fe80::f063:76fc:db1a:905b]) by AM6PR04MB4919.eurprd04.prod.outlook.com ([fe80::f063:76fc:db1a:905b%6]) with mapi id 15.20.3477.035; Fri, 30 Oct 2020 06:09:26 +0000 From: Chester Lin To: ardb@kernel.org, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, dmitry.kasatkin@gmail.com, catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com CC: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, x86@kernel.org, jlee@suse.com, clin@suse.com Subject: [PATCH v3 3/3] arm64/ima: add ima_arch support Date: Fri, 30 Oct 2020 14:08:40 +0800 Message-ID: <20201030060840.1810-4-clin@suse.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201030060840.1810-1-clin@suse.com> References: <20201030060840.1810-1-clin@suse.com> X-Originating-IP: [36.225.26.227] X-ClientProxiedBy: HK0PR01CA0049.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::13) To AM6PR04MB4919.eurprd04.prod.outlook.com (2603:10a6:20b:c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (36.225.26.227) by HK0PR01CA0049.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Fri, 30 Oct 2020 06:09:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8253d210-0609-42e3-bd2e-08d87c9a5ae4 X-MS-TrafficTypeDiagnostic: AS8PR04MB7943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:126; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oBxNZPHidJ5iVU5YzXPKxXQ+jG+XTFBy+T6bFGg3LJQbSc4InuT0UVN0n+Qf5fYStA/UtSyXF9DjSflG7uGPJEHQfr/OG5ktVcbhxYo6f8SOyrxIO4CC3tn8ZQPwZ0D/tCfY1MK2UhzAWty68QvPxyDBVQUiwx9MmSTLHYrcK2p575BqfT8dCF+r6Q/7G7JCk++tkEZcUYtecG9sYYvcJEvzJtwvMZp+X6ArZW9kwtrcS+YAo+dmFBcnfhDVmcJmOuVRNrVezw1Rb8+crKCLq4adVvgIRkojCHbIpXf/sid8E37OgOl5w3/9J45mRd0HRzq6/qpNqp+EeqETz9K2BtG3QsxRz66bMGCWHlfWQmiYp0cgV6FjRkSdOllPnezEJRL9SYNDO5nnePao6kcXhQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4919.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(39860400002)(346002)(376002)(366004)(396003)(4326008)(186003)(2906002)(7416002)(36756003)(2616005)(16526019)(1076003)(956004)(5660300002)(52116002)(6486002)(8676002)(6512007)(66556008)(66476007)(66946007)(86362001)(6506007)(26005)(69590400008)(8936002)(316002)(478600001)(107886003)(6666004)(921003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: fWZIAVkb+eePpvRiUG6vjqF0th33lRsw5HAqhUwaDxdKaSqdkp4lw/tbyykUduw1cOjms8Si0QnEsrY/1OSl0px83DHCh1zCDFLvVoJNkdxJHsJ37HbBpnCLpC/LCtjyWMiM6y8L+fLiV2jX83ZY7E865dqazj/VbnqGlptDUWASbO4jle1ezKM40m3rPbYsu9Cj2uP1lzjY2CcKK8IaYE4vdL6R2szYjP+e+z+qVOjF7ZCz+kE/6LUjZcIUb7b4qPzZy922C4bT+4+r0tkstqdobOFbyDHJjCPra8fjBdAXJcm+YF/ebtukI2E0Z7+kVbnnNU75Ol2xUtBV7N67nmCKLWWN7EBpasBFtOeXDWvZDng3wF9u2TUS71k2GgVNvKfYYYPwlgvGQyfLga+R4HBmYEs+wVGy5dGIyiKRkdbMpQZbg2tCLx0UDUMUJvv5WuK94awQsAxRIKNvh+Y+6ZqhPpllG4aVrH6nAIQ41kfRSUHwvdFD3qDUh9DL3C/9uDUPvNDWmFAWUG1lpjTLerV/1UXsHwRk0nDS1KRcj5oP4tFY2etOzoRuKu93vY6h0Y4a7gx5PG+1AWbP3fM4ON0DUm8UbPQ2Quvg8/Bb8KAF2C+URI7wlXjUq9QuINJJNoqexKrgUUektg1M/b7jbA== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8253d210-0609-42e3-bd2e-08d87c9a5ae4 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4919.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2020 06:09:26.7851 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C/snX50CcrA1A1vy7A7TwHCIOlNxNlLv3bXAAkr7IFX6gU2u/T+TbOLHNpqr87V6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7943 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Add arm64 IMA arch support. The code and arch policy is mainly inherited from x86. Signed-off-by: Chester Lin --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/Makefile | 2 ++ arch/arm64/kernel/ima_arch.c | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 arch/arm64/kernel/ima_arch.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index a42e8d13cc88..496a4a26afc6 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -201,6 +201,7 @@ config ARM64 select SWIOTLB select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK + imply IMA_SECURE_AND_OR_TRUSTED_BOOT if EFI help ARM 64-bit (AArch64) Linux support. diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index bbaf0bc4ad60..0f6cbb50668c 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -69,3 +69,5 @@ extra-y += $(head-y) vmlinux.lds ifeq ($(CONFIG_DEBUG_EFI),y) AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\"" endif + +obj-$(CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT) += ima_arch.o diff --git a/arch/arm64/kernel/ima_arch.c b/arch/arm64/kernel/ima_arch.c new file mode 100644 index 000000000000..564236d77adc --- /dev/null +++ b/arch/arm64/kernel/ima_arch.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 IBM Corporation + */ +#include +#include +#include + +bool arch_ima_get_secureboot(void) +{ + static bool sb_enabled; + static bool initialized; + + if (!initialized & efi_enabled(EFI_BOOT)) { + sb_enabled = ima_get_efi_secureboot(); + initialized = true; + } + + return sb_enabled; +} + +/* secure and trusted boot arch rules */ +static const char * const sb_arch_rules[] = { +#if !IS_ENABLED(CONFIG_KEXEC_SIG) + "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig", +#endif /* CONFIG_KEXEC_SIG */ + "measure func=KEXEC_KERNEL_CHECK", +#if !IS_ENABLED(CONFIG_MODULE_SIG) + "appraise func=MODULE_CHECK appraise_type=imasig", +#endif + "measure func=MODULE_CHECK", + NULL +}; + +const char * const *arch_get_ima_policy(void) +{ + if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) { + if (IS_ENABLED(CONFIG_MODULE_SIG)) + set_module_sig_enforced(); + return sb_arch_rules; + } + return NULL; +}