Felix Zielcke wrote on 20080903:
> could you please address Marco's issues and send a new patch so the
> topic is brought up again?
Please find attached a new patch. I hope I managed to fix all remarks
that were made ;-) If not then please let me know.
This is intended for the Changelog :
2008-09-09 Hans Lambermont <[EMAIL PROTECTED]>
* disk/lvm.c (grub_lvm_scan_device): Allocate buffer space for the
circular metadata worst case scenario. If the metadata is circular
then copy the wrap in place.
* include/grub/lvm.h: Add GRUB_LVM_MDA_HEADER_SIZE, from the LVM2
project lib/format_text/layout.h
Circular metadata bug found and patch debugged by
Jan Derk Gerlings <[EMAIL PROTECTED]>
The 'svn diff --diff-cmd diff -x -up' style patch is attached.
regards,
Hans Lambermont
--
Hans Lambermont, M.Sc. - Newtec - OS-Platform&VAS
http://newtec.eu/ t:+31408519234 m:+31629064887
Index: disk/lvm.c
===================================================================
--- disk/lvm.c (revision 1858)
+++ disk/lvm.c (working copy)
@@ -281,7 +281,8 @@ grub_lvm_scan_device (const char *name)
goto fail;
}
- metadatabuf = grub_malloc (mda_size);
+ /* Allocate buffer space for the circular worst-case scenario. */
+ metadatabuf = grub_malloc (2 * mda_size);
if (! metadatabuf)
goto fail;
@@ -300,6 +301,16 @@ grub_lvm_scan_device (const char *name)
}
rlocn = mdah->raw_locns;
+ if (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) >
+ grub_le_to_cpu64 (mdah->size))
+ {
+ /* Metadata is circular. Copy the wrap in place. */
+ grub_memcpy (metadatabuf + mda_size,
+ metadatabuf + GRUB_LVM_MDA_HEADER_SIZE,
+ grub_le_to_cpu64 (rlocn->offset) +
+ grub_le_to_cpu64 (rlocn->size) -
+ grub_le_to_cpu64 (mdah->size));
+ }
p = q = metadatabuf + grub_le_to_cpu64 (rlocn->offset);
while (*q != ' ' && q < metadatabuf + mda_size)
Index: include/grub/lvm.h
===================================================================
--- include/grub/lvm.h (revision 1858)
+++ include/grub/lvm.h (working copy)
@@ -103,6 +103,7 @@ struct grub_lvm_pv_header {
#define GRUB_LVM_FMTT_MAGIC "\040\114\126\115\062\040\170\133\065\101\045\162\060\116\052\076"
#define GRUB_LVM_FMTT_VERSION 1
+#define GRUB_LVM_MDA_HEADER_SIZE 512
/* On disk */
struct grub_lvm_raw_locn {
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel