linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: steven chen <chenste@linux.microsoft.com>,
	stefanb@linux.ibm.com, roberto.sassu@huaweicloud.com,
	roberto.sassu@huawei.com, eric.snowberg@oracle.com,
	ebiederm@xmission.com, paul@paul-moore.com, code@tyhicks.com,
	bauermann@kolabnow.com, linux-integrity@vger.kernel.org,
	kexec@lists.infradead.org, linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: madvenka@linux.microsoft.com, nramas@linux.microsoft.com,
	James.Bottomley@HansenPartnership.com
Subject: Re: [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf
Date: Fri, 07 Feb 2025 14:10:32 -0500	[thread overview]
Message-ID: <1a7e9cf84715386b7ac3dc2103fd38ba180dd216.camel@linux.ibm.com> (raw)
In-Reply-To: <20250203232033.64123-2-chenste@linux.microsoft.com>

On Mon, 2025-02-03 at 15:20 -0800, steven chen wrote:
> Carrying the IMA measurement list across kexec requires allocating a
> buffer and copying the measurement records.  Separate allocating the
> buffer and copying the measurement records into separate functions in
> order to allocate the buffer at kexec 'load' and copy the measurements
> at kexec 'execute'.
> 
> This patch includes the following changes:
>  - Refactor ima_dump_measurement_list() to move the memory allocation
>    to a separate function ima_alloc_kexec_file_buf() which allocates
>    buffer of size 'kexec_segment_size' at kexec 'load'.
>  - Make the local variable ima_kexec_file in ima_dump_measurement_list()
>    a local static to the file, so that it can be accessed from 
>    ima_alloc_kexec_file_buf(). Compare actual memory required to ensure 
>    there is enough memory for the entire measurement record.
>  - Copy as many measurement events as possible.
>  - Make necessary changes to the function ima_add_kexec_buffer() to call
>    the above two functions.
>  - Compared the memory size allocated with memory size of the entire 
>    measurement record. If there is not enough memory, it will copy as many
>    IMA measurement records as possible, and this situation will result
>    in a failure of remote attestation.
> 
> Author: Tushar Sugandhi <tusharsu@linux.microsoft.com>
> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
> Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
> Signed-off-by: Tushar Sugandhi <tusharsu@linux.microsoft.com>
> Signed-off-by: steven chen <chenste@linux.microsoft.com>
> ---
>  security/integrity/ima/ima.h       |   1 +
>  security/integrity/ima/ima_kexec.c | 105 +++++++++++++++++++++--------
>  security/integrity/ima/ima_queue.c |   4 +-
>  3 files changed, 80 insertions(+), 30 deletions(-)
> 
> diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
> index 3c323ca213d4..447a6eb07c2d 100644
> --- a/security/integrity/ima/ima.h
> +++ b/security/integrity/ima/ima.h
> @@ -274,6 +274,7 @@ bool ima_template_has_modsig(const struct ima_template_desc
> *ima_template);
>  int ima_restore_measurement_entry(struct ima_template_entry *entry);
>  int ima_restore_measurement_list(loff_t bufsize, void *buf);
>  int ima_measurements_show(struct seq_file *m, void *v);
> +int ima_get_binary_runtime_entry_size(struct ima_template_entry *entry);
>  unsigned long ima_get_binary_runtime_size(void);
>  int ima_init_template(void);
>  void ima_init_template_list(void);
> diff --git a/security/integrity/ima/ima_kexec.c
> b/security/integrity/ima/ima_kexec.c
> index 52e00332defe..b60a902460e2 100644
> --- a/security/integrity/ima/ima_kexec.c
> +++ b/security/integrity/ima/ima_kexec.c
> @@ -15,62 +15,99 @@
>  #include "ima.h"
>  
>  #ifdef CONFIG_IMA_KEXEC
> +static struct seq_file ima_kexec_file;
> +
> +static void ima_reset_kexec_file(struct seq_file *sf)
> +{
> +	sf->buf = NULL;
> +	sf->size = 0;
> +	sf->read_pos = 0;
> +	sf->count = 0;
> +}
> +
> +static void ima_free_kexec_file_buf(struct seq_file *sf)
> +{
> +	vfree(sf->buf);
> +	ima_reset_kexec_file(sf);
> +}
> +
> +static int ima_alloc_kexec_file_buf(size_t segment_size)
> +{
> +	/*
> +	 * 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;
> +	}

Nice cleanup from v5.  The line doesn't doesn't need to be split.  Both the
parenthesis and the brackets can be removed.

In the future, before posting patches, please use scripts/checkpatch.pl.

CHECK: Unnecessary parentheses around 'ima_kexec_file.size == segment_size'
#82: FILE: security/integrity/ima/ima_kexec.c:41:
+	if (ima_kexec_file.buf &&
+		(ima_kexec_file.size == segment_size)) {

CHECK: Alignment should match open parenthesis
#83: FILE: security/integrity/ima/ima_kexec.c:42:
+	if (ima_kexec_file.buf &&
+		(ima_kexec_file.size == segment_size)) {

Or simply join the two lines.

thanks,

Mimi

> +
> +	ima_free_kexec_file_buf(&ima_kexec_file);
> +
> +	/* segment size can't change between kexec load and execute */
> +	ima_kexec_file.buf = vmalloc(segment_size);
> +	if (!ima_kexec_file.buf)
> +		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
> */
> +
> +	return 0;
> +}
> 


  parent reply	other threads:[~2025-02-07 19:10 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-03 23:20 [PATCH v7 0/7] ima: kexec: measure events between kexec load and excute steven chen
2025-02-03 23:20 ` [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf steven chen
2025-02-06 16:49   ` Mimi Zohar
2025-02-07 19:20     ` steven chen
2025-02-07 19:36     ` Mimi Zohar
2025-02-07 19:10   ` Mimi Zohar [this message]
2025-02-07 19:23     ` steven chen
2025-02-03 23:20 ` [PATCH v7 2/7] kexec: define functions to map and unmap segments steven chen
2025-02-07 19:15   ` Mimi Zohar
2025-02-10 17:06     ` steven chen
2025-02-12 13:03       ` Mimi Zohar
2025-02-18  4:24         ` Baoquan He
2025-02-03 23:20 ` [PATCH v7 3/7] ima: kexec: skip IMA segment validation after kexec soft reboot steven chen
2025-02-04 19:39   ` Stefan Berger
2025-02-04 20:28     ` steven chen
2025-02-04 22:51       ` Stefan Berger
2025-02-07 19:24     ` steven chen
2025-02-03 23:20 ` [PATCH v7 4/7] ima: kexec: define functions to copy IMA log at soft boot steven chen
2025-02-03 23:20 ` steven chen
2025-02-03 23:20 ` [PATCH v7 5/7] ima: kexec: move IMA log copy from kexec load to execute steven chen
2025-02-03 23:20 ` [PATCH v7 6/7] ima: make the kexec extra memory configurable steven chen
2025-02-07 16:04   ` Mimi Zohar
2025-02-03 23:20 ` [PATCH v7 7/7] ima: measure kexec load and exec events as critical data steven chen
2025-02-07 15:16   ` Mimi Zohar
2025-02-07 17:06     ` Mimi Zohar
2025-02-07 17:48       ` Stefan Berger
2025-02-07 19:26         ` steven chen
  -- strict thread matches above, loose matches on Subject: below --
2025-02-18 17:20 [PATCH v7 0/7] ima: kexec: measure events between kexec load and execute steven chen
2025-02-18 17:20 ` [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf steven chen
2025-02-03 18:45 [PATCH v7 0/7] ima: kexec: measure events between kexec load and excute steven chen
2025-02-03 18:45 ` [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf steven chen
2025-02-03 18:42 [PATCH v7 0/7] ima: kexec: measure events between kexec load and excute steven chen
2025-02-03 18:42 ` [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf steven chen

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=1a7e9cf84715386b7ac3dc2103fd38ba180dd216.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=bauermann@kolabnow.com \
    --cc=chenste@linux.microsoft.com \
    --cc=code@tyhicks.com \
    --cc=ebiederm@xmission.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=madvenka@linux.microsoft.com \
    --cc=nramas@linux.microsoft.com \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=roberto.sassu@huaweicloud.com \
    --cc=stefanb@linux.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).