* [f2fs-dev] [PATCH] f2fs: fix UAF issue in f2fs_merge_page_bio()
@ 2025-09-28 10:24 Chao Yu via Linux-f2fs-devel
2025-09-29 22:30 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
0 siblings, 1 reply; 2+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-09-28 10:24 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-kernel, JY, linux-f2fs-devel
As JY reported in bugzilla [1],
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
pc : [0xffffffe51d249484] f2fs_is_cp_guaranteed+0x70/0x98
lr : [0xffffffe51d24adbc] f2fs_merge_page_bio+0x520/0x6d4
CPU: 3 UID: 0 PID: 6790 Comm: kworker/u16:3 Tainted: P B W OE 6.12.30-android16-5-maybe-dirty-4k #1 5f7701c9cbf727d1eebe77c89bbbeb3371e895e5
Tainted: [P]=PROPRIETARY_MODULE, [B]=BAD_PAGE, [W]=WARN, [O]=OOT_MODULE, [E]=UNSIGNED_MODULE
Workqueue: writeback wb_workfn (flush-254:49)
Call trace:
f2fs_is_cp_guaranteed+0x70/0x98
f2fs_inplace_write_data+0x174/0x2f4
f2fs_do_write_data_page+0x214/0x81c
f2fs_write_single_data_page+0x28c/0x764
f2fs_write_data_pages+0x78c/0xce4
do_writepages+0xe8/0x2fc
__writeback_single_inode+0x4c/0x4b4
writeback_sb_inodes+0x314/0x540
__writeback_inodes_wb+0xa4/0xf4
wb_writeback+0x160/0x448
wb_workfn+0x2f0/0x5dc
process_scheduled_works+0x1c8/0x458
worker_thread+0x334/0x3f0
kthread+0x118/0x1ac
ret_from_fork+0x10/0x20
[1] https://bugzilla.kernel.org/show_bug.cgi?id=220575
The panic was caused by UAF issue w/ below race condition:
kworker
- writepages
- f2fs_write_cache_pages
- f2fs_write_single_data_page
- f2fs_do_write_data_page
- f2fs_inplace_write_data
- f2fs_merge_page_bio
- add_inu_page
: cache page #1 into bio & cache bio in
io->bio_list
- f2fs_write_single_data_page
- f2fs_do_write_data_page
- f2fs_inplace_write_data
- f2fs_merge_page_bio
- add_inu_page
: cache page #2 into bio which is linked
in io->bio_list
write
- f2fs_write_begin
: write page #1
- f2fs_folio_wait_writeback
- f2fs_submit_merged_ipu_write
- f2fs_submit_write_bio
: submit bio which inclues page #1 and #2
software IRQ
- f2fs_write_end_io
- fscrypt_free_bounce_page
: freed bounced page which belongs to page #2
- inc_page_count( , WB_DATA_TYPE(data_folio), false)
: data_folio points to fio->encrypted_page
the bounced page can be freed before
accessing it in f2fs_is_cp_guarantee()
It can reproduce w/ below testcase:
Run below script in shell #1:
for ((i=1;i>0;i++)) do xfs_io -f /mnt/f2fs/enc/file \
-c "pwrite 0 32k" -c "fdatasync"
Run below script in shell #2:
for ((i=1;i>0;i++)) do xfs_io -f /mnt/f2fs/enc/file \
-c "pwrite 0 32k" -c "fdatasync"
So, in f2fs_merge_page_bio(), let's avoid using fio->encrypted_page after
commit page into internal ipu cache.
Fixes: 0b20fcec8651 ("f2fs: cache global IPU bio")
Reported-by: JY <JY.Ho@mediatek.com>
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/data.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 82ae31b8ecc4..9d1d439e2650 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -919,7 +919,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
if (fio->io_wbc)
wbc_account_cgroup_owner(fio->io_wbc, folio, folio_size(folio));
- inc_page_count(fio->sbi, WB_DATA_TYPE(data_folio, false));
+ inc_page_count(fio->sbi, WB_DATA_TYPE(folio, false));
*fio->last_block = fio->new_blkaddr;
*fio->bio = bio;
--
2.49.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] 2+ messages in thread* Re: [f2fs-dev] [PATCH] f2fs: fix UAF issue in f2fs_merge_page_bio()
2025-09-28 10:24 [f2fs-dev] [PATCH] f2fs: fix UAF issue in f2fs_merge_page_bio() Chao Yu via Linux-f2fs-devel
@ 2025-09-29 22:30 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+f2fs--- via Linux-f2fs-devel @ 2025-09-29 22:30 UTC (permalink / raw)
To: Chao Yu; +Cc: jaegeuk, JY.Ho, linux-kernel, linux-f2fs-devel
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Sun, 28 Sep 2025 18:24:22 +0800 you wrote:
> As JY reported in bugzilla [1],
>
> Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
> pc : [0xffffffe51d249484] f2fs_is_cp_guaranteed+0x70/0x98
> lr : [0xffffffe51d24adbc] f2fs_merge_page_bio+0x520/0x6d4
> CPU: 3 UID: 0 PID: 6790 Comm: kworker/u16:3 Tainted: P B W OE 6.12.30-android16-5-maybe-dirty-4k #1 5f7701c9cbf727d1eebe77c89bbbeb3371e895e5
> Tainted: [P]=PROPRIETARY_MODULE, [B]=BAD_PAGE, [W]=WARN, [O]=OOT_MODULE, [E]=UNSIGNED_MODULE
> Workqueue: writeback wb_workfn (flush-254:49)
> Call trace:
> f2fs_is_cp_guaranteed+0x70/0x98
> f2fs_inplace_write_data+0x174/0x2f4
> f2fs_do_write_data_page+0x214/0x81c
> f2fs_write_single_data_page+0x28c/0x764
> f2fs_write_data_pages+0x78c/0xce4
> do_writepages+0xe8/0x2fc
> __writeback_single_inode+0x4c/0x4b4
> writeback_sb_inodes+0x314/0x540
> __writeback_inodes_wb+0xa4/0xf4
> wb_writeback+0x160/0x448
> wb_workfn+0x2f0/0x5dc
> process_scheduled_works+0x1c8/0x458
> worker_thread+0x334/0x3f0
> kthread+0x118/0x1ac
> ret_from_fork+0x10/0x20
>
> [...]
Here is the summary with links:
- [f2fs-dev] f2fs: fix UAF issue in f2fs_merge_page_bio()
https://git.kernel.org/jaegeuk/f2fs/c/edf7e9040fc5
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] 2+ messages in thread
end of thread, other threads:[~2025-09-29 22:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-28 10:24 [f2fs-dev] [PATCH] f2fs: fix UAF issue in f2fs_merge_page_bio() Chao Yu via Linux-f2fs-devel
2025-09-29 22:30 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).