mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] ext4: fix buffer head leak in ext4_ext_precache()
@ 2026-11-27  6:49 jiazhenyuan
  2026-11-27  6:49 ` [PATCH 2/2] ext4: add KUnit test for ext4_ext_precache() buffer head leak jiazhenyuan
  2026-11-27 14:29 ` [PATCH 1/2] ext4: fix buffer head leak in ext4_ext_precache() Jan Kara
  0 siblings, 2 replies; 3+ messages in thread
From: jiazhenyuan @ 2026-11-27  6:49 UTC (permalink / raw)
  To: tytso, adilger.kernel, libaokun, jack, ojaswin, ritesh.list,
	yi.zhang, linux-ext4
  Cc: linux-kernel, gouhao, niecheng1, guanwentao, caina, zhaoshuang, wangqing

ext4_ext_precache() stores each successfully read child extent block in
path[1..depth].p_bh. During normal traversal, these references are
released as the loop backtracks. If a later read fails, traversal breaks
to out and calls ext4_free_ext_path() before all ancestor references
have been dropped.

path[0].p_depth is not initialized, so ext4_ext_drop_refs() only
releases path[0].p_bh. Since the root block is inline and path[0].p_bh
is NULL, buffer heads held by path[1..depth] are leaked.

Set path[0].p_depth to the inode's extent depth so cleanup covers the
entire traversal stack.

Without this patch, the KUnit test added in the following patch reports:

    # test_ext_precache_read_failure_bh_leak: EXPECTATION FAILED at
    # fs/ext4/extents-test.c:1568
    Expected atomic_read(&bh->b_count) == 2, but
        atomic_read(&bh->b_count) == 3 (0x3)

Fixes: 7869a4a6c5caa ("ext4: add support for extent pre-caching")
Cc: stable@vger.kernel.org
Signed-off-by: jiazhenyuan <jiazhenyuan@uniontech.com>
---
 fs/ext4/extents.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index b65b0261ee5c..4c775aa41459 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -638,6 +638,8 @@ int ext4_ext_precache(struct inode *inode)
 		return -ENOMEM;
 	}
 
+	path[0].p_depth = depth;
+
 	path[0].p_hdr = ext_inode_hdr(inode);
 	ret = ext4_ext_check(inode, path[0].p_hdr, depth, 0);
 	if (ret)
-- 
2.20.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27 14:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27  6:49 [PATCH 1/2] ext4: fix buffer head leak in ext4_ext_precache() jiazhenyuan
2026-11-27  6:49 ` [PATCH 2/2] ext4: add KUnit test for ext4_ext_precache() buffer head leak jiazhenyuan
2026-11-27 14:29 ` [PATCH 1/2] ext4: fix buffer head leak in ext4_ext_precache() Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®