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