Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mYcw3-0008KG-5m for mharc-grub-devel@gnu.org; Thu, 07 Oct 2021 19:36:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYcw2-0008Jc-30 for grub-devel@gnu.org; Thu, 07 Oct 2021 19:36:22 -0400 Received: from mta.outflux.net ([2001:19d0:2:6:c0de:0:736d:7471]:47697 helo=smtp.outflux.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYcvx-0000Tq-Ll for grub-devel@gnu.org; Thu, 07 Oct 2021 19:36:21 -0400 Received: from serenity.outflux.net (serenity.outflux.net [10.2.0.2]) by vinyl.outflux.net (8.15.2/8.15.2/Debian-10) with ESMTP id 197NaDLh022672; Thu, 7 Oct 2021 16:36:14 -0700 Authentication-Results: vinyl.outflux.net; dkim=none; dkim-atps=neutral Date: Thu, 7 Oct 2021 16:36:13 -0700 From: Kees Cook To: Petr Vorel Cc: Daniel Kiper , grub-devel@gnu.org Subject: Re: [PATCH] osdep/linux: Fix md array device enumeration Message-ID: <20211007233613.GC1162902@outflux.net> References: <20210926020335.2346634-1-kees@ubuntu.com> <20211005163813.3osmfiey5icpltrf@tomti.i.net-space.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Ubuntu X-MIMEDefang-Filter: outflux$Revision: 1.316 $ X-HELO: serenity.outflux.net X-Scanned-By: MIMEDefang 2.83 Received-SPF: none client-ip=2001:19d0:2:6:c0de:0:736d:7471; envelope-from=kees@ubuntu.com; helo=smtp.outflux.net X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, FORGED_SPF_HELO=1, KHOP_HELO_FCRDNS=0.399, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Oct 2021 23:36:22 -0000 Hi Petr, On Wed, Oct 06, 2021 at 09:28:32AM +0200, Petr Vorel wrote: > Hi Kees, Daniel, > > > On Sat, Sep 25, 2021 at 07:03:35PM -0700, kees@ubuntu.com wrote: > > > From: Kees Cook > > > > GET_ARRAY_INFO's info.nr_disks does not map to GET_DISK_INFO's > > > disk.number, which is an internal kernel index. If an array has had drives > > > added, removed, etc, there may be gaps in GET_DISK_INFO's results. But > > > since the consumer of devicelist cannot tolerate gaps (it expects to walk > > > a NULL-terminated list of device name strings), the devicelist index (j) > > > must be tracked separately from the disk.number index (i). But grub > > > wants to only examine active (i.e. present and non-failed) disks, so how > > > many disks are left to be queried must be also separately tracked > > > (remaining). > > Kees, thanks a lot for taking care for this. You bet! I seem to find some amazing corner cases. ;) > > > > > + /* Skip empty slot: MD_DISK_REMOVED slots don't count toward nr_disks. */ > > > if (disk.state & (1 << MD_DISK_REMOVED)) > > > continue; > > > + remaining--; > > > > - if (disk.state & (1 << MD_DISK_ACTIVE)) > > > - devicelist[j] = grub_find_device (NULL, > > > - makedev (disk.major, disk.minor)); > > > - else > > > - devicelist[j] = NULL; > > > - j++; > > > + /* Only examine disks that are actively participating in the array. */ > > > + if (!(disk.state & (1 << MD_DISK_ACTIVE))) > > > + continue; > > > + > > > + devicelist[j++] = grub_find_device (NULL, makedev (disk.major, > > > + disk.minor)); > > > I would prefer if you leave original if statement as is and update > > grub_find_device() call accordingly... And of course drop else as > > needed... :-) > I suppose you'll need to send v2 due this, but for now: > > Reviewed-by: Petr Vorel Thanks! I've included your reviewed-by in the v2; hopefully that's okay as the changes were just stylistic. -Kees -- Kees Cook