mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: "Jérémy Jean" <Jeremy.Jean@oss.cyber.gouv.fr>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Baoquan He" <baoquan.he@linux.dev>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Pasha Tatashin" <pasha.tatashin@soleen.com>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Roberto Sassu" <roberto.sassu@huawei.com>,
	"Dmitry Kasatkin" <dmitry.kasatkin@gmail.com>
Cc: Eric Snowberg <eric.snowberg@oracle.com>,
	linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 2/3] ima: keep kexec dump state tied to installed image
Date: Fri, 13 Nov 2026 15:50:18 -0500	[thread overview]
Message-ID: <0225c3dbe0f73652994374660500973512203182.camel@linux.ibm.com> (raw)
In-Reply-To: <20261112125246.2715174-4-Jeremy.Jean@oss.cyber.gouv.fr>

On Thu, 2026-11-12 at 12:52 +0000, Jérémy Jean wrote:
[...]

> diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c
> index 0d845693a1f7..3aa8b1096f81 100644
> --- a/security/integrity/ima/ima_kexec.c
> +++ b/security/integrity/ima/ima_kexec.c
> @@ -35,7 +35,8 @@ static void ima_free_kexec_file_buf(struct seq_file *sf)
>  	sf->count = 0;
>  }
>  
> -void ima_measure_kexec_event(const char *event_name)
> +static void ima_measure_kexec_event_size(const char *event_name,
> +					 size_t segment_size)
>  {
>  	char ima_kexec_event[IMA_KEXEC_EVENT_LEN];
>  	size_t buf_size = 0;
> @@ -48,35 +49,26 @@ void ima_measure_kexec_event(const char *event_name)
>  	n = scnprintf(ima_kexec_event, IMA_KEXEC_EVENT_LEN,
>  		      "kexec_segment_size=%lu;ima_binary_runtime_size=%lu;"
>  		      "ima_runtime_measurements_count=%ld;",
> -		      kexec_segment_size, buf_size, len);
> +		      segment_size, buf_size, len);
>  
>  	ima_measure_critical_data("ima_kexec", event_name, ima_kexec_event, n, false, NULL, 0);
>  }
>  
> -static int ima_alloc_kexec_file_buf(size_t segment_size)
> +void ima_measure_kexec_event(const char *event_name)
>  {
> -	/*
> -	 * kexec 'load' may be called multiple times.
> -	 * Free and realloc the buffer only if the segment_size is
> -	 * changed from the previous kexec 'load' call.
> -	 */
> -	if (ima_kexec_file.buf && ima_kexec_file.size == segment_size)
> -		goto out;
> +	ima_measure_kexec_event_size(event_name, kexec_segment_size);
> +}
>  
> -	ima_free_kexec_file_buf(&ima_kexec_file);
> +static int ima_alloc_kexec_file_buf(struct kimage *image, size_t segment_size)
> +{
> +	if (ima_kexec_file.buf && ima_kexec_file.size == segment_size)
> +		return 0;

Please don't drop the comment. The crux of the problem is that a kexec
load may fail, so the installed image's state shouldn't change until
the new image is installed.

To keep this patch as small as possible, could the event-size change be
a separate patch, applied after this one? That would make the overflow
fix easier to review and backport.

Suggested comment:

 * kexec 'load' may be called multiple times, and a load may fail.
 * ima_kexec_file.size is the segment size of the installed image and
 * is only set in ima_kexec_post_load(). Reuse the installed buffer if
 * the segment_size is unchanged, otherwise stage a new one on the image.

Mimi

>  
>  	/* segment size can't change between kexec load and execute */
> -	ima_kexec_file.buf = vmalloc(segment_size);
> -	if (!ima_kexec_file.buf)
> +	image->ima_buffer = vmalloc(segment_size);
> +	if (!image->ima_buffer)
>  		return -ENOMEM;
>  
> -	ima_kexec_file.size = segment_size;
> -
> -out:
> -	ima_kexec_file.read_pos = 0;
> -	ima_kexec_file.count = sizeof(struct ima_kexec_hdr);	/* reserved space */
> -	ima_measure_kexec_event("kexec_load");
> -
>  	return 0;
>  }
>  

  reply	other threads:[~2026-11-13 20:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 12:52 [PATCH v2 0/3] " Jérémy Jean
2026-11-12 12:52 ` [PATCH v2 1/3] kexec_file: update IMA after machine post-load Jérémy Jean
2026-11-12 12:52 ` [PATCH v2 2/3] ima: keep kexec dump state tied to installed image Jérémy Jean
2026-11-13 20:50   ` Mimi Zohar [this message]
2026-11-12 12:52 ` [PATCH v2 3/3] ima: clear kexec state when replacing file image Jérémy Jean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0225c3dbe0f73652994374660500973512203182.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=Jeremy.Jean@oss.cyber.gouv.fr \
    --cc=akpm@linux-foundation.org \
    --cc=baoquan.he@linux.dev \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=rppt@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®