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 04E92C00A8F for ; Tue, 24 Oct 2023 06:47:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvBCA-0000ne-6p; Tue, 24 Oct 2023 02:47:18 -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 1qvBC8-0000n9-IV for grub-devel@gnu.org; Tue, 24 Oct 2023 02:47:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvBC6-0007FC-8H for grub-devel@gnu.org; Tue, 24 Oct 2023 02:47:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698130032; 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=qwPu9w+Z9hS5glrfH724iwrmlvK3IN2VPpHS4KbTYB8=; b=MMuZvyxVrUF/rilCLY2yiBZKBdDiH+rSLDp74Y4ccQqA9X/TDislYjCphZPigEp4dvbtHN pz0PM2ZM5OSBc2vDVHkt0HdAYy/uJRpdlNG+czmQglic7/z6I86ZxmXGwsLQ+MkH/wbWR4 cDOHAZKx74vIfFy3goCAmmrQcVTNwf8= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-QUP0-xHgPO6_zX9YsvSZeQ-1; Tue, 24 Oct 2023 02:46:07 -0400 X-MC-Unique: QUP0-xHgPO6_zX9YsvSZeQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-778a455f975so540218185a.1 for ; Mon, 23 Oct 2023 23:46:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698129967; x=1698734767; 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=qwPu9w+Z9hS5glrfH724iwrmlvK3IN2VPpHS4KbTYB8=; b=AcitI+D8DA/pQ2Nk5sW+ZhzeChjvN6FcVqF4j/olutisjSzzRfiG48J5mciW3CjxO3 37/NMsMnF53brTPk0pTd5fwQeMs8acZhiwBA5JC6d9fipU61a94qrEvIFJ6foa2IMSuO H26EmOpCUcnR3NPqO/vXdMgLZgZ4H9YiImLWyNjiIr+PFYDEIT+hxVURaLkpUXImMiN7 +IgBSER7g2EmsKBoH9xP9zVLvMhTfzp5QelQQaS+v+Ame7K/elDDrRzgg+6FD3BS4adl k/7mjVhFiO/T8E7WZd82Yxf+j7iCmJIft915WdhCZdP97IiNrhr5kMHmSAjD0uMOWlFK Wthg== X-Gm-Message-State: AOJu0YxzqIQKsFbAFuXyL3fIas9gYAXE6aX3H9yvRRqof1RFz6nb8m/F wCZPIhkNHxUv2c8oFUzKqZmZ36sacFUE5slXJGew4/emA7ihX7nak1H4BxXuzxInj6BqqvB45O0 XByPYdLFVa0ad55ERSeqFiwoiq4UP/wO48YSC4AvCAgE0/fdYCq6oTGzVaiYDaCMx7FtIjLLb+Q == X-Received: by 2002:a05:620a:460b:b0:778:ba73:1650 with SMTP id br11-20020a05620a460b00b00778ba731650mr8104513qkb.30.1698129966896; Mon, 23 Oct 2023 23:46:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVTDf4CWUhr+kuEvENuL5tNMO6NE+YGs0xtn3o65OGrYCBChrv3+0GxzuwUFUUatXc535R/A== X-Received: by 2002:a05:620a:460b:b0:778:ba73:1650 with SMTP id br11-20020a05620a460b00b00778ba731650mr8104489qkb.30.1698129966393; Mon, 23 Oct 2023 23:46:06 -0700 (PDT) Received: from [10.202.144.205] (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id d21-20020a05620a141500b0076f12fcb0easm3259070qkj.2.2023.10.23.23.46.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Oct 2023 23:46:06 -0700 (PDT) Message-ID: <3dc55417-14f1-200b-982c-47a6469dfcb8@redhat.com> Date: Tue, 24 Oct 2023 08:46:03 +0200 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 v4] fs/xfs: Fix XFS directory extent parsing To: The development of GNU GRUB , Daniel Kiper , Jon DeVree , sebastian@breakpoint.cc Cc: lidong.chen@oracle.com References: <20231018030347.36174-1-nuxi@vault24.org> <20231018162325.4cfbohhcblkq3qzn@tomti.i.net-space.pl> From: Marta Lewandowska In-Reply-To: <20231018162325.4cfbohhcblkq3qzn@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.133.124; envelope-from=mlewando@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.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, HTML_MESSAGE=0.001, NICE_REPLY_A=-3.339, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.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="===============5535778563394040946==" 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. --===============5535778563394040946== Content-Type: multipart/alternative; boundary="------------h6d0Lsna3ho6BcgwDfi9OIp8" Content-Language: en-US This is a multi-part message in MIME format. --------------h6d0Lsna3ho6BcgwDfi9OIp8 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, I also applied both patches, and tested them on aarch64, ppc64le, and on x64 UEFI and BIOS. Machines were all able to boot, and ournormal gating tests passed. -marta On 10/18/23 18:23, Daniel Kiper wrote: > Adding Marta and Sebastian... > > On Tue, Oct 17, 2023 at 11:03:47PM -0400, Jon DeVree wrote: >> The XFS directory entry parsing code has never been completely correct >> for extent based directories. The parser correctly handles the case >> where the directory is contained in a single extent, but then mistakenly >> assumes the data blocks for the multiple extent case are each identical >> to the single extent case. The difference in the format of the data >> blocks between the two cases is tiny enough that its gone unnoticed for >> a very long time. >> >> A recent change introduced some additional bounds checking into the XFS >> parser. Like GRUB's existing parser, it is correct for the single extent >> case but incorrect for the multiple extent case. When parsing a >> directory with multiple extents, this new bounds checking is sometimes >> (but not always) tripped and triggers an "invalid XFS diretory entry" >> error. This probably would have continued to go unnoticed but the >> /boot/grub/ directory is large enough that it often has multiple >> extents. >> >> The difference between the two cases is that when there are multiple >> extents, the data blocks do not contain a trailer nor do they contain >> any leaf information. That information is stored in a separate set of >> extents dedicated to just the leaf information. These extents come after >> the directory entry extents and are not included in the inode size. So >> the existing parser already ignores the leaf extents. >> >> The only reason to read the trailer/leaf information at all is so that >> the parser can avoid misinterpreting that data as directory entries. So >> this updates the parser as follows: >> >> For the single extent case the parser doesn't change much: >> 1. Read the size of the leaf information from the trailer >> 2. Set the end pointer for the parser to the start of the leaf >> information. (The previous bounds checking set the end pointer to the >> start of the trailer, so this is actually a small improvement.) >> 3. Set the entries variable to the expected number of directory entries. >> >> For the multiple extent case: >> 1. Set the end pointer to the end of the block. >> 2. Do not set up the entries variable. Figuring out how many entries are >> in each individual block is complex and does not seem worth it when >> it appears to be safe to just iterate over the entire block. >> >> The bounds check itself was also dependent upon the faulty XFS parser >> because it accidentally used "filename + length - 1". Presumably this >> was able to pass the fuzzer because in the old parser there was always 8 >> bytes of slack space between the tail pointer and the actual end of the >> block. Since this is no longer the case the bounds check needs to be >> updated to "filename + length + 1" in order to prevent a regressionn in >> the handling of corrupt fliesystems. >> >> Notes: >> * When there is only one extent there will only ever be one block. If >> more than one block is required then XFS will always switch to holding >> leaf information in a separate extent. >> * B-tree based directories seems to be parsed properly by the same code >> that handles multiple extents. This is unlikely to ever occur within >> /boot though because its only used when there are an extremely large >> number of directory entries. >> >> Fixes: ef7850c75 (fs/xfs: Fix issues found while fuzzing the XFS filesystem) >> Fixes: b2499b29c (Adds support for the XFS filesystem.) >> Fixes:https://savannah.gnu.org/bugs/?64376 >> >> Signed-off-by: Jon DeVree > Reviewed-by: Daniel Kiper > > Jon, thank you for fixing this issue. > > Marta, Sebastian, could you test this patch and patch [1] together? > > Daniel > > [1]https://lore.kernel.org/grub-devel/ZS9H5exHL1g3aK37@feynman.vault24.org/T/#m57b1df94e2df65aaff444a89eec3b543184b6f07 > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel --------------h6d0Lsna3ho6BcgwDfi9OIp8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi,

