segfault in grub-probe when spare or faulty disks are found
PATCH 1/1 segfault in grub-probe when spare or faulty disks are found
the actual raid implementation doesn't handle spare or faulty drives in a linux software raid array in a sane way. grub-probe will reproducible crash in such a setup.
please include the attached trivial patch to fix this problem.
for more information see:
https://savannah.gnu.org/bugs/?31119
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593652
=== modified file 'grub-core/disk/raid.c'
disk/raid.c +10 -4
@@ -501,7 +501,8 @@grub_dprintf ("raid" ,"array->nr_devs > array->total_devs (%d)?!?" , array->total_devs); -if (array->device[new_array->index] !=NULL ) +if ((new_array->index <GRUB_RAID_MAX_DEVICES ) && + (array->device[new_array->index] !=NULL ))/* We found multiple devices with the same number. Again, this shouldn't happen. */ grub_dprintf ("raid", "Found two disks with the number %d?!?",
@@ -609,9 +610,14 @@ }/* Add the device to the array. */ - array->device[new_array->index] = disk; - array->start_sector[new_array->index] = start_sector; - array->nr_devs++; + +/* ignore spare/faulty disks and more then GRUB_RAID_MAX_DEVICES */ +if (new_array->index <GRUB_RAID_MAX_DEVICES ) + { + array->device[new_array->index] = disk; + array->start_sector[new_array->index] = start_sector; + array->nr_devs++; + }return 0 ; }
Quoted 6 lines · Martin Schitter
the actual raid implementation doesn't handle spare or faulty drives in a linux software raid array in a sane way. grub-probe will reproducible crash in such a setup.
please include the attached trivial patch to fix this problem.
I didn't respond to the patch because it's not correct: it only propagates the restriction instead of removing it. Thanks for reporting the issue. I'll fix it tomorrow (hopefully)
Quoted 11 lines
for more information see:
https://savannah.gnu.org/bugs/?31119
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593652_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Am 2010-09-28 22:24, schrieb Vladimir 'φ-coder/phcoder' Serbinenko:
Quoted 3 lines
I didn't respond to the patch because it's not correct: it only propagates the restriction instead of removing it. Thanks for reporting the issue. I'll fix it tomorrow (hopefully)
yes, there are more consequent ways to solve the problem. my simple patch doesn't distinguish between all the special cases:
index == 0xffff: spare disk,
index == 0xfffe: faulty disk
index out of range (>= GRUB_RAID_MAX_DEVICES).
it makes a very simple test and ignores all affected devices in any case. isn't that enough to prevent the segmentation fault?
it would be nice, if you could find a better workaround.
Am 2010-09-28 22:24, schrieb Vladimir 'φ-coder/phcoder' Serbinenko:
Quoted 3 lines
I didn't respond to the patch because it's not correct: it only propagates the restriction instead of removing it. Thanks for reporting the issue. I'll fix it tomorrow (hopefully)
the problem with version 1.x raid spare disks still exists (see also: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593652).
could you please come up with a better solution for this problem or correct my patch.
thanks
martin
Quoted 10 lines · Martin Schitter
Am 2010-09-28 22:24, schrieb Vladimir 'φ-coder/phcoder' Serbinenko:
Quoted 3 lines
I didn't respond to the patch because it's not correct: it only propagates the restriction instead of removing it. Thanks for reporting the issue. I'll fix it tomorrow (hopefully)
the problem with version 1.x raid spare disks still exists (see also:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593652).
could you please come up with a better solution for this problem or correct my patch.
Sorry for the delay, I had very busy period. I'll do this this evening
Quoted 8 lines
thanks
martin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 6 lines · Martin Schitter
the actual raid implementation doesn't handle spare or faulty drives in a linux software raid array in a sane way. grub-probe will reproducible crash in such a setup.
please include the attached trivial patch to fix this problem.
Please try the attached patch
Quoted 11 lines
for more information see:
https://savannah.gnu.org/bugs/?31119
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593652_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
=== modified file 'grub-core/disk/mdraid1x_linux.c'
disk/mdraid1x_linux.c +7 -5
@@ -188,12 +188,14 @@ array->total_devs =grub_le_to_cpu32 (real_sb->raid_disks); array->disk_size =grub_le_to_cpu64 (real_sb->size); array->chunk_size =grub_le_to_cpu32 (real_sb->chunksize); -if (grub_le_to_cpu32 (real_sb->dev_number) < + +if (grub_le_to_cpu32 (real_sb->dev_number) >=grub_le_to_cpu32 (real_sb->max_dev)) - array->index =grub_le_to_cpu16 - (real_sb->dev_roles[grub_le_to_cpu32 (real_sb->dev_number)]); -else - array->index =0xffff ;/* disk will be later not used! */ +return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET , +"spares aren't implemented" ); + + array->index =grub_le_to_cpu16 + (real_sb->dev_roles[grub_le_to_cpu32 (real_sb->dev_number)]); array->uuid_len =16 ; array->uuid =grub_malloc (16 );if (!array->uuid)
=== modified file 'grub-core/disk/mdraid_linux.c'
disk/mdraid_linux.c +3 -0
@@ -194,6 +194,9 @@ sb.level != 5 && sb.level != 6 && sb.level != 10)return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET ,"unsupported RAID level: %d" , sb.level); +if (sb.this_disk.number ==0xffff || sb.this_disk.number ==0xfffe ) +return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET , +"spares aren't implemented" ); array->name =NULL ; array->number = sb.md_minor;
=== modified file 'grub-core/disk/raid.c'
disk/raid.c +45 -17
137 lines not on this page · raw message
=== modified file 'grub-core/disk/raid5_recover.c'
disk/raid5_recover.c +1 -1
@@ -45,7 +45,7 @@if (i == disknr)continue ; - err =grub_disk_read (array->device[i], sector,0 , size, buf2); + err =grub_disk_read (array->members[i].device, sector,0 , size, buf2);if (err) {
=== modified file 'grub-core/disk/raid6_recover.c'
disk/raid6_recover.c +10 -9
@@ -118,8 +118,9 @@ bad1 = i; else { -if ((array->device[pos]) && - (!grub_disk_read (array->device[pos], sector,0 , size, buf))) +if ((array->members[pos].device) && + (!grub_disk_read (array->members[pos].device, sector, +0 , size, buf))) {grub_raid_block_xor (pbuf, buf, size);grub_raid_block_mul (raid6_table2[i][i], buf, size);
@@ -148,21 +149,21 @@if (bad2 <0 ) {/* One bad device */ -if ((array->device[p]) && - (!grub_disk_read (array->device[p], sector,0 , size, buf))) +if ((array->members[p].device) && + (!grub_disk_read (array->members[p].device, sector,0 , size, buf))) {grub_raid_block_xor (buf, pbuf, size); goto quit; } -if (! array->device[q]) +if (! array->members[q].device) {grub_error (GRUB_ERR_READ_ERROR ,"not enough disk to restore" ); goto quit; } grub_errno =GRUB_ERR_NONE ; -if (grub_disk_read (array->device[q], sector,0 , size, buf)) +if (grub_disk_read (array->members[q].device, sector,0 , size, buf)) goto quit;grub_raid_block_xor (buf, qbuf, size);
@@ -174,18 +175,18 @@/* Two bad devices */ grub_uint8_t c; -if ((! array->device[p]) || (! array->device[q])) +if ((! array->members[p].device) || (! array->members[q].device)) {grub_error (GRUB_ERR_READ_ERROR ,"not enough disk to restore" ); goto quit; } -if (grub_disk_read (array->device[p], sector,0 , size, buf)) +if (grub_disk_read (array->members[p].device, sector,0 , size, buf)) goto quit;grub_raid_block_xor (pbuf, buf, size); -if (grub_disk_read (array->device[q], sector,0 , size, buf)) +if (grub_disk_read (array->members[q].device, sector,0 , size, buf)) goto quit;grub_raid_block_xor (qbuf, buf, size);
=== modified file 'include/grub/raid.h'
grub/raid.h +10 -6
@@ -22,8 +22,6 @@#include <grub/types.h> -#define GRUB_RAID_MAX_DEVICES 32 -#define GRUB_RAID_LAYOUT_LEFT_ASYMMETRIC 0#define GRUB_RAID_LAYOUT_RIGHT_ASYMMETRIC 1#define GRUB_RAID_LAYOUT_LEFT_SYMMETRIC 2
@@ -32,6 +30,13 @@#define GRUB_RAID_LAYOUT_RIGHT_MASK 1#define GRUB_RAID_LAYOUT_SYMMETRIC_MASK 2 +struct grub_raid_member +{ +grub_disk_t device;/* Array of total_devs devices. */ +grub_disk_addr_t start_sector; +/* Start of each device, in 512 byte sectors. */ +}; +struct grub_raid_array {int number;/* The device number, taken from md_minor so we
@@ -43,16 +48,15 @@grub_size_t chunk_size;/* The size of a chunk, in 512 byte sectors. */ grub_uint64_t disk_size;/* Size of an individual disk, in 512 byte sectors. */ -int index;/* Index of current device. */ +unsigned int index;/* Index of current device. */ int uuid_len;/* The length of uuid. */ char *uuid;/* The UUID of the device. */ /* The following field is setup by the caller. */ char *name;/* That will be "md<number>". */ unsigned int nr_devs;/* The number of devices we've found so far. */ -grub_disk_t device[GRUB_RAID_MAX_DEVICES ];/* Array of total_devs devices. */ -grub_disk_addr_t start_sector[GRUB_RAID_MAX_DEVICES ]; -/* Start of each device, in 512 byte sectors. */ +unsigned int allocated_devs; +struct grub_raid_member *members;struct grub_raid_array *next;#ifdef GRUB_UTIL
Am 2010-10-26 10:58, schrieb Vladimir 'φ-coder/phcoder' Serbinenko:
Quoted 1 line
Please try the attached patch
yes, this patch seems to fix the problem!
thanks!
martin