dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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