linux/fs/ocfs2
Deepanshu Kartikey 78a63493f8 ocfs2: clear extent cache after moving/defragmenting extents
The extent map cache can become stale when extents are moved or
defragmented, causing subsequent operations to see outdated extent flags. 
This triggers a BUG_ON in ocfs2_refcount_cal_cow_clusters().

The problem occurs when:
1. copy_file_range() creates a reflinked extent with OCFS2_EXT_REFCOUNTED
2. ioctl(FITRIM) triggers ocfs2_move_extents()
3. __ocfs2_move_extents_range() reads and caches the extent (flags=0x2)
4. ocfs2_move_extent()/ocfs2_defrag_extent() calls __ocfs2_move_extent()
   which clears OCFS2_EXT_REFCOUNTED flag on disk (flags=0x0)
5. The extent map cache is not invalidated after the move
6. Later write() operations read stale cached flags (0x2) but disk has
   updated flags (0x0), causing a mismatch
7. BUG_ON(!(rec->e_flags & OCFS2_EXT_REFCOUNTED)) triggers

Fix by clearing the extent map cache after each extent move/defrag
operation in __ocfs2_move_extents_range().  This ensures subsequent
operations read fresh extent data from disk.

Link: https://lore.kernel.org/all/20251009142917.517229-1-kartikey406@gmail.com/T/
Link: https://lkml.kernel.org/r/20251009154903.522339-1-kartikey406@gmail.com
Fixes: 53069d4e76 ("Ocfs2/move_extents: move/defrag extents within a certain range.")
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Reported-by: syzbot+6fdd8fa3380730a4b22c@syzkaller.appspotmail.com
Tested-by: syzbot+6fdd8fa3380730a4b22c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?id=2959889e1f6e216585ce522f7e8bc002b46ad9e7
Reviewed-by: Mark Fasheh <mark@fasheh.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-10-15 13:24:33 -07:00
..
cluster treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
dlm Patch series in this pull request: 2025-10-02 18:44:54 -07:00
dlmfs vfs-6.18-rc1.workqueue 2025-09-29 10:27:17 -07:00
Kconfig
Makefile
acl.c
acl.h
alloc.c ocfs2: remove unnecessary NULL check in ocfs2_grab_folios() 2025-09-13 17:32:49 -07:00
alloc.h ocfs2: convert ocfs2_map_and_dirty_page() to ocfs2_map_and_dirty_folio() 2025-01-12 20:21:13 -08:00
aops.c Significant patch series in this pull request: 2025-08-03 16:23:09 -07:00
aops.h ocfs2: remove ocfs2_start_walk_page_trans() prototype 2025-01-12 20:21:13 -08:00
blockcheck.c
blockcheck.h
buffer_head_io.c ocfs2: fix possible null-ptr-deref in ocfs2_set_buffer_uptodate 2024-09-09 15:15:54 -07:00
buffer_head_io.h
dcache.c ocfs2_dentry_revalidate(): use stable parent inode and name passed by caller 2025-01-27 19:25:24 -05:00
dcache.h
dir.c ocfs2: avoid NULL pointer dereference in dx_dir_lookup_rec() 2025-07-19 19:08:27 -07:00
dir.h
dlmglue.c ocfs2: use str_yes_no() and str_no_yes() helper functions 2025-01-24 22:47:28 -08:00
dlmglue.h ocfs2: convert ocfs2_inode_lock_with_page() to ocfs2_inode_lock_with_folio() 2025-01-12 20:21:10 -08:00
export.c exportfs: Remove EXPORT_OP_ASYNC_LOCK 2024-10-01 17:01:08 +02:00
export.h
extent_map.c ocfs2: fix recursive semaphore deadlock in fiemap call 2025-09-08 23:45:11 -07:00
extent_map.h
file.c fs: replace mmap hook with .mmap_prepare for simple mappings 2025-06-19 13:56:59 +02:00
file.h ocfs2: store cookie in private data 2024-09-12 11:58:44 +02:00
filecheck.c ocfs2: simplify return statement in ocfs2_filecheck_attr_store() 2025-05-11 17:54:08 -07:00
filecheck.h
heartbeat.c
heartbeat.h
inode.c ocfs2: add suballoc slot check in ocfs2_validate_inode_block() 2025-09-13 17:32:53 -07:00
inode.h
ioctl.c ocfs2: avoid extra calls to strlen() after ocfs2_sprintf_system_inode_name() 2025-09-22 20:11:00 -07:00
ioctl.h tree-wide: s/struct fileattr/struct file_kattr/g 2025-07-04 16:14:39 +02:00
journal.c ocfs2: stop quota recovery before disabling quotas 2025-05-07 23:39:40 -07:00
journal.h ocfs2: stop quota recovery before disabling quotas 2025-05-07 23:39:40 -07:00
localalloc.c ocfs2: fix the space leak in LA when releasing LA 2024-12-18 19:04:41 -08:00
localalloc.h
locks.c
locks.h
mmap.c fs: replace mmap hook with .mmap_prepare for simple mappings 2025-06-19 13:56:59 +02:00
mmap.h fs: replace mmap hook with .mmap_prepare for simple mappings 2025-06-19 13:56:59 +02:00
move_extents.c ocfs2: clear extent cache after moving/defragmenting extents 2025-10-15 13:24:33 -07:00
move_extents.h
namei.c ocfs2: update d_splice_alias() return code checking 2025-07-09 22:57:57 -07:00
namei.h
ocfs1_fs_compat.h
ocfs2.h ocfs2: stop quota recovery before disabling quotas 2025-05-07 23:39:40 -07:00
ocfs2_fs.h ocfs2: fix super block reserved field offset comment 2025-09-13 17:32:49 -07:00
ocfs2_ioctl.h ocfs2: miscellaneous spelling fixes 2025-01-12 20:21:07 -08:00
ocfs2_lockid.h ocfs2: miscellaneous spelling fixes 2025-01-12 20:21:07 -08:00
ocfs2_lockingver.h
ocfs2_trace.h ocfs2: convert to the new mount API 2025-01-12 20:21:06 -08:00
quota.h ocfs2: remove unused declaration in header file 2024-11-05 17:12:26 -08:00
quota_global.c ocfs2: remove reference to bh->b_page 2025-03-16 23:24:13 -07:00
quota_local.c ocfs2: fix possible memory leak in ocfs2_finish_quota_recovery 2025-05-11 17:54:11 -07:00
refcounttree.c VFS: rename kern_path_locked() and related functions. 2025-09-23 12:37:36 +02:00
refcounttree.h
reservations.c ocfs2: correctly use ocfs2_find_next_zero_bit() 2024-04-25 21:07:01 -07:00
reservations.h ocfs2: miscellaneous spelling fixes 2025-01-12 20:21:07 -08:00
resize.c ocfs2: uncache inode which has failed entering the group 2024-11-14 22:43:48 -08:00
resize.h
slot_map.c
slot_map.h
stack_o2cb.c ocfs2: miscellaneous spelling fixes 2025-01-12 20:21:07 -08:00
stack_user.c Patch series in this pull request: 2025-10-02 18:44:54 -07:00
stackglue.c ocfs2: remove unnecessary NULL check before unregister_sysctl_table() 2025-05-11 17:54:11 -07:00
stackglue.h ocfs2: miscellaneous spelling fixes 2025-01-12 20:21:07 -08:00
suballoc.c ocfs2: fix the issue with discontiguous allocation in the global_bitmap 2025-05-07 23:39:37 -07:00
suballoc.h ocfs2: fix the issue with discontiguous allocation in the global_bitmap 2025-05-07 23:39:37 -07:00
super.c new helper: set_default_d_op() 2025-06-10 22:21:16 -04:00
super.h
symlink.c ocfs2: use a folio in ocfs2_fast_symlink_read_folio() 2025-01-12 20:21:13 -08:00
symlink.h
sysfile.c ocfs2: avoid extra calls to strlen() after ocfs2_sprintf_system_inode_name() 2025-09-22 20:11:00 -07:00
sysfile.h
uptodate.c
uptodate.h
xattr.c ocfs2: miscellaneous spelling fixes 2025-01-12 20:21:07 -08:00
xattr.h