Skip to contentSkip to conversation

lvm: Grub2 fails to detect LVM volumes due to an incorrect computation of mda_end

PATCH In review Glenn Washburn 2 participants 4 messages May 6, 2024 – May 16, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lvm: Grub2 fails to detect LVM volumes due to an incorrect computation of mda_end

From: Rogier <[email protected]>

When handling a regular LVM volume, Grub can fail with the message:
error: disk `lvmid/******-****-****-****-****-****- ****/******-****-****-****-****-****-******' not found.

If the condition which triggers this exists, grub-probe will report the error mentioned above. Similarly, the grub boot code will fail to detect LVM volumes, resulting in a failure to boot off of LVM disks/partitions. The condition can be created on any LVM VG by an LVM configuration change, so any system with /boot on LVM can become unbootable at 'any' time (after any LVM configuration change).

The problem is caused by an incorrect computation of mda_end in lvm.c, when the metadata area wraps around. Apparently, this can start happening at around 220 metadata changes to the VG.

Fixes 879c4a834 (lvm: Fix two more potential data-dependent alloc overflows)

---
I have done no testing of this patch. I've only created a suitable patch for review. This seems like a fairly serious issue that might one day bite me, so I think it deserves a review.

Glenn

---
 grub-core/disk/lvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/disk/lvm.c +1 -1
index 794248540cd3..8535d5a5863a 100644
@@ -290,7 +290,7 @@ grub_lvm_detect (grub_disk_t disk,
 
   p = q = (char *)ptr;
 
-  if (grub_add ((grub_size_t)metadatabuf, (grub_size_t)mda_size, &ptr))
+  if (grub_add (ptr, (grub_size_t)grub_le_to_cpu64 (rlocn->size), &ptr))
     goto error_parsing_metadata;
 
   mda_end = (char *)ptr;
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by Daniel Kiper on v1 1/1
#1 lore raw

Adding Marta...

Quoted 17 lines · Glenn Washburn

From: Rogier <[email protected]>

When handling a regular LVM volume, Grub can fail with the message:
error: disk `lvmid/******-****-****-****-****-****- ****/******-****-****-****-****-****-******' not found.

If the condition which triggers this exists, grub-probe will report the error mentioned above. Similarly, the grub boot code will fail to detect LVM volumes, resulting in a failure to boot off of LVM disks/partitions. The condition can be created on any LVM VG by an LVM configuration change, so any system with /boot on LVM can become unbootable at 'any' time (after any LVM configuration change).

The problem is caused by an incorrect computation of mda_end in lvm.c, when the metadata area wraps around. Apparently, this can start happening at around 220 metadata changes to the VG.

Quoted 5 lines
Fixes 879c4a834 (lvm: Fix two more potential data-dependent alloc overflows)

Marta, may I ask you to test this patch?

Quoted 15 lines

---
I have done no testing of this patch. I've only created a suitable patch for review. This seems like a fairly serious issue that might one day bite me, so I think it deserves a review.

Glenn

---
 grub-core/disk/lvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/disk/lvm.c +0 -0
index 794248540cd3..8535d5a5863a 100644

