Skip to content

Commit 5909bed

Browse files
Yongpeng YangJaegeuk Kim
authored andcommitted
f2fs: protect extension_list reading with sb_lock in f2fs_sbi_show()
In f2fs_sbi_show(), the extension_list, extension_count and hot_ext_count are read without holding sbi->sb_lock. If a concurrent sysfs store modifies the extension list via f2fs_update_extension_list(), the show path may read inconsistent count and array contents, potentially leading to out-of-bounds access or displaying stale data. Fix this by holding sb_lock around the entire extension list read and format operation. Fixes: b6a06cb ("f2fs: support hot file extension") Signed-off-by: Yongpeng Yang <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent b8b902f commit 5909bed

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

fs/f2fs/sysfs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,20 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
387387
if (!strcmp(a->attr.name, "extension_list")) {
388388
__u8 (*extlist)[F2FS_EXTENSION_LEN] =
389389
sbi->raw_super->extension_list;
390-
int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
391-
int hot_count = sbi->raw_super->hot_ext_count;
390+
int cold_count, hot_count;
392391
int len = 0, i;
393392

393+
f2fs_down_read(&sbi->sb_lock);
394+
cold_count = le32_to_cpu(sbi->raw_super->extension_count);
395+
hot_count = sbi->raw_super->hot_ext_count;
394396
len += sysfs_emit_at(buf, len, "cold file extension:\n");
395397
for (i = 0; i < cold_count; i++)
396398
len += sysfs_emit_at(buf, len, "%s\n", extlist[i]);
397399

398400
len += sysfs_emit_at(buf, len, "hot file extension:\n");
399401
for (i = cold_count; i < cold_count + hot_count; i++)
400402
len += sysfs_emit_at(buf, len, "%s\n", extlist[i]);
403+
f2fs_up_read(&sbi->sb_lock);
401404

402405
return len;
403406
}

0 commit comments

Comments
 (0)