* [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT
@ 2026-07-24 14:38 Yun Zhou
2026-07-24 15:26 ` Greg KH
2026-07-26 12:04 ` Sasha Levin
0 siblings, 2 replies; 7+ messages in thread
From: Yun Zhou @ 2026-07-24 14:38 UTC (permalink / raw)
To: gregkh; +Cc: harshit.m.mogalapalli, stable, patches
commit c143957520c6c9b5cd72e0de8b52b814f0c576fe upstream.
Reject the EXT4_IOC_MOVE_EXT ioctl early if the donor file does not
belong to the same superblock as the original file. Currently, this
validation is performed inside ext4_move_extents() by
mext_check_validity(), but only after lock_two_nondirectories() has
already acquired the inode locks. When the donor fd refers to a file
on a different filesystem (e.g., overlayfs), this late validation
creates a circular lock dependency:
CPU0 (overlayfs write) CPU1 (ext4 ioctl)
---- ----
inode_lock(ovl_inode)
mnt_want_write_file(filp)
sb_start_write(ext4_sb) [sb_writers]
backing_file_write_iter()
vfs_iter_write(real_file)
file_start_write(real_file)
sb_start_write(ext4_sb) [blocked by freeze]
lock_two_nondirectories()
inode_lock(ovl_inode) [blocked]
With a concurrent freeze operation holding sb_writers write side, this
forms a deadlock cycle: CPU0 waits for freeze to complete, freeze waits
for CPU1's sb_writers reader to exit, CPU1 waits for CPU0's inode lock.
Since EXT4_IOC_MOVE_EXT exchanges physical extents between two files,
it fundamentally requires both files to reside on the same ext4
filesystem. Moving the superblock check before any lock acquisition
is both semantically correct and eliminates the circular dependency
by ensuring that cross-filesystem donor fds are rejected before
sb_writers or inode locks are taken.
Fixes: fcf6b1b729bc ("ext4: refactor ext4_move_extents code base")
Reported-by: syzbot+ad6118a7584b607c67f2@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ad6118a7584b607c67f2
Signed-off-by: Yun Zhou <yun.zhou@windriver.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Link: https://patch.msgid.link/20260608152521.1292656-1-yun.zhou@windriver.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
fs/ext4/ioctl.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 99d185d00f37..e437cf1a84e5 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1366,6 +1366,11 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
goto mext_out;
}
+ if (file_inode(filp)->i_sb != file_inode(fd_file(donor))->i_sb) {
+ err = -EXDEV;
+ goto mext_out;
+ }
+
err = mnt_want_write_file(filp);
if (err)
goto mext_out;
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT
2026-07-24 14:38 [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT Yun Zhou
@ 2026-07-24 15:26 ` Greg KH
2026-07-25 2:43 ` Zhou, Yun
2026-07-26 12:04 ` Sasha Levin
1 sibling, 1 reply; 7+ messages in thread
From: Greg KH @ 2026-07-24 15:26 UTC (permalink / raw)
To: Yun Zhou; +Cc: harshit.m.mogalapalli, stable, patches
On Fri, Jul 24, 2026 at 10:38:28PM +0800, Yun Zhou wrote:
> commit c143957520c6c9b5cd72e0de8b52b814f0c576fe upstream.
>
> Reject the EXT4_IOC_MOVE_EXT ioctl early if the donor file does not
> belong to the same superblock as the original file. Currently, this
> validation is performed inside ext4_move_extents() by
> mext_check_validity(), but only after lock_two_nondirectories() has
> already acquired the inode locks. When the donor fd refers to a file
> on a different filesystem (e.g., overlayfs), this late validation
> creates a circular lock dependency:
>
> CPU0 (overlayfs write) CPU1 (ext4 ioctl)
> ---- ----
> inode_lock(ovl_inode)
> mnt_want_write_file(filp)
> sb_start_write(ext4_sb) [sb_writers]
> backing_file_write_iter()
> vfs_iter_write(real_file)
> file_start_write(real_file)
> sb_start_write(ext4_sb) [blocked by freeze]
> lock_two_nondirectories()
> inode_lock(ovl_inode) [blocked]
>
> With a concurrent freeze operation holding sb_writers write side, this
> forms a deadlock cycle: CPU0 waits for freeze to complete, freeze waits
> for CPU1's sb_writers reader to exit, CPU1 waits for CPU0's inode lock.
>
> Since EXT4_IOC_MOVE_EXT exchanges physical extents between two files,
> it fundamentally requires both files to reside on the same ext4
> filesystem. Moving the superblock check before any lock acquisition
> is both semantically correct and eliminates the circular dependency
> by ensuring that cross-filesystem donor fds are rejected before
> sb_writers or inode locks are taken.
>
> Fixes: fcf6b1b729bc ("ext4: refactor ext4_move_extents code base")
> Reported-by: syzbot+ad6118a7584b607c67f2@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=ad6118a7584b607c67f2
> Signed-off-by: Yun Zhou <yun.zhou@windriver.com>
> Reviewed-by: Jan Kara <jack@suse.cz>
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> Link: https://patch.msgid.link/20260608152521.1292656-1-yun.zhou@windriver.com
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
> fs/ext4/ioctl.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index 99d185d00f37..e437cf1a84e5 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1366,6 +1366,11 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> goto mext_out;
> }
>
> + if (file_inode(filp)->i_sb != file_inode(fd_file(donor))->i_sb) {
> + err = -EXDEV;
> + goto mext_out;
> + }
> +
> err = mnt_want_write_file(filp);
> if (err)
> goto mext_out;
> --
> 2.43.0
>
I already merged the original, can you send a fix-up patch that I can
just apply instead?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT
2026-07-24 15:26 ` Greg KH
@ 2026-07-25 2:43 ` Zhou, Yun
2026-07-25 5:18 ` Greg KH
0 siblings, 1 reply; 7+ messages in thread
From: Zhou, Yun @ 2026-07-25 2:43 UTC (permalink / raw)
To: Greg KH; +Cc: harshit.m.mogalapalli, stable, patches
On 7/24/2026 11:26 PM, Greg KH wrote:
>
> I already merged the original, can you send a fix-up patch that I can
> just apply instead?
>
Sure, I've already sent it out. My previous understanding was incorrect.
BR,
Yun
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT
2026-07-25 2:43 ` Zhou, Yun
@ 2026-07-25 5:18 ` Greg KH
0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2026-07-25 5:18 UTC (permalink / raw)
To: Zhou, Yun; +Cc: harshit.m.mogalapalli, stable, patches
On Sat, Jul 25, 2026 at 10:43:18AM +0800, Zhou, Yun wrote:
> On 7/24/2026 11:26 PM, Greg KH wrote:
> >
> > I already merged the original, can you send a fix-up patch that I can
> > just apply instead?
> >
>
> Sure, I've already sent it out. My previous understanding was incorrect.
Not your fault, thanks for the fix, I'll go queue it up later today!
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT
2026-07-24 14:38 [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT Yun Zhou
2026-07-24 15:26 ` Greg KH
@ 2026-07-26 12:04 ` Sasha Levin
2026-07-26 12:56 ` Zhou, Yun
1 sibling, 1 reply; 7+ messages in thread
From: Sasha Levin @ 2026-07-26 12:04 UTC (permalink / raw)
To: gregkh; +Cc: Sasha Levin, harshit.m.mogalapalli, stable, patches, Yun Zhou
> commit c143957520c6c9b5cd72e0de8b52b814f0c576fe upstream.
Thanks Yun, and thanks Harshit for spotting the donor-fd leak.
Since the original backport is already queued, the cleanest thing is an
incremental fixup on top rather than a full replacement (which just
duplicates the merged commit). In 6.12 the fix is to turn the early
"return -EXDEV;" into "err = -EXDEV; goto mext_out;" so the fdput(donor)
cleanup at the mext_out label is not bypassed. Could you send that
one-line delta and I will apply it? Thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT
2026-07-26 12:04 ` Sasha Levin
@ 2026-07-26 12:56 ` Zhou, Yun
2026-07-26 21:24 ` Sasha Levin
0 siblings, 1 reply; 7+ messages in thread
From: Zhou, Yun @ 2026-07-26 12:56 UTC (permalink / raw)
To: Sasha Levin, gregkh; +Cc: harshit.m.mogalapalli, stable, patches
On 7/26/2026 8:04 PM, Sasha Levin wrote:
>> commit c143957520c6c9b5cd72e0de8b52b814f0c576fe upstream.
>
> Thanks Yun, and thanks Harshit for spotting the donor-fd leak.
>
> Since the original backport is already queued, the cleanest thing is an
> incremental fixup on top rather than a full replacement (which just
> duplicates the merged commit). In 6.12 the fix is to turn the early
> "return -EXDEV;" into "err = -EXDEV; goto mext_out;" so the fdput(donor)
> cleanup at the mext_out label is not bypassed. Could you send that
> one-line delta and I will apply it? Thanks.
>
I see that the fix-up patch [1] has already been merged. Could you
please double-check it?
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.12.y&id=913e7b4459d6eef807bb8088b39b890ed6a74ee3
BR,
Yun
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT
2026-07-26 12:56 ` Zhou, Yun
@ 2026-07-26 21:24 ` Sasha Levin
0 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2026-07-26 21:24 UTC (permalink / raw)
To: gregkh; +Cc: Sasha Levin, harshit.m.mogalapalli, stable, patches, Zhou, Yun
> I see that the fix-up patch [1] has already been merged. Could you
> please double-check it?
Double-checked, and 6.12.y is complete: the original backport went out
in 6.12.97 and your fd-leak fixup in 6.12.98. In the merged result the
cross-superblock rejection sets err and jumps to mext_out, so the
fdput(donor) is no longer bypassed.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-07-26 21:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24 14:38 [PATCH 6.12.y] ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT Yun Zhou
2026-07-24 15:26 ` Greg KH
2026-07-25 2:43 ` Zhou, Yun
2026-07-25 5:18 ` Greg KH
2026-07-26 12:04 ` Sasha Levin
2026-07-26 12:56 ` Zhou, Yun
2026-07-26 21:24 ` Sasha Levin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.