Skip to contentSkip to conversation

fs: ext4: Unmount FS in do_fs_type()

PATCH New Marek Vasut 2 participants 2 messages Feb 6, 2019 – Feb 19, 2019 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: ext4: Unmount FS in do_fs_type()

Unlike other generic FS accessors, fs_get_info() does not call fs_close() at the end of it's operation. Thus, using fs_get_info() in do_fs_type() without calling fs_close() causes potential memory leak by creating new filesystem structures on each call of do_fs_type().

The test case to trigger this problem is as follows. It is required to have ext4 filesystem on the first partition of the SDMMC device, since ext4 requires stateful mount and causes memory allocation. => while true ; do mmc rescan ; fstype mmc 1 ; done Eventually, the mounting of ext4 will fail due to malloc failures and the filesystem will not be correctly detected.

This patch fixes the problem by adding the missing fs_close().

---
 fs/fs.c | 2 ++
 1 file changed, 2 insertions(+)
fs/fs.c +2 -0
index 0e9c2f1062..c5c35ebf5f 100644
@@ -801,6 +801,8 @@ int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	else
 		printf("%s\n", info->name);
 
+	fs_close();
+
 	return CMD_RET_SUCCESS;
 }
 
Signature · 1 line
2.19.2
#1 lore raw

PATCH 1/1 fs: ext4: Unmount FS in do_fs_type()

Quoted 13 lines · Marek Vasut

Unlike other generic FS accessors, fs_get_info() does not call fs_close() at the end of it's operation. Thus, using fs_get_info() in do_fs_type() without calling fs_close() causes potential memory leak by creating new filesystem structures on each call of do_fs_type().

The test case to trigger this problem is as follows. It is required to have ext4 filesystem on the first partition of the SDMMC device, since ext4 requires stateful mount and causes memory allocation. => while true ; do mmc rescan ; fstype mmc 1 ; done Eventually, the mounting of ext4 will fail due to malloc failures and the filesystem will not be correctly detected.

Quoted 9 lines

This patch fixes the problem by adding the missing fs_close().

---
 fs/fs.c | 2 ++
 1 file changed, 2 insertions(+)