]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 13:08:22 +0000 (15:08 +0200)
commit d2b537b3e533f28e0d97293fe9293161fe8cd137 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/exfat/balloc.c

index ab091440e8b934464d06c83dff1aee2e6913d7f4..0501b8c04d8d785bdbc39750faf56f04ef4fcee6 100644 (file)
@@ -110,11 +110,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);
@@ -122,6 +119,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))