I also applied both patches, and tested them on aarch64, ppc64le, and
on x64 UEFI and BIOS. Machines were all able to boot, and our normal
gating tests passed.


-marta


On 10/18/23 18:23, Daniel Kiper wrote:
Adding Marta and Sebastian...

On Tue, Oct 17, 2023 at 11:03:47PM -0400, Jon DeVree wrote:
The XFS directory entry parsing code has never been completely correct
for extent based directories. The parser correctly handles the case
where the directory is contained in a single extent, but then mistakenly
assumes the data blocks for the multiple extent case are each identical
to the single extent case. The difference in the format of the data
blocks between the two cases is tiny enough that its gone unnoticed for
a very long time.

A recent change introduced some additional bounds checking into the XFS
parser. Like GRUB's existing parser, it is correct for the single extent
case but incorrect for the multiple extent case. When parsing a
directory with multiple extents, this new bounds checking is sometimes
(but not always) tripped and triggers an "invalid XFS diretory entry"
error. This probably would have continued to go unnoticed but the
/boot/grub/<arch> directory is large enough that it often has multiple
extents.

The difference between the two cases is that when there are multiple
extents, the data blocks do not contain a trailer nor do they contain
any leaf information. That information is stored in a separate set of
extents dedicated to just the leaf information. These extents come after
the directory entry extents and are not included in the inode size. So
the existing parser already ignores the leaf extents.

