[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251008042325.468846-1-kartikey406@gmail.com>
Date: Wed, 8 Oct 2025 09:53:25 +0530
From: Deepanshu Kartikey <kartikey406@...il.com>
To: mark@...heh.com,
jlbec@...lplan.org,
joseph.qi@...ux.alibaba.com
Cc: ocfs2-devel@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Deepanshu Kartikey <kartikey406@...il.com>,
syzbot+6fdd8fa3380730a4b22c@...kaller.appspotmail.com
Subject: [PATCH] ocfs2: fix stale extent map cache during COW operations
The extent map cache can become stale during COW operations, causing
ocfs2_refcount_cal_cow_clusters() to see an outdated extent state.
The problem occurs when:
1. ocfs2_get_clusters() reads and caches an extent with OCFS2_EXT_REFCOUNTED
2. ocfs2_refcount_cow_hunk() performs COW, clearing the REFCOUNTED flag
3. The extent map cache still contains the stale REFCOUNTED flag
4. Subsequent access on the same extent via the cache gets incorrect flags,
triggering BUG_ON(!(rec->e_flags & OCFS2_EXT_REFCOUNTED))
Fix by clearing the extent map cache at the start of COW operations.
This ensures that ocfs2_get_clusters() always reads fresh extent data
from disk during COW instead of using stale cached data.
Reported-by: syzbot+6fdd8fa3380730a4b22c@...kaller.appspotmail.com
Tested-by: syzbot+6fdd8fa3380730a4b22c@...kaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <kartikey406@...il.com>
---
fs/ocfs2/refcounttree.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index 267b50e8e42e..e8c8fcdc3dd9 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -3451,7 +3451,8 @@ int ocfs2_refcount_cow(struct inode *inode,
int ret = 0;
u32 p_cluster, num_clusters;
unsigned int ext_flags;
-
+ /* Clear extent map cache before COW operations to avoid stale data */
+ ocfs2_extent_map_trunc(inode, 0);
while (write_len) {
ret = ocfs2_get_clusters(inode, cpos, &p_cluster,
&num_clusters, &ext_flags);
--
2.43.0
Powered by blists - more mailing lists