forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
powerpc: Refactor kexec functions to move arch independent code to IMA
The functions ima_get_kexec_buffer(), ima_free_kexec_buffer(), remove_ima_buffer(), and delete_fdt_mem_rsv() that handle carrying forward the IMA measurement logs on kexec for powerpc do not have architecture specific code, but they are currently defined for powerpc only. Move these functions to IMA subsystem so that it can be used for other architectures as well. A later patch in this series will use these functions for carrying forward the IMA measurement log for ARM64. Rename remove_ima_buffer() to ima_remove_kexec_buffer(). Define FDT_PROP_IMA_KEXEC_BUFFER for the chosen node, namely "linux,ima-kexec-buffer", that is added to the DTB to hold the address and the size of the memory reserved to carry the IMA measurement log. Co-developed-by: Prakhar Srivastava <prsriva@linux.microsoft.com> Signed-off-by: Prakhar Srivastava <prsriva@linux.microsoft.com> Signed-off-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
- Loading branch information
1 parent
f75aef3
commit 2d9181b
Showing
12 changed files
with
214 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* | ||
* Copyright (C) 2020 Microsoft Corporation | ||
* | ||
* Author: Lakshmi Ramasubramanian (nramas@linux.microsoft.com) | ||
* | ||
* ima_fdt.c | ||
* Implements functions to handle IMA buffer in device tree | ||
*/ | ||
|
||
#include <linux/libfdt.h> | ||
#include <linux/kexec.h> | ||
#include <linux/ima.h> | ||
#include "ima.h" | ||
|
||
/** | ||
* do_get_kexec_buffer - Get address and size of IMA kexec buffer | ||
* | ||
* @prop: IMA kexec buffer node in the device tree | ||
* @addr: Return address of the node | ||
* @size: Return size of the node | ||
*/ | ||
int do_get_kexec_buffer(const void *prop, int len, unsigned long *addr, | ||
size_t *size) | ||
{ | ||
int addr_cells, 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); | ||
|
||
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_remove_kexec_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 ima_remove_kexec_buffer(void *fdt, int chosen_node) | ||
{ | ||
int ret, len; | ||
unsigned long addr; | ||
size_t size; | ||
const void *prop; | ||
|
||
prop = fdt_getprop(fdt, chosen_node, FDT_PROP_IMA_KEXEC_BUFFER, &len); | ||
if (!prop) { | ||
pr_err("Unable to find the ima kexec buffer node\n"); | ||
return; | ||
} | ||
|
||
ret = do_get_kexec_buffer(prop, len, &addr, &size); | ||
fdt_delprop(fdt, chosen_node, FDT_PROP_IMA_KEXEC_BUFFER); | ||
if (ret) { | ||
pr_err("Unable to delete the ima kexec buffer node\n"); | ||
return; | ||
} | ||
|
||
ret = delete_fdt_mem_rsv(fdt, addr, size); | ||
if (!ret) | ||
pr_err("Removed old IMA buffer reservation.\n"); | ||
} |
Oops, something went wrong.