linux-yocto/fs/erofs
Gao Xiang 5244536e65 erofs: fix rare pcluster memory leak after unmounting
commit b10a1e5643 upstream.

There may still exist some pcluster with valid reference counts
during unmounting.  Instead of introducing another synchronization
primitive, just try again as unmounting is relatively rare.  This
approach is similar to z_erofs_cache_invalidate_folio().

It was also reported by syzbot as a UAF due to commit f5ad9f9a60
("erofs: free pclusters if no cached folio is attached"):

BUG: KASAN: slab-use-after-free in do_raw_spin_trylock+0x72/0x1f0 kernel/locking/spinlock_debug.c:123
..
 queued_spin_trylock include/asm-generic/qspinlock.h:92 [inline]
 do_raw_spin_trylock+0x72/0x1f0 kernel/locking/spinlock_debug.c:123
 __raw_spin_trylock include/linux/spinlock_api_smp.h:89 [inline]
 _raw_spin_trylock+0x20/0x80 kernel/locking/spinlock.c:138
 spin_trylock include/linux/spinlock.h:361 [inline]
 z_erofs_put_pcluster fs/erofs/zdata.c:959 [inline]
 z_erofs_decompress_pcluster fs/erofs/zdata.c:1403 [inline]
 z_erofs_decompress_queue+0x3798/0x3ef0 fs/erofs/zdata.c:1425
 z_erofs_decompressqueue_work+0x99/0xe0 fs/erofs/zdata.c:1437
 process_one_work kernel/workqueue.c:3229 [inline]
 process_scheduled_works+0xa68/0x1840 kernel/workqueue.c:3310
 worker_thread+0x870/0xd30 kernel/workqueue.c:3391
 kthread+0x2f2/0x390 kernel/kthread.c:389
 ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
 </TASK>

However, it seems a long outstanding memory leak.  Fix it now.

Fixes: f5ad9f9a60 ("erofs: free pclusters if no cached folio is attached")
Reported-by: syzbot+7ff87b095e7ca0c5ac39@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/r/674c1235.050a0220.ad585.0032.GAE@google.com
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20241203072821.1885740-1-hsiangkao@linux.alibaba.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-07-17 18:37:23 +02:00
..
compress.h erofs: avoid refcounting short-lived pages 2024-07-11 15:14:26 +08:00
data.c erofs: fix to add missing tracepoint in erofs_readahead() 2025-07-17 18:37:18 +02:00
decompressor_deflate.c erofs: tidy up stream decompressors 2024-07-09 19:04:41 +08:00
decompressor_lzma.c erofs: convert comma to semicolon 2024-07-26 18:48:12 +08:00
decompressor_zstd.c erofs: tidy up stream decompressors 2024-07-09 19:04:41 +08:00
decompressor.c erofs: address D-cache aliasing 2025-07-17 18:37:15 +02:00
dir.c erofs: simplify readdir operation 2024-08-19 11:06:20 +08:00
erofs_fs.h erofs: restrict pcluster size limitations 2024-09-12 23:00:09 +08:00
fileio.c erofs: refine readahead tracepoint 2025-07-17 18:37:18 +02:00
fscache.c erofs: reference struct erofs_device_info for erofs_map_dev 2024-12-27 14:02:00 +01:00
inode.c erofs: reject inodes with negative i_size 2024-09-12 23:00:09 +08:00
internal.h erofs: address D-cache aliasing 2025-07-17 18:37:15 +02:00
Kconfig erofs: mark experimental fscache backend deprecated 2024-09-10 15:27:11 +08:00
Makefile erofs: support unencoded inodes for fileio 2024-09-10 15:26:36 +08:00
namei.c erofs_buf: store address_space instead of inode 2024-04-25 00:57:14 -04:00
super.c erofs: avoid using multiple devices with different type 2025-06-19 15:31:29 +02:00
sysfs.c erofs: clean up erofs_register_sysfs() 2024-09-10 00:46:34 +08:00
xattr.c add a string-to-qstr constructor 2025-07-10 16:05:08 +02:00
xattr.h
zdata.c erofs: refine readahead tracepoint 2025-07-17 18:37:18 +02:00
zmap.c erofs: handle NONHEAD !delta[1] lclusters gracefully 2024-12-05 14:02:00 +01:00
zutil.c erofs: fix rare pcluster memory leak after unmounting 2025-07-17 18:37:23 +02:00