[PATCH] f2fs: migrate all curseg types when reserving device alias
From: Kyuwon Cho
Date: Thu Dec 03 2026 - 11:39:03 EST
The device-alias reserve ioctl moves persistent current segments out of
the target range before reserving it, but leaves the in-memory ATGC
current segment in place. A subsequent ATGC allocation can then consume a
block that the ioctl has marked reserved and corrupt the SIT accounting.
Iterate through every current segment type, as free_segment_range() does,
so no active allocation cursor remains in the reserved range.
Fixes: eae3faf210bd ("f2fs: support dynamic reserve/release for device aliasing")
Signed-off-by: Kyuwon Cho <kyuwon.cho@xxxxxxxx>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype.
The reproducer mounts a two-device F2FS filesystem, places the ATGC
current segment on the secondary device, reserves that device as an alias,
and triggers another ATGC allocation. The mount and device-management
ioctls require root in the initial namespace.
The decoded trace is:
WARNING: fs/f2fs/segment.c:2669 at update_sit_entry
update_sit_entry (fs/f2fs/segment.c:2669)
f2fs_reserve_device_alias (fs/f2fs/segment.c:2759)
f2fs_ioc_reserve_dev_alias (fs/f2fs/file.c:3861)
With this patch, the reproducer completes without the warning on
fe6ff8d5d675. The patch also builds on the current F2FS tree at
b61a029304bb.
fs/f2fs/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c80dbbe76f8f..ebfe010fec43 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4111,7 +4111,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *filp)
f2fs_reset_gc_victim_resource(sbi, start, end);
/* Move out cursegs from the target range */
- for (type = CURSEG_HOT_DATA; type < NR_CURSEG_PERSIST_TYPE; type++) {
+ for (type = CURSEG_HOT_DATA; type < NR_CURSEG_TYPE; type++) {
err = f2fs_allocate_segment_for_resize(sbi, type, start, end);
if (err)
goto out_gc_unlock;