Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11D87C4829E for ; Thu, 15 Feb 2024 15:04:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1radHm-0006dC-4W; Thu, 15 Feb 2024 10:04:26 -0500 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 1radHj-0006cx-L2 for grub-devel@gnu.org; Thu, 15 Feb 2024 10:04:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1radHh-0002JA-6l for grub-devel@gnu.org; Thu, 15 Feb 2024 10:04:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708009458; h=from:from:reply-to:subject:subject: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=d62kgDTseFNr5rPcSbSf4Bzlmq9eSIZ5BhNfnK7tFus=; b=JSwlDjGrak2WRLF3IISDsChK9LiHO6wKQbz4dCMD+1FKcHcF+hlaU06FOPKBWGeRDGULQC 7ofFoprB/fjHEhbibq0I4pZ+90OPO10i5TNgcPiHrSTY3s3QC4NZy9cZkav+Sv9j1kb+wl CU5aDhAvI2HcuKQZ5YzgXh3Z0bpiCQA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-QKGkqhojMqa2wi6dHxyWew-1; Thu, 15 Feb 2024 10:03:11 -0500 X-MC-Unique: QKGkqhojMqa2wi6dHxyWew-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-33d0d313b81so194475f8f.3 for ; Thu, 15 Feb 2024 07:03:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708009390; x=1708614190; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=d62kgDTseFNr5rPcSbSf4Bzlmq9eSIZ5BhNfnK7tFus=; b=ccmwJrtsCdFZST8kEbOA4xicZtJGxumT+8tCBbyYA+wmMb7QIyMLlLGJYYrvPtFU6c /zgIJPerAusAKwhCWGV8tWp/lFA43ZZNuf/xIEKkIOuclkCf2vRD3Nz/j705EAF8BRHz CL1QvPzVmJJKeuoOXl+L6jpLO6UwAoSflA+w/JD2hn9rV0wvFsJi6Tzu0zIk41YWo8xp jYoPPHtLOoOv/bcNtDvDfFnfLe/rkEzg1RDpeLlo5qiQ6TUoc3Fmk5ylPVq7CFJiBDPp A8bi2WtHayuWbxRA4h6GLbaL8tiKCOIlPIMuD71yTDgzr3XoqXK9JWpv0ejBuR+3YwrZ Hegg== X-Gm-Message-State: AOJu0YwNFqM6URNFfqjCjQ79c1rHZLDuGAT5m6AR7wkyiW+6sxijITR8 +7ZTt5TDq7IIbarojRrp/WLeMSlle2RSSy5sfQhc89p8G7qG4bcv5dPOdaxDkTVgyMuvN9vTAfy S2rDDScWowi2u64AFiyHePQ2v5Yv85Zl7q4/q9f2OFxVqJ3g7 X-Received: by 2002:adf:e70a:0:b0:33b:697c:1fc6 with SMTP id c10-20020adfe70a000000b0033b697c1fc6mr1459615wrm.20.1708009390266; Thu, 15 Feb 2024 07:03:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFagkxB4LUKLw5wZPSGGAb78fwOU71eUFFz7j2q8ekeLujhKxI4QA94P0Z4zrMYHbDAvyM7SQ== X-Received: by 2002:adf:e70a:0:b0:33b:697c:1fc6 with SMTP id c10-20020adfe70a000000b0033b697c1fc6mr1459600wrm.20.1708009389890; Thu, 15 Feb 2024 07:03:09 -0800 (PST) Received: from ?IPV6:2a02:8308:a186:8d00:a5ab:f27f:909d:d7d7? ([2a02:8308:a186:8d00:a5ab:f27f:909d:d7d7]) by smtp.gmail.com with ESMTPSA id n18-20020a5d67d2000000b0033cf0f5a01fsm1997889wrw.33.2024.02.15.07.03.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Feb 2024 07:03:09 -0800 (PST) Message-ID: <038f4870-eace-7a44-24b7-ad468bc30688@redhat.com> Date: Thu, 15 Feb 2024 16:03:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] fs/xfs: Handle non-continuous data blocks in directory extents To: Daniel Kiper , Jon DeVree , nfrayer@redhat.com, phcoder@gmail.com, sebastian@breakpoint.cc Cc: grub-devel@gnu.org References: <20240211153457.31786-2-nuxi@vault24.org> <20240215135118.7tnaqehjvydtudss@tomti.i.net-space.pl> From: Marta Lewandowska In-Reply-To: <20240215135118.7tnaqehjvydtudss@tomti.i.net-space.pl> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Received-SPF: pass client-ip=170.10.129.124; envelope-from=mlewando@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -61 X-Spam_score: -6.2 X-Spam_bar: ------ X-Spam_report: (-6.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.772, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, NICE_REPLY_A=-3.337, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: , Reply-To: The development of GNU GRUB Content-Type: multipart/mixed; boundary="===============4511066187764394180==" Errors-To: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org Sender: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org This is a multi-part message in MIME format. --===============4511066187764394180== Content-Type: multipart/alternative; boundary="------------3061owqzJEc6cKMbl4uAi27f" Content-Language: en-US This is a multi-part message in MIME format. --------------3061owqzJEc6cKMbl4uAi27f Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Thank you, Jon. I am also happy to test. Nicolas and I are all too familiar with this now! -marta On 2/15/24 14:51, Daniel Kiper wrote: > Adding Marta, Nicolas, Sebastian and Vladimir... > > Jon, thank you for the patch! > > Marta, Nicolas and Sebastian, may I ask you to run tests with this fix? > > Daniel > > On Sun, Feb 11, 2024 at 10:34:58AM -0500, Jon DeVree wrote: >> The directory extent list does not have to be a continuous list of data >> blocks. When GRUB tries to read a non-existant member of the list, >> grub_xfs_read_file() will return a block of zero'ed memory. Checking for >> a zero'ed magic number is sufficient to skip this non-existant data >> block. >> >> Prior to commit 07318ee7e this was handled as a subtle side effect of >> reading the (non-existant) tail data structure. Since the block was >> zero'ed the computation of the number of directory entries in the block >> would return 0 as well. >> >> Fixes: 07318ee7e (fs/xfs: Fix XFS directory extent parsing) >> Fixes:https://bugzilla.redhat.com/show_bug.cgi?id=2254370 >> Signed-off-by: Jon DeVree >> --- >> grub-core/fs/xfs.c | 10 ++++++++++ >> 1 file changed, 10 insertions(+) >> >> diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c >> index bc2224dbb..a6cce9cfe 100644 >> --- a/grub-core/fs/xfs.c >> +++ b/grub-core/fs/xfs.c >> @@ -902,6 +902,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, >> grub_xfs_first_de(dir->data, dirblock); >> int entries = -1; >> char *end = dirblock + dirblk_size; >> + grub_uint32_t magic; >> >> numread = grub_xfs_read_file (dir, 0, 0, >> blk << dirblk_log2, >> @@ -912,6 +913,15 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, >> return 0; >> } >> >> + /* >> + * If this data block isn't actually part of the extent list then >> + * grub_xfs_read_file() returns a block of zeros. So if the magic number >> + * field is all zeros then this block should be skipped. >> + */ >> + magic = *(grub_uint32_t *)dirblock; >> + if (!magic) >> + continue; >> + >> /* >> * Leaf and tail information are only in the data block if the number >> * of extents is 1. >> -- >> 2.43.0 --------------3061owqzJEc6cKMbl4uAi27f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Thank you, Jon. I am also happy to test. Nicolas and I are all too familiar with this now!

-marta


On 2/15/24 14:51, Daniel Kiper wrote:
Adding Marta, Nicolas, Sebastian and Vladimir...

Jon, thank you for the patch!

Marta, Nicolas and Sebastian, may I ask you to run tests with this fix?

Daniel

On Sun, Feb 11, 2024 at 10:34:58AM -0500, Jon DeVree wrote:
The directory extent list does not have to be a continuous list of data
blocks. When GRUB tries to read a non-existant member of the list,
grub_xfs_read_file() will return a block of zero'ed memory. Checking for
a zero'ed magic number is sufficient to skip this non-existant data
block.

Prior to commit 07318ee7e this was handled as a subtle side effect of
reading the (non-existant) tail data structure. Since the block was
zero'ed the computation of the number of directory entries in the block
would return 0 as well.

Fixes: 07318ee7e (fs/xfs: Fix XFS directory extent parsing)
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2254370
Signed-off-by: Jon DeVree <nuxi@vault24.org>
---
 grub-core/fs/xfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
index bc2224dbb..a6cce9cfe 100644
--- a/grub-core/fs/xfs.c
+++ b/grub-core/fs/xfs.c
@@ -902,6 +902,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
 					grub_xfs_first_de(dir->data, dirblock);
 	    int entries = -1;
 	    char *end = dirblock + dirblk_size;
+	    grub_uint32_t magic;

 	    numread = grub_xfs_read_file (dir, 0, 0,
 					  blk << dirblk_log2,
@@ -912,6 +913,15 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
 	        return 0;
 	      }

+	    /*
+	     * If this data block isn't actually part of the extent list then
+	     * grub_xfs_read_file() returns a block of zeros. So if the magic number
+	     * field is all zeros then this block should be skipped.
+	     */
+	    magic = *(grub_uint32_t *)dirblock;
+	    if (!magic)
+	      continue;
+
 	    /*
 	     * Leaf and tail information are only in the data block if the number
 	     * of extents is 1.
--
2.43.0

    
--------------3061owqzJEc6cKMbl4uAi27f-- --===============4511066187764394180== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --===============4511066187764394180==--