Skip to contentSkip to conversation

fsck.f2fs: allow to print more infos before assert() in init_sb_info()

PATCH New Chao Yu via Linux-f2fs-devel 1 participant 3 messages Jul 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 fsck.f2fs: allow to print more infos before assert() in init_sb_info()

It allows to print more informations once assert() is triggered in init_sb_info().

---
 fsck/mount.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fsck/mount.c +7 -2
index a7f16e7..dbbeb56 100644
@@ -1261,8 +1261,13 @@ int init_sb_info(struct f2fs_sb_info *sbi)
 			if (get_device_info(i))
 				ASSERT(0);
 		} else if (c.func != INJECT) {
-			ASSERT(!strcmp((char *)sb->devs[i].path,
-						(char *)c.devices[i].path));
+			if (strcmp((char *)sb->devs[i].path,
+					(char *)c.devices[i].path)) {
+				MSG(0, "paths mismatch: %s, %s\n",
+					(char *)sb->devs[i].path,
+					(char *)c.devices[i].path);
+				ASSERT(0);
+			}
 		}
 
 		c.devices[i].total_segments =
Signature · 8 lines
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

PATCH 2/3 mkfs.f2fs: fix to limit length of main device path in f2fs_parse_options()

Otherwise, mkfs.f2fs may persist truncated path of main device.

- mkfs.f2fs /mnt/f2fs/0123456789012345678901234567890123456789012345678901234 \
-c /mnt/f2fs/012345678901234567890123456789012345678901234567890123 -f
- mount /mnt/f2fs/0123456789012345678901234567890123456789012345678901234 /mnt/f2fs/loop

F2FS-fs (loop0): Mount Device [ 0]: /mnt/f2fs/012345678901234567890123456789012345678901234567890123, 511, 0 - 3ffff
F2FS-fs (loop0): Failed to find devices

---
 mkfs/f2fs_format_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
mkfs/f2fs_format_main.c +6 -0
index 3a8fde0..f0bec4f 100644
@@ -384,6 +384,12 @@ static void f2fs_parse_options(int argc, char *argv[])
 		mkfs_usage();
 	}
 
+	if (c.ndevs > 1 && strlen(argv[optind]) > MAX_PATH_LEN) {
+		MSG(0, "Error: main device path %s should be equal or "
+				"less than %d characters\n",
+				argv[optind], MAX_PATH_LEN);
+		mkfs_usage();
+	}
 	/* [0] : META, [1 to MAX_DEVICES - 1] : NODE/DATA */
 	c.devices[0].path = strdup(argv[optind]);
 
Signature · 8 lines
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#2 lore raw

PATCH 3/3 fsck.f2fs: fix to use strncmp to avoid out-of-boundary access

In reply to Chao Yu via Linux-f2fs-devel

Otherwise, if length of main device path is equal to MAX_PATH_LEN, it will trigger assert() as below:

[ASSERT] (init_sb_info:1264) !strcmp((char *)sb->devs[i].path, (char *)c.devices[i].path)

This is because there is no null character in the end of devcie path string, result in out-of-boundary access in devs.path[].

Let's use strncmp instead of strcmp to compare device path to fix this issue.

---
 fsck/mount.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fsck/mount.c +3 -2
index dbbeb56..a1c4cbb 100644
@@ -1261,8 +1261,9 @@ int init_sb_info(struct f2fs_sb_info *sbi)
 			if (get_device_info(i))
 				ASSERT(0);
 		} else if (c.func != INJECT) {
-			if (strcmp((char *)sb->devs[i].path,
-					(char *)c.devices[i].path)) {
+			if (strncmp((char *)sb->devs[i].path,
+					(char *)c.devices[i].path,
+					MAX_PATH_LEN)) {
 				MSG(0, "paths mismatch: %s, %s\n",
 					(char *)sb->devs[i].path,
 					(char *)c.devices[i].path);
Signature · 8 lines
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel