From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mYlCM-0000tA-6v for mharc-grub-devel@gnu.org; Fri, 08 Oct 2021 04:25:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYlCK-0000rk-Rb for grub-devel@gnu.org; Fri, 08 Oct 2021 04:25:44 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:50522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYlCJ-0001HN-3z for grub-devel@gnu.org; Fri, 08 Oct 2021 04:25:44 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0A9B0223C3; Fri, 8 Oct 2021 08:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1633681539; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ySOuJi0PFzt4BFB14B5/CwHZVxzusiVsj/hDfBqHztU=; b=UPubDUmzymCJMrosIwFuCwPGD02be1dv73CA3g/8vuxziG5BfiZqxRrUyKHEyDhqAxbXrO XA5OYJZ9hUIjkKv9KWUsOPnH4AM+zyBLU6X28ppiNGtP6vcPtWP+TOtB7UNqkcHvCZk9lB GYNrBIUxOTxApRY2N3DyIo7zfqNFugA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1633681539; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ySOuJi0PFzt4BFB14B5/CwHZVxzusiVsj/hDfBqHztU=; b=+GC6J1AFGIq4lvjVaguSzWpUvX6d4iXEOnpCWHNg6iyv2ePq7Nb2/oRHJyKp7/t7ZA93cw eor2TD4noJ3yfHBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D8EA313D3D; Fri, 8 Oct 2021 08:25:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nsfzMoIAYGGZZAAAMHmgww (envelope-from ); Fri, 08 Oct 2021 08:25:38 +0000 Date: Fri, 8 Oct 2021 10:25:37 +0200 From: Petr Vorel To: Kees Cook Cc: Daniel Kiper , grub-devel@gnu.org Subject: Re: [PATCH] osdep/linux: Fix md array device enumeration Message-ID: Reply-To: Petr Vorel References: <20210926020335.2346634-1-kees@ubuntu.com> <20211005163813.3osmfiey5icpltrf@tomti.i.net-space.pl> <20211007233613.GC1162902@outflux.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211007233613.GC1162902@outflux.net> Received-SPF: pass client-ip=195.135.220.28; envelope-from=pvorel@suse.cz; helo=smtp-out1.suse.de 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, 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 autolearn=ham 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: Fri, 08 Oct 2021 08:25:45 -0000 Hi Kees, > 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. ;) Yep, but both of your bug reports are really worth of fixing. > > > > > > + /* 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. Sure, changes in v2 are really minor + already asked to do by Daniel. Thanks! Kind regards, Petr > -Kees