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

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