* grub-core/disk/diskfilter.c (insert_array): Choose the smallest

device.
	* grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Reject too
	small devices.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-27 00:46:08 +01:00
parent 036985b8ce
commit 1e9a9a3faf
3 changed files with 36 additions and 23 deletions

View File

@ -1,3 +1,10 @@
2012-02-26 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/disk/diskfilter.c (insert_array): Choose the smallest
device.
* grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Reject too
small devices.
2012-02-26 Vladimir Serbinenko <phcoder@gmail.com>
Remove grub_{modname}_init and grub_{modname}_fini. They should never

View File

@ -966,33 +966,33 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id,
struct grub_diskfilter_lv *lv;
/* FIXME: Check whether the update time of the superblocks are
the same. */
if (pv->disk && grub_disk_get_size (disk) >= pv->part_size)
return GRUB_ERR_NONE;
pv->disk = grub_disk_open (disk->name);
if (!pv->disk)
return grub_errno;
/* This could happen to LVM on RAID, pv->disk points to the
raid device, we shouldn't change it. */
if (! pv->disk)
{
pv->disk = grub_disk_open (disk->name);
if (! pv->disk)
return grub_errno;
pv->part_start = grub_partition_get_start (disk->partition);
pv->part_size = grub_disk_get_size (disk);
pv->start_sector -= pv->part_start;
pv->part_start = grub_partition_get_start (disk->partition);
pv->part_size = grub_disk_get_size (disk);
#ifdef GRUB_UTIL
{
grub_size_t s = 1;
grub_partition_t p;
for (p = disk->partition; p; p = p->parent)
s++;
pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0]));
s = 0;
for (p = disk->partition; p; p = p->parent)
pv->partmaps[s++] = xstrdup (p->partmap->name);
pv->partmaps[s++] = 0;
}
{
grub_size_t s = 1;
grub_partition_t p;
for (p = disk->partition; p; p = p->parent)
s++;
pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0]));
s = 0;
for (p = disk->partition; p; p = p->parent)
pv->partmaps[s++] = xstrdup (p->partmap->name);
pv->partmaps[s++] = 0;
}
#endif
if (start_sector != (grub_uint64_t)-1)
pv->start_sector = start_sector;
pv->start_sector += pv->part_start;
}
if (start_sector != (grub_uint64_t)-1)
pv->start_sector = start_sector;
pv->start_sector += pv->part_start;
/* Add the device to the array. */
for (lv = array->lvs; lv; lv = lv->next)
if (!lv->became_readable_at && lv->fullname && is_lv_readable (lv))

View File

@ -192,6 +192,11 @@ grub_mdraid_detect (grub_disk_t disk,
/* Unsupported version. */
return NULL;
/* No need for explicit check that sb.size is 0 (unspecified) since
0 >= non-0 is false. */
if (((grub_disk_addr_t) grub_le_to_cpu32 (sb.size)) * 2 >= size)
return NULL;
/* FIXME: Check the checksum. */
level = grub_le_to_cpu32 (sb.level);
@ -229,7 +234,8 @@ grub_mdraid_detect (grub_disk_t disk,
grub_snprintf (buf, sizeof (buf), "md%d", grub_le_to_cpu32 (sb.md_minor));
return grub_diskfilter_make_raid (16, (char *) uuid,
grub_le_to_cpu32 (sb.raid_disks), buf,
(sb.size) ? grub_le_to_cpu32 (sb.size) * 2
(sb.size) ? ((grub_disk_addr_t)
grub_le_to_cpu32 (sb.size)) * 2
: sector,
grub_le_to_cpu32 (sb.chunk_size) >> 9,
grub_le_to_cpu32 (sb.layout),