Skip to contentSkip to conversation

memory leak in udf_process_sequence

PATCH In review syzbot 3 participants 4 messages Sep 21, 2020 – Sep 23, 2020 UDF filesystem

lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

Hello,

syzbot found the following issue on:

HEAD commit:    325d0eab Merge branch 'akpm' (patches from Andrew)
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=13ec44d3900000
kernel config:  https://syzkaller.appspot.com/x/.config?x=a1f3c5052e8097e9
dashboard link: https://syzkaller.appspot.com/bug?extid=128f4dd6e796c98b3760
compiler:       gcc (GCC) 10.1.0-syz 20200507
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=101a0e9b900000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17ae18d3900000

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]
BUG: memory leak
unreferenced object 0xffff88811a1d0a00 (size 512):
  comm "syz-executor299", pid 6519, jiffies 4294943224 (age 15.090s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<000000009ea2686e>] kmalloc include/linux/slab.h:554 [inline]
    [<000000009ea2686e>] kmalloc_array include/linux/slab.h:593 [inline]
    [<000000009ea2686e>] kcalloc include/linux/slab.h:605 [inline]
    [<000000009ea2686e>] udf_process_sequence+0x7e/0x1080 fs/udf/super.c:1676
    [<00000000d9f60715>] udf_load_sequence fs/udf/super.c:1795 [inline]
    [<00000000d9f60715>] udf_check_anchor_block+0xdc/0x1a0 fs/udf/super.c:1835
    [<0000000067395456>] udf_scan_anchors+0x9e/0x240 fs/udf/super.c:1868
    [<00000000966a1b37>] udf_find_anchor fs/udf/super.c:1925 [inline]
    [<00000000966a1b37>] udf_load_vrs+0x1be/0x3b0 fs/udf/super.c:1990
    [<0000000004bba192>] udf_fill_super+0x286/0x7a5 fs/udf/super.c:2183
    [<00000000d48efb9b>] mount_bdev+0x1d3/0x210 fs/super.c:1417
    [<00000000280e173c>] legacy_get_tree+0x26/0x70 fs/fs_context.c:592
    [<0000000059fde270>] vfs_get_tree+0x28/0xe0 fs/super.c:1547
    [<00000000904c79e7>] do_new_mount fs/namespace.c:2875 [inline]
    [<00000000904c79e7>] path_mount+0x90e/0xda0 fs/namespace.c:3192
    [<000000008e0f8bcd>] do_mount fs/namespace.c:3205 [inline]
    [<000000008e0f8bcd>] __do_sys_mount fs/namespace.c:3413 [inline]
    [<000000008e0f8bcd>] __se_sys_mount fs/namespace.c:3390 [inline]
    [<000000008e0f8bcd>] __x64_sys_mount+0x140/0x190 fs/namespace.c:3390
    [<00000000e981acac>] do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
    [<000000006322386a>] entry_SYSCALL_64_after_hwframe+0x44/0xa9

---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot. syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

#1 lore raw

PATCH 1/1 udf: Fix memory leak in udf_process_sequence()

udf_process_sequence() is leaking memory. Free data.part_descs_loc before returning.

Fixes 7b78fd02fb19 ("udf: Fix handling of Partition Descriptors")
Reported-and-tested-by [email protected]
---
 fs/udf/super.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
fs/udf/super.c +13 -7
index 1c42f544096d..b0d862ab3024 100644
@@ -1698,7 +1698,8 @@ static noinline int udf_process_sequence(
 					"Pointers (max %u supported)\n",
 					UDF_MAX_TD_NESTING);
 				brelse(bh);
-				return -EIO;
+				ret = -EIO;
+				goto out;
 			}
 
 			vdp = (struct volDescPtr *)bh->b_data;
@@ -1718,7 +1719,8 @@ static noinline int udf_process_sequence(
 			curr = get_volume_descriptor_record(ident, bh, &data);
 			if (IS_ERR(curr)) {
 				brelse(bh);
-				return PTR_ERR(curr);
+				ret = PTR_ERR(curr);
+				goto out;
 			}
 			/* Descriptor we don't care about? */
 			if (!curr)
@@ -1740,28 +1742,32 @@ static noinline int udf_process_sequence(
 	 */
 	if (!data.vds[VDS_POS_PRIMARY_VOL_DESC].block) {
 		udf_err(sb, "Primary Volume Descriptor not found!\n");
-		return -EAGAIN;
+		ret = -EAGAIN;
+		goto out;
 	}
 	ret = udf_load_pvoldesc(sb, data.vds[VDS_POS_PRIMARY_VOL_DESC].block);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	if (data.vds[VDS_POS_LOGICAL_VOL_DESC].block) {
 		ret = udf_load_logicalvol(sb,
 				data.vds[VDS_POS_LOGICAL_VOL_DESC].block,
 				fileset);
 		if (ret < 0)
-			return ret;
+			goto out;
 	}
 
 	/* Now handle prevailing Partition Descriptors */
 	for (i = 0; i < data.num_part_descs; i++) {
 		ret = udf_load_partdesc(sb, data.part_descs_loc[i].rec.block);
 		if (ret < 0)
-			return ret;
+			goto out;
 	}
 
-	return 0;
+	ret = 0;
+out:
+	kfree(data.part_descs_loc);
+	return ret;
 }
 
 /*
Signature · 1 line
2.25.1
#2 lore raw

Re: [Linux-kernel-mentees] [PATCH] udf: Fix memory leak in udf_process_sequence()

Quoted 8 lines · Peilin Ye

udf_process_sequence() is leaking memory. Free data.part_descs_loc before returning.

Fixes 7b78fd02fb19 ("udf: Fix handling of Partition Descriptors")
Reported-and-tested-by [email protected]

Thanks for the patch but I've just yesterday written exactly the same patch and merged it to my tree...

Honza

Quoted 69 lines
---
 fs/udf/super.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
fs/udf/super.c +13 -7
index 1c42f544096d..b0d862ab3024 100644
@@ -1698,7 +1698,8 @@ static noinline int udf_process_sequence(
 					"Pointers (max %u supported)\n",
 					UDF_MAX_TD_NESTING);
 				brelse(bh);
-				return -EIO;
+				ret = -EIO;
+				goto out;
 			}
 
 			vdp = (struct volDescPtr *)bh->b_data;
@@ -1718,7 +1719,8 @@ static noinline int udf_process_sequence(
 			curr = get_volume_descriptor_record(ident, bh, &data);
 			if (IS_ERR(curr)) {
 				brelse(bh);
-				return PTR_ERR(curr);
+				ret = PTR_ERR(curr);
+				goto out;
 			}
 			/* Descriptor we don't care about? */
 			if (!curr)
@@ -1740,28 +1742,32 @@ static noinline int udf_process_sequence(
 	 */
 	if (!data.vds[VDS_POS_PRIMARY_VOL_DESC].block) {
 		udf_err(sb, "Primary Volume Descriptor not found!\n");
-		return -EAGAIN;
+		ret = -EAGAIN;
+		goto out;
 	}
 	ret = udf_load_pvoldesc(sb, data.vds[VDS_POS_PRIMARY_VOL_DESC].block);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	if (data.vds[VDS_POS_LOGICAL_VOL_DESC].block) {
 		ret = udf_load_logicalvol(sb,
 				data.vds[VDS_POS_LOGICAL_VOL_DESC].block,
 				fileset);
 		if (ret < 0)
-			return ret;
+			goto out;
 	}
 
 	/* Now handle prevailing Partition Descriptors */
 	for (i = 0; i < data.num_part_descs; i++) {
 		ret = udf_load_partdesc(sb, data.part_descs_loc[i].rec.block);
 		if (ret < 0)
-			return ret;
+			goto out;
 	}
 
-	return 0;
+	ret = 0;
+out:
+	kfree(data.part_descs_loc);
+	return ret;
 }
 
 /*
Signature · 1 line
2.25.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw

Re: [Linux-kernel-mentees] [PATCH] udf: Fix memory leak in udf_process_sequence()

Hi,

Quoted 4 lines · Jan Kara
Quoted 3 lines · Peilin Ye

udf_process_sequence() is leaking memory. Free data.part_descs_loc before returning.

Quoted 8 lines
Quoted 5 lines
Fixes 7b78fd02fb19 ("udf: Fix handling of Partition Descriptors")
Reported-and-tested-by [email protected]

Thanks for the patch but I've just yesterday written exactly the same patch and merged it to my tree...

Ah, no worries, happy to see the bug gets fixed!

Peilin Ye