]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
exfat: fix refcount leak in exfat_find
authorShuhao Fu <sfual@cse.ust.hk>
Tue, 21 Oct 2025 08:42:28 +0000 (16:42 +0800)
committerNamjae Jeon <linkinjeon@kernel.org>
Wed, 3 Dec 2025 01:00:16 +0000 (10:00 +0900)
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>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/exfat/namei.c

index 745dce29ddb532f7f4ca6d9aad5ddc8943aab4b5..dfe957493d49eeb6050beb16be4d0b90b8528719 100644 (file)
@@ -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)",