[PATCH v5 4/8] ima: kexec: define functions to copy IMA log at soft boot
Mimi Zohar
zohar at linux.ibm.com
Wed Feb 21 14:39:34 PST 2024
Additional comments ...
> diff --git a/security/integrity/ima/ima_kexec.c
> b/security/integrity/ima/ima_kexec.c
> index ccb072617c2d..1d4d6c122d82 100644
> --- a/security/integrity/ima/ima_kexec.c
> +++ b/security/integrity/ima/ima_kexec.c
> @@ -12,10 +12,14 @@
> #include <linux/kexec.h>
> #include <linux/of.h>
> #include <linux/ima.h>
> +#include <linux/reboot.h>
> +#include <asm/page.h>
> #include "ima.h"
>
> #ifdef CONFIG_IMA_KEXEC
> static struct seq_file ima_kexec_file;
> +static void *ima_kexec_buffer;
> +static bool ima_kexec_update_registered;
>
> static void ima_reset_kexec_file(struct seq_file *sf)
> {
> @@ -184,6 +188,48 @@ void ima_add_kexec_buffer(struct kimage *image)
> kexec_dprintk("kexec measurement buffer for the loaded kernel at
> 0x%lx.\n",
> kbuf.mem);
> }
> +
> +/*
> + * Called during kexec execute so that IMA can update the measurement list.
> + */
> +static int ima_update_kexec_buffer(struct notifier_block *self,
> + unsigned long action, void *data)
> +{
> + return NOTIFY_OK;
> +}
> +
> +struct notifier_block update_buffer_nb = {
This should be defined as static. update_buffer_nb should be prefixed with
'ima_'.
> + .notifier_call = ima_update_kexec_buffer,
> +};
> +
> +/*
> + * Create a mapping for the source pages that contain the IMA buffer
> + * so we can update it later.
> + */
> +void ima_kexec_post_load(struct kimage *image)
> +{
In ima_alloc_kexec_file_buf(), the buffer is only re-allocated if the size
changes. Here there doesn't seem to be way of detecting a size change. At
least, add a comment here indicating that kexec 'load' may be called multiple
times.
Mimi
> + if (ima_kexec_buffer) {
> + kimage_unmap_segment(ima_kexec_buffer);
> + ima_kexec_buffer = NULL;
> + }
> +
> + if (!image->ima_buffer_addr)
> + return;
> +
> + ima_kexec_buffer = kimage_map_segment(image,
> + image->ima_buffer_addr,
> + image->ima_buffer_size);
> + if (!ima_kexec_buffer) {
> + pr_err("%s: Could not map measurements buffer.\n", __func__);
> + return;
> + }
> +
> + if (!ima_kexec_update_registered) {
> + register_reboot_notifier(&update_buffer_nb);
> + ima_kexec_update_registered = true;
> + }
> +}
> +
> #endif /* IMA_KEXEC */
>
> /*
More information about the kexec
mailing list