Skip to contentSkip to conversation

tpm: Skip loopback image measurement

PATCH In review Michael Chang via Grub-devel 2 participants 2 messages Oct 3, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: Skip loopback image measurement

The loopback image is configured to function as a disk by being mapped as a block device. Instead of measuring the entire block device, we should focus on tracking the individual files accessed from it. For example, we do not directly measure block devices like disk hd0, but the files opened from it.

This method is important to avoid running out of memory, since loopback images can be very large. Trying to read and measure the whole image at once could cause out of memory errors and disrupt the boot process.

---
 grub-core/commands/tpm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
grub-core/commands/tpm.c +10 -0
index 324423ef8..2350d660d 100644
@@ -36,6 +36,16 @@ grub_tpm_verify_init (grub_file_t io,
 {
   *context = io->name;
   *flags |= GRUB_VERIFY_FLAGS_SINGLE_CHUNK;
+
+  /*
+   * The loopback image is mapped as a disk, allowing it to function like a
+   * block device. However, we measure the files read from the block device,
+   * not the device itself. For example, we don't measure block devices like
+   * disk hd0 directly. This process is crucial to prevent out-of-memory
+   * errors, as loopback images are inherently large.
+   */
+  if ((type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_LOOPBACK)
+    *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
   return GRUB_ERR_NONE;
 }
 
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Michael Chang via Grub-devel

The loopback image is configured to function as a disk by being mapped as a block device. Instead of measuring the entire block device, we should focus on tracking the individual files accessed from it. For example, we do not directly measure block devices like disk hd0, but the files opened from it.

This method is important to avoid running out of memory, since loopback images can be very large. Trying to read and measure the whole image at once could cause out of memory errors and disrupt the boot process.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel