diskfilter: check calloc() result for NULL
PATCH 1/2 diskfilter: check calloc() result for NULL
With wildly corrupt inputs, we can end up trying to calloc a very large amount of memory, which will fail and give us a NULL pointer. We need to check that to avoid a crash. (And, even if we blocked such inputs, it is good practice to check the results of allocations anyway.)
--- grub-core/disk/diskfilter.c | 3 +++ 1 file changed, 3 insertions(+)
grub-core/disk/diskfilter.c +3 -0
@@ -1163,6 +1163,9 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, array->lvs->segments->raid_member_size = disk_size; array->lvs->segments->nodes =grub_calloc (nmemb,sizeof (array->lvs->segments->nodes[0 ])); +if (array->lvs->segments->nodes ==NULL ) + goto fail; + array->lvs->segments->stripe_size = stripe_size;for (i =0 ; i < nmemb; i++) {
Signature · 1 line
2.25.1
PATCH 2/2 diskfilter: don't make a RAID array with more than 1024 disks
This is 'belt and braces' with the last fix: we end up trying to use too much memory in situations like corrupted Linux software raid setups purporting to usew a huge number of disks. Simply refuse to permit such configurations.
1024 is a bit arbitrary, yes, and I feel a bit like I'm tempting fate here, but I think 1024 disks in an array (that grub has to read to boot!) should be enough for anyone.
--- grub-core/disk/diskfilter.c | 7 +++++++ 1 file changed, 7 insertions(+)
grub-core/disk/diskfilter.c +7 -0
@@ -1046,6 +1046,13 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb,struct grub_diskfilter_pv *pv;grub_err_t err; +/* We choose not to support more than 1024 disks */ +if (nmemb >1024 ) + { +grub_free (uuid); +return NULL ; + } +switch (level) {case 1 :
Signature · 1 line
2.25.1
Re: [PATCH 2/2] diskfilter: don't make a RAID array with more than 1024 disks
Quoted 19 lines · Daniel Axtens
This is 'belt and braces' with the last fix: we end up trying to use too much memory in situations like corrupted Linux software raid setups purporting to usew a huge number of disks. Simply refuse to permit such configurations.
1024 is a bit arbitrary, yes, and I feel a bit like I'm tempting fate here, but I think 1024 disks in an array (that grub has to read to boot!) should be enough for anyone.
Signed-off-by Daniel Axtens <[email protected]>--- grub-core/disk/diskfilter.c | 7 +++++++ 1 file changed, 7 insertions(+)grub-core/disk/diskfilter.c +0
-0
grub-core/disk/diskfilter.c grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, · line 1050
Quoted 5 lines
grub-core/disk/diskfilter.c +2
-0@@ -1046,6 +1046,13 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb,struct grub_diskfilter_pv *pv;grub_err_t err; +/* We choose not to support more than 1024 disks */ +if (nmemb >1024 )
Ergh, nmemb is an int; I will do a v2 that also checks that it's greater than 0 (or 1, given that it's RAID? I will do some tests.)
-- d
Re: [PATCH 2/2] diskfilter: don't make a RAID array with more than 1024 disks
Quoted 24 lines · Daniel Axtens
Quoted 22 lines · Daniel Axtens
This is 'belt and braces' with the last fix: we end up trying to use too much memory in situations like corrupted Linux software raid setups purporting to usew a huge number of disks. Simply refuse to permit such configurations.
1024 is a bit arbitrary, yes, and I feel a bit like I'm tempting fate here, but I think 1024 disks in an array (that grub has to read to boot!) should be enough for anyone.
Signed-off-by Daniel Axtens <[email protected]>--- grub-core/disk/diskfilter.c | 7 +++++++ 1 file changed, 7 insertions(+)grub-core/disk/diskfilter.c +0
-0@@ -1046,6 +1046,13 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb,struct grub_diskfilter_pv *pv;grub_err_t err;
Quoted 5 lines
grub-core/disk/diskfilter.c grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, · line 1050
Quoted 2 lines
grub-core/disk/diskfilter.c +2
-0+/* We choose not to support more than 1024 disks */ +if (nmemb >1024 )Ergh, nmemb is an int; I will do a v2 that also checks that it's greater than 0 (or 1, given that it's RAID? I will do some tests.)
Could you repost this patch with the fix? Or both with my RB for first one...
Daniel
Quoted 7 lines · Daniel Axtens
With wildly corrupt inputs, we can end up trying to calloc a very large amount of memory, which will fail and give us a NULL pointer. We need to check that to avoid a crash. (And, even if we blocked such inputs, it is good practice to check the results of allocations anyway.)
Signed-off-by Daniel Axtens <[email protected]>
Daniel