linux/fs/f2fs
Yongpeng Yang 438a405fba f2fs: fix out-of-bounds access in sysfs attribute read/write
[ Upstream commit 98ea0039db ]

Some f2fs sysfs attributes suffer from out-of-bounds memory access and
incorrect handling of integer values whose size is not 4 bytes.

For example:
vm:~# echo 65537 > /sys/fs/f2fs/vde/carve_out
vm:~# cat /sys/fs/f2fs/vde/carve_out
65537
vm:~# echo 4294967297 > /sys/fs/f2fs/vde/atgc_age_threshold
vm:~# cat /sys/fs/f2fs/vde/atgc_age_threshold
1

carve_out maps to {struct f2fs_sb_info}->carve_out, which is a 8-bit
integer. However, the sysfs interface allows setting it to a value
larger than 255, resulting in an out-of-range update.

atgc_age_threshold maps to {struct atgc_management}->age_threshold,
which is a 64-bit integer, but its sysfs interface cannot correctly set
values larger than UINT_MAX.

The root causes are:
1. __sbi_store() treats all default values as unsigned int, which
prevents updating integers larger than 4 bytes and causes out-of-bounds
writes for integers smaller than 4 bytes.

2. f2fs_sbi_show() also assumes all default values are unsigned int,
leading to out-of-bounds reads and incorrect access to integers larger
than 4 bytes.

This patch introduces {struct f2fs_attr}->size to record the actual size
of the integer associated with each sysfs attribute. With this
information, sysfs read and write operations can correctly access and
update values according to their real data size, avoiding memory
corruption and truncation.

Fixes: b59d0bae6c ("f2fs: add sysfs support for controlling the gc_thread")
Cc: stable@kernel.org
Signed-off-by: Jinbao Liu <liujinbao1@xiaomi.com>
Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
[ adapted F2FS_STAT_ATTR macro to include .size field ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-02-19 16:21:47 +01:00
..
acl.c vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
acl.h vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
checkpoint.c f2fs: fix typos in comments 2024-06-16 13:39:36 +02:00
compress.c f2fs: fix typos in comments 2024-06-16 13:39:36 +02:00
data.c f2fs: fix to avoid UAF in f2fs_write_end_io() 2026-02-19 16:21:47 +01:00
debug.c f2fs: use spin_lock to avoid hang 2022-04-08 14:23:58 +02:00
dir.c f2fs: Introduce linear search for dentries 2025-03-13 12:50:14 +01:00
extent_cache.c f2fs: fix KMSAN uninit-value in extent_info usage 2025-08-28 16:24:12 +02:00
f2fs.h f2fs: use global inline_xattr_slab instead of per-sb slab cache 2026-01-19 13:10:07 +01:00
file.c f2fs: fix to avoid updating zero-sized extent in extent cache 2026-01-19 13:10:07 +01:00
gc.c f2fs: reduce stack memory cost by using bitfield in struct f2fs_io_info 2024-03-26 18:21:32 -04:00
gc.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
hash.c f2fs: don't use casefolded comparison for "." and ".." 2022-06-09 10:23:17 +02:00
inline.c f2fs: Introduce linear search for dentries 2025-03-13 12:50:14 +01:00
inode.c f2fs: fix to do sanity check on ino and xnid 2025-08-28 16:24:31 +02:00
iostat.c f2fs: fix to avoid potential memory corruption in __update_iostat_latency() 2023-03-11 13:57:26 +01:00
iostat.h f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
Kconfig f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
Makefile f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
namei.c f2fs: invalidate dentry cache on failed whiteout creation 2026-01-19 13:09:51 +01:00
node.c f2fs: fix to avoid out-of-boundary access in dnode page 2025-08-28 16:24:36 +02:00
node.h f2fs: swap: support migrating swapfile in aligned write mode 2021-06-23 01:09:35 -07:00
recovery.c f2fs: fix to detect recoverable inode during dryrun of find_fsync_dnodes() 2026-01-19 13:10:07 +01:00
segment.c f2fs: check curseg->inited before write_sum_page in change_curseg 2024-12-14 19:51:05 +01:00
segment.h f2fs: remove struct segment_allocation default_salloc_ops 2024-12-14 19:51:05 +01:00
shrinker.c f2fs: avoid race condition for shrinker count 2020-12-03 00:59:26 -08:00
super.c f2fs: fix to propagate error from f2fs_enable_checkpoint() 2026-01-19 13:10:07 +01:00
sysfs.c f2fs: fix out-of-bounds access in sysfs attribute read/write 2026-02-19 16:21:47 +01:00
verity.c fs: f2fs: initialize fsdata in pagecache_write() 2023-03-11 13:57:23 +01:00
xattr.c f2fs: use global inline_xattr_slab instead of per-sb slab cache 2026-01-19 13:10:07 +01:00
xattr.h f2fs: use global inline_xattr_slab instead of per-sb slab cache 2026-01-19 13:10:07 +01:00