exfat: fix memory leak in exfat_load_bitmap()
authorYuezhang Mo <Yuezhang.Mo@sony.com>
Tue, 3 Sep 2024 07:01:09 +0000 (15:01 +0800)
committerNamjae Jeon <linkinjeon@kernel.org>
Tue, 17 Sep 2024 22:40:58 +0000 (07:40 +0900)
If the first directory entry in the root directory is not a bitmap
directory entry, 'bh' will not be released and reassigned, which
will cause a memory leak.

Fixes: 1e49a94cf707 ("exfat: add bitmap operations")
Cc: stable@vger.kernel.org
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/exfat/balloc.c

index 0356c88252bd34abcdb28e2d478f66f656f3ec4c..ce9be95c9172f680f9c99a1379ace8bd1fec9855 100644 (file)
@@ -91,11 +91,8 @@ int exfat_load_bitmap(struct super_block *sb)
                                return -EIO;
 
                        type = exfat_get_entry_type(ep);
-                       if (type == TYPE_UNUSED)
-                               break;
-                       if (type != TYPE_BITMAP)
-                               continue;
-                       if (ep->dentry.bitmap.flags == 0x0) {
+                       if (type == TYPE_BITMAP &&
+                           ep->dentry.bitmap.flags == 0x0) {
                                int err;
 
                                err = exfat_allocate_bitmap(sb, ep);
@@ -103,6 +100,9 @@ int exfat_load_bitmap(struct super_block *sb)
                                return err;
                        }
                        brelse(bh);
+
+                       if (type == TYPE_UNUSED)
+                               return -EINVAL;
                }
 
                if (exfat_get_next_cluster(sb, &clu.dir))