Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Elkin Cruz <elkin@google.com>, David Sterba <dsterba@suse.com>,
	Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Chris Mason <mason@kernel.org>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, irogers@google.com, stable@vger.kernel.org
Subject: Re: [PATCH v2] btrfs: tree-checker: verify tree_block_info bounds in check_extent_item()
Date: Thu, 26 Nov 2026 11:47:02 +1030	[thread overview]
Message-ID: <03dd7e64-2357-4e8a-9383-d748b4883efa@suse.com> (raw)
In-Reply-To: <20261126004332.1712403-1-elkin@google.com>



在 2026/11/26 11:13, Elkin Cruz 写道:
> check_extent_item() only verifies item_size >= sizeof(*ei) before
> reading struct btrfs_tree_block_info on non-skinny tree block extent
> items (BTRFS_EXTENT_ITEM_KEY with BTRFS_EXTENT_FLAG_TREE_BLOCK). A
> crafted filesystem image with 24 <= item_size < 42 causes
> btrfs_tree_block_level() to read past the item and potentially past the
> extent buffer's populated folios.
> 
> Verify ptr + sizeof(*info) <= end before accessing
> btrfs_tree_block_info, matching the inline ref bounds checks below.
> 
> Fixes: f82d1c7ca8ae ("btrfs: tree-checker: Add EXTENT_ITEM and METADATA_ITEM check")
> Cc: stable@vger.kernel.org
> Signed-off-by: Elkin Cruz <elkin@google.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Will push to for-next soon.

Thanks,
Qu

> ---
> 
> Changes in v2:
> - Use (ptr + sizeof(*info) > end) with matching extent_err() format to
>    follow the existing pattern in check_extent_item(), thanks to Qu
>    Wenruo for the review.
> 
> v1: https://lore.kernel.org/r/20261125221849.1424464-1-elkin@google.com
> 
> I am trying out new Clang static analysis checks for kernel bug
> classes, and they flagged this code as possibly buggy. The findings
> were triaged/fixed and commit descriptions were drafted with help of AI,
> then checked against linux-next (not runtime-tested on hardware).
> 
> Thanks,
> Elkin
> 
>   fs/btrfs/tree-checker.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
> index d2bf21c7b848..40f2355cbb1d 100644
> --- a/fs/btrfs/tree-checker.c
> +++ b/fs/btrfs/tree-checker.c
> @@ -1665,6 +1665,12 @@ static int check_extent_item(struct extent_buffer *leaf,
>   	if (is_tree_block && key->type != BTRFS_METADATA_ITEM_KEY) {
>   		struct btrfs_tree_block_info *info;
>   
> +		if (unlikely(ptr + sizeof(*info) > end)) {
> +			extent_err(leaf, slot,
> +				   "tree block info overflows extent item, ptr %lu info size %zu end %lu",
> +				   ptr, sizeof(*info), end);
> +			return -EUCLEAN;
> +		}
>   		info = (struct btrfs_tree_block_info *)ptr;
>   		if (unlikely(btrfs_tree_block_level(leaf, info) >= BTRFS_MAX_LEVEL)) {
>   			extent_err(leaf, slot,


      reply	other threads:[~2026-11-26  1:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  0:43 [PATCH v2] btrfs: tree-checker: verify tree_block_info bounds in check_extent_item() Elkin Cruz
2026-11-26  1:17 ` Qu Wenruo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=03dd7e64-2357-4e8a-9383-d748b4883efa@suse.com \
    --to=wqu@suse.com \
    --cc=dsterba@suse.com \
    --cc=elkin@google.com \
    --cc=irogers@google.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mason@kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox