diff mbox series

[v1] exfat: fix memory leak in exfat_load_bitmap()

Message ID PUZPR04MB6316152C6E22EF7D5D5973C3819B2@PUZPR04MB6316.apcprd04.prod.outlook.com (mailing list archive)
State New
Headers show
Series [v1] exfat: fix memory leak in exfat_load_bitmap() | expand

Commit Message

Yuezhang.Mo@sony.com Sept. 11, 2024, 1:45 a.m. UTC
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")

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
---
 fs/exfat/balloc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Namjae Jeon Sept. 11, 2024, 11:40 a.m. UTC | #1
On Wed, Sep 11, 2024 at 10:46 AM Yuezhang.Mo@sony.com
<Yuezhang.Mo@sony.com> wrote:
>
> 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")
>
> Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
> Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Applied it to #dev.
Thank you!
diff mbox series

Patch

diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c
index 0356c88252bd..ce9be95c9172 100644
--- a/fs/exfat/balloc.c
+++ b/fs/exfat/balloc.c
@@ -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))