grub-core/disk/lvm.c grub_lvm_detect (grub_disk_t disk, · line 296

Quoted 8 lines
grub-core/disk/lvm.c +1 -1
@@ -290,7 +290,7 @@ grub_lvm_detect (grub_disk_t disk,
 
   p = q = (char *)ptr;
 
-  if (grub_add ((grub_size_t)metadatabuf, (grub_size_t)mda_size, &ptr))
+  if (grub_add (ptr, (grub_size_t)grub_le_to_cpu64 (rlocn->size), &ptr))
     goto error_parsing_metadata;
 
   mda_end = (char *)ptr;

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Tested-by Michael Chang
#2 lore raw
Quoted 19 lines · Daniel Kiper via Grub-devel

Adding Marta...

Quoted 16 lines · Glenn Washburn

From: Rogier <[email protected]>

When handling a regular LVM volume, Grub can fail with the message:
error: disk `lvmid/******-****-****-****-****-****- ****/******-****-****-****-****-****-******' not found.

If the condition which triggers this exists, grub-probe will report the error mentioned above. Similarly, the grub boot code will fail to detect LVM volumes, resulting in a failure to boot off of LVM disks/partitions. The condition can be created on any LVM VG by an LVM configuration change, so any system with /boot on LVM can become unbootable at 'any' time (after any LVM configuration change).

The problem is caused by an incorrect computation of mda_end in lvm.c, when the metadata area wraps around. Apparently, this can start happening at around 220 metadata changes to the VG.

The number of times to commit a wrap actually depends on the size of the metadata area, how many LVs and VGs are connected to the PV and whichever would take part in the size of active raw metadata block within the area.

I managed to use the attached shell script to prepare a LVM disk where the metadata area is in wrapped state. It took about 100 cycles for me. With that, I could see the error occurred, and with the patch, the problem is gone.

So, Feel free to add my:

Thanks,
Michael

Quoted 33 lines
Quoted 6 lines
Fixes 879c4a834 (lvm: Fix two more potential data-dependent alloc overflows)

Marta, may I ask you to test this patch?

Quoted 22 lines

---
I have done no testing of this patch. I've only created a suitable patch for review. This seems like a fairly serious issue that might one day bite me, so I think it deserves a review.

Glenn

---
 grub-core/disk/lvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/disk/lvm.c +1 -1
index 794248540cd3..8535d5a5863a 100644
@@ -290,7 +290,7 @@ grub_lvm_detect (grub_disk_t disk,
 
   p = q = (char *)ptr;
 
-  if (grub_add ((grub_size_t)metadatabuf, (grub_size_t)mda_size, &ptr))
+  if (grub_add (ptr, (grub_size_t)grub_le_to_cpu64 (rlocn->size), &ptr))
     goto error_parsing_metadata;
 
Quoted 8 lines

grub-core/disk/lvm.c grub_lvm_detect (grub_disk_t disk, · line 296

Quoted 1 line
grub-core/disk/lvm.c +0 -0
   mda_end = (char *)ptr;

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw
Quoted 21 lines · Michael Chang
Quoted 19 lines · Daniel Kiper via Grub-devel

Adding Marta...

Quoted 16 lines · Glenn Washburn

From: Rogier <[email protected]>

When handling a regular LVM volume, Grub can fail with the message:
error: disk `lvmid/******-****-****-****-****-****- ****/******-****-****-****-****-****-******' not found.

If the condition which triggers this exists, grub-probe will report the error mentioned above. Similarly, the grub boot code will fail to detect LVM volumes, resulting in a failure to boot off of LVM disks/partitions. The condition can be created on any LVM VG by an LVM configuration change, so any system with /boot on LVM can become unbootable at 'any' time (after any LVM configuration change).

The problem is caused by an incorrect computation of mda_end in lvm.c, when the metadata area wraps around. Apparently, this can start happening at around 220 metadata changes to the VG.

Quoted 7 lines

The number of times to commit a wrap actually depends on the size of the metadata area, how many LVs and VGs are connected to the PV and whichever would take part in the size of active raw metadata block within the area.

I managed to use the attached shell script to prepare a LVM disk where the metadata area is in wrapped state. It took about 100 cycles for me.

Hm. In each cycle, two changes (lvcreate/lvremove) are committed. Combined with the initial 30 LVs commit, the total is very close to your 220 metadata changes.

Thanks,
Michael

Quoted 51 lines

With that, I could see the error occurred, and with the patch, the problem is gone.

So, Feel free to add my:

Thanks,
Michael

Quoted 41 lines
Quoted 6 lines
Fixes 879c4a834 (lvm: Fix two more potential data-dependent alloc overflows)

Marta, may I ask you to test this patch?

Quoted 15 lines

---
I have done no testing of this patch. I've only created a suitable patch for review. This seems like a fairly serious issue that might one day bite me, so I think it deserves a review.

Glenn

---
 grub-core/disk/lvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/disk/lvm.c +0 -0
index 794248540cd3..8535d5a5863a 100644

grub-core/disk/lvm.c grub_lvm_detect (grub_disk_t disk, · line 296

Quoted 8 lines
grub-core/disk/lvm.c +1 -1
@@ -290,7 +290,7 @@ grub_lvm_detect (grub_disk_t disk,
 
   p = q = (char *)ptr;
 
-  if (grub_add ((grub_size_t)metadatabuf, (grub_size_t)mda_size, &ptr))
+  if (grub_add (ptr, (grub_size_t)grub_le_to_cpu64 (rlocn->size), &ptr))
     goto error_parsing_metadata;
 
   mda_end = (char *)ptr;

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel