* [PATCH] f2fs: reject overlapping move range after len expansion
@ 2026-07-08 6:54 ` Hao-Qun Huang
0 siblings, 0 replies; 6+ messages in thread
From: Hao-Qun Huang @ 2026-07-08 6:54 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu
Cc: linux-f2fs-devel, linux-kernel, Hao-Qun Huang, stable
F2FS_IOC_MOVE_RANGE treats a zero length as a request to move data
from pos_in to EOF. However, the same-file overlap check runs before
that expansion, so a request with len == 0 bypasses the overlap
rejection added for same-file moves.
For example, with a four-block file, moving from block 0 to block 1
with len == 0 is accepted by the old check because pos_in + len is
still pos_in at that point. The code then expands len to cover the
rest of the file and calls __exchange_data_block() on overlapping
source and destination ranges in the same inode, which is the
data-corruption case the overlap check was meant to reject.
Move the overlap check after the source range has been validated and
len == 0 has been expanded, so it sees the effective length. This is a
no-op for non-zero len (the value is unchanged there) and keeps the
existing early return for identical positions.
Fixes: d95fd91c1ac1 ("f2fs: exclude special cases for f2fs_move_file_range")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-fable-5
Signed-off-by: Hao-Qun Huang <alvinhuang0603@gmail.com>
---
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4b52c56d71f0..fdfef01dc799 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3144,8 +3144,6 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
if (src == dst) {
if (pos_in == pos_out)
return 0;
- if (pos_out > pos_in && pos_out < pos_in + len)
- return -EINVAL;
}
inode_lock(src);
@@ -3171,6 +3169,8 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
goto out_unlock;
if (len == 0)
olen = len = src->i_size - pos_in;
+ if (src == dst && pos_out > pos_in && pos_out < pos_in + len)
+ goto out_unlock;
if (pos_in + len == src->i_size)
len = ALIGN(src->i_size, F2FS_BLKSIZE) - pos_in;
if (len == 0) {
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [f2fs-dev] [PATCH] f2fs: reject overlapping move range after len expansion
@ 2026-07-08 6:54 ` Hao-Qun Huang
0 siblings, 0 replies; 6+ messages in thread
From: Hao-Qun Huang @ 2026-07-08 6:54 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu
Cc: Hao-Qun Huang, linux-kernel, stable, linux-f2fs-devel
F2FS_IOC_MOVE_RANGE treats a zero length as a request to move data
from pos_in to EOF. However, the same-file overlap check runs before
that expansion, so a request with len == 0 bypasses the overlap
rejection added for same-file moves.
For example, with a four-block file, moving from block 0 to block 1
with len == 0 is accepted by the old check because pos_in + len is
still pos_in at that point. The code then expands len to cover the
rest of the file and calls __exchange_data_block() on overlapping
source and destination ranges in the same inode, which is the
data-corruption case the overlap check was meant to reject.
Move the overlap check after the source range has been validated and
len == 0 has been expanded, so it sees the effective length. This is a
no-op for non-zero len (the value is unchanged there) and keeps the
existing early return for identical positions.
Fixes: d95fd91c1ac1 ("f2fs: exclude special cases for f2fs_move_file_range")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-fable-5
Signed-off-by: Hao-Qun Huang <alvinhuang0603@gmail.com>
---
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4b52c56d71f0..fdfef01dc799 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3144,8 +3144,6 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
if (src == dst) {
if (pos_in == pos_out)
return 0;
- if (pos_out > pos_in && pos_out < pos_in + len)
- return -EINVAL;
}
inode_lock(src);
@@ -3171,6 +3169,8 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
goto out_unlock;
if (len == 0)
olen = len = src->i_size - pos_in;
+ if (src == dst && pos_out > pos_in && pos_out < pos_in + len)
+ goto out_unlock;
if (pos_in + len == src->i_size)
len = ALIGN(src->i_size, F2FS_BLKSIZE) - pos_in;
if (len == 0) {
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: reject overlapping move range after len expansion
2026-07-08 6:54 ` [f2fs-dev] " Hao-Qun Huang
@ 2026-08-03 7:07 ` Chao Yu
-1 siblings, 0 replies; 6+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2026-08-03 7:07 UTC (permalink / raw)
To: Hao-Qun Huang, Jaegeuk Kim; +Cc: linux-kernel, stable, linux-f2fs-devel
On 7/8/26 14:54, Hao-Qun Huang wrote:
> F2FS_IOC_MOVE_RANGE treats a zero length as a request to move data
> from pos_in to EOF. However, the same-file overlap check runs before
> that expansion, so a request with len == 0 bypasses the overlap
> rejection added for same-file moves.
>
> For example, with a four-block file, moving from block 0 to block 1
> with len == 0 is accepted by the old check because pos_in + len is
> still pos_in at that point. The code then expands len to cover the
> rest of the file and calls __exchange_data_block() on overlapping
> source and destination ranges in the same inode, which is the
> data-corruption case the overlap check was meant to reject.
>
> Move the overlap check after the source range has been validated and
> len == 0 has been expanded, so it sees the effective length. This is a
> no-op for non-zero len (the value is unchanged there) and keeps the
> existing early return for identical positions.
>
> Fixes: d95fd91c1ac1 ("f2fs: exclude special cases for f2fs_move_file_range")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Hao-Qun Huang <alvinhuang0603@gmail.com>
> ---
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 4b52c56d71f0..fdfef01dc799 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -3144,8 +3144,6 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
> if (src == dst) {
> if (pos_in == pos_out)
> return 0;
> - if (pos_out > pos_in && pos_out < pos_in + len)
> - return -EINVAL;
> }
>
> inode_lock(src);
> @@ -3171,6 +3169,8 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
> goto out_unlock;
> if (len == 0)
> olen = len = src->i_size - pos_in;
> + if (src == dst && pos_out > pos_in && pos_out < pos_in + len)
> + goto out_unlock;
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
> if (pos_in + len == src->i_size)
> len = ALIGN(src->i_size, F2FS_BLKSIZE) - pos_in;
> if (len == 0) {
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] f2fs: reject overlapping move range after len expansion
@ 2026-08-03 7:07 ` Chao Yu
0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2026-08-03 7:07 UTC (permalink / raw)
To: Hao-Qun Huang, Jaegeuk Kim; +Cc: chao, linux-f2fs-devel, linux-kernel, stable
On 7/8/26 14:54, Hao-Qun Huang wrote:
> F2FS_IOC_MOVE_RANGE treats a zero length as a request to move data
> from pos_in to EOF. However, the same-file overlap check runs before
> that expansion, so a request with len == 0 bypasses the overlap
> rejection added for same-file moves.
>
> For example, with a four-block file, moving from block 0 to block 1
> with len == 0 is accepted by the old check because pos_in + len is
> still pos_in at that point. The code then expands len to cover the
> rest of the file and calls __exchange_data_block() on overlapping
> source and destination ranges in the same inode, which is the
> data-corruption case the overlap check was meant to reject.
>
> Move the overlap check after the source range has been validated and
> len == 0 has been expanded, so it sees the effective length. This is a
> no-op for non-zero len (the value is unchanged there) and keeps the
> existing early return for identical positions.
>
> Fixes: d95fd91c1ac1 ("f2fs: exclude special cases for f2fs_move_file_range")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Hao-Qun Huang <alvinhuang0603@gmail.com>
> ---
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 4b52c56d71f0..fdfef01dc799 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -3144,8 +3144,6 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
> if (src == dst) {
> if (pos_in == pos_out)
> return 0;
> - if (pos_out > pos_in && pos_out < pos_in + len)
> - return -EINVAL;
> }
>
> inode_lock(src);
> @@ -3171,6 +3169,8 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
> goto out_unlock;
> if (len == 0)
> olen = len = src->i_size - pos_in;
> + if (src == dst && pos_out > pos_in && pos_out < pos_in + len)
> + goto out_unlock;
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
> if (pos_in + len == src->i_size)
> len = ALIGN(src->i_size, F2FS_BLKSIZE) - pos_in;
> if (len == 0) {
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: reject overlapping move range after len expansion
2026-07-08 6:54 ` [f2fs-dev] " Hao-Qun Huang
@ 2026-08-05 21:20 ` patchwork-bot+f2fs
-1 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+f2fs--- via Linux-f2fs-devel @ 2026-08-05 21:20 UTC (permalink / raw)
To: Hao-Qun Huang; +Cc: jaegeuk, linux-kernel, stable, linux-f2fs-devel
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Wed, 8 Jul 2026 14:54:39 +0800 you wrote:
> F2FS_IOC_MOVE_RANGE treats a zero length as a request to move data
> from pos_in to EOF. However, the same-file overlap check runs before
> that expansion, so a request with len == 0 bypasses the overlap
> rejection added for same-file moves.
>
> For example, with a four-block file, moving from block 0 to block 1
> with len == 0 is accepted by the old check because pos_in + len is
> still pos_in at that point. The code then expands len to cover the
> rest of the file and calls __exchange_data_block() on overlapping
> source and destination ranges in the same inode, which is the
> data-corruption case the overlap check was meant to reject.
>
> [...]
Here is the summary with links:
- [f2fs-dev] f2fs: reject overlapping move range after len expansion
https://git.kernel.org/jaegeuk/f2fs/c/28c1ef094e7c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: reject overlapping move range after len expansion
@ 2026-08-05 21:20 ` patchwork-bot+f2fs
0 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+f2fs @ 2026-08-05 21:20 UTC (permalink / raw)
To: Hao-Qun Huang; +Cc: jaegeuk, chao, linux-kernel, stable, linux-f2fs-devel
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Wed, 8 Jul 2026 14:54:39 +0800 you wrote:
> F2FS_IOC_MOVE_RANGE treats a zero length as a request to move data
> from pos_in to EOF. However, the same-file overlap check runs before
> that expansion, so a request with len == 0 bypasses the overlap
> rejection added for same-file moves.
>
> For example, with a four-block file, moving from block 0 to block 1
> with len == 0 is accepted by the old check because pos_in + len is
> still pos_in at that point. The code then expands len to cover the
> rest of the file and calls __exchange_data_block() on overlapping
> source and destination ranges in the same inode, which is the
> data-corruption case the overlap check was meant to reject.
>
> [...]
Here is the summary with links:
- [f2fs-dev] f2fs: reject overlapping move range after len expansion
https://git.kernel.org/jaegeuk/f2fs/c/28c1ef094e7c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-08-05 21:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 6:54 [PATCH] f2fs: reject overlapping move range after len expansion Hao-Qun Huang
2026-07-08 6:54 ` [f2fs-dev] " Hao-Qun Huang
2026-08-03 7:07 ` Chao Yu via Linux-f2fs-devel
2026-08-03 7:07 ` Chao Yu
2026-08-05 21:20 ` [f2fs-dev] " patchwork-bot+f2fs--- via Linux-f2fs-devel
2026-08-05 21:20 ` patchwork-bot+f2fs
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.