Skip to contentSkip to conversation

mkfs.f2fs: Fix out-of-bounds read in f2fs_prepare_super_block

PATCH New Peter Collingbourne via Linux-f2fs-devel 1 participant 1 message Jul 27, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.f2fs: Fix out-of-bounds read in f2fs_prepare_super_block

The path field in c.devices[i] is a pointer and is normally filled in using strdup. This makes it invalid to copy MAX_PATH_LEN bytes from it because the string may be shorter than that. Therefore, fix the code to use strncpy to copy the string instead.

---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +1 -1
index c9d335a..b053685 100644
@@ -316,7 +316,7 @@ static int f2fs_prepare_super_block(void)
 					c.blks_per_seg - 1;
 		}
 		if (c.ndevs > 1) {
-			memcpy(sb->devs[i].path, c.devices[i].path, MAX_PATH_LEN);
+			strncpy((char *)sb->devs[i].path, c.devices[i].path, MAX_PATH_LEN);
 			sb->devs[i].total_segments =
 					cpu_to_le32(c.devices[i].total_segments);
 		}
Signature · 8 lines
2.46.0.rc1.232.g9752f9e123-goog



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