linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shuhao Fu <sfual@cse.ust.hk>
To: Namjae Jeon <linkinjeon@kernel.org>,
	Sungjong Seo <sj1557.seo@samsung.com>
Cc: Yuezhang Mo <yuezhang.mo@sony.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] exfat: fix refcount leak in exfat_find
Date: Mon, 20 Oct 2025 15:00:53 +0000	[thread overview]
Message-ID: <aPZOpRfVPZCP8vPw@chcpu18> (raw)

Fix refcount leaks in `exfat_find` related to `exfat_get_dentry_set`.

Function `exfat_get_dentry_set` would increase the reference counter of 
`es->bh` on success. Therefore, `exfat_put_dentry_set` must be called
after `exfat_get_dentry_set` to ensure refcount consistency. In 
`exfat_find`, two branchs fail to call `exfat_put_dentry_set`, leading
to possible resource leaks.

Fixes: 82ebecdc74ff ("exfat: fix improper check of dentry.stream.valid_size")
Fixes: 13940cef9549 ("exfat: add a check for invalid data size")
Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
---
 fs/exfat/namei.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 745dce29d..083a9d790 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -646,11 +646,13 @@ static int exfat_find(struct inode *dir, const struct qstr *qname,
 	info->size = le64_to_cpu(ep2->dentry.stream.size);
 
 	if (info->valid_size < 0) {
+		exfat_put_dentry_set(&es, false);
 		exfat_fs_error(sb, "data valid size is invalid(%lld)", info->valid_size);
 		return -EIO;
 	}
 
 	if (unlikely(EXFAT_B_TO_CLU_ROUND_UP(info->size, sbi) > sbi->used_clusters)) {
+		exfat_put_dentry_set(&es, false);
 		exfat_fs_error(sb, "data size is invalid(%lld)", info->size);
 		return -EIO;
 	}
-- 
2.39.5 (Apple Git-154)


             reply	other threads:[~2025-10-20 15:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 15:00 Shuhao Fu [this message]
2025-10-21  1:38 ` [PATCH] exfat: fix refcount leak in exfat_find Yuezhang.Mo
2025-10-21  8:04   ` Shuhao Fu
2025-10-21  8:21     ` Yuezhang.Mo
2025-10-21  8:47       ` Shuhao Fu

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=aPZOpRfVPZCP8vPw@chcpu18 \
    --to=sfual@cse.ust.hk \
    --cc=linkinjeon@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    --cc=yuezhang.mo@sony.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;
as well as URLs for NNTP newsgroup(s).