ima: kexec: measure events between kexec load and excute
Subsystems (7)
v7 cover ima: kexec: measure events between kexec load and excute
The current kernel behavior is IMA measurements snapshot is taken at kexec 'load' and not at kexec 'execute'. IMA log is then carried over to the new kernel after kexec 'execute'.
New events can be measured during/after the IMA log snapshot at kexec 'load' and before the system boots to the new kernel. In this scenario, the TPM PCRs are extended with these events, but they are not carried over to the new kernel after kexec soft reboot since the snapshot is already taken. This results in mismatch between TPM PCR quotes and the actual IMA measurements list after kexec soft reboot, which in turn results in remote attestation failure.
To solve this problem -
- allocate the necessary buffer at kexec 'load' time,
- populate the buffer with the IMA measurements at kexec 'execute' time,
- and measure two new IMA events 'kexec_load' and 'kexec_execute' as critical data to help detect missing events after kexec soft reboot.
The solution details include:
- refactoring the existing code to allocate a buffer to hold IMA measurements at kexec 'load', and dump the measurements at kexec 'execute'
- IMA functionality to suspend and resume measurements as needed during buffer copy at kexec 'execute',
- kexec functionality for mapping the segments from the current kernel to the subsequent one,
- necessary changes to the kexec_file_load syscall, enabling it to call the ima functions,
- registering a reboot notifier which gets called during kexec 'execute',
- introducing a new Kconfig option to configure the extra memory to be allocated for passing IMA log from the current Kernel to the next,
- introducing two new events to be measured by IMA during kexec, to help diagnose if the IMA log was copied fully or partially, from the current Kernel to the next,
- excluding IMA segment while calculating and storing digest in function kexec_calculate_store_digests(), since IMA segment can be modified after the digest is computed during kexec 'load'. This will ensure that the segment is not added to the 'purgatory_sha_regions', and thus not verified by verify_sha256_digest().
The changes proposed in this series ensure the integrity of the IMA measurements is preserved across kexec soft reboots, thus significantly improving the security of the kernel post kexec soft reboots.
There were previous attempts to fix this issue [1], [2], [3]. But they were not merged into the mainline kernel.
We took inspiration from the past work [1] and [2] while working on this patch series.
V4 of this series is available here[6] for reference.
V5 of this series is available here[7] for reference.
V6 of this series is available here[8] for reference.
References:
-----------
[1] [PATHC v2 5/9] ima: on soft reboot, save the measurement list
https://lore.kernel.org/lkml/[email protected]/
[2] PATCH v2 4/6] kexec_file: Add mechanism to update kexec segments.
https://lkml.org/lkml/2016/8/16/577
[3] [PATCH 1/6] kexec_file: Add buffer hand-over support
https://lore.kernel.org/linuxppc-dev/[email protected]/T/
[4] [PATCH v2 0/7] ima: kexec: measure events between kexec load and execute
https://lore.kernel.org/all/[email protected]/
[5] [PATCH v3 0/7] ima: kexec: measure events between kexec load and execute
https://lore.kernel.org/all/[email protected]/
[6] [PATCH v4 0/7] ima: kexec: measure events between kexec load and execute
https://lore.kernel.org/all/[email protected]/
[7] [PATCH v5 0/8] ima: kexec: measure events between kexec load and execute
https://lore.kernel.org/all/[email protected]/
[8] [PATCH v6 0/7] ima: kexec: measure events between kexec load and execute
https://lore.kernel.org/all/[email protected]/
Change Log v7:
- Incorporated feedback from the community (Stefan Berger, Tyler Hicks) on v6 of this series[8].
- Verified all the patches are bisect-safe by booting into each patch and verifying multiple kexec 'load' operations work, and also verifying kexec soft reboot works, and IMA log gets carried over for each patch.
Change Log v6:
- Incorporated feedback from the community (Stefan Berger, Mimi Zohar, and Petr Tesařík) on v5 of this series[7].
- Rebased the patch series to mainline 6.12.0.
- Verified all the patches are bisect-safe by booting into each patch and verifying multiple kexec 'load' operations work, and also verifying kexec soft reboot works, and IMA log gets carried over for each patch.
- 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.
- [PATCH V5 6/8] was removed. Per petr comment on [PATCH V5 6/8], during the handover, other CPUs are taken offline (look for migrate_to_reboot_cpu() in kernel/kexec_core.c) and even the reboot CPU will be sufficiently shut down as not to be able to add any more measurements.
Change Log v5:
- Incorporated feedback from the community (Stefan Berger and Mimi Zohar) on v4 of this series[6].
- Rebased the patch series to mainline 6.8.0-rc1.
- Verified all the patches are bisect-safe by booting into each patch and verifying multiple kexec 'load' operations work, and also verifying kexec soft reboot works, and IMA log gets carried over for each patch.
- Divided the patch #4 in the v4 of the series[6] into two separate patches. One to setup the infrastructure/stub functions to prepare the IMA log copy from Kexec 'load' to 'execute', and another one to actually copy the log.
- Updated the config description for IMA_KEXEC_EXTRA_MEMORY_KB to remove unnecessary references related to backwards compatibility.
- Fixed a typo in log message/removed an extra line etc.
- Updated patch descriptions as necessary.
Change Log v4:
- Incorporated feedback from the community (Stefan Berger and Mimi Zohar) on v3 of this series[5].
- Rearranged patches so that they remain bisect-safe i.e. the system can go through kexec soft reboot, and IMA log is carried over after each patch.
- Verified all the patches are bisect-safe by booting into each patch and verifying kexec soft reboot works, and IMA log gets carried over.
- Suspend-resume measurements is now a separate patch (patch #5) and all the relevant code is part of the same patch.
- Excluding IMA segment from segment digest verification is now a separate patch. (patch #3).
- Registering reboot notifier and functions related to move ima log copy from kexec load to execute are now part of the same patch (patch #4) to protect bisect-safeness of the series.
- Updated the title of patch #6 as per the feedback.
- The default value of kexec extra memory for IMA measurements is set to half the PAGESIZE to maintain backwards compatibility.
- Added number of IMA measurement records as part of 'kexec_load' and 'kexec_execute' IMA critical data events.
- Updated patch descriptions as necessary.
Change Log v3:
- Incorporated feedback from the community (Stefan Berger and Mimi Zohar) on v2 of this series[4].
- Renamed functions and removed extraneous checks and code comments.
- Updated patch descriptions and titles as necessary.
- Updated kexec_calculate_store_digests() in patch 2/7 to exclude ima segment from calculating and storing digest.
- Updated patch 3/7 to use kmalloc_array instead of kmalloc and freed memory early to avoid potential memory leak.
- Updated patch 6/7 to change Kconfig option IMA_KEXEC_EXTRA_PAGES to IMA_KEXEC_EXTRA_MEMORY_KB to allocate the memory in kb rather than in number of pages.
- Optimized patch 7/7 not to free and alloc memory if the buffer size hasn't changed during multiple kexec 'load' operations.
- Fixed a bug in patch 7/7 to measure multiple 'kexec_load' events even if buffer size hasn't changed.
- Verified the patches are bisect-safe by compiling and booting into each patch individually.
Change Log v2:
- Incorporated feedback from the community on v1 series.
- Refactored the existing ima_dump_measurement_list to move buffer allocation functionality to ima_alloc_kexec_buf() function.
- Introduced a new Kconfig option to configure the memory.
- Updated the logic to copy the IMA log only in case of kexec soft reboot, and not on kexec crash.
- Updated the logic to copy as many IMA events as possible in case of memory constraint, rather than just bailing out.
- Introduced two new events to be measured by IMA during kexec, to help diagnose if the IMA log was copied fully or partially from the current Kernel to the next.
- Refactored patches to ensure no warnings during individual patch compilation.
- Used virt_to_page instead of phys_to_page.
- Updated patch descriptions as necessary.
steven chen (7):
ima: define and call ima_alloc_kexec_file_buf
kexec: define functions to map and unmap segments
ima: kexec: skip IMA segment validation after kexec soft reboot
ima: kexec: define functions to copy IMA log at soft boot
ima: kexec: move IMA log copy from kexec load to execute
ima: make the kexec extra memory configurable
ima: measure kexec load and exec events as critical data
include/linux/ima.h | 3 + include/linux/kexec.h | 10 ++ kernel/kexec_core.c | 54 ++++++++ kernel/kexec_file.c | 31 +++++ security/integrity/ima/Kconfig | 10 ++ security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_kexec.c | 208 ++++++++++++++++++++++++----- security/integrity/ima/ima_queue.c | 4 +- 8 files changed, 284 insertions(+), 37 deletions(-)
Signature · 1 line
2.25.1
PATCH v7 1/7 ima: define and call ima_alloc_kexec_file_buf
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 <[email protected]>
--- 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(-)
security/integrity/ima/ima.h +1 -0
@@ -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 );
security/integrity/ima/ima_kexec.c +77 -28
165 lines not on this page · raw message
security/integrity/ima/ima_queue.c +2 -2
@@ -71,7 +71,7 @@ static struct ima_queue_entry *ima_lookup_digest_entry(u8 *digest_value,* binary_runtime_measurement list entry, which contains a * couple of variable length fields (e.g template name and data). */ -static int get_binary_runtime_size (struct ima_template_entry *entry) +int ima_get_binary_runtime_entry_size (struct ima_template_entry *entry) {int size =0 ;
@@ -115,7 +115,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry,if (binary_runtime_size !=ULONG_MAX ) {int size; - size =get_binary_runtime_size (entry); + size =ima_get_binary_runtime_entry_size (entry); binary_runtime_size = (binary_runtime_size <ULONG_MAX - size) ? binary_runtime_size + size :ULONG_MAX ; }
Signature · 1 line
2.25.1
Mimi Zohar
maintainerRe: [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf
Thanks, Steven, for picking up and working on Tushar's patch set.
I normally finish reviewing the patch set, before commenting. In this case, there's a generic comment that relates to all of the patches. It's also a way of letting you know that I've started reviewing the patch set. The remaining comments will come after I finish reviewing the patch set.
Quoted 22 lines · steven chen
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:
- Refactorima_dump_measurement_list()to move the memory allocation to a separate functionima_alloc_kexec_file_buf()which allocates buffer of size 'kexec_segment_size' at kexec 'load'.
- Make the local variableima_kexec_fileinima_dump_measurement_list()a local static to the file, so that it can be accessed fromima_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 functionima_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.
Quoted 1 line
Author: Tushar Sugandhi <[email protected]>
I understand you want to credit Tushar for the patch, but the mechanism is described in Documentation/process/submitting-patches.rst. Refer to the paragraph on "Co- developed-by". There is no tag named "Author".
Quoted 2 lines
Reviewed-by Stefan Berger <[email protected]>Suggested-by Mimi Zohar <[email protected]>
"Suggested-by" goes before the Signed-off-by tag(s). "Reviewed-by" tag goes after your and/or Tushar's Signed-off-tag.
Quoted 2 lines
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>
Before the "Co-developed-by" tag was defined, it was implied simply by this ordering of the "Signed-off-by" tags.
For those patches you didn't modify, simply import Tushar's patch with him as the author and add your Signed-off-by tag after his.
thanks,
Mimi
Re: [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf
Quoted 45 lines · Mimi Zohar
Thanks, Steven, for picking up and working on Tushar's patch set.
I normally finish reviewing the patch set, before commenting. In this case, there's a generic comment that relates to all of the patches. It's also a way of letting you know that I've started reviewing the patch set. The remaining comments will come after I finish reviewing the patch set.
Quoted 22 lines · steven chen
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:
- Refactorima_dump_measurement_list()to move the memory allocation to a separate functionima_alloc_kexec_file_buf()which allocates buffer of size 'kexec_segment_size' at kexec 'load'.
- Make the local variableima_kexec_fileinima_dump_measurement_list()a local static to the file, so that it can be accessed fromima_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 functionima_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.Quoted 1 line
Author: Tushar Sugandhi <[email protected]>
I understand you want to credit Tushar for the patch, but the mechanism is described in
Documentation/process/submitting-patches.rst. Refer to the paragraph on "Co- developed-by". There is no tag named "Author".Quoted 2 lines
Reviewed-by Stefan Berger <[email protected]>Suggested-by Mimi Zohar <[email protected]>"Suggested-by" goes before the Signed-off-by tag(s). "Reviewed-by" tag goes after your and/or Tushar's Signed-off-tag.
Quoted 2 lines
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>Before the "Co-developed-by" tag was defined, it was implied simply by this ordering of the "Signed-off-by" tags.
Quoted 6 lines
For those patches you didn't modify, simply import Tushar's patch with him as the author and add your Signed-off-by tag after his.
thanks,
Mimi
Thanks Mimi, will update it in next release.
Mimi Zohar
maintainerRe: [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf
In reply to Mimi ZoharQuoted 48 lines · Mimi Zohar
Thanks, Steven, for picking up and working on Tushar's patch set.
I normally finish reviewing the patch set, before commenting. In this case, there's
a generic comment that relates to all of the patches. It's also a way of letting you
know that I've started reviewing the patch set. The remaining comments will come after I finish reviewing the patch set.Quoted 22 lines · steven chen
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:
- Refactorima_dump_measurement_list()to move the memory allocation to a separate functionima_alloc_kexec_file_buf()which allocates buffer of size 'kexec_segment_size' at kexec 'load'.
- Make the local variableima_kexec_fileinima_dump_measurement_list()a local static to the file, so that it can be accessed fromima_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 functionima_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.Quoted 1 line
Author: Tushar Sugandhi <[email protected]>
I understand you want to credit Tushar for the patch, but the mechanism is described
in Documentation/process/submitting-patches.rst. Refer to the paragraph on "Co- developed-by". There is no tag named "Author".Quoted 2 lines
Reviewed-by Stefan Berger <[email protected]>Suggested-by Mimi Zohar <[email protected]>"Suggested-by" goes before the Signed-off-by tag(s). "Reviewed-by" tag goes after your and/or Tushar's Signed-off-tag.
Quoted 2 lines
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>
Quoted 6 lines
Before the "Co-developed-by" tag was defined, it was implied simply by this ordering
of the "Signed-off-by" tags.For those patches you didn't modify, simply import Tushar's patch with him as the author and add your Signed-off-by tag after his.
Thanks, Steven. The patch set at this point is bi-sect safe. The are just a few formatting cleanups based on "scripts/checkpatch --strict --codespell". Before re- posting, please re-base on the next-integrity branch and address the missing "kexec_execute" critical data.
Eric is the kexec maintainer so we need his Ack.
thanks,
Mimi
Mimi Zohar
maintainerRe: [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf
In reply to steven chenQuoted 72 lines · steven chen
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:
- Refactorima_dump_measurement_list()to move the memory allocation to a separate functionima_alloc_kexec_file_buf()which allocates buffer of size 'kexec_segment_size' at kexec 'load'.
- Make the local variableima_kexec_fileinima_dump_measurement_list()a local static to the file, so that it can be accessed fromima_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 functionima_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 <[email protected]>
Reviewed-by Stefan Berger <[email protected]>Suggested-by Mimi Zohar <[email protected]>Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>---
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(-)security/integrity/ima/ima.h +1
-0@@ -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);security/integrity/ima/ima_kexec.c +0
-0@@ -15,62 +15,99 @@ #include "ima.h"
#ifdefCONFIG_IMA_KEXECsecurity/integrity/ima/ima_kexec.c +17
-0+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)
security/integrity/ima/ima_kexec.c line 44
Quoted 10 lines
security/integrity/ima/ima_kexec.c +10
-0+{ +/* +* 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
Quoted 18 lines
security/integrity/ima/ima_kexec.c +13
-0+ +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 */
security/integrity/ima/ima_kexec.c +3
-0+ +return 0 ; +}
Re: [PATCH v7 1/7] ima: define and call ima_alloc_kexec_file_buf
Quoted 114 lines · Mimi Zohar
Quoted 72 lines · steven chen
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:
- Refactorima_dump_measurement_list()to move the memory allocation to a separate functionima_alloc_kexec_file_buf()which allocates buffer of size 'kexec_segment_size' at kexec 'load'.
- Make the local variableima_kexec_fileinima_dump_measurement_list()a local static to the file, so that it can be accessed fromima_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 functionima_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 <[email protected]>
Reviewed-by Stefan Berger <[email protected]>Suggested-by Mimi Zohar <[email protected]>Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>--- 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(-)security/integrity/ima/ima.h +1
-0@@ -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);security/integrity/ima/ima_kexec.c +17
-0@@ -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)security/integrity/ima/ima_kexec.c line 44
Quoted 10 lines
security/integrity/ima/ima_kexec.c +10
-0+{ +/* +* 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:security/integrity/ima/ima_kexec.c +2
-0+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:security/integrity/ima/ima_kexec.c +2
-0+if (ima_kexec_file.buf && + (ima_kexec_file.size == segment_size)) {Or simply join the two lines.
thanks,
Mimi
Quoted 10 lines
security/integrity/ima/ima_kexec.c +10
-0+ +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; +
Quoted 8 lines
security/integrity/ima/ima_kexec.c line 69
Quoted 8 lines
security/integrity/ima/ima_kexec.c +6
-0+out: + ima_kexec_file.read_pos =0 ; + ima_kexec_file.count =sizeof (struct ima_kexec_hdr );/* reserved space */ + +return 0 ; +}
Thanks, Mimi, will update in the next release
PATCH v7 2/7 kexec: define functions to map and unmap segments
In reply to steven chenCurrently, the mechanism to map and unmap segments to the kimage structure is not available to the subsystems outside of kexec. This functionality is needed when IMA is allocating the memory segments during kexec 'load' operation. Implement functions to map and unmap segments to kimage.
Implement kimage_map_segment() to enable mapping of IMA buffer source pages to the kimage structure post kexec 'load'. This function, accepting a kimage pointer, an address, and a size, will gather the source pages within the specified address range, create an array of page pointers, and map these to a contiguous virtual address range. The function returns the start of this range if successful, or NULL if unsuccessful.
Implement kimage_unmap_segment() for unmapping segments using vunmap().
From: Tushar Sugandhi <[email protected]>
Author: Tushar Sugandhi <[email protected]>
--- include/linux/kexec.h | 7 ++++++ kernel/kexec_core.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
include/linux/kexec.h +7 -0
@@ -467,6 +467,9 @@ extern bool kexec_file_dbg_print; #define kexec_dprintk(fmt, arg...) \ do { if (kexec_file_dbg_print) pr_info(fmt, ##arg); } while (0) +extern void *kimage_map_segment (struct kimage *image, +unsigned long addr,unsigned long size); +extern void kimage_unmap_segment (void *buffer);#else /* !CONFIG_KEXEC_CORE */ struct pt_regs ;struct task_struct ;
@@ -474,6 +477,10 @@ static inline void __crash_kexec(struct pt_regs *regs) { }static inline void crash_kexec (struct pt_regs *regs) { }static inline int kexec_should_crash (struct task_struct *p) {return 0 ; }static inline int kexec_crash_loaded (void ) {return 0 ; } +static inline void *kimage_map_segment (struct kimage *image, +unsigned long addr,unsigned long size) +{return NULL ; } +static inline void kimage_unmap_segment (void *buffer) { }#define kexec_in_progress false#endif /* CONFIG_KEXEC_CORE */
kernel/kexec_core.c +54 -0
60 lines not on this page · raw message
Signature · 1 line
2.25.1
Mimi Zohar
maintainerRe: [PATCH v7 2/7] kexec: define functions to map and unmap segments
Hi Steven,
Quoted 14 lines · steven chen
Currently, the mechanism to map and unmap segments to the kimage structure is not available to the subsystems outside of kexec. This functionality is needed when IMA is allocating the memory segments during kexec 'load' operation. Implement functions to map and unmap segments to kimage.
Implement
kimage_map_segment()to enable mapping of IMA buffer source pages to the kimage structure post kexec 'load'. This function, accepting a kimage pointer, an address, and a size, will gather the source pages within the specified address range, create an array of page pointers, and map these to a contiguous virtual address range. The function returns the start of this range if successful, or NULL if unsuccessful.
Quoted 7 lines
Implement
kimage_unmap_segment()for unmapping segments usingvunmap().From: Tushar Sugandhi <[email protected]>
Author: Tushar Sugandhi <[email protected]>Reviewed-by Stefan Berger <[email protected]>Reviewed-by Mimi Zohar <[email protected]>
I don't recall previously adding my "Reviewed-by" tag.
Eric, I'd appreciate your reviewing this and the subsequent patch "[PATCH v7 3/7]
ima: kexec: skip IMA segment validation after kexec soft reboot" in particular.
Quoted 15 lines
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>---
include/linux/kexec.h | 7 ++++++
kernel/kexec_core.c | 54 +++++++++++++++++++++++++++++++++++++++++++2 files changed, 61 insertions(+)include/linux/kexec.h +0
-0@@ -467,6 +467,9 @@ extern bool kexec_file_dbg_print; #define kexec_dprintk(fmt, arg...) \ do { if (kexec_file_dbg_print) pr_info(fmt, ##arg); } while (0)
include/linux/kexec.h extern bool kexec_file_dbg_print; · line 471
Quoted 2 lines
include/linux/kexec.h +2
-0+extern void *kimage_map_segment (struct kimage *image, +unsigned long addr,unsigned long size);
scripts/Checkpatch.pl complains about the parenthesis alignment here and elsewhere.
Mimi
Quoted 15 lines
+extern void
kimage_unmap_segment(void *buffer);
#else /* !CONFIG_KEXEC_CORE */
structpt_regs;
structtask_struct;include/linux/kexec.h +4
-0@@ -474,6 +477,10 @@ static inline void __crash_kexec(struct pt_regs *regs) { } static inline void crash_kexec(struct pt_regs *regs) { } static inline int kexec_should_crash(struct task_struct *p) { return 0; } static inline int kexec_crash_loaded(void) { return 0; } +static inline void *kimage_map_segment (struct kimage *image, +unsigned long addr,unsigned long size) +{return NULL ; } +static inline void kimage_unmap_segment (void *buffer) { } #define kexec_in_progress false #endif /* CONFIG_KEXEC_CORE */
Re: [PATCH v7 2/7] kexec: define functions to map and unmap segments
Quoted 20 lines · Mimi Zohar
Hi Steven,
Quoted 17 lines · steven chen
Currently, the mechanism to map and unmap segments to the kimage structure is not available to the subsystems outside of kexec. This functionality is needed when IMA is allocating the memory segments during kexec 'load' operation. Implement functions to map and unmap segments to kimage.
Implement
kimage_map_segment()to enable mapping of IMA buffer source pages to the kimage structure post kexec 'load'. This function, accepting a kimage pointer, an address, and a size, will gather the source pages within the specified address range, create an array of page pointers, and map these to a contiguous virtual address range. The function returns the start of this range if successful, or NULL if unsuccessful.Implement
kimage_unmap_segment()for unmapping segments usingvunmap().
Quoted 8 lines
Quoted 4 lines
From: Tushar Sugandhi <[email protected]>
Author: Tushar Sugandhi <[email protected]>Reviewed-by Stefan Berger <[email protected]>Reviewed-by Mimi Zohar <[email protected]>I don't recall previously adding my "Reviewed-by" tag.
Eric, I'd appreciate your reviewing this and the subsequent patch "[PATCH v7 3/7]
ima: kexec: skip IMA segment validation after kexec soft reboot" in particular.
Hi Eric, Could you help to review this patch as Mimi mentioned? Thanks!
Quoted 22 lines
Quoted 13 lines
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>--- include/linux/kexec.h | 7 ++++++ kernel/kexec_core.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)include/linux/kexec.h +0
-0include/linux/kexec.h extern bool kexec_file_dbg_print; · line 471
Quoted 5 lines
include/linux/kexec.h +2
-0@@ -467,6 +467,9 @@ extern bool kexec_file_dbg_print; #define kexec_dprintk(fmt, arg...) \ do { if (kexec_file_dbg_print) pr_info(fmt, ##arg); } while (0) +extern void *kimage_map_segment (struct kimage *image, +unsigned long addr,unsigned long size);
scripts/Checkpatch.plcomplains about the parenthesis alignment here and elsewhere.Mimi
Quoted 15 lines
Quoted 5 lines
include/linux/kexec.h +1
-0+extern void kimage_unmap_segment (void *buffer); #else /* !CONFIG_KEXEC_CORE */ struct pt_regs; struct task_struct;include/linux/kexec.h static inline void __crash_kexec(struct pt_regs *regs) { } · line 486
Quoted 10 lines
include/linux/kexec.h +4
-0@@ -474,6 +477,10 @@ static inline void __crash_kexec(struct pt_regs *regs) { } static inline void crash_kexec(struct pt_regs *regs) { } static inline int kexec_should_crash(struct task_struct *p) { return 0; } static inline int kexec_crash_loaded(void) { return 0; } +static inline void *kimage_map_segment (struct kimage *image, +unsigned long addr,unsigned long size) +{return NULL ; } +static inline void kimage_unmap_segment (void *buffer) { } #define kexec_in_progress false #endif /* CONFIG_KEXEC_CORE */
Thanks, Mimi, I will update in next version
Mimi Zohar
maintainerRe: [PATCH v7 2/7] kexec: define functions to map and unmap segments
Quoted 25 lines · steven chen
Quoted 24 lines · Mimi Zohar
Hi Steven,
Quoted 21 lines · steven chen
Currently, the mechanism to map and unmap segments to the kimage structure is not available to the subsystems outside of kexec. This functionality is needed when IMA is allocating the memory segments during kexec 'load' operation. Implement functions to map and unmap segments to kimage.
Implement
kimage_map_segment()to enable mapping of IMA buffer source pages to the kimage structure post kexec 'load'. This function, accepting a kimage pointer, an address, and a size, will gather the source pages within the specified address range, create an array of page pointers, and map these to a contiguous virtual address range. The function returns the start of this range if successful, or NULL if unsuccessful.Implement
kimage_unmap_segment()for unmapping segments usingvunmap().From: Tushar Sugandhi <[email protected]>
Author: Tushar Sugandhi <[email protected]>Reviewed-by Stefan Berger <[email protected]>Reviewed-by Mimi Zohar <[email protected]>
Quoted 7 lines
Quoted 4 lines
I don't recall previously adding my "Reviewed-by" tag.
Eric, I'd appreciate your reviewing this and the subsequent patch "[PATCH v7 3/7]
ima: kexec: skip IMA segment validation after kexec soft reboot" in particular.Hi Eric, Could you help to review this patch as Mimi mentioned? Thanks!
Quoted 2 lines
Quoted 2 lines
Signed-off-by Tushar Sugandhi <[email protected]>
Steven, since these patches impact kdump, before re-posting the patch set, please include the following tags before your Signed-off-by tag on the kexec patches.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Signed-off-by steven chen <[email protected]>
thanks,
Mimi
Re: [PATCH v7 2/7] kexec: define functions to map and unmap segments
Quoted 28 lines · Mimi Zohar
Quoted 27 lines · steven chen
Quoted 26 lines · Mimi Zohar
Hi Steven,
Quoted 14 lines · steven chen
Currently, the mechanism to map and unmap segments to the kimage structure is not available to the subsystems outside of kexec. This functionality is needed when IMA is allocating the memory segments during kexec 'load' operation. Implement functions to map and unmap segments to kimage.
Implement
kimage_map_segment()to enable mapping of IMA buffer source pages to the kimage structure post kexec 'load'. This function, accepting a kimage pointer, an address, and a size, will gather the source pages within the specified address range, create an array of page pointers, and map these to a contiguous virtual address range. The function returns the start of this range if successful, or NULL if unsuccessful.Quoted 7 lines
Implement
kimage_unmap_segment()for unmapping segments usingvunmap().From: Tushar Sugandhi <[email protected]>
Author: Tushar Sugandhi <[email protected]>Reviewed-by Stefan Berger <[email protected]>Reviewed-by Mimi Zohar <[email protected]>I don't recall previously adding my "Reviewed-by" tag.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Eric, I'd appreciate your reviewing this and the subsequent patch "[PATCH v7 3/7]
ima: kexec: skip IMA segment validation after kexec soft reboot" in particular.Hi Eric, Could you help to review this patch as Mimi mentioned? Thanks!
Quoted 2 lines
Quoted 2 lines
Signed-off-by Tushar Sugandhi <[email protected]>Steven, since these patches impact kdump, before re-posting the patch set, please include the following tags before your Signed-off-by tag on the kexec patches.
Thanks, Mimi.
Yes, Steven, please add me in CC when reposting. Thanks in advance.
I will check this version to see if there's impact on kexec/kdump from my side.
And by the way, kdump should not need IMA, it's better be disabled by default. I will have a look and try disabling it in kdump kernel, while really appreciate it if any IMA expert can do it.
Thanks
Baoquan
PATCH v7 3/7 ima: kexec: skip IMA segment validation after kexec soft reboot
In reply to steven chenkexec_calculate_store_digests() calculates and stores the digest of the segment at kexec_file_load syscall where the IMA segment is also allocated. With this series, the IMA segment will be updated with the measurement log at kexec excute stage when soft reboot is initiated. Therefore, it may fail digest verification in verify_sha256_digest() after kexec soft reboot into the new kernel. Therefore, the digest calculation/verification of the IMA segment needs to be skipped.
Skip IMA segment from calculating and storing digest in function kexec_calculate_store_digests() so that it is not added to the 'purgatory_sha_regions'.
Since verify_sha256_digest() only verifies 'purgatory_sha_regions', no change is needed in verify_sha256_digest() in this context.
With this change, the IMA segment is not included in the digest calculation, storage, and verification.
Author: Tushar Sugandhi <[email protected]>
--- include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 23 +++++++++++++++++++++++ security/integrity/ima/ima_kexec.c | 3 +++ 3 files changed, 29 insertions(+)
include/linux/kexec.h +3 -0
@@ -362,6 +362,9 @@ struct kimage {phys_addr_t ima_buffer_addr;size_t ima_buffer_size; + +unsigned long ima_segment_index; +bool is_ima_segment_index_set;#endif /* Core ELF header buffer */
kernel/kexec_file.c +23 -0
@@ -38,6 +38,22 @@ void set_kexec_sig_enforced(void) }#endif +#ifdef CONFIG_IMA_KEXEC +static bool check_ima_segment_index (struct kimage *image,int i) +{ +if (image->is_ima_segment_index_set && + i == image->ima_segment_index) +return true; +else +return false; +} +#else +static bool check_ima_segment_index (struct kimage *image,int i) +{ +return false; +} +#endif +static int kexec_calculate_store_digests (struct kimage *image);/* Maximum size in bytes for kernel/initrd files. */
@@ -764,6 +780,13 @@ static int kexec_calculate_store_digests(struct kimage *image)if (ksegment->kbuf == pi->purgatory_buf)continue ; +/* +* Skip the segment if ima_segment_index is set and matches +* the current index +*/ +if (check_ima_segment_index (image, i)) +continue ; + ret =crypto_shash_update (desc, ksegment->kbuf, ksegment->bufsz);if (ret)
security/integrity/ima/ima_kexec.c +3 -0
@@ -162,6 +162,7 @@ void ima_add_kexec_buffer(struct kimage *image) kbuf.buffer = kexec_buffer; kbuf.bufsz = kexec_buffer_size; kbuf.memsz = kexec_segment_size; + image->is_ima_segment_index_set = false; ret =kexec_add_buffer (&kbuf);if (ret) {pr_err ("Error passing over kexec measurement buffer.\n" );
@@ -172,6 +173,8 @@ void ima_add_kexec_buffer(struct kimage *image) image->ima_buffer_addr = kbuf.mem; image->ima_buffer_size = kexec_segment_size; image->ima_buffer = kexec_buffer; + image->ima_segment_index = image->nr_segments -1 ; + image->is_ima_segment_index_set = true;/* * kexec owns kexec_buffer after kexec_add_buffer() is called
Signature · 1 line
2.25.1
Re: [PATCH v7 3/7] ima: kexec: skip IMA segment validation after kexec soft reboot
Quoted 4 lines · steven chen
kexec_calculate_store_digests()calculates and stores the digest of the segment atkexec_file_loadsyscall where the IMA segment is also allocated. With this series, the IMA segment will be updated with the measurement log at kexec excute stage when soft reboot is initiated.
s/excute/execute
Quoted 5 lines
Therefore, it may fail digest verification in
verify_sha256_digest()after kexec soft reboot into the new kernel. Therefore, the digest calculation/verification of the IMA segment needs to be skipped.Skip IMA segment from calculating and storing digest in function
Skip the calculation and storing of the digest of the IMA segment in kexec_calculate_store_digests() so that ...
Quoted 36 lines
kexec_calculate_store_digests()so that it is not added to the 'purgatory_sha_regions'.Since
verify_sha256_digest()only verifies 'purgatory_sha_regions', no change is needed inverify_sha256_digest()in this context.With this change, the IMA segment is not included in the digest calculation, storage, and verification.
Author: Tushar Sugandhi <[email protected]>
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>--->
include/linux/kexec.h| 3 +++kernel/kexec_file.c | 23 +++++++++++++++++++++++ security/integrity/ima/ima_kexec.c | 3 +++ 3 files changed, 29 insertions(+)include/linux/kexec.h +3
-0@@ -362,6 +362,9 @@ struct kimage {phys_addr_t ima_buffer_addr;size_t ima_buffer_size; + +unsigned long ima_segment_index; +bool is_ima_segment_index_set;#endif /* Core ELF header buffer */ kernel/kexec_file.c +0
-0
kernel/kexec_file.c void set_kexec_sig_enforced(void) · line 45
Quoted 8 lines
kernel/kexec_file.c +5
-0@@ -38,6 +38,22 @@ void set_kexec_sig_enforced(void) }#endif +#ifdef CONFIG_IMA_KEXEC +static bool check_ima_segment_index (struct kimage *image,int i) +{ +if (image->is_ima_segment_index_set && + i == image->ima_segment_index)
The 'i =' should be indented under 'image->'.
With these nits fixed:
Quoted 49 lines
kernel/kexec_file.c +18
-0+return true; + else + return false; +} +#else +static bool check_ima_segment_index (struct kimage *image,int i) +{ +return false; +} +#endif +static int kexec_calculate_store_digests (struct kimage *image);/* Maximum size in bytes for kernel/initrd files. */ @@ -764,6 +780,13 @@ static int kexec_calculate_store_digests(struct kimage *image)if (ksegment->kbuf == pi->purgatory_buf)continue ; +/* +* Skip the segment if ima_segment_index is set and matches +* the current index +*/ +if (check_ima_segment_index (image, i)) +continue ; + ret =crypto_shash_update (desc, ksegment->kbuf, ksegment->bufsz);if (ret)security/integrity/ima/ima_kexec.c +3
-0@@ -162,6 +162,7 @@ void ima_add_kexec_buffer(struct kimage *image) kbuf.buffer = kexec_buffer; kbuf.bufsz = kexec_buffer_size; kbuf.memsz = kexec_segment_size; + image->is_ima_segment_index_set = false; ret =kexec_add_buffer (&kbuf);if (ret) {pr_err ("Error passing over kexec measurement buffer.\n" );@@ -172,6 +173,8 @@ void ima_add_kexec_buffer(struct kimage *image) image->ima_buffer_addr = kbuf.mem; image->ima_buffer_size = kexec_segment_size; image->ima_buffer = kexec_buffer; + image->ima_segment_index = image->nr_segments -1 ; + image->is_ima_segment_index_set = true;/* * kexec owns kexec_buffer after kexec_add_buffer() is called
Re: [PATCH v7 3/7] ima: kexec: skip IMA segment validation after kexec soft reboot
Quoted 104 lines · Stefan Berger
Quoted 4 lines · steven chen
kexec_calculate_store_digests()calculates and stores the digest of the segment atkexec_file_loadsyscall where the IMA segment is also allocated. With this series, the IMA segment will be updated with the measurement log at kexec excute stage when soft reboot is initiated.s/excute/execute
Quoted 5 lines
Therefore, it may fail digest verification in
verify_sha256_digest()after kexec soft reboot into the new kernel. Therefore, the digest calculation/verification of the IMA segment needs to be skipped.Skip IMA segment from calculating and storing digest in function
Skip the calculation and storing of the digest of the IMA segment in
kexec_calculate_store_digests()so that ...Quoted 37 lines
kexec_calculate_store_digests()so that it is not added to the 'purgatory_sha_regions'.Since
verify_sha256_digest()only verifies 'purgatory_sha_regions', no change is needed inverify_sha256_digest()in this context.With this change, the IMA segment is not included in the digest calculation, storage, and verification.
Author: Tushar Sugandhi <[email protected]>
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>---> include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 23 +++++++++++++++++++++++
security/integrity/ima/ima_kexec.c| 3 +++3 files changed, 29 insertions(+)include/linux/kexec.h +3
-0@@ -362,6 +362,9 @@ struct kimage { phys_addr_t ima_buffer_addr; size_t ima_buffer_size; + + unsigned long ima_segment_index; + bool is_ima_segment_index_set; #endif /* Core ELF header buffer */kernel/kexec_file.c +0
-0@@ -38,6 +38,22 @@ void set_kexec_sig_enforced(void) } #endif+#ifdef
CONFIG_IMA_KEXECkernel/kexec_file.c void set_kexec_sig_enforced(void) · line 45
Quoted 4 lines
kernel/kexec_file.c +4
-0+static bool check_ima_segment_index (struct kimage *image,int i) +{ + if (image->is_ima_segment_index_set && + i == image->ima_segment_index)The 'i =' should be indented under 'image->'.
With these nits fixed:
Reviewed-by Stefan Berger <[email protected]>Quoted 39 lines
+ return true;
+ else
+ return false;kernel/kexec_file.c +8
-0+} +#else +static bool check_ima_segment_index (struct kimage *image,int i) +{ + return false; +} +#endif +static int
kexec_calculate_store_digests(struct kimage *image); /* Maximum size in bytes for kernel/initrd files. */kernel/kexec_file.c +0
-0@@ -764,6 +780,13 @@ static int kexec_calculate_store_digests(struct kimage *image) if (ksegment->kbuf == pi->purgatory_buf) continue;+ /*
+ * Skip the segment ifima_segment_indexis set and matches + * the current index
+ */
+ if (check_ima_segment_index(image, i))
+ continue;
+
ret =crypto_shash_update(desc, ksegment->kbuf, ksegment->bufsz);
if (ret)security/integrity/ima/ima_kexec.c +1
-0@@ -162,6 +162,7 @@ void ima_add_kexec_buffer(struct kimage *image) kbuf.buffer = kexec_buffer; kbuf.bufsz = kexec_buffer_size; kbuf.memsz = kexec_segment_size; + image->is_ima_segment_index_set = false; ret = kexec_add_buffer(&kbuf); if (ret) { pr_err("Error passing over kexec measurement buffer.\n");
Quoted 8 lines
security/integrity/ima/ima_kexec.c void ima_add_kexec_buffer(struct kimage *image) · line 179
Quoted 8 lines
security/integrity/ima/ima_kexec.c +2
-0@@ -172,6 +173,8 @@ void ima_add_kexec_buffer(struct kimage *image) image->ima_buffer_addr = kbuf.mem; image->ima_buffer_size = kexec_segment_size; image->ima_buffer = kexec_buffer; + image->ima_segment_index = image->nr_segments - 1; + image->is_ima_segment_index_set = true; /** kexec owns kexec_buffer after kexec_add_buffer() is called
Hi Stefan, I will update in next release. Thanks!
Re: [PATCH v7 3/7] ima: kexec: skip IMA segment validation after kexec soft reboot
Quoted 5 lines · steven chen
Quoted 1 line · Stefan Berger
On 2/3/25 6:20 PM, steven chen wrote:
Hi Stefan, I will update in next release. Thanks!
You should try to rebase it on 6.14-rc1. There were a few changes.
Re: [PATCH v7 3/7] ima: kexec: skip IMA segment validation after kexec soft reboot
In reply to Stefan BergerQuoted 104 lines · Stefan Berger
Quoted 4 lines · steven chen
kexec_calculate_store_digests()calculates and stores the digest of the segment atkexec_file_loadsyscall where the IMA segment is also allocated. With this series, the IMA segment will be updated with the measurement log at kexec excute stage when soft reboot is initiated.s/excute/execute
Quoted 5 lines
Therefore, it may fail digest verification in
verify_sha256_digest()after kexec soft reboot into the new kernel. Therefore, the digest calculation/verification of the IMA segment needs to be skipped.Skip IMA segment from calculating and storing digest in function
Skip the calculation and storing of the digest of the IMA segment in
kexec_calculate_store_digests()so that ...Quoted 37 lines
kexec_calculate_store_digests()so that it is not added to the 'purgatory_sha_regions'.Since
verify_sha256_digest()only verifies 'purgatory_sha_regions', no change is needed inverify_sha256_digest()in this context.With this change, the IMA segment is not included in the digest calculation, storage, and verification.
Author: Tushar Sugandhi <[email protected]>
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>---> include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 23 +++++++++++++++++++++++
security/integrity/ima/ima_kexec.c| 3 +++3 files changed, 29 insertions(+)include/linux/kexec.h +3
-0@@ -362,6 +362,9 @@ struct kimage { phys_addr_t ima_buffer_addr; size_t ima_buffer_size; + + unsigned long ima_segment_index; + bool is_ima_segment_index_set; #endif /* Core ELF header buffer */kernel/kexec_file.c +0
-0@@ -38,6 +38,22 @@ void set_kexec_sig_enforced(void) } #endif+#ifdef
CONFIG_IMA_KEXECkernel/kexec_file.c void set_kexec_sig_enforced(void) · line 45
Quoted 4 lines
kernel/kexec_file.c +4
-0+static bool check_ima_segment_index (struct kimage *image,int i) +{ + if (image->is_ima_segment_index_set && + i == image->ima_segment_index)The 'i =' should be indented under 'image->'.
With these nits fixed:
Reviewed-by Stefan Berger <[email protected]>Quoted 39 lines
+ return true;
+ else
+ return false;kernel/kexec_file.c +8
-0+} +#else +static bool check_ima_segment_index (struct kimage *image,int i) +{ + return false; +} +#endif +static int
kexec_calculate_store_digests(struct kimage *image); /* Maximum size in bytes for kernel/initrd files. */kernel/kexec_file.c +0
-0@@ -764,6 +780,13 @@ static int kexec_calculate_store_digests(struct kimage *image) if (ksegment->kbuf == pi->purgatory_buf) continue;+ /*
+ * Skip the segment ifima_segment_indexis set and matches + * the current index
+ */
+ if (check_ima_segment_index(image, i))
+ continue;
+
ret =crypto_shash_update(desc, ksegment->kbuf, ksegment->bufsz);
if (ret)security/integrity/ima/ima_kexec.c +1
-0@@ -162,6 +162,7 @@ void ima_add_kexec_buffer(struct kimage *image) kbuf.buffer = kexec_buffer; kbuf.bufsz = kexec_buffer_size; kbuf.memsz = kexec_segment_size; + image->is_ima_segment_index_set = false; ret = kexec_add_buffer(&kbuf); if (ret) { pr_err("Error passing over kexec measurement buffer.\n");
Quoted 8 lines
security/integrity/ima/ima_kexec.c void ima_add_kexec_buffer(struct kimage *image) · line 179
Quoted 8 lines
security/integrity/ima/ima_kexec.c +2
-0@@ -172,6 +173,8 @@ void ima_add_kexec_buffer(struct kimage *image) image->ima_buffer_addr = kbuf.mem; image->ima_buffer_size = kexec_segment_size; image->ima_buffer = kexec_buffer; + image->ima_segment_index = image->nr_segments - 1; + image->is_ima_segment_index_set = true; /** kexec owns kexec_buffer after kexec_add_buffer() is called
Thanks, Stefan, I will update it in next version
PATCH v7 4/7 ima: kexec: define functions to copy IMA log at soft boot
In reply to steven chenIMA log is copied to the new Kernel during kexec 'load' using ima_dump_measurement_list(). The log copy at kexec 'load' may result in loss of IMA measurements during kexec soft reboot. It needs to be copied over during kexec 'execute'. Setup the needed infrastructure to move the IMA log copy from kexec 'load' to 'execute'.
Define a new IMA hook ima_update_kexec_buffer() as a stub function. It will be used to call ima_dump_measurement_list() during kexec 'execute'.
Implement ima_kexec_post_load() function to be invoked after the new Kernel image has been loaded for kexec. ima_kexec_post_load() maps the IMA buffer to a segment in the newly loaded Kernel. It also registers the reboot notifier_block to trigger ima_update_kexec_buffer() at exec 'execute'.
Author: Tushar Sugandhi <[email protected]>
--- include/linux/ima.h | 3 ++ security/integrity/ima/ima_kexec.c | 46 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
include/linux/ima.h +3 -0
@@ -32,6 +32,9 @@ static inline void ima_appraise_parse_cmdline(void) {}#ifdef CONFIG_IMA_KEXEC extern void ima_add_kexec_buffer (struct kimage *image); +extern void ima_kexec_post_load (struct kimage *image); +#else +static inline void ima_kexec_post_load (struct kimage *image) {}#endif #else
security/integrity/ima/ima_kexec.c +46 -0
62 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 4/7 ima: kexec: define functions to copy IMA log at soft boot
In reply to steven chenIMA log is copied to the new Kernel during kexec 'load' using ima_dump_measurement_list(). The log copy at kexec 'load' may result in loss of IMA measurements during kexec soft reboot. It needs to be copied over during kexec 'execute'. Setup the needed infrastructure to move the IMA log copy from kexec 'load' to 'execute'.
Define a new IMA hook ima_update_kexec_buffer() as a stub function. It will be used to call ima_dump_measurement_list() during kexec 'execute'.
Implement ima_kexec_post_load() function to be invoked after the new Kernel image has been loaded for kexec. ima_kexec_post_load() maps the IMA buffer to a segment in the newly loaded Kernel. It also registers the reboot notifier_block to trigger ima_update_kexec_buffer() at exec 'execute'.
Author: Tushar Sugandhi <[email protected]>
--- include/linux/ima.h | 3 ++ security/integrity/ima/ima_kexec.c | 46 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
include/linux/ima.h +3 -0
@@ -32,6 +32,9 @@ static inline void ima_appraise_parse_cmdline(void) {}#ifdef CONFIG_IMA_KEXEC extern void ima_add_kexec_buffer (struct kimage *image); +extern void ima_kexec_post_load (struct kimage *image); +#else +static inline void ima_kexec_post_load (struct kimage *image) {}#endif #else
security/integrity/ima/ima_kexec.c +46 -0
62 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 5/7 ima: kexec: move IMA log copy from kexec load to execute
In reply to steven chenima_dump_measurement_list() is called during kexec 'load', which may result in loss of IMA measurements during kexec soft reboot. It needs to be called during kexec 'execute'.
This patch includes the following changes:
- Implement kimage_file_post_load() function to be invoked after the new Kernel image has been loaded for kexec.
- Call kimage_file_post_load() from kexec_file_load() syscall only for kexec soft reboot scenarios and not for KEXEC_FILE_ON_CRASH. It will map the IMA segment, and register reboot notifier for the function ima_update_kexec_buffer() which would copy the IMA log at kexec soft reboot.
- Make kexec_segment_size variable local static to the file, for it to be accessible both during kexec 'load' and 'execute'.
- Move ima_dump_measurement_list() call from ima_add_kexec_buffer() to ima_update_kexec_buffer().
- Remove ima_reset_kexec_file() call from ima_add_kexec_buffer(), now that the buffer is being copied at kexec 'execute', and resetting the file at kexec 'load' will corrupt the buffer.
Author: Tushar Sugandhi <[email protected]>
--- kernel/kexec_file.c | 8 ++++++ security/integrity/ima/ima_kexec.c | 43 +++++++++++++++++++----------- 2 files changed, 36 insertions(+), 15 deletions(-)
kernel/kexec_file.c +8 -0
@@ -202,6 +202,11 @@ kimage_validate_signature(struct kimage *image) }#endif +static void kimage_file_post_load (struct kimage *image) +{ +ima_kexec_post_load (image); +} +/* * In file mode list of segments is prepared by kernel. Copy relevant * data from user space, do error checking, prepare segment list
@@ -429,6 +434,9 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,kimage_terminate (image); +if (!(flags &KEXEC_FILE_ON_CRASH )) +kimage_file_post_load (image); + ret =machine_kexec_post_load (image);if (ret) goto out;
security/integrity/ima/ima_kexec.c +28 -15
73 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 6/7 ima: make the kexec extra memory configurable
In reply to steven chenThe 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 <[email protected]>
Author: Tushar Sugandhi <[email protected]>
--- security/integrity/ima/Kconfig | 10 ++++++++++ security/integrity/ima/ima_kexec.c | 16 ++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-)
security/integrity/ima/Kconfig +10 -0
@@ -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 "Extra memory for IMA measurements added during kexec soft reboot" + 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
security/integrity/ima/ima_kexec.c +10 -6
@@ -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" );
Signature · 1 line
2.25.1
Mimi Zohar
maintainerRe: [PATCH v7 6/7] ima: make the kexec extra memory configurable
Hi Steven,
Quoted 30 lines · steven chen
The extra memory allocated for carrying the IMA measurement list across kexec is hard-coded as half a PAGE. Make it configurable.
Define a
Kconfigoption,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 theKconfigoption value, rather than the currently hard-coded one.From: Tushar Sugandhi <[email protected]>
Author: Tushar Sugandhi <[email protected]>Suggested-by Stefan Berger <[email protected]>Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>---
security/integrity/ima/Kconfig | 10 ++++++++++security/integrity/ima/ima_kexec.c| 16 ++++++++++------2 files changed, 20 insertions(+), 6 deletions(-)security/integrity/ima/Kconfig +0
-0@@ -321,4 +321,14 @@ config IMA_DISABLE_HTABLEhelp
This option disables htable to allow measurement of duplicate records.
security/integrity/ima/Kconfig config IMA_DISABLE_HTABLE · line 332
Quoted 9 lines
security/integrity/ima/Kconfig +9
-0+config IMA_KEXEC_EXTRA_MEMORY_KB + int "Extra memory for IMA measurements added during kexec soft reboot" + 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.
-> If set to the default value of 0, an extra half page ...
Quoted 22 lines
+
endifsecurity/integrity/ima/ima_kexec.c +1
-1@@ -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;
/*security/integrity/ima/ima_kexec.c +1
-2-* Reserve an extra half page of memory for additional measurements -* added during the kexec load. +* Reserve extra memory for measurements added during kexec.
Quoted 1 line
*/
Please rename the variable from "extra_size" to "extra_memory".
thanks,
Mimmi
Quoted 17 lines
security/integrity/ima/ima_kexec.c +6
-1- 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; elsesecurity/integrity/ima/ima_kexec.c +2
-2- 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");
PATCH v7 7/7 ima: measure kexec load and exec events as critical data
In reply to steven chenThe amount of memory allocated at kexec load, even with the extra memory allocated, might not be large enough for the entire measurement list. The indeterminate interval between kexec 'load' and 'execute' could exacerbate this problem.
Define two new IMA events, 'kexec_load' and 'kexec_execute', to be measured as critical data at kexec 'load' and 'execute' respectively. Report the allocated kexec segment size, IMA binary log size and the runtime measurements count as part of those events.
These events, and the values reported through them, serve as markers in the IMA log to verify the IMA events are captured during kexec soft reboot. The presence of a 'kexec_load' event in between the last two 'boot_aggregate' events in the IMA log implies this is a kexec soft reboot, and not a cold-boot. And the absence of 'kexec_execute' event after kexec soft reboot implies missing events in that window which results in inconsistency with TPM PCR quotes, necessitating a cold boot for a successful remote attestation.
Author: Tushar Sugandhi <[email protected]>
--- security/integrity/ima/ima_kexec.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
security/integrity/ima/ima_kexec.c +23 -0
@@ -17,6 +17,8 @@#include "ima.h" #ifdef CONFIG_IMA_KEXEC +#define IMA_KEXEC_EVENT_LEN 256 +static struct seq_file ima_kexec_file;static void *ima_kexec_buffer;static size_t kexec_segment_size;
@@ -36,6 +38,24 @@ static void ima_free_kexec_file_buf(struct seq_file *sf)ima_reset_kexec_file (sf); } +static void ima_measure_kexec_event (const char *event_name) +{ +char ima_kexec_event[IMA_KEXEC_EVENT_LEN ]; +size_t buf_size =0 ; +long len; + + buf_size =ima_get_binary_runtime_size (); + len =atomic_long_read (&ima_htable.len); + +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); + +ima_measure_critical_data ("ima_kexec" , event_name, ima_kexec_event, +strlen (ima_kexec_event), false,NULL ,0 ); +} +static int ima_alloc_kexec_file_buf (size_t segment_size) {/*
@@ -60,6 +80,7 @@ static int ima_alloc_kexec_file_buf(size_t 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 ; }
@@ -201,6 +222,8 @@ static int ima_update_kexec_buffer(struct notifier_block *self,return ret; } +ima_measure_kexec_event ("kexec_execute" ); + ret =ima_dump_measurement_list (&buf_size, &buf, kexec_segment_size);
Signature · 1 line
2.25.1
Mimi Zohar
maintainerRe: [PATCH v7 7/7] ima: measure kexec load and exec events as critical data
Quoted 10 lines · steven chen
The amount of memory allocated at kexec load, even with the extra memory allocated, might not be large enough for the entire measurement list. The indeterminate interval between kexec 'load' and 'execute' could exacerbate this problem.
Define two new IMA events, '
kexec_load' and 'kexec_execute', to be measured as critical data at kexec 'load' and 'execute' respectively. Report the allocated kexec segment size, IMA binary log size and the runtime measurements count as part of those events.
Quoted 8 lines
These events, and the values reported through them, serve as markers in the IMA log to verify the IMA events are captured during kexec soft reboot. The presence of a '
kexec_load' event in between the last two 'boot_aggregate' events in the IMA log implies this is a kexec soft reboot, and not a cold-boot. And the absence of 'kexec_execute' event after kexec soft reboot implies missing events in that window which results in inconsistency with TPM PCR quotes, necessitating a cold boot for a successful remote attestation.
As a reminder, please include directions for verifying the buffer data hash against the buffer data. The directions would be similar to those in commit 6b4da8c0e7f ("IMA: Define a new template field buf").
Quoted 30 lines
Reviewed-by Stefan Berger <[email protected]>Author: Tushar Sugandhi <[email protected]>
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>---
security/integrity/ima/ima_kexec.c | 23 +++++++++++++++++++++++1 file changed, 23 insertions(+)security/integrity/ima/ima_kexec.c +0
-0@@ -17,6 +17,8 @@ #include "ima.h"
#ifdefCONFIG_IMA_KEXECsecurity/integrity/ima/ima_kexec.c +2
-0+#define IMA_KEXEC_EVENT_LEN 256 +static struct
seq_fileima_kexec_file;
static void*ima_kexec_buffer;
staticsize_tkexec_segment_size;security/integrity/ima/ima_kexec.c +0
-0@@ -36,6 +38,24 @@ static void ima_free_kexec_file_buf(struct seq_file *sf) ima_reset_kexec_file(sf); }security/integrity/ima/ima_kexec.c +3
-0+static void ima_measure_kexec_event (const char *event_name) +{ +char ima_kexec_event[IMA_KEXEC_EVENT_LEN ];
security/integrity/ima/ima_kexec.c static void ima_free_kexec_file_buf(struct seq_file *sf) · line 53
Quoted 10 lines
security/integrity/ima/ima_kexec.c +10
-0+size_t buf_size =0 ; +long len; + + buf_size =ima_get_binary_runtime_size (); + len =atomic_long_read (&ima_htable.len); + +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);
From scripts/checkpatch.pl, "Alignment should match open parenthesis".
security/integrity/ima/ima_kexec.c static void ima_free_kexec_file_buf(struct seq_file *sf) · line 56
Quoted 3 lines
security/integrity/ima/ima_kexec.c +3
-0+ +ima_measure_critical_data ("ima_kexec" , event_name, ima_kexec_event, +strlen (ima_kexec_event), false,NULL ,0 );
From the kernel-doc scnprintf(), returns the number of bytes. There should be no need to calculate it using strlen().
Quoted 20 lines
security/integrity/ima/ima_kexec.c +2
-0+} +static int
ima_alloc_kexec_file_buf(size_t segment_size){
/*security/integrity/ima/ima_kexec.c +0
-0@@ -60,6 +80,7 @@ static int ima_alloc_kexec_file_buf(size_t segment_size)out:
ima_kexec_file.read_pos = 0;
ima_kexec_file.count =sizeof(struct ima_kexec_hdr); /* reserved space
*/security/integrity/ima/ima_kexec.c +1
-0+ima_measure_kexec_event ("kexec_load" );
return 0;
}security/integrity/ima/ima_kexec.c +0
-0@@ -201,6 +222,8 @@ static int ima_update_kexec_buffer(struct notifier_block *self, return ret; }security/integrity/ima/ima_kexec.c +2
-0+ima_measure_kexec_event ("kexec_execute" ); +
Quoted 3 lines
ret =
ima_dump_measurement_list(&buf_size, &buf, kexec_segment_size);
After fixing up and applying this patch set to 6.14.0-rc1, I'm not seeing the "kexec_execute". Even after changing the default extra memory, I'm still not seeing the measurement.
Mimi
Mimi Zohar
maintainerRe: [PATCH v7 7/7] ima: measure kexec load and exec events as critical data
Quoted 97 lines · Mimi Zohar
Quoted 10 lines · steven chen
The amount of memory allocated at kexec load, even with the extra memory allocated, might not be large enough for the entire measurement list. The indeterminate interval between kexec 'load' and 'execute' could exacerbate this problem.
Define two new IMA events, '
kexec_load' and 'kexec_execute', to be measured as critical data at kexec 'load' and 'execute' respectively. Report the allocated kexec segment size, IMA binary log size and the runtime measurements count as part of those events.Quoted 8 lines
These events, and the values reported through them, serve as markers in the IMA log to verify the IMA events are captured during kexec soft reboot. The presence of a '
kexec_load' event in between the last two 'boot_aggregate' events in the IMA log implies this is a kexec soft reboot, and not a cold-boot. And the absence of 'kexec_execute' event after kexec soft reboot implies missing events in that window which results in inconsistency with TPM PCR quotes, necessitating a cold boot for a successful remote attestation.As a reminder, please include directions for verifying the buffer data hash against the buffer data. The directions would be similar to those in commit
6b4da8c0e7f("IMA: Define a new template field buf").Quoted 30 lines
Reviewed-by Stefan Berger <[email protected]>Author: Tushar Sugandhi <[email protected]>
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>---
security/integrity/ima/ima_kexec.c | 23 +++++++++++++++++++++++1 file changed, 23 insertions(+)security/integrity/ima/ima_kexec.c +0
-0@@ -17,6 +17,8 @@ #include "ima.h"
#ifdefCONFIG_IMA_KEXECsecurity/integrity/ima/ima_kexec.c +2
-0+#define IMA_KEXEC_EVENT_LEN 256 +static struct
seq_fileima_kexec_file;
static void*ima_kexec_buffer;
staticsize_tkexec_segment_size;security/integrity/ima/ima_kexec.c +0
-0@@ -36,6 +38,24 @@ static void ima_free_kexec_file_buf(struct seq_file *sf) ima_reset_kexec_file(sf); }security/integrity/ima/ima_kexec.c +3
-0+static void ima_measure_kexec_event (const char *event_name) +{ +char ima_kexec_event[IMA_KEXEC_EVENT_LEN ];security/integrity/ima/ima_kexec.c static void ima_free_kexec_file_buf(struct seq_file *sf) · line 53
Quoted 10 lines
security/integrity/ima/ima_kexec.c +10
-0+size_t buf_size =0 ; +long len; + + buf_size =ima_get_binary_runtime_size (); + len =atomic_long_read (&ima_htable.len); + +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);From
scripts/checkpatch.pl, "Alignment should match open parenthesis".Quoted 4 lines
security/integrity/ima/ima_kexec.c +3
-0+ + ima_measure_critical_data("ima_kexec", event_name, ima_kexec_event, + strlen(ima_kexec_event), false, NULL,0);
From the kernel-doc
scnprintf(), returns the number of bytes. There should be no need to calculate it usingstrlen().Quoted 22 lines
security/integrity/ima/ima_kexec.c +2
-0+} +static int
ima_alloc_kexec_file_buf(size_t segment_size){
/*security/integrity/ima/ima_kexec.c +0
-0@@ -60,6 +80,7 @@ static int ima_alloc_kexec_file_buf(size_t segment_size)out:
ima_kexec_file.read_pos = 0;
ima_kexec_file.count =sizeof(struct ima_kexec_hdr); /* reserved
space
*/security/integrity/ima/ima_kexec.c +1
-0+ima_measure_kexec_event ("kexec_load" );
return 0;
}security/integrity/ima/ima_kexec.c +0
-0@@ -201,6 +222,8 @@ static int ima_update_kexec_buffer(struct notifier_block *self, return ret; }security/integrity/ima/ima_kexec.c +2
-0+ima_measure_kexec_event ("kexec_execute" ); +
Quoted 8 lines
Quoted 3 lines
ret =
ima_dump_measurement_list(&buf_size, &buf, kexec_segment_size);After fixing up and applying this patch set to 6.14.0-rc1, I'm not seeing the "kexec_execute". Even after changing the default extra memory, I'm still not seeing
the measurement.
FYI, after reverting commit 254ef9541d68 ("ima: Suspend PCR extends and log appends when rebooting"), I'm seeing the "kexec_execute" measurement.
Mimi
Re: [PATCH v7 7/7] ima: measure kexec load and exec events as critical data
Quoted 107 lines · Mimi Zohar
Quoted 95 lines · Mimi Zohar
Quoted 10 lines · steven chen
The amount of memory allocated at kexec load, even with the extra memory allocated, might not be large enough for the entire measurement list. The indeterminate interval between kexec 'load' and 'execute' could exacerbate this problem.
Define two new IMA events, '
kexec_load' and 'kexec_execute', to be measured as critical data at kexec 'load' and 'execute' respectively. Report the allocated kexec segment size, IMA binary log size and the runtime measurements count as part of those events.Quoted 8 lines
These events, and the values reported through them, serve as markers in the IMA log to verify the IMA events are captured during kexec soft reboot. The presence of a '
kexec_load' event in between the last two 'boot_aggregate' events in the IMA log implies this is a kexec soft reboot, and not a cold-boot. And the absence of 'kexec_execute' event after kexec soft reboot implies missing events in that window which results in inconsistency with TPM PCR quotes, necessitating a cold boot for a successful remote attestation.As a reminder, please include directions for verifying the buffer data hash against the buffer data. The directions would be similar to those in commit
6b4da8c0e7f("IMA: Define a new template field buf").Quoted 30 lines
Reviewed-by Stefan Berger <[email protected]>Author: Tushar Sugandhi <[email protected]>
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>--- security/integrity/ima/ima_kexec.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)security/integrity/ima/ima_kexec.c +5
-0@@ -17,6 +17,8 @@ #include "ima.h" #ifdef CONFIG_IMA_KEXEC +#define IMA_KEXEC_EVENT_LEN 256 + static struct seq_file ima_kexec_file; static void *ima_kexec_buffer; static size_t kexec_segment_size;@@ -36,6 +38,24 @@ static void ima_free_kexec_file_buf(struct seq_file *sf) ima_reset_kexec_file(sf); } +static void ima_measure_kexec_event (const char *event_name) +{ +char ima_kexec_event[IMA_KEXEC_EVENT_LEN ];security/integrity/ima/ima_kexec.c static void ima_free_kexec_file_buf(struct seq_file *sf) · line 53
Quoted 10 lines
security/integrity/ima/ima_kexec.c +10
-0+size_t buf_size =0 ; +long len; + + buf_size =ima_get_binary_runtime_size (); + len =atomic_long_read (&ima_htable.len); + +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);From
scripts/checkpatch.pl, "Alignment should match open parenthesis".security/integrity/ima/ima_kexec.c static void ima_free_kexec_file_buf(struct seq_file *sf)
Quoted 4 lines
security/integrity/ima/ima_kexec.c +3
-0+ +ima_measure_critical_data ("ima_kexec" , event_name, ima_kexec_event, +strlen (ima_kexec_event), false,NULL ,0 );From the kernel-doc
scnprintf(), returns the number of bytes. There should be no
need to calculate it usingstrlen().Quoted 20 lines
security/integrity/ima/ima_kexec.c +2
-0+} + static int ima_alloc_kexec_file_buf(size_t segment_size) {/*
security/integrity/ima/ima_kexec.c +0
-0@@ -60,6 +80,7 @@ static int ima_alloc_kexec_file_buf(size_t segment_size) out: ima_kexec_file.read_pos = 0; ima_kexec_file.count = sizeof(struct ima_kexec_hdr); /* reservedspace
*/security/integrity/ima/ima_kexec.c +1
-0+ima_measure_kexec_event ("kexec_load" ); return 0; }@@ -201,6 +222,8 @@ static int ima_update_kexec_buffer(struct notifier_block *self, return ret; }Quoted 10 lines
security/integrity/ima/ima_kexec.c static int ima_update_kexec_buffer(struct notifier_block *self, · line 228
Quoted 5 lines
security/integrity/ima/ima_kexec.c +2
-0+ima_measure_kexec_event ("kexec_execute" ); + ret = ima_dump_measurement_list(&buf_size, &buf, kexec_segment_size);After fixing up and applying this patch set to 6.14.0-rc1, I'm not seeing the "kexec_execute". Even after changing the default extra memory, I'm still not seeing
the measurement.
Quoted 2 lines
FYI, after reverting commit
254ef9541d68("ima: Suspend PCR extends and log appends when rebooting"), I'm seeing the "kexec_execute" measurement.
I would try sth. like this:
static int ima_reboot_notifier(struct notifier_block *nb,
unsigned long action, void *data)
{
if (action == SYS_RESTART && data && !strcmp(data, "kexec reboot"))
ima_measure_kexec_event("kexec_execute");Quoted 4 lines
Mimi
Re: [PATCH v7 7/7] ima: measure kexec load and exec events as critical data
Quoted 112 lines · Stefan Berger
Quoted 106 lines · Mimi Zohar
Quoted 96 lines · Mimi Zohar
Quoted 10 lines · steven chen
The amount of memory allocated at kexec load, even with the extra memory allocated, might not be large enough for the entire measurement list. The indeterminate interval between kexec 'load' and 'execute' could exacerbate this problem.
Define two new IMA events, '
kexec_load' and 'kexec_execute', to be measured as critical data at kexec 'load' and 'execute' respectively. Report the allocated kexec segment size, IMA binary log size and the runtime measurements count as part of those events.Quoted 8 lines
These events, and the values reported through them, serve as markers in the IMA log to verify the IMA events are captured during kexec soft reboot. The presence of a '
kexec_load' event in between the last two 'boot_aggregate' events in the IMA log implies this is a kexec soft reboot, and not a cold-boot. And the absence of 'kexec_execute' event after kexec soft reboot implies missing events in that window which results in inconsistency with TPM PCR quotes, necessitating a cold boot for a successful remote attestation.As a reminder, please include directions for verifying the buffer data hash against the buffer data. The directions would be similar to those in commit
6b4da8c0e7f("IMA: Define a new template field buf").Quoted 29 lines
Reviewed-by Stefan Berger <[email protected]>Author: Tushar Sugandhi <[email protected]>
Signed-off-by Tushar Sugandhi <[email protected]>Signed-off-by steven chen <[email protected]>---
security/integrity/ima/ima_kexec.c | 23 +++++++++++++++++++++++1 file changed, 23 insertions(+)security/integrity/ima/ima_kexec.c +4
-0@@ -17,6 +17,8 @@ #include "ima.h" #ifdef CONFIG_IMA_KEXEC +#define IMA_KEXEC_EVENT_LEN 256 + static struct seq_file ima_kexec_file; static void *ima_kexec_buffer; static size_t kexec_segment_size;@@ -36,6 +38,24 @@ static void ima_free_kexec_file_buf(struct seq_file *sf) ima_reset_kexec_file(sf); } +static void ima_measure_kexec_event(const char *event_name) +{ + char ima_kexec_event[IMA_KEXEC_EVENT_LEN];security/integrity/ima/ima_kexec.c static void ima_free_kexec_file_buf(struct · line 53
Quoted 10 lines
security/integrity/ima/ima_kexec.c +10
-0+ size_t buf_size = 0; + long len; + + buf_size = ima_get_binary_runtime_size(); + len = atomic_long_read(&ima_htable.len); + + 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);From
scripts/checkpatch.pl, "Alignment should match open parenthesis".security/integrity/ima/ima_kexec.c static void ima_free_kexec_file_buf(struct · line 58
Quoted 5 lines
security/integrity/ima/ima_kexec.c +3
-0+ + ima_measure_critical_data("ima_kexec", event_name, ima_kexec_event, + strlen(ima_kexec_event), false, NULL,0 );From the kernel-doc
scnprintf(), returns the number of bytes. There should be no need to calculate it usingstrlen().Quoted 21 lines
security/integrity/ima/ima_kexec.c +2
-0+} +static int
ima_alloc_kexec_file_buf(size_t segment_size){
/*security/integrity/ima/ima_kexec.c +0
-0@@ -60,6 +80,7 @@ static int ima_alloc_kexec_file_buf(size_t 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;
}security/integrity/ima/ima_kexec.c +0
-0@@ -201,6 +222,8 @@ static int ima_update_kexec_buffer(struct
notifier_block
*self,
return ret;
}
+ima_measure_kexec_event("kexec_execute");Quoted 8 lines
Quoted 3 lines
+
ret =ima_dump_measurement_list(&buf_size, &buf, kexec_segment_size);After fixing up and applying this patch set to 6.14.0-rc1, I'm not seeing the "kexec_execute". Even after changing the default extra memory, I'm still not seeing
the measurement.Quoted 2 lines
FYI, after reverting commit
254ef9541d68("ima: Suspend PCR extends and log appends when rebooting"), I'm seeing the "kexec_execute" measurement.
Quoted 11 lines
I would try sth. like this:
static int ima_reboot_notifier(structnotifier_block*nb, unsigned long action,
void *data)
{
if (action ==SYS_RESTART&& data && !strcmp(data, "kexec reboot"))ima_measure_kexec_event("kexec_execute");Quoted 4 lines
Mimi
Thanks, will fix this in 6.14.0-rc1 in next version