* [PATCH] ext4: don't clobber the migration error in ext4_ext_migrate()
@ 2026-09-10 5:29 Yichong Chen
2026-09-10 10:17 ` Jan Kara
2026-11-19 14:46 ` Theodore Ts'o
0 siblings, 2 replies; 3+ messages in thread
From: Yichong Chen @ 2026-09-10 5:29 UTC (permalink / raw)
To: Theodore Ts'o
Cc: linux-ext4, linux-kernel, Andreas Dilger, Baokun Li, Jan Kara,
Ojaswin Mujoo, Ritesh Harjani, Zhang Yi, Yichong Chen
ext4_ext_migrate() records the failure of the migration in retval, but
ext4_journal_ensure_credits() overwrites it: it returns 0 when the handle
has enough credits or the transaction could be extended, and 1 when the
transaction had to be restarted. A failed migration is therefore
reported as success, and a restart leaks the internal value 1 to
userspace through EXT4_IOC_MIGRATE and FS_IOC_SETFLAGS.
Fixes: a413036791d0 ("ext4: Provide function to handle transaction restarts")
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
---
fs/ext4/migrate.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
index 2aa6572088cf..e06d847033a1 100644
--- a/fs/ext4/migrate.c
+++ b/fs/ext4/migrate.c
@@ -410,7 +410,7 @@ static int free_ext_block(handle_t *handle, struct inode *inode)
int ext4_ext_migrate(struct inode *inode)
{
handle_t *handle;
- int retval = 0, i;
+ int retval = 0, err, i;
__le32 *i_data;
struct ext4_inode_info *ei;
struct inode *tmp_inode = NULL;
@@ -567,9 +567,12 @@ int ext4_ext_migrate(struct inode *inode)
}
/* We mark the tmp_inode dirty via ext4_ext_tree_init. */
- retval = ext4_journal_ensure_credits(handle, 1, 0);
- if (retval < 0)
+ err = ext4_journal_ensure_credits(handle, 1, 0);
+ if (err < 0) {
+ if (!retval)
+ retval = err;
goto out_stop;
+ }
/*
* Mark the tmp_inode as of size zero
*/
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: don't clobber the migration error in ext4_ext_migrate()
2026-09-10 5:29 [PATCH] ext4: don't clobber the migration error in ext4_ext_migrate() Yichong Chen
@ 2026-09-10 10:17 ` Jan Kara
2026-11-19 14:46 ` Theodore Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2026-09-10 10:17 UTC (permalink / raw)
To: Yichong Chen
Cc: Theodore Ts'o, linux-ext4, linux-kernel, Andreas Dilger,
Baokun Li, Jan Kara, Ojaswin Mujoo, Ritesh Harjani, Zhang Yi
On Thu 10-09-26 13:29:27, Yichong Chen wrote:
> ext4_ext_migrate() records the failure of the migration in retval, but
> ext4_journal_ensure_credits() overwrites it: it returns 0 when the handle
> has enough credits or the transaction could be extended, and 1 when the
> transaction had to be restarted. A failed migration is therefore
> reported as success, and a restart leaks the internal value 1 to
> userspace through EXT4_IOC_MIGRATE and FS_IOC_SETFLAGS.
>
> Fixes: a413036791d0 ("ext4: Provide function to handle transaction restarts")
> Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
Indeed. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/migrate.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
> index 2aa6572088cf..e06d847033a1 100644
> --- a/fs/ext4/migrate.c
> +++ b/fs/ext4/migrate.c
> @@ -410,7 +410,7 @@ static int free_ext_block(handle_t *handle, struct inode *inode)
> int ext4_ext_migrate(struct inode *inode)
> {
> handle_t *handle;
> - int retval = 0, i;
> + int retval = 0, err, i;
> __le32 *i_data;
> struct ext4_inode_info *ei;
> struct inode *tmp_inode = NULL;
> @@ -567,9 +567,12 @@ int ext4_ext_migrate(struct inode *inode)
> }
>
> /* We mark the tmp_inode dirty via ext4_ext_tree_init. */
> - retval = ext4_journal_ensure_credits(handle, 1, 0);
> - if (retval < 0)
> + err = ext4_journal_ensure_credits(handle, 1, 0);
> + if (err < 0) {
> + if (!retval)
> + retval = err;
> goto out_stop;
> + }
> /*
> * Mark the tmp_inode as of size zero
> */
> --
> 2.51.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: don't clobber the migration error in ext4_ext_migrate()
2026-09-10 5:29 [PATCH] ext4: don't clobber the migration error in ext4_ext_migrate() Yichong Chen
2026-09-10 10:17 ` Jan Kara
@ 2026-11-19 14:46 ` Theodore Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2026-11-19 14:46 UTC (permalink / raw)
To: Ext4 Developers List, Yichong Chen
Cc: Theodore Ts'o, linux-kernel, Andreas Dilger, Baokun Li,
Jan Kara, Ojaswin Mujoo, Ritesh Harjani, Zhang Yi
On Thu, 10 Sep 2026 13:29:27 +0800, Yichong Chen wrote:
> ext4_ext_migrate() records the failure of the migration in retval, but
> ext4_journal_ensure_credits() overwrites it: it returns 0 when the handle
> has enough credits or the transaction could be extended, and 1 when the
> transaction had to be restarted. A failed migration is therefore
> reported as success, and a restart leaks the internal value 1 to
> userspace through EXT4_IOC_MIGRATE and FS_IOC_SETFLAGS.
>
> [...]
Applied, thanks!
[1/1] ext4: don't clobber the migration error in ext4_ext_migrate()
commit: 82e2a5743b6ada7c77e072ca67c9ec55e9e18923
Best regards,
--
Theodore Ts'o <tytso@mit.edu>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 14:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10 5:29 [PATCH] ext4: don't clobber the migration error in ext4_ext_migrate() Yichong Chen
2026-09-10 10:17 ` Jan Kara
2026-11-19 14:46 ` Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®