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: 11837475 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 75EC514B3 for ; Wed, 14 Oct 2020 10:43:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1EA2A2173E for ; Wed, 14 Oct 2020 10:43:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sFvRvetJ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.com header.i=@suse.com header.b="PcoGuYWf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EA2A2173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0T9mnzYGJAkpJg9nedDGNK7Pu6EJBFJNEgJaiRJGU2I=; b=sFvRvetJkZpFz5S4OsqiWydRk 6PjB89Gcv4D2eRhOlF34GLs9nnIAQea+SCtOm57jIIK8SaVjQGLnRjucYNMS7koD/s2oiaC4Wf3uZ wC6en1oocAfO2WHmEUu2JtJoyDqJB/c720MwzGayVC791b9XJHkr87kBX5f262ipXCOT5wWJu+Q+K gl6yt87j11vmD5C9fadndVdOlfQm130oEqUX5NGTsD4Cul4WqtGBV6wPNA0XdvOAOLWpx/PiOyicE RKHxh5Cm5K/YDuoGnLaq+UHiRWdoPNM6BTfUpc9rjx70tDyjDXEcL4YFCZ4Jgc/Ej44/7GjY0uDRH snyCDB6jQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSeDs-0001lA-OE; Wed, 14 Oct 2020 10:41:32 +0000 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSeDn-0001jw-Vv for linux-arm-kernel@lists.infradead.org; Wed, 14 Oct 2020 10:41:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1602672086; 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=PcoGuYWfc/csUnCNtsKumhIgvJWtVkwKdFUG6u8OpJKiCgENvXdlU3M65ffHiRskjdBS3H sYzeoBjgf3D6yaDw17uxWY4gaaC4E0mz7a1U1K0/RZGWuGyH3ZZuIhuL00ZmiNJt9PBtZT 603m6h6VsonvAGWI1q9P5fo9mzCAdq8= 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201014_064128_152390_803BDBE5 X-CRM114-Status: GOOD ( 13.69 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [62.140.7.102 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [62.140.7.102 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: clin@suse.com, linux-efi@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, jlee@suse.com, linux-integrity@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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: 11837469 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 4123D14B3 for ; Wed, 14 Oct 2020 10:41:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D001A20878 for ; Wed, 14 Oct 2020 10:41:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="s0OU0iya"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.com header.i=@suse.com header.b="SdsFpH39" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D001A20878 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IZKJB2obrnuxnfcQGPKTuuG/Fr+pysshaV1f387nyJU=; b=s0OU0iyaOdHRXm7/XlFFryx7A DZzoU62ffqjnXr8LJd8esjY6osk+VYFJdRechBTL3cMCnXUIZi8eHFQbccuCdVrlDfJcqwdIbhaci VohQeWX2e7LXIt6j6MEe5mE5rUYnHKK0BGYgh4L4Z3UsyCzDmvMsP3FtSvja6rboB3JNeR93Rsc4s qLoIuAzaADD2wPT6QH88eisf1ZlAIB0CeWxoH8gw8ErVb4yyn8tGBkyzWAYAufTqeNXgA5ejjKjbY Mp8B/5Kh4yYtr6RYpTQHTOA2WvThF9Nv6ktXmPI9g98llH5cbEjbv35OAPazsFPpsyV0TNSEv46M0 bJz8n6HjQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSeDx-0001mP-Qx; Wed, 14 Oct 2020 10:41:37 +0000 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSeDv-0001lN-7V for linux-arm-kernel@lists.infradead.org; Wed, 14 Oct 2020 10:41:36 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201014_064135_490793_DD3FC432 X-CRM114-Status: GOOD ( 16.49 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [62.140.7.102 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [62.140.7.102 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: clin@suse.com, linux-efi@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, jlee@suse.com, linux-integrity@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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; +}