linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: steven chen <chenste@linux.microsoft.com>
To: Stefan Berger <stefanb@linux.ibm.com>,
	zohar@linux.ibm.com, roberto.sassu@huaweicloud.com,
	petr@tesarici.cz, eric.snowberg@oracle.com, paul@paul-moore.com,
	code@tyhicks.com, nramas@linux.microsoft.com,
	James.Bottomley@HansenPartnership.com,
	madvenka@linux.microsoft.com
Cc: linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 6/7] ima: make the kexec extra memory configurable
Date: Tue, 28 Jan 2025 10:34:02 -0800	[thread overview]
Message-ID: <eeeed6d2-7790-4f2a-8484-23b8d8e9f540@linux.microsoft.com> (raw)
In-Reply-To: <d127dad9-e392-49ef-af52-a7bcdaebe317@linux.ibm.com>

On 1/28/2025 7:18 AM, Stefan Berger wrote:
>
>
> On 1/24/25 5:55 PM, steven chen wrote:
>> The extra memory allocated for carrying the IMA measurement list across
>> kexec is hard-coded as half a PAGE.  Make it configurable.
>>
>> Define a Kconfig option, IMA_KEXEC_EXTRA_MEMORY_KB, to configure the
>> extra memory (in kb) to be allocated for IMA measurements added during
>> kexec soft reboot.  Ensure the default value of the option is set such
>> that extra half a page of memory for additional measurements is 
>> allocated
>> for the additional measurements.
>>
>> Update ima_add_kexec_buffer() function to allocate memory based on the
>> Kconfig option value, rather than the currently hard-coded one.
>>
>> From: Tushar Sugandhi <tusharsu@linux.microsoft.com>
>> Author: Tushar Sugandhi <tusharsu@linux.microsoft.com>
>> Suggested-by: Stefan Berger <stefanb@linux.ibm.com>
>> Signed-off-by: Tushar Sugandhi <tusharsu@linux.microsoft.com>
>> Signed-off-by: steven chen <chenste@linux.microsoft.com>
>> ---
>>   security/integrity/ima/Kconfig     | 10 ++++++++++
>>   security/integrity/ima/ima_kexec.c | 16 ++++++++++------
>>   2 files changed, 20 insertions(+), 6 deletions(-)
>>
>> diff --git a/security/integrity/ima/Kconfig 
>> b/security/integrity/ima/Kconfig
>> index 475c32615006..7dd2ed8b2cdc 100644
>> --- a/security/integrity/ima/Kconfig
>> +++ b/security/integrity/ima/Kconfig
>> @@ -321,4 +321,14 @@ config IMA_DISABLE_HTABLE
>>       help
>>          This option disables htable to allow measurement of 
>> duplicate records.
>>   +config IMA_KEXEC_EXTRA_MEMORY_KB
>> +    int
>
> int "Extra memory for IMA measurements added during kexec soft reboot"
>
> Without the description I wasn't able to modify the value.
>
>> +    depends on IMA_KEXEC
>> +    default 0
>> +    help
>> +      IMA_KEXEC_EXTRA_MEMORY_KB determines the extra memory to be
>> +      allocated (in kb) for IMA measurements added during kexec soft 
>> reboot.
>> +      If set to the default value, an extra half a page of memory 
>> for those
>> +      additional measurements will be allocated.
>> +
>>   endif
>> diff --git a/security/integrity/ima/ima_kexec.c 
>> b/security/integrity/ima/ima_kexec.c
>> index d5f004cfeaec..c9c916f69ca7 100644
>> --- a/security/integrity/ima/ima_kexec.c
>> +++ b/security/integrity/ima/ima_kexec.c
>> @@ -128,22 +128,26 @@ void ima_add_kexec_buffer(struct kimage *image)
>>                     .buf_min = 0, .buf_max = ULONG_MAX,
>>                     .top_down = true };
>>       unsigned long binary_runtime_size;
>> -
>> +    unsigned long extra_size;
>>       /* use more understandable variable names than defined in kbuf */
>>       void *kexec_buffer = NULL;
>>       size_t kexec_buffer_size = 0;
>>       int ret;
>>         /*
>> -     * Reserve an extra half page of memory for additional measurements
>> -     * added during the kexec load.
>> +     * Reserve extra memory for measurements added during kexec.
>>        */
>> -    binary_runtime_size = ima_get_binary_runtime_size();
>> +    if (CONFIG_IMA_KEXEC_EXTRA_MEMORY_KB <= 0)
>> +        extra_size = PAGE_SIZE / 2;
>> +    else
>> +        extra_size = CONFIG_IMA_KEXEC_EXTRA_MEMORY_KB * 1024;
>> +    binary_runtime_size = ima_get_binary_runtime_size() + extra_size;
>> +
>>       if (binary_runtime_size >= ULONG_MAX - PAGE_SIZE)
>>           kexec_segment_size = ULONG_MAX;
>>       else
>> -        kexec_segment_size = ALIGN(ima_get_binary_runtime_size() +
>> -                       PAGE_SIZE / 2, PAGE_SIZE);
>> +        kexec_segment_size = ALIGN(binary_runtime_size, PAGE_SIZE);
>> +
>>       if ((kexec_segment_size == ULONG_MAX) ||
>>           ((kexec_segment_size >> PAGE_SHIFT) > totalram_pages() / 2)) {
>>           pr_err("Binary measurement list too large.\n");
>
> With the changes to Kconfig:
>
>
> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
>
Thanks, will update in the next release


  reply	other threads:[~2025-01-28 18:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-24 22:55 [PATCH v6 0/7] ima: kexec: measure events between kexec load and excute steven chen
2025-01-24 22:55 ` [PATCH v6 1/7] ima: define and call ima_alloc_kexec_file_buf steven chen
2025-01-24 22:55 ` [PATCH v6 2/7] kexec: define functions to map and unmap segments steven chen
2025-01-24 22:55 ` [PATCH v6 3/7] ima: kexec: skip IMA segment validation after kexec soft reboot steven chen
2025-01-28 15:23   ` Stefan Berger
2025-01-29 17:58     ` steven chen
2025-01-24 22:55 ` [PATCH v6 4/7] ima: kexec: define functions to copy IMA log at soft boot steven chen
2025-01-24 22:55 ` [PATCH v6 5/7] ima: kexec: move IMA log copy from kexec load to execute steven chen
2025-01-24 22:55 ` [PATCH v6 6/7] ima: make the kexec extra memory configurable steven chen
2025-01-28 15:18   ` Stefan Berger
2025-01-28 18:34     ` steven chen [this message]
2025-01-24 22:55 ` [PATCH 7/7] ima: measure kexec load and exec events as critical data steven chen
2025-01-28 15:28   ` Stefan Berger
2025-01-28 17:29     ` Stefan Berger
2025-01-28 18:35       ` steven chen
  -- strict thread matches above, loose matches on Subject: below --
2025-01-24 22:42 [PATCH v6 0/7] *** SUBJECT HERE *** steven chen
2025-01-24 22:42 ` [PATCH v6 6/7] ima: make the kexec extra memory configurable 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=eeeed6d2-7790-4f2a-8484-23b8d8e9f540@linux.microsoft.com \
    --to=chenste@linux.microsoft.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=code@tyhicks.com \
    --cc=eric.snowberg@oracle.com \
    --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=petr@tesarici.cz \
    --cc=roberto.sassu@huaweicloud.com \
    --cc=stefanb@linux.ibm.com \
    --cc=zohar@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).