]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
disk/diskfilter: Don't make a RAID array with more than 1024 disks
authorDaniel Axtens <dja@axtens.net>
Wed, 19 Oct 2022 09:23:22 +0000 (20:23 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 27 Oct 2022 18:10:18 +0000 (20:10 +0200)
This is "belt and braces" with commit 12e20a6a695f (disk/diskfilter:
Check calloc() result for NULL): we end up trying to use too much memory
in situations like corrupted Linux software RAID setups purporting to
use 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 <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/disk/diskfilter.c

index 4ac50320ef4e8832556a096d1bc62e9784bfa106..1c568927b8bac3c0eb9958b12ffe9a2b5ea38e9d 100644 (file)
@@ -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 < 1 || nmemb > 1024)
+    {
+      grub_free (uuid);
+      return NULL;
+    }
+
   switch (level)
     {
     case 1: