disk: Generalize MD_MAX_DISKS to GRUB_MDRAID_MAX_DISKS

Move the constant from grub-core/osdep/linux/getroot.c to
include/grub/disk.h and then reuse it in place of the
hardcoded 1024 limit in diskfilter.

Fixes: 2a5e3c1f2 (disk/diskfilter: Don't make a RAID array with more than 1024 disks)

Cc: Daniel Axtens <dja@axtens.net>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Julian Andres Klode authored and Daniel Kiper committed 2023-06-23 00:50:38 +02:00
1 parent 87247635c0
commit b2c72f4641
3 files changed
+15 -12

No files matched your search

+2 -10
View File
@@ -44,6 +44,7 @@
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/disk.h>
#include <grub/emu/misc.h>
#include <grub/emu/hostdisk.h>
#include <grub/emu/getroot.h>
@@ -130,15 +131,6 @@ struct mountinfo_entry
char fstype[ESCAPED_PATH_MAX + 1], device[ESCAPED_PATH_MAX + 1];
};
/*
* GET_DISK_INFO nr_disks (total count) does not map to disk.number,
* which is an internal kernel index. Instead, do what mdadm does
* and keep scanning until we find enough valid disks. The limit is
* copied from there, which notes that it is sufficiently high given
* that the on-disk metadata for v1.x can only support 1920.
*/
#define MD_MAX_DISKS 4096
static char **
grub_util_raid_getmembers (const char *name, int bootable)
{
@@ -176,7 +168,7 @@ grub_util_raid_getmembers (const char *name, int bootable)
devicelist = xcalloc (info.nr_disks + 1, sizeof (char *));
remaining = info.nr_disks;
for (i = 0, j = 0; i < MD_MAX_DISKS && remaining > 0; i++)
for (i = 0, j = 0; i < GRUB_MDRAID_MAX_DISKS && remaining > 0; i++)
{
disk.number = i;
ret = ioctl (fd, GET_DISK_INFO, &disk);