]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
btrfs: fix wrong length parameter for btrfs_cleanup_ordered_extents()
authorQu Wenruo <wqu@suse.com>
Sun, 20 Jul 2025 05:31:39 +0000 (15:01 +0930)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Aug 2025 16:36:32 +0000 (18:36 +0200)
commit8b212f605a89b3d348064017e5cfa62020e2497c
tree8f74b99d63253a3b8d1b0cfbf18a5b949d75da9d
parent26a1409686ae8ca54d242cbd6e862a076dba1c08
btrfs: fix wrong length parameter for btrfs_cleanup_ordered_extents()

commit deaf895212da74635a7f0a420e1ecf8f5eca1fe5 upstream.

Inside nocow_one_range(), if the checksum cloning for data reloc inode
failed, we call btrfs_cleanup_ordered_extents() to cleanup the just
allocated ordered extents.

But unlike extent_clear_unlock_delalloc(),
btrfs_cleanup_ordered_extents() requires a length, not an inclusive end
bytenr.

This can be problematic, as the @end is normally way larger than @len.

This means btrfs_cleanup_ordered_extents() can be called on folios
out of the correct range, and if the out-of-range folio is under
writeback, we can incorrectly clear the ordered flag of the folio, and
trigger the DEBUG_WARN() inside btrfs_writepage_cow_fixup().

Fix the wrong parameter with correct length instead.

Fixes: 94f6c5c17e52 ("btrfs: move ordered extent cleanup to where they are allocated")
CC: stable@vger.kernel.org # 6.15+
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/inode.c