Skip to content

Commit 913e7b4

Browse files
zhouyun1306gregkh
authored andcommitted
ext4: fix fd leak in EXT4_IOC_MOVE_EXT cross-sb validation
The backport of upstream commit c143957 ("ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT") uses a bare 'return -EXDEV' which is safe upstream because the fd is managed via CLASS(fd) with automatic cleanup (commit 8152f82 ("fdget(), more trivial conversions")). However, on 6.12.y the ioctl still uses the traditional fdget/fdput pattern, so the bare return bypasses fdput(donor) at the mext_out label, leaking the file reference. Fix by setting err and using goto mext_out. Fixes: 74796e8 ("ext4: validate donor file superblock early in EXT4_IOC_MOVE_EXT") Reported-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> Signed-off-by: Yun Zhou <yun.zhou@windriver.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0fdd406 commit 913e7b4

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

fs/ext4/ioctl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,10 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
13721372
goto mext_out;
13731373
}
13741374

1375-
if (file_inode(filp)->i_sb != file_inode(fd_file(donor))->i_sb)
1376-
return -EXDEV;
1375+
if (file_inode(filp)->i_sb != file_inode(fd_file(donor))->i_sb) {
1376+
err = -EXDEV;
1377+
goto mext_out;
1378+
}
13771379

13781380
err = mnt_want_write_file(filp);
13791381
if (err)

0 commit comments

Comments
 (0)