]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commit
libext2fs: fix a extent tree corruption bug in ext2fs_extent_set_bmap()
authorTheodore Ts'o <tytso@mit.edu>
Fri, 6 Jun 2025 13:07:11 +0000 (09:07 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 9 Jun 2025 20:58:08 +0000 (16:58 -0400)
commitf1c141f1b5ff013741483ffb42fab20e755afc46
tree24a86c513a010f598a11f67e417d3a3d8cf2fa04
parent22469000cec543621061e75f26d2bc2a6689cb08
libext2fs: fix a extent tree corruption bug in ext2fs_extent_set_bmap()

In the case where we are moving a particular logical block mapping
from a particular extent tree entry, to the immediately precending
entry (when the physical block or uninitialized flag is changing so it
can be coalesced with the precending entry) and the precending entry
is in a different extent tree block, the resulting extent tree can get
corrupted.

Fix this by removing the original logical block mapping before adding
the new logical block mapping.  Per the warning in the comments before
ext2fs_extents_fix_parents():

  Note a subtlety of this function -- if there happen to be two extents
  mapping the same lblk and someone calls fix_parents on the second of
  the two extents, the position of the extent handle after the call will
  be the second extent if nothing happened, or the first extent if
  something did.  A caller in this situation must use
  ext2fs_extent_goto() after calling this function.  Or simply don't map
  the same lblk with two extents, ever.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
(cherry picked from commit b914701223255c116745a11f30563652c9fdbb4b)
lib/ext2fs/extent.c