linux-yocto/fs/f2fs
Zhiguo Niu 5d604d40cd f2fs: compress: fix UAF of f2fs_inode_info in f2fs_free_dic
[ Upstream commit 39868685c2 ]

The decompress_io_ctx may be released asynchronously after
I/O completion. If this file is deleted immediately after read,
and the kworker of processing post_read_wq has not been executed yet
due to high workloads, It is possible that the inode(f2fs_inode_info)
is evicted and freed before it is used f2fs_free_dic.

    The UAF case as below:
    Thread A                                      Thread B
    - f2fs_decompress_end_io
     - f2fs_put_dic
      - queue_work
        add free_dic work to post_read_wq
                                                   - do_unlink
                                                    - iput
                                                     - evict
                                                      - call_rcu
    This file is deleted after read.

    Thread C                                 kworker to process post_read_wq
    - rcu_do_batch
     - f2fs_free_inode
      - kmem_cache_free
     inode is freed by rcu
                                             - process_scheduled_works
                                              - f2fs_late_free_dic
                                               - f2fs_free_dic
                                                - f2fs_release_decomp_mem
                                      read (dic->inode)->i_compress_algorithm

This patch store compress_algorithm and sbi in dic to avoid inode UAF.

In addition, the previous solution is deprecated in [1] may cause system hang.
[1] https://lore.kernel.org/all/c36ab955-c8db-4a8b-a9d0-f07b5f426c3f@kernel.org

Cc: Daeho Jeong <daehojeong@google.com>
Fixes: bff139b49d ("f2fs: handle decompress only post processing in softirq")
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Signed-off-by: Baocong Liu <baocong.liu@unisoc.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
[ In Linux 6.6.y, the f2fs_vmalloc() function parameters are not
  related to the f2fs_sb_info structure, the code changes for
  f2fs_vmalloc() have not been backported. ]
Signed-off-by: Bin Lan <lanbincn@139.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-12-01 11:41:51 +01:00
..
acl.c
acl.h
checkpoint.c Revert "f2fs: rebuild nat_bits during umount" 2025-04-25 10:45:16 +02:00
compress.c f2fs: compress: fix UAF of f2fs_inode_info in f2fs_free_dic 2025-12-01 11:41:51 +01:00
data.c f2fs: fix wrong block mapping for multi-devices 2025-10-23 16:16:23 +02:00
debug.c f2fs: use BLKS_PER_SEG, BLKS_PER_SEC, and SEGS_PER_SEC 2024-06-12 11:12:28 +02:00
dir.c f2fs: Introduce linear search for dentries 2025-02-08 09:52:35 +01:00
extent_cache.c f2fs: fix infinite loop in __insert_extent_tree() 2025-11-24 10:29:40 +01:00
f2fs.h f2fs: compress: fix UAF of f2fs_inode_info in f2fs_free_dic 2025-12-01 11:41:51 +01:00
file.c f2fs: fix to mitigate overhead of f2fs_zero_post_eof_page() 2025-10-15 11:58:01 +02:00
gc.c f2fs: fix to avoid use GC_AT when setting gc_mode as GC_URGENT_LOW or GC_URGENT_MID 2024-12-09 10:32:26 +01:00
gc.h
hash.c
inline.c f2fs: Introduce linear search for dentries 2025-02-08 09:52:35 +01:00
inode.c f2fs: fix to avoid panic in f2fs_evict_inode 2025-08-15 12:08:58 +02:00
iostat.c
iostat.h
Kconfig
Makefile
namei.c f2fs: prevent kernel warning due to negative i_nlink from corrupted image 2025-06-27 11:08:48 +01:00
node.c f2fs: fix to avoid out-of-boundary access in dnode page 2025-08-28 16:28:36 +02:00
node.h f2fs: use BLKS_PER_SEG, BLKS_PER_SEC, and SEGS_PER_SEC 2024-06-12 11:12:28 +02:00
recovery.c f2fs: use BLKS_PER_SEG, BLKS_PER_SEC, and SEGS_PER_SEC 2024-06-12 11:12:28 +02:00
segment.c f2fs: fix to set atomic write status more clear 2025-06-27 11:08:56 +01:00
segment.h f2fs: fix to calculate dirty data during has_not_enough_free_secs() 2025-08-15 12:08:59 +02:00
shrinker.c
super.c f2fs: don't over-report free space or inodes in statvfs 2025-07-06 11:00:09 +02:00
sysfs.c f2fs: introduce f2fs_base_attr for global sysfs entries 2025-06-04 14:42:12 +02:00
verity.c
xattr.c f2fs: reduce expensive checkpoint trigger frequency 2024-10-04 16:29:36 +02:00
xattr.h