The EXT4_IOC_MOVE_EXT ioctl manipulates file extents directly without running the permission hooks used by regular reads and writes. Check read permission on the source and write permission on the donor before moving extents. Built and tested on x86-64 QEMU against the base revision. Fixes: f156524e5d72 ("fsnotify: introduce pre-content permission events") Signed-off-by: Shawn Shao --- Additional test information: HEAD commit: 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046 git tree: 194227446ae61b4971eea1b7bed06856fe3cc477 source version: Linux 7.4.0-rc4 compiler: gcc 11.4.0, GNU ld 2.38 A reproducer and positive/control logs are available privately to maintainers. fs/ext4/ioctl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 83630cd40712c..be272853d1fa7 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -1687,6 +1688,14 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (file_inode(filp)->i_sb != file_inode(fd_file(donor))->i_sb) return -EXDEV; + /* Extent movement reads the source and overwrites the donor. */ + err = fsnotify_file_perm(filp, MAY_READ); + if (err) + return err; + err = fsnotify_file_perm(fd_file(donor), MAY_WRITE); + if (err) + return err; + err = mnt_want_write_file(filp); if (err) return err; -- 2.34.1