All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] exfat: fix refcount leak in exfat_find
@ 2025-10-21  8:42 Shuhao Fu
  2025-10-21  9:20 ` Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Shuhao Fu @ 2025-10-21  8:42 UTC (permalink / raw)
  To: Namjae Jeon, Sungjong Seo; +Cc: Yuezhang Mo, linux-fsdevel, linux-kernel

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. This patch
relocate two checks to avoid possible 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>
---
Change to v1: [1]
- relocate two checks

[1] https://lore.kernel.org/linux-fsdevel/aPZOpRfVPZCP8vPw@chcpu18/
---
 fs/exfat/namei.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 745dce29d..dfe957493 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -645,16 +645,6 @@ static int exfat_find(struct inode *dir, const struct qstr *qname,
 	info->valid_size = le64_to_cpu(ep2->dentry.stream.valid_size);
 	info->size = le64_to_cpu(ep2->dentry.stream.size);
 
-	if (info->valid_size < 0) {
-		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_fs_error(sb, "data size is invalid(%lld)", info->size);
-		return -EIO;
-	}
-
 	info->start_clu = le32_to_cpu(ep2->dentry.stream.start_clu);
 	if (!is_valid_cluster(sbi, info->start_clu) && info->size) {
 		exfat_warn(sb, "start_clu is invalid cluster(0x%x)",
@@ -692,6 +682,16 @@ static int exfat_find(struct inode *dir, const struct qstr *qname,
 			     0);
 	exfat_put_dentry_set(&es, false);
 
+	if (info->valid_size < 0) {
+		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_fs_error(sb, "data size is invalid(%lld)", info->size);
+		return -EIO;
+	}
+
 	if (ei->start_clu == EXFAT_FREE_CLUSTER) {
 		exfat_fs_error(sb,
 			       "non-zero size file starts with zero cluster (size : %llu, p_dir : %u, entry : 0x%08x)",
-- 
2.39.5 (Apple Git-154)


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

* Re: [PATCH v2] exfat: fix refcount leak in exfat_find
  2025-10-21  8:42 [PATCH v2] exfat: fix refcount leak in exfat_find Shuhao Fu
@ 2025-10-21  9:20 ` Markus Elfring
  2025-10-22  4:55 ` Yuezhang.Mo
  2025-10-22  5:41 ` Namjae Jeon
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-10-21  9:20 UTC (permalink / raw)
  To: Shuhao Fu, linux-fsdevel, Namjae Jeon, Sungjong Seo; +Cc: LKML, Yuezhang Mo

…
> 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. This patch
> relocate two checks to avoid possible leaks.
…

* Would it be preferred to refer to the term “reference count” in consistent ways?

* I see possibilities to improve such a change description another bit.
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc1#n94


Regards,
Markus

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

* Re: [PATCH v2] exfat: fix refcount leak in exfat_find
  2025-10-21  8:42 [PATCH v2] exfat: fix refcount leak in exfat_find Shuhao Fu
  2025-10-21  9:20 ` Markus Elfring
@ 2025-10-22  4:55 ` Yuezhang.Mo
  2025-10-22  5:41 ` Namjae Jeon
  2 siblings, 0 replies; 4+ messages in thread
From: Yuezhang.Mo @ 2025-10-22  4:55 UTC (permalink / raw)
  To: Shuhao Fu, Namjae Jeon, Sungjong Seo
  Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org

On Tue, Oct 21, 2025 16:42 Shuhao Fu <sfual@cse.ust.hk> wrote:
> 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. This patch
> relocate two checks to avoid possible 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>
> ---
> Change to v1: [1]
> - relocate two checks
> 
> [1] https://lore.kernel.org/linux-fsdevel/aPZOpRfVPZCP8vPw@chcpu18/
> ---
>  fs/exfat/namei.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
> index 745dce29d..dfe957493 100644
> --- a/fs/exfat/namei.c
> +++ b/fs/exfat/namei.c
> @@ -645,16 +645,6 @@ static int exfat_find(struct inode *dir, const struct qstr *qname,
>         info->valid_size = le64_to_cpu(ep2->dentry.stream.valid_size);
>         info->size = le64_to_cpu(ep2->dentry.stream.size);
> 
> -       if (info->valid_size < 0) {
> -               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_fs_error(sb, "data size is invalid(%lld)", info->size);
> -               return -EIO;
> -       }
> -
>         info->start_clu = le32_to_cpu(ep2->dentry.stream.start_clu);
>         if (!is_valid_cluster(sbi, info->start_clu) && info->size) {
>                 exfat_warn(sb, "start_clu is invalid cluster(0x%x)",
> @@ -692,6 +682,16 @@ static int exfat_find(struct inode *dir, const struct qstr *qname,
>                              0);
>         exfat_put_dentry_set(&es, false);
> 
> +       if (info->valid_size < 0) {
> +               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_fs_error(sb, "data size is invalid(%lld)", info->size);
> +               return -EIO;
> +       }
> +
>         if (ei->start_clu == EXFAT_FREE_CLUSTER) {
>                 exfat_fs_error(sb,
>                                "non-zero size file starts with zero cluster (size : %llu, p_dir : %u, entry : 0x%08x)",

Looks good to me.
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>

> --
> 2.39.5 (Apple Git-154)

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

* Re: [PATCH v2] exfat: fix refcount leak in exfat_find
  2025-10-21  8:42 [PATCH v2] exfat: fix refcount leak in exfat_find Shuhao Fu
  2025-10-21  9:20 ` Markus Elfring
  2025-10-22  4:55 ` Yuezhang.Mo
@ 2025-10-22  5:41 ` Namjae Jeon
  2 siblings, 0 replies; 4+ messages in thread
From: Namjae Jeon @ 2025-10-22  5:41 UTC (permalink / raw)
  To: Shuhao Fu; +Cc: Sungjong Seo, Yuezhang Mo, linux-fsdevel, linux-kernel

On Tue, Oct 21, 2025 at 5:42 PM Shuhao Fu <sfual@cse.ust.hk> wrote:
>
> 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. This patch
> relocate two checks to avoid possible 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>
Applied it with a reviewed-by tag to #dev.
Thanks!

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

end of thread, other threads:[~2025-10-22  5:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21  8:42 [PATCH v2] exfat: fix refcount leak in exfat_find Shuhao Fu
2025-10-21  9:20 ` Markus Elfring
2025-10-22  4:55 ` Yuezhang.Mo
2025-10-22  5:41 ` Namjae Jeon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.