From patchwork Wed Oct 14 10:40:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 11837463 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 C39AA14B3 for ; Wed, 14 Oct 2020 10:41:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F3A9208B3 for ; Wed, 14 Oct 2020 10:41:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="WpDRCrvl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387928AbgJNKle (ORCPT ); Wed, 14 Oct 2020 06:41:34 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:48759 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387810AbgJNKl3 (ORCPT ); Wed, 14 Oct 2020 06:41:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1602672087; 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=DX1ZK3/1sTmoPzvnoNhBiQWKtM8tWGS4p6JMf2/xZwY=; b=WpDRCrvl0tbu17eY36/NfvQv+3BgxsmblR3I5alUBr2tkbkLZiw43EuML8UQ4heio3iIs4 MzQ1VlsLsojqamv9tgDMeHmuS0QMZKN5JNddkxBOS7fCR7fnIo7CuuGAVUJc9347JkRdlU ChDLqyKoXPlhYpURN/nQAeHBIZ9f1PA= Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2052.outbound.protection.outlook.com [104.47.14.52]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-30-AeUS50VUOPWU93jj9CvnXQ-1; Wed, 14 Oct 2020 12:41:25 +0200 X-MC-Unique: AeUS50VUOPWU93jj9CvnXQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PkyIoOh6hnC7y7hl8d9nqyv8tVK+NzH1efYsr467nqibXxLrE8ftKqoCEQxhU6OJD8NyY9mnrkK7pRIwLT7kvPHFiTRvREkdiMtpDAvFcG4o49nmTJ2Wux3s3K8zbRSa2kpU7YMwFvpCA2wXXiRcBeCcng+PR4nUqqLnzrGts5C89yB5ThHliL84CYFqNOGlc3y5XTp8vsL9Ri0p5Mdpb7yuSybaBkNC+RJ3/vX92o1JOc7ZhPkiGxSTNrOGn/wQ8+e9aec/g1gVLFzn83usyl74JyN2Y0v74D4CA+UK6e6tEr6PmhlWRmKL9VnvndvnfcNtMvm6hvvR/462Uk9DaQ== 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=NzQTPQkBdGFKOP5+s4UUfeGv1eDzjOXLoRlcEAHF4ww=; b=OvWaDpJWVneFL+9tO75HerqH5b5KVSBRMm19ounyvfl1cgR55i5X1+OgewBlhEPETUuq73JvfPd24rBx4V82QghOsIFzix0nUj78RjIyNePvIIJ745kXZJ5hLAepD7cDIgOuJx341DxiNsTFtsDwtoxjYgSXwO2SpuKA7MSGNbDkXlbE4AuApJDk7HhueUBSecuFBmExmajPonrQvblh4TMR1zrY0eUiv2g6Ug0tQq7gpQO+pbyGFqKzSINUkM1LWNG4bRJtzOMTBzeShZ3riqC0u1LiEbSORJ2V1FofGmbz3VeHvVBruKo4tLorKOJPcfG5aIDtpewiv8nICfEjSQ== 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: linux.ibm.com; dkim=none (message not signed) header.d=none;linux.ibm.com; dmarc=none action=none header.from=suse.com; Received: from VI1PR04MB4928.eurprd04.prod.outlook.com (2603:10a6:803:57::13) by VI1PR0402MB3600.eurprd04.prod.outlook.com (2603:10a6:803:7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.28; Wed, 14 Oct 2020 10:41:24 +0000 Received: from VI1PR04MB4928.eurprd04.prod.outlook.com ([fe80::e922:583c:a9bf:66e0]) by VI1PR04MB4928.eurprd04.prod.outlook.com ([fe80::e922:583c:a9bf:66e0%6]) with mapi id 15.20.3477.020; Wed, 14 Oct 2020 10:41:24 +0000 From: Chester Lin To: zohar@linux.ibm.com, ardb@kernel.org, catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, samitolvanen@google.com, masahiroy@kernel.org CC: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-efi@vger.kernel.org, jlee@suse.com, clin@suse.com Subject: [PATCH v2 1/2] efi: add secure boot get helper Date: Wed, 14 Oct 2020 18:40:31 +0800 Message-ID: <20201014104032.9776-2-clin@suse.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20201014104032.9776-1-clin@suse.com> References: <20201014104032.9776-1-clin@suse.com> X-Originating-IP: [118.166.52.150] X-ClientProxiedBy: AM0PR01CA0074.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::15) To VI1PR04MB4928.eurprd04.prod.outlook.com (2603:10a6:803:57::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-8mug.suse.cz (118.166.52.150) by AM0PR01CA0074.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Wed, 14 Oct 2020 10:41:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 55aab5a2-b9d1-4d72-ced9-08d8702db285 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3600: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:169; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YqJgbaCVtfKsC4XzDmfV5SQxrp68IJ2NWUTXNwn1MFzMysnm+NAozoUXwy/3xqlsl1Azy/qHfdcHRunlrPNvvWJUlqdN4HbKXHJRLpaUNBaQPmg45aSobuQ0MOIdenkT6zwQ9whrsnrqHY/03tWMDs6E57+0eZCKlKPiRLtdZYe33ip3aDBvUJ57ffAPuzH0VbDG2Gq/D8w0sXKHCZ9Ar3Ax/blhe7id72EmuQJRxcwJn3mQXg9pFi5Ye6myJjt4SQjAFqgD6mvfBM3jBZHSHNYaVzA9UVbPPiWKQZIYaWHJBTy2v5qsn6JoxJuqO4sBIj1DMakV6kSTuFmgnhSWabU/t9uQk6/dj0gDQP/6hoIx+EUgmrddKmxx75q5O3RB X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB4928.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(136003)(39860400002)(346002)(396003)(26005)(66556008)(5660300002)(2906002)(6666004)(4326008)(66476007)(66946007)(16526019)(186003)(1076003)(83380400001)(316002)(2616005)(956004)(55236004)(86362001)(6486002)(6506007)(36756003)(107886003)(478600001)(8936002)(6512007)(7416002)(8676002)(52116002)(921003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: v40dyIburKf5ZXKIlf2nPcDZz4jCwjn6ds6DdzPO66oslwxxCn9mKryDE7FazD//Fh5Vt5TOxxa7z6vYjS6N8ihv+UN/6OM5nJ2PqSFhoj8ydK5TKV8/fDYBPvwdYSKy2Juet8AWI/ghwGsdKLc1dRbMPGGmun9hPxFtKOTP1ax1px/fGvSF82CyaNhl7I0gvFnsNDQ5fr2y9W9dtejKJXeEx2UlzsEAb6eJ5uJyUJay7iucFZXyTgTO2onUAGA2Whz52CipLlFFG/wahl1+suWSf7Bn6cCDUIYwvbgNDbPsZZUOJRPmrml48uQXiH/E4uh2CAdht0bGchVRzPIDln12QLpfJrRwL5jE2Wsp8WTcXAwoDfIzF/dxCFAMeKeYwoz6590mHVlt8ZG4e4CBZ2H+eLOxp0m6D7rh+2EegmyB1EeeTehfbKl1x2veowkzrZxGXCl4CfJ9D8ifeW7iUfEwc8BrI/OKQ6HMDp9zA2mEjSMZqIsg/LOtGHe9l1EhfpvdRcKiHvOglSOw2LDD4Ee+tUxVbN1DnOlXBFbabwkFad/dnBtRMXkg4gopDv1V72m0Uu0i+3NKl2Wwt4l01qnG9SBXtihjVEMoiU2M9i2aOs0vvobeb78yLvmgbni7dP7Kh9Pn6Cw7shK23ODqBA== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55aab5a2-b9d1-4d72-ced9-08d8702db285 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB4928.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2020 10:41:24.7566 (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: MRaqifrhK93lK3E0ScLbWudPlFF0zcbthqn65iARrB5VLEozWXx9xIKXpX+E0woh X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3600 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Separate the get_sb_mode() from arch/x86 and treat it as a common function [rename to efi_get_secureboot_mode] so all EFI-based architectures can reuse the same logic. Signed-off-by: Chester Lin --- arch/x86/kernel/ima_arch.c | 47 ++------------------------------------ drivers/firmware/efi/efi.c | 43 ++++++++++++++++++++++++++++++++++ include/linux/efi.h | 5 ++++ 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/arch/x86/kernel/ima_arch.c b/arch/x86/kernel/ima_arch.c index 7dfb1e808928..ed4623ecda6e 100644 --- a/arch/x86/kernel/ima_arch.c +++ b/arch/x86/kernel/ima_arch.c @@ -8,49 +8,6 @@ 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; @@ -60,7 +17,7 @@ bool arch_ima_get_secureboot(void) sb_mode = boot_params.secure_boot; if (sb_mode == efi_secureboot_mode_unset) - sb_mode = get_sb_mode(); + sb_mode = efi_get_secureboot_mode(); initialized = true; } @@ -70,7 +27,7 @@ bool arch_ima_get_secureboot(void) return false; } -/* 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/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 5e5480a0a32d..68ffa6a069c0 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -1022,3 +1022,46 @@ static int __init register_update_efi_random_seed(void) } late_initcall(register_update_efi_random_seed); #endif + +enum efi_secureboot_mode efi_get_secureboot_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; +} diff --git a/include/linux/efi.h b/include/linux/efi.h index d7c0e73af2b9..a73e5ae04672 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1076,8 +1076,13 @@ static inline int efi_runtime_map_copy(void *buf, size_t bufsz) #ifdef CONFIG_EFI extern bool efi_runtime_disabled(void); +extern enum efi_secureboot_mode efi_get_secureboot_mode(void); #else static inline bool efi_runtime_disabled(void) { return true; } +static inline enum efi_secureboot_mode efi_get_secureboot_mode(void) +{ + return efi_secureboot_mode_disabled; +} #endif extern void efi_call_virt_check_flags(unsigned long flags, const char *call); From patchwork Wed Oct 14 10:40:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 11837465 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 DE48914B5 for ; Wed, 14 Oct 2020 10:41:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4C4221527 for ; Wed, 14 Oct 2020 10:41:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="SdsFpH39" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388132AbgJNKln (ORCPT ); Wed, 14 Oct 2020 06:41:43 -0400 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:58554 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388085AbgJNKlh (ORCPT ); Wed, 14 Oct 2020 06:41:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1602672094; 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=5BBItUcPEBwXGi//ddCPz3H7K+gQOWlFfdylaPsz7GA=; b=SdsFpH39ihlyqRLkcFeu+hdiMvetCy6OQXxpIuHzoIMYz07JnP2zsnPqcC7E6shBklq+dr uHBzqtBEqmxw++gm41DDYA2Z9lMSdDwVPhn9IFH9mBtkJu2RA1IPTLYNpItg3YPo/3y6h/ yBRPx1CEWdwFWsRHpoYSI+6EeblmXS8= Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2055.outbound.protection.outlook.com [104.47.14.55]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-38-2lk8D948Mbm9weTaqeL9vA-1; Wed, 14 Oct 2020 12:41:32 +0200 X-MC-Unique: 2lk8D948Mbm9weTaqeL9vA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oDD+rmUK4Dlun/z1Ul2srHcXcHmc50Sxy4iE7GwnYaTD9dTJX6craUk4CYa9tZndGS2mSdMlNLmFpDG/upMVNYc1hfJYiEo3RZ5ZMDl1ElMnfAPI1jWrKmOZrcJfPx2n7QPJxa2OPI14PmBuIUXnW/BmsCa0qhi3qVMkLBhGKHzsGNQIRzo24IQCvTGNFPjCNP8fEymAer2LlNzE/I7RoIATSQb9cmUFGLcwF7p9taP6TLm3PhI/Eh8TClBpJnp1zWrcBLBB49oqCMVeNDESrR1CJPmLP2u+8Hp2+XpId5ngLNf2TVM0F5pnH4K1X8Vz8BcEADGKWNV0kq9B7enOUA== 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=WEJy2cfW0nHSDc/ccRkwbCKNK82k9/qPYrIHj4xgT+8=; b=TZi3kleHXbeOpZ43+Q1c+xBVpaOegjshBnxr6CUs8bMShlO36t5PPm+3tLV+zUPWv8RzSEil/va5LGcwsz8E5nGS7nEvTY6vJ/fnftdUStpW5fx/kBp/NQYBDkNqUj7cgiG1JlyUHdWmJSH4uTs5T6Oc+99YbR9YNdf6hddWS1cZQxV4QmZZOqCaxG8SR6FnQNm5PobrvVLdVubB4tUHymLk0PiRepCnL/rsvAo0C4L4YHQ0pobtzhy135NEX3oQGKBYcplXNLBtJE/XYX6MIAD531cUgDNQzS3Un7mZmzqvlPpzG8bMnZPzGwlVC539qBxWbUO4fKXtGZb2cV44Uw== 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: linux.ibm.com; dkim=none (message not signed) header.d=none;linux.ibm.com; dmarc=none action=none header.from=suse.com; Received: from VI1PR04MB4928.eurprd04.prod.outlook.com (2603:10a6:803:57::13) by VI1PR0402MB3600.eurprd04.prod.outlook.com (2603:10a6:803:7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.28; Wed, 14 Oct 2020 10:41:31 +0000 Received: from VI1PR04MB4928.eurprd04.prod.outlook.com ([fe80::e922:583c:a9bf:66e0]) by VI1PR04MB4928.eurprd04.prod.outlook.com ([fe80::e922:583c:a9bf:66e0%6]) with mapi id 15.20.3477.020; Wed, 14 Oct 2020 10:41:31 +0000 From: Chester Lin To: zohar@linux.ibm.com, ardb@kernel.org, catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, samitolvanen@google.com, masahiroy@kernel.org CC: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-efi@vger.kernel.org, jlee@suse.com, clin@suse.com Subject: [PATCH v2 2/2] arm64/ima: add ima_arch support Date: Wed, 14 Oct 2020 18:40:32 +0800 Message-ID: <20201014104032.9776-3-clin@suse.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20201014104032.9776-1-clin@suse.com> References: <20201014104032.9776-1-clin@suse.com> X-Originating-IP: [118.166.52.150] X-ClientProxiedBy: AM0PR01CA0074.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::15) To VI1PR04MB4928.eurprd04.prod.outlook.com (2603:10a6:803:57::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-8mug.suse.cz (118.166.52.150) by AM0PR01CA0074.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Wed, 14 Oct 2020 10:41:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d0c2b70a-03f2-442f-565f-08d8702db684 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3600: 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: 9o51FEUhxiGXJp/sIkwxx4JqZaM1VktV9odTkbx2yBDqwsDtSDwSb5plfpuR3G0h+eUjlaXZZCAsun75RdMZMvbvK2z90e2OSWENJgqcqVA8thVqmaUv8t6ciOF22TR0ynLuMD9egU3VDfIV5cu+9PIgzGkuDzCVe4RI/tuB6/DwzYAmlqAu9xdpYpoPkF2FsA9eiql0MXpOZxR4eyF7R6+KQmLSNDiThunkoYY/OrIuLQWe6V6T/ly1ufyyhmip57X8Xf2DGDfZVxmwe3QITrcpzafjzIe1AK6Y+x3IP6QtiYl5KKRFIOZ4YL57ViBdZ4S8Am14y3OPtEFmxSxokJZSbwoqgeSLbObsnWu2Imw2g78GwvQiOemPX8rTWFdm X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB4928.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(136003)(39860400002)(346002)(396003)(26005)(66556008)(5660300002)(2906002)(6666004)(4326008)(66476007)(66946007)(16526019)(186003)(1076003)(316002)(2616005)(956004)(55236004)(86362001)(6486002)(6506007)(36756003)(107886003)(478600001)(8936002)(6512007)(7416002)(8676002)(52116002)(921003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1YPfwdCaVfd69iPFriUNW49LI1jDLplKhM26jAvB+OGPDbqfRI2vwGs2cl8rDRZ8p9PvPN7M2a2ll7rhDFHECvd6+4RNjNnaRXb9+g3X1wM4lNGErEl8LMXBUG2yDn8U8oUWE1XqZEBz31u2sLAkSbx1Ou25GIYAwJ/VtBq0NprNzHgTnhouRB+9C0wlu9Fcw81xoq21YuLoaOhY3ta1Fa1YBQ9xDlGEglh+SR5yHUsS5Sc1UrFqylR1xulQcBcTljkO7nwDe1a/y9JQL6Cfsk02ZVykia0nEXo/IU0RLknGOUolew7RcfZocAR3Nugq42ISg8mbG7DBj68r7Wj83d3QPk+XHvKHXCFdUz6rjzvgfvaIpXJktFhdnYn5tEpWNfpgvjGMUIzjhEl2TNl3L8QCZrlMJv+BXcffbl6AjcEQ+7OBeIsoK74H1TslYjVq3LiLaGcZaowz+d7/wOpVRDpVpsN2t+j+27zWrJcY5deOTO3OZHYQS7+jrLcp6vejlTAtfAByudSROrUYtVfw9jHwKEhOHTmwUSMwpUVWNVFCai2cWHKem1EY8XZ9EfgE2XjoOxlIh6UKWZVwuvGRRBXSEIR2IAaj0k4Q+/oy4zcih3mvA2UIoa+kFERxLdCgq7JCwFEE+9wgbudp0OKZNg== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0c2b70a-03f2-442f-565f-08d8702db684 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB4928.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2020 10:41:31.4558 (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: o5aV0xjoJyWrxROzG6DhFdgaLrupKxrzTixKAeKJlyeuRU5z8pVrm+2zhdXP00Pg X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3600 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 | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 arch/arm64/kernel/ima_arch.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 08fa3a1c50f0..15b7a3bbb7e5 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -199,6 +199,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..f3103c8a2cab --- /dev/null +++ b/arch/arm64/kernel/ima_arch.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 IBM Corporation + */ +#include +#include +#include + +bool arch_ima_get_secureboot(void) +{ + static enum efi_secureboot_mode sb_mode; + static bool initialized; + + if (!initialized && efi_enabled(EFI_BOOT)) { + sb_mode = efi_get_secureboot_mode(); + initialized = true; + } + + if (sb_mode == efi_secureboot_mode_enabled) + return true; + else + return false; +} + +/* 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; +}