mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: jiazhenyuan <jiazhenyuan@uniontech.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca,
	libaokun@linux.alibaba.com, jack@suse.cz, ojaswin@linux.ibm.com,
	ritesh.list@gmail.com, yi.zhang@huawei.com,
	linux-ext4@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, gouhao@uniontech.com,
	niecheng1@uniontech.com, guanwentao@uniontech.com,
	caina@uniontech.com, zhaoshuang@uniontech.com,
	wangqing@uniontech.com
Subject: [PATCH 1/2] ext4: fix buffer head leak in ext4_ext_precache()
Date: Fri, 27 Nov 2026 14:49:25 +0800	[thread overview]
Message-ID: <20261127064926.135945-1-jiazhenyuan@uniontech.com> (raw)

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


             reply	other threads:[~2026-11-27  6:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  6:49 jiazhenyuan [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127064926.135945-1-jiazhenyuan@uniontech.com \
    --to=jiazhenyuan@uniontech.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=caina@uniontech.com \
    --cc=gouhao@uniontech.com \
    --cc=guanwentao@uniontech.com \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=niecheng1@uniontech.com \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=wangqing@uniontech.com \
    --cc=yi.zhang@huawei.com \
    --cc=zhaoshuang@uniontech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®