dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0454-disk-lvm-Don-t-blast-past-the-end-of-the-circular-me.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Daniel Axtens <dja@axtens.net>
9723a8
Date: Thu, 21 Jan 2021 18:19:51 +1100
9723a8
Subject: [PATCH] disk/lvm: Don't blast past the end of the circular metadata
9723a8
 buffer
9723a8
9723a8
This catches at least some OOB reads, and it's possible I suppose that
9723a8
if 2 * mda_size is less than GRUB_LVM_MDA_HEADER_SIZE it might catch some
9723a8
OOB writes too (although that hasn't showed up as a crash in fuzzing yet).
9723a8
9723a8
It's a bit ugly and I'd appreciate better suggestions.
9723a8
9723a8
Signed-off-by: Daniel Axtens <dja@axtens.net>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/disk/lvm.c | 10 ++++++++++
9723a8
 1 file changed, 10 insertions(+)
9723a8
9723a8
diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c
9723a8
index 0f466040a55..ec3545e164b 100644
9723a8
--- a/grub-core/disk/lvm.c
9723a8
+++ b/grub-core/disk/lvm.c
9723a8
@@ -215,6 +215,16 @@ grub_lvm_detect (grub_disk_t disk,
9723a8
   if (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) >
9723a8
       grub_le_to_cpu64 (mdah->size))
9723a8
     {
9723a8
+      if (2 * mda_size < GRUB_LVM_MDA_HEADER_SIZE ||
9723a8
+          (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) -
9723a8
+	   grub_le_to_cpu64 (mdah->size) > mda_size - GRUB_LVM_MDA_HEADER_SIZE))
9723a8
+	{
9723a8
+#ifdef GRUB_UTIL
9723a8
+	  grub_util_info ("cannot copy metadata wrap in circular buffer");
9723a8
+#endif
9723a8
+	  goto fail2;
9723a8
+	}
9723a8
+
9723a8
       /* Metadata is circular. Copy the wrap in place. */
9723a8
       grub_memcpy (metadatabuf + mda_size,
9723a8
 		   metadatabuf + GRUB_LVM_MDA_HEADER_SIZE,