The only reason to read the trailer/leaf information at all is so that
the parser can avoid misinterpreting that data as directory entries. So
this updates the parser as follows:

For the single extent case the parser doesn't change much:
1. Read the size of the leaf information from the trailer
2. Set the end pointer for the parser to the start of the leaf
   information. (The previous bounds checking set the end pointer to the
   start of the trailer, so this is actually a small improvement.)
3. Set the entries variable to the expected number of directory entries.

For the multiple extent case:
1. Set the end pointer to the end of the block.
2. Do not set up the entries variable. Figuring out how many entries are
   in each individual block is complex and does not seem worth it when
   it appears to be safe to just iterate over the entire block.

The bounds check itself was also dependent upon the faulty XFS parser
because it accidentally used "filename + length - 1". Presumably this
was able to pass the fuzzer because in the old parser there was always 8
bytes of slack space between the tail pointer and the actual end of the
block. Since this is no longer the case the bounds check needs to be
updated to "filename + length + 1" in order to prevent a regressionn in
the handling of corrupt fliesystems.

Notes:
* When there is only one extent there will only ever be one block. If
  more than one block is required then XFS will always switch to holding
  leaf information in a separate extent.
* B-tree based directories seems to be parsed properly by the same code
  that handles multiple extents. This is unlikely to ever occur within
  /boot though because its only used when there are an extremely large
  number of directory entries.

Fixes: ef7850c75 (fs/xfs: Fix issues found while fuzzing the XFS filesystem)
Fixes: b2499b29c (Adds support for the XFS filesystem.)
Fixes: https://savannah.gnu.org/bugs/?64376

Signed-off-by: Jon DeVree <nuxi@vault24.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Jon, thank you for fixing this issue.

Marta, Sebastian, could you test this patch and patch [1] together?

Daniel

[1] https://lore.kernel.org/grub-devel/ZS9H5exHL1g3aK37@feynman.vault24.org/T/#m57b1df94e2df65aaff444a89eec3b543184b6f07

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
--------------h6d0Lsna3ho6BcgwDfi9OIp8-- --===============5535778563394040946== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --===============5535778563394040946==--