FAILED: patch "[PATCH] udf: fix preallocation discarding before an empty allocation extent" failed to apply to 5.15-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 0c52750caaaccee8b0e929450fe6538ec4985722
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 0c52750caaaccee8b0e929450fe6538ec4985722 Mon Sep 17 00:00:00 2001
From: Matthias Goergens <[email protected]>
Date: Fri, 30 Oct 2026 22:05:36 +0800
Subject: [PATCH] udf: fix preallocation discarding before an empty allocation
extent
udf_discard_prealloc() finds the last extent of a file by peeking at the next one with udf_next_aext() and stopping when that returns 0. The peek reads into eloc and elen, and the code then uses them as the last extent. But when udf_next_aext() returns 0 they hold no defined
value: if the extent list ends in a continuation descriptor that leads to an empty allocation extent, they describe that continuation, i.e. the block of the empty allocation extent, one block long.
The kernel creates such lists itself: when udf_delete_aext() removes the only descriptor of the last allocation extent in a list, it leaves that allocation extent empty and the continuation to it in place.
If the last extent is a preallocation, udf_discard_prealloc() deletes it with udf_delete_aext(), which finds the following allocation extent empty, so it also removes the continuation and frees that allocation extent's block. udf_discard_prealloc() then frees eloc and elen: that block a second time, instead of the preallocated blocks. On a space bitmap the preallocated blocks leak and the free block count drifts. On an unallocated space table the second free adds a second free extent for the same block, which is later handed out twice: fsx as run by generic/091 and generic/263 ends up with two parts of its test file in one block and reads back bad data.
Peek into separate variables, so that eloc and elen keep the last extent that udf_next_aext() returned with 1.
--- fs/udf/truncate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/udf/truncate.c +4 -3
@@ -124,8 +124,8 @@ void udf_discard_prealloc(struct inode *inode) {struct extent_position epos = {};struct extent_position prev_epos = {}; -struct kernel_lb_addr eloc; -uint32_t elen; +struct kernel_lb_addr eloc, tmpeloc; +uint32_t elen, tmpelen;uint64_t lbcount =0 ;int8_t etype =-1 ;struct udf_inode_info *iinfo =UDF_I (inode);
@@ -141,7 +141,8 @@ void udf_discard_prealloc(struct inode *inode)/* Find the last extent in the file */ while (1 ) { - ret =udf_next_aext (inode, &epos, &eloc, &elen, &tmpetype,0 ); + ret =udf_next_aext (inode, &epos, &tmpeloc, &tmpelen, + &tmpetype,0 );if (ret <0 ) goto out;if (ret ==0 )
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 udf: fix preallocation discarding before an empty allocation extent
From: Matthias Goergens <[email protected]>
[ Upstream commit 0c52750caaaccee8b0e929450fe6538ec4985722 ]
udf_discard_prealloc() finds the last extent of a file by peeking at the next one with udf_next_aext() and stopping when that returns 0. The peek reads into eloc and elen, and the code then uses them as the last extent. But when udf_next_aext() returns 0 they hold no defined
value: if the extent list ends in a continuation descriptor that leads to an empty allocation extent, they describe that continuation, i.e. the block of the empty allocation extent, one block long.
The kernel creates such lists itself: when udf_delete_aext() removes the only descriptor of the last allocation extent in a list, it leaves that allocation extent empty and the continuation to it in place.
If the last extent is a preallocation, udf_discard_prealloc() deletes it with udf_delete_aext(), which finds the following allocation extent empty, so it also removes the continuation and frees that allocation extent's block. udf_discard_prealloc() then frees eloc and elen: that block a second time, instead of the preallocated blocks. On a space bitmap the preallocated blocks leak and the free block count drifts. On an unallocated space table the second free adds a second free extent for the same block, which is later handed out twice: fsx as run by generic/091 and generic/263 ends up with two parts of its test file in one block and reads back bad data.
Peek into separate variables, so that eloc and elen keep the last extent that udf_next_aext() returned with 1.
--- fs/udf/truncate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/udf/truncate.c +4 -3
@@ -122,8 +122,8 @@ void udf_discard_prealloc(struct inode *inode) {struct extent_position epos = {};struct extent_position prev_epos = {}; -struct kernel_lb_addr eloc; -uint32_t elen; +struct kernel_lb_addr eloc, tmpeloc; +uint32_t elen, tmpelen;uint64_t lbcount =0 ;int8_t etype =-1 , netype;struct udf_inode_info *iinfo =UDF_I (inode);
@@ -136,7 +136,8 @@ void udf_discard_prealloc(struct inode *inode) epos.block = iinfo->i_location;/* Find the last extent in the file */ -while ((netype =udf_next_aext (inode, &epos, &eloc, &elen,0 )) !=-1 ) { +while ((netype =udf_next_aext (inode, &epos, &tmpeloc, &tmpelen, +0 )) !=-1 ) {brelse (prev_epos.bh); prev_epos = epos;if (prev_epos.bh)
Signature · 1 line
2.53.0