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; +}