Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q93YA-0003mU-Bs for mharc-grub-devel@gnu.org; Tue, 13 Jun 2023 08:55:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q93Y2-0003lr-Nj for grub-devel@gnu.org; Tue, 13 Jun 2023 08:55:00 -0400 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q93Y0-0002rC-Mj for grub-devel@gnu.org; Tue, 13 Jun 2023 08:54:58 -0400 Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 6ABBC3F26A for ; Tue, 13 Jun 2023 12:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1686660892; bh=QuSPFto+1t7yvC+8zmISCfe3TorCBMsYXMII4OUGQTM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=iqgb9OkMHtqOfXgXhbHuy9RGrpwnu4mgAL4G8bN1WOKP8BXJiPdNo3T7mjyL6sX+J DkMYPlbVVACbcvkBjCqhELvWINrQ/ewM0ZJifYV4VbJrP1peK6fXacFl2kFAUDlxDY UYw1N+Vj/wGHhMxbvjnH/2PPkC0dhF9vOqQaaLTtliFiDhlrO4OvbHNdFH9h7Syp5g ZptyQz+Drh9txGU8h1R0GJXKi7b/v3OddcgkClYlWdgAskfO4rOLmXFXOtW6Tz9L3B 44oPQhGEwFnabF+H93AJVJKIPqyO7VjCakgP1P5tpT7/KlODzy6FFTr34eTtt4Oaoc 1kRmG1m/CCYRQ== Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2b1e6258204so36877081fa.3 for ; Tue, 13 Jun 2023 05:54:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686660891; x=1689252891; h=content-transfer-encoding:lines:status:mime-version:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QuSPFto+1t7yvC+8zmISCfe3TorCBMsYXMII4OUGQTM=; b=feGHDD1eiy+tfJokCxmyXs6YHAE+EiDgHYMB7s9HTcTNQRjH09SlO9VzIGMpDHmvjK cCKxr1D+KBcfL+YmMvt+YHoqO4/HM4njfYQi570DpB4gO+WtTwzphqOGjhPCKhUkF6N1 2XDWRcXL39JNljLkm++3DN+9Zct3jc2yiOCaKknfNKxe1O/RuS6jl3D6+RRkuoKr4lsP MHBiPIz0jSyB8w7cf2H7qB2sE1heTLnENWttrgKwJubNrXJtQ7azGSTzft01LlagVdIq eJzjTJhOszLOf2o9trU0vyDKr4UZ9aTqmjCYCaABSOHqTCjcZdAQMdJchLEQOSG/hwJ0 oRmA== X-Gm-Message-State: AC+VfDyZlBxFQNP2Tuz61Q9DHYljRvIHtETt30+V0npY2AkuVHatEeqx 24hMaz0rvduYcJ9//muMzzB9tollMp+WGhW81jg/HjGYlKYq7bzwcakubMwTvZzWyOZYKW/n9RF 1q9JCwVLAQEiF8jQHuXmLkSvAcq6Qu7hyb7PN X-Received: by 2002:a2e:3102:0:b0:2b3:4361:87db with SMTP id x2-20020a2e3102000000b002b3436187dbmr67368ljx.27.1686660891386; Tue, 13 Jun 2023 05:54:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lz7K4P1Wh5gy2xQl99NyZualOH7sf7kGJbBuOn9aWrAKDVe9QGRSRzt7PEYz1S8RWe4obng== X-Received: by 2002:a2e:3102:0:b0:2b3:4361:87db with SMTP id x2-20020a2e3102000000b002b3436187dbmr67350ljx.27.1686660891034; Tue, 13 Jun 2023 05:54:51 -0700 (PDT) Received: from jak-t14-g3.. ([2a02:908:2812:7d20::e336]) by smtp.gmail.com with ESMTPSA id w8-20020aa7cb48000000b0051632dc69absm6379207edt.86.2023.06.13.05.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 05:54:50 -0700 (PDT) From: Julian Andres Klode To: grub-devel@gnu.org Cc: Julian Andres Klode , Daniel Axtens , Kees Cook Subject: [PATCH] Generalize MD_MAX_DISKS to GRUB_MDRAID_MAX_DISKS Date: Tue, 13 Jun 2023 14:54:48 +0200 Message-Id: <20230613125448.2099443-1-julian.klode@canonical.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=185.125.188.123; envelope-from=julian.klode@canonical.com; helo=smtp-relay-internal-1.canonical.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Jun 2023 12:55:00 -0000 Move the constant from getroot.c to disk.h and then reuse it 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 Cc: Kees Cook --- grub-core/disk/diskfilter.c | 4 ++-- grub-core/osdep/linux/getroot.c | 12 ++---------- include/grub/disk.h | 10 ++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c index 1c568927b..61a311efd 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -1046,8 +1046,8 @@ 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) + /* We choose not to support more than the specified number of disks. */ + if (nmemb < 1 || nmemb > GRUB_MDRAID_MAX_DISKS) { grub_free (uuid); return NULL; diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c index 9cf037ec2..7dd775d2a 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/include/grub/disk.h b/include/grub/disk.h index 071b2f7df..cbd05e9c7 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -172,6 +172,16 @@ typedef struct grub_disk_memberlist *grub_disk_memberlist_t; /* The maximum number of disk caches. */ #define GRUB_DISK_CACHE_NUM 1021 +/* The maximum number of disks in an mdraid device. + * + * 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 GRUB_MDRAID_MAX_DISKS 4096 + /* The size of a disk cache in 512B units. Must be at least as big as the largest supported sector size, currently 16K. */ #define GRUB_DISK_CACHE_BITS 6 -- 2.40.1