Skip to contentSkip to conversation

ext4: clear journal restart indication after inserting extent

PATCH Applied Yichong Chen 4 participants 4 messages Sep 9 – Nov 19 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: clear journal restart indication after inserting extent

ext4_datasem_ensure_credits() returns 1 when it successfully restarts the transaction. finish_range() leaves that value in retval when the subsequent ext4_ext_insert_extent() succeeds. Its callers interpret any nonzero return as a migration failure, so they stop building the extent tree and take the cleanup path instead of completing the migration.

Before ext4_ext_insert_extent() was changed to return a path, its integer return value overwrote the restart indication. Restore that behavior with PTR_ERR_OR_ZERO(), preserving insertion errors and returning zero on success.

Fixes f7d1331f16a8 ("ext4: get rid of ppath in ext4_ext_insert_extent()")
---
 fs/ext4/migrate.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/migrate.c +1 -2
index 5d60ef10fe11..d467b5a13c62 100644
@@ -53,8 +53,7 @@ static int finish_range(handle_t *handle, struct inode *inode,
 	if (retval < 0)
 		goto err_out;
 	path = ext4_ext_insert_extent(handle, inode, path, &newext, 0);
-	if (IS_ERR(path))
-		retval = PTR_ERR(path);
+	retval = PTR_ERR_OR_ZERO(path);
 err_out:
 	up_write((&EXT4_I(inode)->i_data_sem));
 	ext4_free_ext_path(path);
Signature · 1 line
2.51.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Preexisting bug: update_extent_range does not cap contiguous block accumulation at EXT_INIT_MAX_LEN, leading to silent data corruption during migration. --

commit 7520d7fb83f021805cdf612c9f4b9753118b3505
Author: Yichong Chen <[email protected]>

ext4: clear journal restart indication after inserting extent

ext4_datasem_ensure_credits() returns 1 when it successfully restarts the transaction. finish_range() leaves that value in retval when the subsequent ext4_ext_insert_extent() succeeds.

fs/ext4/migrate.c static int finish_range(handle_t *handle, struct inode *inode, · line 55

Quoted 8 lines
fs/ext4/migrate.c +0 -0
index 5d60ef10fe110..d467b5a13c62e 100644
@@ -53,8 +53,7 @@ static int finish_range(handle_t *handle, struct inode *inode,
 	if (retval < 0)
 		goto err_out;
 	path = ext4_ext_insert_extent(handle, inode, path, &newext, 0);

[Severity: Critical]
This is a pre-existing issue, but does update_extent_range() fail to cap contiguous block accumulation at EXT_INIT_MAX_LEN?

If a local user executes chattr +e on a file they own that contains a contiguous block allocation exceeding 128MB, update_extent_range() appears to aggressively merge blocks that are physically and logically contiguous without bounds checking:

fs/ext4/migrate.c:update_extent_range() {
	if (lb->first_pblock &&
		(lb->last_pblock+1 == pblock) &&
		(lb->last_block+1 == lb->curr_block)) {
		lb->last_pblock = pblock;
		lb->last_block = lb->curr_block;
		lb->curr_block++;
		return 0;
	}
    ...
}

Could this create an extent larger than 32768 blocks? When finish_range() creates the extent:

fs/ext4/migrate.c:finish_range() {
    ...
	newext.ee_len   = cpu_to_le16(lb->last_block - lb->first_block + 1);
    ...
}

Will this unbounded length assignment to a 16-bit field cause truncation or set the unwritten flag for values > 32768, potentially leading to silent data loss during migration?

Quoted 6 lines
fs/ext4/migrate.c +1 -2
-	if (IS_ERR(path))
-		retval = PTR_ERR(path);
+	retval = PTR_ERR_OR_ZERO(path);
 err_out:
 	up_write((&EXT4_I(inode)->i_data_sem));
 	ext4_free_ext_path(path);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Yichong Chen
Quoted 6 lines · Yichong Chen

ext4_datasem_ensure_credits() returns 1 when it successfully restarts the transaction. finish_range() leaves that value in retval when the subsequent ext4_ext_insert_extent() succeeds. Its callers interpret any nonzero return as a migration failure, so they stop building the extent tree and take the cleanup path instead of completing the migration.

Quoted 7 lines

Before ext4_ext_insert_extent() was changed to return a path, its integer return value overwrote the restart indication. Restore that behavior with PTR_ERR_OR_ZERO(), preserving insertion errors and returning zero on success.

Fixes f7d1331f16a8 ("ext4: get rid of ppath in ext4_ext_insert_extent()")

Looks good. Feel free to add:

Honza

Quoted 21 lines
---
 fs/ext4/migrate.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/migrate.c +1 -2
index 5d60ef10fe11..d467b5a13c62 100644
@@ -53,8 +53,7 @@ static int finish_range(handle_t *handle, struct inode *inode,
 	if (retval < 0)
 		goto err_out;
 	path = ext4_ext_insert_extent(handle, inode, path, &newext, 0);
-	if (IS_ERR(path))
-		retval = PTR_ERR(path);
+	retval = PTR_ERR_OR_ZERO(path);
 err_out:
 	up_write((&EXT4_I(inode)->i_data_sem));
 	ext4_free_ext_path(path);
Signature · 1 line
2.51.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#3 lore raw
In reply to Yichong Chen
Quoted 6 lines · Yichong Chen

ext4_datasem_ensure_credits() returns 1 when it successfully restarts the transaction. finish_range() leaves that value in retval when the subsequent ext4_ext_insert_extent() succeeds. Its callers interpret any nonzero return as a migration failure, so they stop building the extent tree and take the cleanup path instead of completing the migration.

Quoted 6 lines

Before ext4_ext_insert_extent() was changed to return a path, its integer return value overwrote the restart indication. Restore that behavior with PTR_ERR_OR_ZERO(), preserving insertion errors and returning zero on success.

[...]

Applied, thanks!

[1/1] ext4: clear journal restart indication after inserting extent

      commit: 3b6aee59883c3056bb0a5e7491f9dc995bbac964

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>