From patchwork Fri Dec 4 19:51:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nramas X-Patchwork-Id: 338491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0DA9C433FE for ; Fri, 4 Dec 2020 19:53:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 858C722C9C for ; Fri, 4 Dec 2020 19:53:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730621AbgLDTwh (ORCPT ); Fri, 4 Dec 2020 14:52:37 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52586 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbgLDTwh (ORCPT ); Fri, 4 Dec 2020 14:52:37 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id B132520B717B; Fri, 4 Dec 2020 11:51:55 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B132520B717B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111516; bh=aI4rIemLm3GHqyZ/WWq5CkE6W7Xpb/ccyPzXipZF3IQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ip+9aKCpVnQXoEq6N5aboBwZa1gZuRESPZY+VXjXuL+/H914zahVfHTia5uB/rXKj jG4Fqd+KijZkqKbuvCZ25fW+CPbEhWZByNWJtd1hCYiELef88aCKH2v4EPx/o17KTG 6ggCk+pejhTTEC3nOK+f4OvpDSoXpsWrL3kQrONA= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 1/8] powerpc: fix compiler warnings and errors Date: Fri, 4 Dec 2020 11:51:42 -0800 Message-Id: <20201204195149.611-2-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The function prototype for the functions defined in ima.c for powerpc are given in the header file ima.h. But this header file is not included in ima.c resulting in compilation errors such as given below. arch/powerpc/kexec/ima.c:56:5: error: no previous prototype for 'ima_get_kexec_buffer' [-Werror=missing-prototypes] 56 | int ima_get_kexec_buffer(void **addr, size_t *size) | ^~~~~~~~~~~~~~~~~~~~ The function parameters for remove_ima_buffer() and arch_ima_add_kexec_buffer() are not described in the function header resulting in warnings such as given below. arch/powerpc/kexec/ima.c:111: warning: Function parameter or member 'fdt' not described in 'remove_ima_buffer' Include ima.h in ima.c for powerpc. Describe the function parameters for remove_ima_buffer() and arch_ima_add_kexec_buffer(). Co-developed-by: Prakhar Srivastava Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian Reviewed-by: Mimi Zohar Reviewed-by: Thiago Jung Bauermann --- arch/powerpc/kexec/ima.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/powerpc/kexec/ima.c b/arch/powerpc/kexec/ima.c index 720e50e490b6..a36c39db4b1a 100644 --- a/arch/powerpc/kexec/ima.c +++ b/arch/powerpc/kexec/ima.c @@ -11,6 +11,7 @@ #include #include #include +#include static int get_addr_size_cells(int *addr_cells, int *size_cells) { @@ -103,6 +104,9 @@ int ima_free_kexec_buffer(void) /** * remove_ima_buffer - remove the IMA buffer property and reservation from @fdt * + * @fdt: Flattened Device Tree to update + * @chosen_node: Offset to the chosen node in the device tree + * * The IMA measurement buffer is of no use to a subsequent kernel, so we always * remove it from the device tree. */ @@ -131,6 +135,10 @@ void remove_ima_buffer(void *fdt, int chosen_node) /** * arch_ima_add_kexec_buffer - do arch-specific steps to add the IMA buffer * + * @image: kimage struct to set IMA buffer data + * @load_addr: Starting address where IMA buffer is loaded at + * @size: Number of bytes in the IMA buffer + * * Architectures should use this function to pass on the IMA buffer * information to the next kernel. * From patchwork Fri Dec 4 19:51:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nramas X-Patchwork-Id: 338490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16CB4C19437 for ; Fri, 4 Dec 2020 19:53:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E208622CA0 for ; Fri, 4 Dec 2020 19:53:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730815AbgLDTwj (ORCPT ); Fri, 4 Dec 2020 14:52:39 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52620 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726021AbgLDTwi (ORCPT ); Fri, 4 Dec 2020 14:52:38 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 6342D20B7185; Fri, 4 Dec 2020 11:51:56 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6342D20B7185 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111517; bh=427MsiV0MJQ9LDUV1/OKNAuvCmpzH/SyuDnprhY+alQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oZ1AzWqjEKlap+yDtpbJhlld1/VXmdjiKXrXXSzy+8u+8MWOf32gLWFQp81AtLSmU IdtE+Zu14NmIFiqnpYysmruB5AaHI1zFxGQSt6Be75DYSqIMi6jzelIUgB5fBu8d4l Af9hbwl9gVdMeCD735Jvg10hLKPz74PoUuWAn2Ew= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 2/8] powerpc: Move delete_fdt_mem_rsv() to drivers/of/kexec.c Date: Fri, 4 Dec 2020 11:51:43 -0800 Message-Id: <20201204195149.611-3-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org delete_fdt_mem_rsv() retrieves the memory reserve map entry, for the given starting address and size, from the device tree blob, and removes the entry from the device tree blob. This function is called to free the resources reserved for the buffer used for carrying forward the IMA measurement logs on kexec. This function does not have architecture specific code, but is currently limited to powerpc. Move delete_fdt_mem_rsv() to "drivers/of/kexec_fdt.c" so that it is accessible for other architectures as well. Co-developed-by: Prakhar Srivastava Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian --- arch/powerpc/include/asm/kexec.h | 1 - arch/powerpc/kexec/file_load.c | 32 ----------------- drivers/of/Makefile | 1 + drivers/of/kexec.c | 61 ++++++++++++++++++++++++++++++++ include/linux/kexec.h | 5 +++ 5 files changed, 67 insertions(+), 33 deletions(-) create mode 100644 drivers/of/kexec.c diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h index 55d6ede30c19..7c223031ecdd 100644 --- a/arch/powerpc/include/asm/kexec.h +++ b/arch/powerpc/include/asm/kexec.h @@ -126,7 +126,6 @@ int setup_purgatory(struct kimage *image, const void *slave_code, int setup_new_fdt(const struct kimage *image, void *fdt, unsigned long initrd_load_addr, unsigned long initrd_len, const char *cmdline); -int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size); #ifdef CONFIG_PPC64 struct kexec_buf; diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c index 9a232bc36c8f..9efc98b1e2ae 100644 --- a/arch/powerpc/kexec/file_load.c +++ b/arch/powerpc/kexec/file_load.c @@ -109,38 +109,6 @@ int setup_purgatory(struct kimage *image, const void *slave_code, return 0; } -/** - * delete_fdt_mem_rsv - delete memory reservation with given address and size - * - * Return: 0 on success, or negative errno on error. - */ -int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size) -{ - int i, ret, num_rsvs = fdt_num_mem_rsv(fdt); - - for (i = 0; i < num_rsvs; i++) { - uint64_t rsv_start, rsv_size; - - ret = fdt_get_mem_rsv(fdt, i, &rsv_start, &rsv_size); - if (ret) { - pr_err("Malformed device tree.\n"); - return -EINVAL; - } - - if (rsv_start == start && rsv_size == size) { - ret = fdt_del_mem_rsv(fdt, i); - if (ret) { - pr_err("Error deleting device tree reservation.\n"); - return -EINVAL; - } - - return 0; - } - } - - return -ENOENT; -} - /* * setup_new_fdt - modify /chosen and memory reservation for the next kernel * @image: kexec image being loaded. diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 6e1e5212f058..77d24712c0c8 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -13,5 +13,6 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +obj-$(CONFIG_OF_FLATTREE) += kexec.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/ diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c new file mode 100644 index 000000000000..b7d59105fcb8 --- /dev/null +++ b/drivers/of/kexec.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Microsoft Corporation + * + * Author: Lakshmi Ramasubramanian (nramas@linux.microsoft.com) + * + * File: kexec.c + * Defines kexec related functions. + */ + +#define pr_fmt(fmt) "OF: kexec: " fmt + +#include +#include +#include +#include +#include +#include +#include + +/** + * delete_fdt_mem_rsv - delete memory reservation with given address and size + * + * @fdt: Flattened Device Tree to update + * @start: Starting address of the reservation to delete + * @size: Size of the reservation to delete + * + * Return: 0 on success, or negative errno on error. + */ +int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size) +{ + int i, ret, num_rsvs; + + if (!IS_ENABLED(CONFIG_KEXEC_FILE)) + return 0; + + num_rsvs = fdt_num_mem_rsv(fdt); + for (i = 0; i < num_rsvs; i++) { + uint64_t rsv_start, rsv_size; + + ret = fdt_get_mem_rsv(fdt, i, &rsv_start, &rsv_size); + if (ret) { + pr_err("Malformed device tree.\n"); + return -EINVAL; + } + + if (rsv_start == start && rsv_size == size) { + ret = fdt_del_mem_rsv(fdt, i); + if (ret) { + pr_err("Error deleting device tree reservation.\n"); + return -EINVAL; + } + + pr_debug("Freed reserved memory at %lu of size %lu\n", + start, size); + return 0; + } + } + + return -ENOENT; +} diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 9e93bef52968..d0234c4815da 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -407,6 +407,11 @@ static inline int kexec_crash_loaded(void) { return 0; } #define kexec_in_progress false #endif /* CONFIG_KEXEC_CORE */ +#if defined(CONFIG_OF_FLATTREE) +extern int delete_fdt_mem_rsv(void *fdt, unsigned long start, + unsigned long size); +#endif /* CONFIG_OF_FLATTREE */ + #endif /* !defined(__ASSEBMLY__) */ #endif /* LINUX_KEXEC_H */ From patchwork Fri Dec 4 19:51:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nramas X-Patchwork-Id: 337873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0628C2BB40 for ; Fri, 4 Dec 2020 19:53:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D86D22582 for ; Fri, 4 Dec 2020 19:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730871AbgLDTwo (ORCPT ); Fri, 4 Dec 2020 14:52:44 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52672 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730647AbgLDTwi (ORCPT ); Fri, 4 Dec 2020 14:52:38 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 26F0820B7187; Fri, 4 Dec 2020 11:51:57 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 26F0820B7187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111517; bh=QjzwkKap5j6BGZIXUMFZtVLppXuA87W5hY580CxO5Fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JsemOQH9A0VzQkpzu03at+NXfh706D2DoAoDdrG1/MmUhSONyN2/YTRZXVoXyQ5qW QirUmFfkFCoE9TbQUEtDcbIJysS5MV1n6YhCF9SgBjjaQSgTaEjPSgSu/8KLYVc6yr E/V1PcoQJRM/YLEXSx3DOw9eUrApETd35T5b+7Z4= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 3/8] powerpc: Move ima buffer functions to drivers/of/kexec.c Date: Fri, 4 Dec 2020 11:51:44 -0800 Message-Id: <20201204195149.611-4-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The functions do_get_kexec_buffer() and get_addr_size_cells(), defined in arch/powerpc/kexec/ima.c, retrieve the address and size of the given property from the device tree blob. These functions do not have architecture specific code, but are currently limited to powerpc. do_get_kexec_buffer() correctly handles a device tree property that is a child node of the root node, but not anything other than the immediate root child nodes. Move architecture independent functions get_ima_kexec_buffer() and get_root_addr_size_cells() to "drivers/of/kexec.c". These functions retrieve the chosen node "linux,ima-kexec-buffer" from the device tree, and return the address and size of the buffer used for carrying forward the IMA measurement log across kexec system call. Co-developed-by: Prakhar Srivastava Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian Reviewed-by: Thiago Jung Bauermann --- drivers/of/kexec.c | 70 +++++++++++++++++++++++++++++++++++++++++++ include/linux/kexec.h | 3 ++ 2 files changed, 73 insertions(+) diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index b7d59105fcb8..516b86f7113a 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -59,3 +59,73 @@ int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size) return -ENOENT; } + +/** + * get_root_addr_size_cells - Get address and size of root node + * + * @addr_cells: Return address of the root node + * @size_cells: Return size of the root node + * + * Return: 0 on success, or negative errno on error. + */ +int get_root_addr_size_cells(int *addr_cells, int *size_cells) +{ + struct device_node *root; + + if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC)) + return -EOPNOTSUPP; + + root = of_find_node_by_path("/"); + if (!root) + return -EINVAL; + + *addr_cells = of_n_addr_cells(root); + *size_cells = of_n_size_cells(root); + + of_node_put(root); + + return 0; +} + +/** + * get_ima_kexec_buffer - Get address and size of IMA kexec buffer + * + * @fdt: Flattened Device Tree + * @chosen_node: Offset of chosen node in the FDT + * @addr: Return address of the node + * @size: Return size of the node + * + * Return: 0 on success, or negative errno on error. + */ +int get_ima_kexec_buffer(void *fdt, int chosen_node, + unsigned long *addr, size_t *size) +{ + const void *prop; + int addr_cells, size_cells, prop_len; + int rc; + + if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC)) + return -EOPNOTSUPP; + + rc = get_root_addr_size_cells(&addr_cells, &size_cells); + if (rc) + return rc; + + if (fdt) + prop = fdt_getprop(fdt, chosen_node, + "linux,ima-kexec-buffer", &prop_len); + else + prop = of_get_property(of_chosen, + "linux,ima-kexec-buffer", &prop_len); + + if (!prop) + return -ENOENT; + + if (prop_len < 4 * (addr_cells + size_cells)) + return -EINVAL; + + *addr = of_read_number(prop, addr_cells); + *size = of_read_number(prop + 4 * addr_cells, size_cells); + + return 0; +} diff --git a/include/linux/kexec.h b/include/linux/kexec.h index d0234c4815da..10ff704ab670 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -408,6 +408,9 @@ static inline int kexec_crash_loaded(void) { return 0; } #endif /* CONFIG_KEXEC_CORE */ #if defined(CONFIG_OF_FLATTREE) +extern int get_root_addr_size_cells(int *addr_cells, int *size_cells); +extern int get_ima_kexec_buffer(void *fdt, int chosen_node, + unsigned long *addr, size_t *size); extern int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size); #endif /* CONFIG_OF_FLATTREE */ From patchwork Fri Dec 4 19:51:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nramas X-Patchwork-Id: 338489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F26FC1B087 for ; Fri, 4 Dec 2020 19:53:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AE6F22C9C for ; Fri, 4 Dec 2020 19:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730782AbgLDTwj (ORCPT ); Fri, 4 Dec 2020 14:52:39 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52720 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730768AbgLDTwj (ORCPT ); Fri, 4 Dec 2020 14:52:39 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id D285320B7189; Fri, 4 Dec 2020 11:51:57 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D285320B7189 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111518; bh=oX8q8wUf3czcB5Lpc7ifTPAnAev+bG+rCwc+gi4XvUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FL2BncW0XZNcxdSQJnZoOwuNT4KJGnjd5Or6yXYns8mUQyBvqJdnb5SotsTPu1pHT udw4UuRkCpBD4YjcppCYhZn2UUUiQuh2QZrYtqY1CyMsZg3TjYPRCQj0Q5L17Y2brS XANnYBlH27xZTtKu/JaTP6giUyc6dJzVN1NGP3qc= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 4/8] powerpc: Use ima kexec node functions Date: Fri, 4 Dec 2020 11:51:45 -0800 Message-Id: <20201204195149.611-5-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org do_get_kexec_buffer() and get_addr_size_cells() are called by ima_get_kexec_buffer(), ima_free_kexec_buffer, and remove_ima_buffer() to retrieve the address and size of the buffer used for carrying forward the IMA measurement log across kexec system call. These functions correctly handle a device tree property that is a child node of the root node, but not anything other than the immediate root child nodes. Use the architecture independent functions get_ima_kexec_buffer() and get_root_addr_size_cells() defined in "drivers/of/ima_kexec.c", to get the address and size of the IMA measurement log buffer from the device tree. Remove do_get_kexec_buffer() and get_addr_size_cells() since they are not used anymore. Co-developed-by: Prakhar Srivastava Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian --- arch/powerpc/kexec/ima.c | 58 +++++----------------------------------- 1 file changed, 7 insertions(+), 51 deletions(-) diff --git a/arch/powerpc/kexec/ima.c b/arch/powerpc/kexec/ima.c index a36c39db4b1a..906e8212435d 100644 --- a/arch/powerpc/kexec/ima.c +++ b/arch/powerpc/kexec/ima.c @@ -13,40 +13,6 @@ #include #include -static int get_addr_size_cells(int *addr_cells, int *size_cells) -{ - struct device_node *root; - - root = of_find_node_by_path("/"); - if (!root) - return -EINVAL; - - *addr_cells = of_n_addr_cells(root); - *size_cells = of_n_size_cells(root); - - of_node_put(root); - - return 0; -} - -static int do_get_kexec_buffer(const void *prop, int len, unsigned long *addr, - size_t *size) -{ - int ret, addr_cells, size_cells; - - ret = get_addr_size_cells(&addr_cells, &size_cells); - if (ret) - return ret; - - if (len < 4 * (addr_cells + size_cells)) - return -ENOENT; - - *addr = of_read_number(prop, addr_cells); - *size = of_read_number(prop + 4 * addr_cells, size_cells); - - return 0; -} - /** * ima_get_kexec_buffer - get IMA buffer from the previous kernel * @addr: On successful return, set to point to the buffer contents. @@ -56,16 +22,11 @@ static int do_get_kexec_buffer(const void *prop, int len, unsigned long *addr, */ int ima_get_kexec_buffer(void **addr, size_t *size) { - int ret, len; + int ret; unsigned long tmp_addr; size_t tmp_size; - const void *prop; - prop = of_get_property(of_chosen, "linux,ima-kexec-buffer", &len); - if (!prop) - return -ENOENT; - - ret = do_get_kexec_buffer(prop, len, &tmp_addr, &tmp_size); + ret = get_ima_kexec_buffer(NULL, 0, &tmp_addr, &tmp_size); if (ret) return ret; @@ -89,7 +50,7 @@ int ima_free_kexec_buffer(void) if (!prop) return -ENOENT; - ret = do_get_kexec_buffer(prop->value, prop->length, &addr, &size); + ret = get_ima_kexec_buffer(NULL, 0, &addr, &size); if (ret) return ret; @@ -98,7 +59,6 @@ int ima_free_kexec_buffer(void) return ret; return memblock_free(addr, size); - } /** @@ -112,19 +72,15 @@ int ima_free_kexec_buffer(void) */ void remove_ima_buffer(void *fdt, int chosen_node) { - int ret, len; + int ret; unsigned long addr; size_t size; - const void *prop; - prop = fdt_getprop(fdt, chosen_node, "linux,ima-kexec-buffer", &len); - if (!prop) + ret = get_ima_kexec_buffer(fdt, chosen_node, &addr, &size); + if (ret) return; - ret = do_get_kexec_buffer(prop, len, &addr, &size); fdt_delprop(fdt, chosen_node, "linux,ima-kexec-buffer"); - if (ret) - return; ret = delete_fdt_mem_rsv(fdt, addr, size); if (!ret) @@ -191,7 +147,7 @@ int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node) if (!image->arch.ima_buffer_size) return 0; - ret = get_addr_size_cells(&addr_cells, &size_cells); + ret = get_root_addr_size_cells(&addr_cells, &size_cells); if (ret) return ret; From patchwork Fri Dec 4 19:51:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nramas X-Patchwork-Id: 337871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05123C2BB40 for ; Fri, 4 Dec 2020 19:53:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCEDC22CAF for ; Fri, 4 Dec 2020 19:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730928AbgLDTxS (ORCPT ); Fri, 4 Dec 2020 14:53:18 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52954 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730743AbgLDTxS (ORCPT ); Fri, 4 Dec 2020 14:53:18 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 89B2520B718A; Fri, 4 Dec 2020 11:51:58 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 89B2520B718A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111519; bh=drG9z5++NDKCI6ahOaQyIoHZgSgy1kpa74CvAavpIa0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fMWQZUi9uhP9xJLTTq8g/qcpJ0xSr338r9tAnIeo5ziCqIPG7log8yaNeWoGQxefq XRDCwQzWLonOFG89C4QhXtQaTmoemQdIgsm7TDdUxuRE5IvWZHJmtPAbt6WsgQk4ht Wk3zIBXZejVpjGUJUYjYWGUccm9A/xpRtBQxAdYk= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 5/8] powerpc: Move remove_ima_buffer() to drivers/of/kexec.c Date: Fri, 4 Dec 2020 11:51:46 -0800 Message-Id: <20201204195149.611-6-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org remove_ima_buffer() removes the chosen node "linux,ima-kexec-buffer" from the device tree and frees the memory reserved for carrying forward the IMA measurement logs on kexec. This function does not have architecture specific code, but is currently limited to powerpc. Move remove_ima_buffer() to "drivers/of/ima_kexec.c" so that it is accessible for other architectures as well. Co-developed-by: Prakhar Srivastava Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian Reviewed-by: Thiago Jung Bauermann --- arch/powerpc/include/asm/ima.h | 8 ++------ arch/powerpc/kexec/ima.c | 26 -------------------------- drivers/of/kexec.c | 29 +++++++++++++++++++++++++++++ include/linux/kexec.h | 1 + 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/arch/powerpc/include/asm/ima.h b/arch/powerpc/include/asm/ima.h index ead488cf3981..a2fc71bc3b23 100644 --- a/arch/powerpc/include/asm/ima.h +++ b/arch/powerpc/include/asm/ima.h @@ -2,17 +2,13 @@ #ifndef _ASM_POWERPC_IMA_H #define _ASM_POWERPC_IMA_H +#include + struct kimage; int ima_get_kexec_buffer(void **addr, size_t *size); int ima_free_kexec_buffer(void); -#ifdef CONFIG_IMA -void remove_ima_buffer(void *fdt, int chosen_node); -#else -static inline void remove_ima_buffer(void *fdt, int chosen_node) {} -#endif - #ifdef CONFIG_IMA_KEXEC int arch_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr, size_t size); diff --git a/arch/powerpc/kexec/ima.c b/arch/powerpc/kexec/ima.c index 906e8212435d..68017123b07d 100644 --- a/arch/powerpc/kexec/ima.c +++ b/arch/powerpc/kexec/ima.c @@ -61,32 +61,6 @@ int ima_free_kexec_buffer(void) return memblock_free(addr, size); } -/** - * remove_ima_buffer - remove the IMA buffer property and reservation from @fdt - * - * @fdt: Flattened Device Tree to update - * @chosen_node: Offset to the chosen node in the device tree - * - * The IMA measurement buffer is of no use to a subsequent kernel, so we always - * remove it from the device tree. - */ -void remove_ima_buffer(void *fdt, int chosen_node) -{ - int ret; - unsigned long addr; - size_t size; - - ret = get_ima_kexec_buffer(fdt, chosen_node, &addr, &size); - if (ret) - return; - - fdt_delprop(fdt, chosen_node, "linux,ima-kexec-buffer"); - - ret = delete_fdt_mem_rsv(fdt, addr, size); - if (!ret) - pr_debug("Removed old IMA buffer reservation.\n"); -} - #ifdef CONFIG_IMA_KEXEC /** * arch_ima_add_kexec_buffer - do arch-specific steps to add the IMA buffer diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index 516b86f7113a..42d16dfff78d 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -129,3 +129,32 @@ int get_ima_kexec_buffer(void *fdt, int chosen_node, return 0; } + +/** + * remove_ima_buffer - remove the IMA buffer property and reservation from @fdt + * + * @fdt: Flattened Device Tree to update + * @chosen_node: Offset to the chosen node in the device tree + * + * The IMA measurement buffer is of no use to a subsequent kernel, so we always + * remove it from the device tree. + */ +void remove_ima_buffer(void *fdt, int chosen_node) +{ + int ret; + unsigned long addr; + size_t size; + + if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC)) + return; + + ret = get_ima_kexec_buffer(fdt, chosen_node, &addr, &size); + if (ret) + return; + + fdt_delprop(fdt, chosen_node, "linux,ima-kexec-buffer"); + + ret = delete_fdt_mem_rsv(fdt, addr, size); + if (!ret) + pr_debug("Removed old IMA buffer reservation.\n"); +} diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 10ff704ab670..52a0efff184d 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -411,6 +411,7 @@ static inline int kexec_crash_loaded(void) { return 0; } extern int get_root_addr_size_cells(int *addr_cells, int *size_cells); extern int get_ima_kexec_buffer(void *fdt, int chosen_node, unsigned long *addr, size_t *size); +extern void remove_ima_buffer(void *fdt, int chosen_node); extern int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size); #endif /* CONFIG_OF_FLATTREE */ From patchwork Fri Dec 4 19:51:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nramas X-Patchwork-Id: 338488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB644C1B0D8 for ; Fri, 4 Dec 2020 19:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97CE422CA1 for ; Fri, 4 Dec 2020 19:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387771AbgLDTx1 (ORCPT ); Fri, 4 Dec 2020 14:53:27 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52956 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730647AbgLDTxS (ORCPT ); Fri, 4 Dec 2020 14:53:18 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 3EB2020B718B; Fri, 4 Dec 2020 11:51:59 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3EB2020B718B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111519; bh=c9hfHV9xUhOxPKkKCPQSF8NLSo8arbAWLA6eKI8Sitc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f5rlirFjXGIEhNFVOMz2N0x0e3iCjqzeaz7YFF+NNooFvETzoWEslCHbtWMMNvY48 7SjCdlZf667+5ps92NgDwTrAfjv8xiW32ofWM4m5ZwmOVxw6A2HxYIOhR32ISkJe4r aGjw4qkUlLEx39fvr6ON190AI5qVnBQzq//YnLec= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 6/8] powerpc: Move ima_get_kexec_buffer() and ima_free_kexec_buffer() to ima Date: Fri, 4 Dec 2020 11:51:47 -0800 Message-Id: <20201204195149.611-7-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org ima_get_kexec_buffer() retrieves the address and size of the buffer used for carrying forward the IMA measurement logs on kexec from the device tree. ima_free_kexec_buffer() removes the chosen node "linux,ima-kexec-buffer" from the device tree, and frees the buffer used for carrying forward the IMA measurement logs on kexec. These functions do not have architecture specific code, but are currently limited to powerpc. Move ima_get_kexec_buffer() and ima_free_kexec_buffer() to ima_kexec.c in IMA so that they are accessible for other architectures as well. With the above change the functions in arch/powerpc/kexec/ima.c are defined only when the kernel config CONFIG_IMA_KEXEC is enabled. Update the Makefile to build arch/powerpc/kexec/ima.c only when CONFIG_IMA_KEXEC is enabled and remove "#ifdef CONFIG_IMA_KEXEC" in arch/powerpc/kexec/ima.c. Co-developed-by: Prakhar Srivastava Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian Reviewed-by: Mimi Zohar --- arch/powerpc/include/asm/ima.h | 3 -- arch/powerpc/kexec/Makefile | 7 +--- arch/powerpc/kexec/ima.c | 50 ----------------------------- security/integrity/ima/ima_kexec.c | 51 ++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 59 deletions(-) diff --git a/arch/powerpc/include/asm/ima.h b/arch/powerpc/include/asm/ima.h index a2fc71bc3b23..d8444d27f0d8 100644 --- a/arch/powerpc/include/asm/ima.h +++ b/arch/powerpc/include/asm/ima.h @@ -6,9 +6,6 @@ struct kimage; -int ima_get_kexec_buffer(void **addr, size_t *size); -int ima_free_kexec_buffer(void); - #ifdef CONFIG_IMA_KEXEC int arch_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr, size_t size); diff --git a/arch/powerpc/kexec/Makefile b/arch/powerpc/kexec/Makefile index 4aff6846c772..f54a9dbff4c8 100644 --- a/arch/powerpc/kexec/Makefile +++ b/arch/powerpc/kexec/Makefile @@ -9,12 +9,7 @@ obj-$(CONFIG_PPC32) += relocate_32.o obj-$(CONFIG_KEXEC_FILE) += file_load.o ranges.o file_load_$(BITS).o elf_$(BITS).o -ifdef CONFIG_HAVE_IMA_KEXEC -ifdef CONFIG_IMA -obj-y += ima.o -endif -endif - +obj-$(CONFIG_IMA_KEXEC) += ima.o # Disable GCOV, KCOV & sanitizers in odd or sensitive code GCOV_PROFILE_core_$(BITS).o := n diff --git a/arch/powerpc/kexec/ima.c b/arch/powerpc/kexec/ima.c index 68017123b07d..bf7084c0c4da 100644 --- a/arch/powerpc/kexec/ima.c +++ b/arch/powerpc/kexec/ima.c @@ -13,55 +13,6 @@ #include #include -/** - * ima_get_kexec_buffer - get IMA buffer from the previous kernel - * @addr: On successful return, set to point to the buffer contents. - * @size: On successful return, set to the buffer size. - * - * Return: 0 on success, negative errno on error. - */ -int ima_get_kexec_buffer(void **addr, size_t *size) -{ - int ret; - unsigned long tmp_addr; - size_t tmp_size; - - ret = get_ima_kexec_buffer(NULL, 0, &tmp_addr, &tmp_size); - if (ret) - return ret; - - *addr = __va(tmp_addr); - *size = tmp_size; - - return 0; -} - -/** - * ima_free_kexec_buffer - free memory used by the IMA buffer - */ -int ima_free_kexec_buffer(void) -{ - int ret; - unsigned long addr; - size_t size; - struct property *prop; - - prop = of_find_property(of_chosen, "linux,ima-kexec-buffer", NULL); - if (!prop) - return -ENOENT; - - ret = get_ima_kexec_buffer(NULL, 0, &addr, &size); - if (ret) - return ret; - - ret = of_remove_property(of_chosen, prop); - if (ret) - return ret; - - return memblock_free(addr, size); -} - -#ifdef CONFIG_IMA_KEXEC /** * arch_ima_add_kexec_buffer - do arch-specific steps to add the IMA buffer * @@ -154,4 +105,3 @@ int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node) return 0; } -#endif /* CONFIG_IMA_KEXEC */ diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c index 121de3e04af2..4d354593aecf 100644 --- a/security/integrity/ima/ima_kexec.c +++ b/security/integrity/ima/ima_kexec.c @@ -9,7 +9,10 @@ #include #include +#include +#include #include +#include #include "ima.h" #ifdef CONFIG_IMA_KEXEC @@ -133,6 +136,54 @@ void ima_add_kexec_buffer(struct kimage *image) } #endif /* IMA_KEXEC */ +/** + * ima_get_kexec_buffer - get IMA buffer from the previous kernel + * @addr: On successful return, set to point to the buffer contents. + * @size: On successful return, set to the buffer size. + * + * Return: 0 on success, negative errno on error. + */ +static int ima_get_kexec_buffer(void **addr, size_t *size) +{ + int ret; + unsigned long tmp_addr; + size_t tmp_size; + + ret = get_ima_kexec_buffer(NULL, 0, &tmp_addr, &tmp_size); + if (ret) + return ret; + + *addr = __va(tmp_addr); + *size = tmp_size; + + return 0; +} + +/** + * ima_free_kexec_buffer - free memory used by the IMA buffer + */ +static int ima_free_kexec_buffer(void) +{ + int ret; + unsigned long addr; + size_t size; + struct property *prop; + + prop = of_find_property(of_chosen, "linux,ima-kexec-buffer", NULL); + if (!prop) + return -ENOENT; + + ret = get_ima_kexec_buffer(NULL, 0, &addr, &size); + if (ret) + return ret; + + ret = of_remove_property(of_chosen, prop); + if (ret) + return ret; + + return memblock_free(addr, size); +} + /* * Restore the measurement list from the previous kernel. */ From patchwork Fri Dec 4 19:51:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nramas X-Patchwork-Id: 337872 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96B37C19437 for ; Fri, 4 Dec 2020 19:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D39322CE3 for ; Fri, 4 Dec 2020 19:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730943AbgLDTxS (ORCPT ); Fri, 4 Dec 2020 14:53:18 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52950 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727877AbgLDTxR (ORCPT ); Fri, 4 Dec 2020 14:53:17 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 0001720B718C; Fri, 4 Dec 2020 11:51:59 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0001720B718C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111520; bh=RYcDmiClExarWqft2RPrsbd40L4/wuzZPH77VZjBycQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s1qEpeOQTXn69iJ45FIdvBMZ2l4FJD8AfFgq9DYqKyOk5uSyHuj0Tg4FC+iTFebQH DKhJz7gaGU1/+rpDiYUr7awiNGOyYbAkK6pMdJ0HqI3vT6E5YzNhZ130Lipj+xZx3Q tYS4dIun10H4ziTrz+9I7z4hqzjqa1/rMch2g7Pc= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 7/8] powerpc: Move arch_ima_add_kexec_buffer to ima Date: Fri, 4 Dec 2020 11:51:48 -0800 Message-Id: <20201204195149.611-8-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org arch_ima_add_kexec_buffer() sets the address and size of the IMA measurement log in the architecture specific field in struct kimage. This function does not have architecture specific code, but is currently limited to powerpc. Move arch_ima_add_kexec_buffer() to security/integrity/ima/ima_kexec.c so that it is accessible for other architectures as well. Signed-off-by: Lakshmi Ramasubramanian Reviewed-by: Thiago Jung Bauermann --- arch/powerpc/include/asm/ima.h | 3 --- arch/powerpc/kexec/ima.c | 21 --------------------- security/integrity/ima/ima_kexec.c | 22 ++++++++++++++++++++++ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/arch/powerpc/include/asm/ima.h b/arch/powerpc/include/asm/ima.h index d8444d27f0d8..d6ab5d944dcd 100644 --- a/arch/powerpc/include/asm/ima.h +++ b/arch/powerpc/include/asm/ima.h @@ -7,9 +7,6 @@ struct kimage; #ifdef CONFIG_IMA_KEXEC -int arch_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr, - size_t size); - int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node); #else static inline int setup_ima_buffer(const struct kimage *image, void *fdt, diff --git a/arch/powerpc/kexec/ima.c b/arch/powerpc/kexec/ima.c index bf7084c0c4da..b2793be353a9 100644 --- a/arch/powerpc/kexec/ima.c +++ b/arch/powerpc/kexec/ima.c @@ -13,27 +13,6 @@ #include #include -/** - * arch_ima_add_kexec_buffer - do arch-specific steps to add the IMA buffer - * - * @image: kimage struct to set IMA buffer data - * @load_addr: Starting address where IMA buffer is loaded at - * @size: Number of bytes in the IMA buffer - * - * Architectures should use this function to pass on the IMA buffer - * information to the next kernel. - * - * Return: 0 on success, negative errno on error. - */ -int arch_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr, - size_t size) -{ - image->arch.ima_buffer_addr = load_addr; - image->arch.ima_buffer_size = size; - - return 0; -} - static int write_number(void *p, u64 value, int cells) { if (cells == 1) { diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c index 4d354593aecf..5263dafe8f4d 100644 --- a/security/integrity/ima/ima_kexec.c +++ b/security/integrity/ima/ima_kexec.c @@ -74,6 +74,28 @@ static int ima_dump_measurement_list(unsigned long *buffer_size, void **buffer, return ret; } +/** + * arch_ima_add_kexec_buffer - do arch-specific steps to add the IMA buffer + * + * @image: kimage struct to set IMA buffer data + * @load_addr: Starting address where IMA buffer is loaded at + * @size: Number of bytes in the IMA buffer + * + * Architectures should use this function to pass on the IMA buffer + * information to the next kernel. + * + * Return: 0 on success, negative errno on error. + */ +static int arch_ima_add_kexec_buffer(struct kimage *image, + unsigned long load_addr, + size_t size) +{ + image->arch.ima_buffer_addr = load_addr; + image->arch.ima_buffer_size = size; + + return 0; +} + /* * Called during kexec_file_load so that IMA can add a segment to the kexec * image for the measurement list for the next kernel. From patchwork Fri Dec 4 19:51:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nramas X-Patchwork-Id: 338487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23F42C2BBCA for ; Fri, 4 Dec 2020 19:53:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE32B22C9C for ; Fri, 4 Dec 2020 19:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730895AbgLDTxS (ORCPT ); Fri, 4 Dec 2020 14:53:18 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52951 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728143AbgLDTxR (ORCPT ); Fri, 4 Dec 2020 14:53:17 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id B549420B7194; Fri, 4 Dec 2020 11:52:00 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B549420B7194 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111521; bh=MJ8cApvzkCo+bglSdhsIgMyxGTncBwj3/wC3rLK+6TM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dtlg6+rPwCFvBMX4nQQlpvm4IFAigipISMvjueCbe4ks28F0/8XZOngMxTqfkJsc1 VSehnFsPnUpW19jIiZxB8fTKbfHwxx0g2xdHku4nCnCLUXNN+OF6M14O3sL1C6g4hn 7tTxV3s6mTgRW3V2tc/231f+dxd92J+90gNPV02Y= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 8/8] arm64: Add IMA log information in kimage used for kexec Date: Fri, 4 Dec 2020 11:51:49 -0800 Message-Id: <20201204195149.611-9-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Address and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec. Any existing "linux,ima-kexec-buffer" property in the device tree needs to be removed and its corresponding memory reservation in the currently running kernel needs to be freed. The address and size of the current kernel's IMA measurement log need to be added to the device tree's IMA kexec buffer node and memory for the buffer needs to be reserved for the log to be carried over to the next kernel on the kexec call. Add address and size fields to "struct kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer. Remove any existing "linux,ima-kexec-buffer" property in the device tree and free the corresponding memory reservation in the currently running kernel. Add "linux,ima-kexec-buffer" property to the device tree and reserve the memory for storing the IMA log that needs to be passed from the current kernel to the next one. Update CONFIG_KEXEC_FILE to select CONFIG_HAVE_IMA_KEXEC to indicate that the IMA measurement log information is present in the device tree for ARM64. Co-developed-by: Prakhar Srivastava Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian Reviewed-by: Thiago Jung Bauermann --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/ima.h | 22 ++++++++++++++ arch/arm64/include/asm/kexec.h | 5 ++++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/ima.c | 41 ++++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 8 +++++ 6 files changed, 78 insertions(+) create mode 100644 arch/arm64/include/asm/ima.h create mode 100644 arch/arm64/kernel/ima.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1515f6f153a0..bcca4a467eda 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1094,6 +1094,7 @@ config KEXEC config KEXEC_FILE bool "kexec file based system call" select KEXEC_CORE + select HAVE_IMA_KEXEC help This is new version of kexec system call. This system call is file based and takes file descriptors as system call argument diff --git a/arch/arm64/include/asm/ima.h b/arch/arm64/include/asm/ima.h new file mode 100644 index 000000000000..354adc8b444c --- /dev/null +++ b/arch/arm64/include/asm/ima.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019 Microsoft Corporation + * + * Author: Prakhar Srivastava + * + */ +#ifndef _ASM_ARCH_IMA_H +#define _ASM_ARCH_IMA_H + +struct kimage; + +#ifdef CONFIG_IMA_KEXEC +extern int setup_ima_buffer(struct kimage *image, void *dtb, int off); +#else +static inline int setup_ima_buffer(struct kimage *image, void *dtb, int off) +{ + return 0; +} +#endif /* CONFIG_IMA_KEXEC */ + +#endif /* _ASM_ARCH_IMA_H */ diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index d24b527e8c00..2bd19ccb6c43 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -100,6 +100,11 @@ struct kimage_arch { void *elf_headers; unsigned long elf_headers_mem; unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC + phys_addr_t ima_buffer_addr; + size_t ima_buffer_size; +#endif }; extern const struct kexec_file_ops kexec_image_ops; diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index bbaf0bc4ad60..da83f1b3367e 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -60,6 +60,7 @@ obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o obj-$(CONFIG_ARM64_MTE) += mte.o +obj-$(CONFIG_IMA_KEXEC) += ima.o obj-y += vdso/ probes/ obj-$(CONFIG_COMPAT_VDSO) += vdso32/ diff --git a/arch/arm64/kernel/ima.c b/arch/arm64/kernel/ima.c new file mode 100644 index 000000000000..d65bdbe1adf6 --- /dev/null +++ b/arch/arm64/kernel/ima.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2016 IBM Corporation + * + * Authors: + * Lakshmi Ramasubramanian + */ + +#include +#include +#include +#include + +/** + * setup_ima_buffer - add IMA buffer information to the fdt + * + * @image: kexec image being loaded. + * @dtb: Flattened device tree for the next kernel. + * @off: Offset to the chosen node. + * + * Return: 0 on success, or negative errno on error. + */ +int setup_ima_buffer(struct kimage *image, void *dtb, int off) +{ + int ret = 0; + + /* add ima-kexec-buffer */ + if (image->arch.ima_buffer_size > 0) { + ret = fdt_appendprop_addrrange(dtb, 0, off, + "linux,ima-kexec-buffer", + image->arch.ima_buffer_addr, + image->arch.ima_buffer_size); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + + ret = fdt_add_mem_rsv(dtb, image->arch.ima_buffer_addr, + image->arch.ima_buffer_size); + } + + return ret; +} diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 03210f644790..ca7ae1cf3c1d 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -21,7 +21,9 @@ #include #include #include +#include #include +#include /* relevant device tree properties */ #define FDT_PROP_KEXEC_ELFHDR "linux,elfcorehdr" @@ -62,6 +64,8 @@ static int setup_dtb(struct kimage *image, off = ret; + remove_ima_buffer(dtb, ret); + ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR); if (ret && ret != -FDT_ERR_NOTFOUND) goto out; @@ -136,6 +140,10 @@ static int setup_dtb(struct kimage *image, FDT_PROP_KASLR_SEED); } + ret = setup_ima_buffer(image, dtb, off); + if (ret) + goto out; + /* add rng-seed */ if (rng_is_initialized()) { void *rng_seed;