Blame SOURCES/0458-disk-lvm-Sanitize-rlocn-offset-to-prevent-wild-read.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Daniel Axtens <dja@axtens.net>
9723a8
Date: Fri, 22 Jan 2021 14:43:58 +1100
9723a8
Subject: [PATCH] disk/lvm: Sanitize rlocn->offset to prevent wild read
9723a8
9723a8
rlocn->offset is read directly from disk and added to the metadatabuf
9723a8
pointer to create a pointer to a block of metadata. It's a 64-bit
9723a8
quantity so as long as you don't overflow you can set subsequent
9723a8
pointers to point anywhere in memory.
9723a8
9723a8
Require that rlocn->offset fits within the metadata buffer size.
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 | 8 ++++++++
9723a8
 1 file changed, 8 insertions(+)
9723a8
9723a8
diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c
b71686
index 267be7b95..9eda28d85 100644
9723a8
--- a/grub-core/disk/lvm.c
9723a8
+++ b/grub-core/disk/lvm.c
9723a8
@@ -212,6 +212,14 @@ grub_lvm_detect (grub_disk_t disk,
9723a8
     }
9723a8
 
9723a8
   rlocn = mdah->raw_locns;
9723a8
+  if (grub_le_to_cpu64 (rlocn->offset) >= grub_le_to_cpu64 (mda_size))
9723a8
+    {
9723a8
+#ifdef GRUB_UTIL
9723a8
+      grub_util_info ("metadata offset is beyond end of metadata area");
9723a8
+#endif
9723a8
+      goto fail2;
9723a8
+    }
9723a8
+
9723a8
   if (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) >
9723a8
       grub_le_to_cpu64 (mdah->size))
9723a8
     {