Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q99lv-0004m2-7K for mharc-grub-devel@gnu.org; Tue, 13 Jun 2023 15:33:43 -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 1q99lt-0004lo-Gy for grub-devel@gnu.org; Tue, 13 Jun 2023 15:33:41 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q99lr-0004HA-N0 for grub-devel@gnu.org; Tue, 13 Jun 2023 15:33:41 -0400 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-394c7ba4cb5so2662767b6e.1 for ; Tue, 13 Jun 2023 12:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686684817; x=1689276817; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1iJKtkyHB6GsPw13gDq5H6XYiUqs1rfBeCtdwnPj+fo=; b=I/CAfT6Vi49A4NbM76yod1fNSr2JHqNdn3b8AqQa+27craf/3gMwvHuIghce7r+fwC p1/EHlQPWEcMaq1Ja0vtOJH02ULiImrOEiOZlC0TyxNWOg0BHM84u0ky0/r5Ra0QZHDn vZuTeWI5S4zKT+lPcfTAELw+2sOJCYJD6zvpI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686684817; x=1689276817; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1iJKtkyHB6GsPw13gDq5H6XYiUqs1rfBeCtdwnPj+fo=; b=hb6qUAdbjrxWtp/7PG8BbmE2eH/1fCta1aSLKGHlyks5dfpbTf+jv9OL5ETaaZmYLL aXQbzp42EaC7air5PpzCDkujq8U8pWvPcd2UfZ6w074Uc7mr7F8d25CkAlPnNJ7stIIc MMuSq4oENe+BFmjJm/l8VD17x7oxUQGdVbL6qY/ACeB8zkKSl+WMrNl/Ym4S7VbeeSik 7Zu4gi260Ss/x2LExabBf/T/xA35dfBlo6p/YceSNClixyWFou4JGNvrcDvOZ5LjJuBw JF0L1EF1pRTamT+gU80FAUNmpbRhs7wi+jqfThGacFFU081ZGtdng7xl7dARB5CKPMmv oL6w== X-Gm-Message-State: AC+VfDyOBu2L5CnPI6y9w94LXzZsLV95R72YsoHiBbfKEoL+A86iSlU6 lZ6ntgc/MV6rZrdZXyEBv0vKcg== X-Google-Smtp-Source: ACHHUZ6BPFR/e2zDM+4ykcfY22k4S2dIit4fIj2q5dKlDBE6WC7CJqdJ/3qLFidf/vb3QWODB2Xn8A== X-Received: by 2002:aca:230b:0:b0:394:4642:7148 with SMTP id e11-20020aca230b000000b0039446427148mr8089570oie.48.1686684817675; Tue, 13 Jun 2023 12:33:37 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id u10-20020a170902bf4a00b001b2063d43a7sm10569219pls.249.2023.06.13.12.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 12:33:37 -0700 (PDT) Date: Tue, 13 Jun 2023 12:33:36 -0700 From: Kees Cook To: Julian Andres Klode Cc: grub-devel@gnu.org, Daniel Axtens Subject: Re: [PATCH] Generalize MD_MAX_DISKS to GRUB_MDRAID_MAX_DISKS Message-ID: <202306131233.AFBB8FF7C@keescook> References: <20230613125448.2099443-1-julian.klode@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230613125448.2099443-1-julian.klode@canonical.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::233; envelope-from=keescook@chromium.org; helo=mail-oi1-x233.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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 19:33:41 -0000 On Tue, Jun 13, 2023 at 02:54:48PM +0200, Julian Andres Klode wrote: > 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 Yup, looks good to me. Thanks! Reviewed-by: Kees Cook -Kees > --- > 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 > -- Kees Cook