Skip to content

Commit b905baf

Browse files
leocstonebrauner
authored andcommitted
hfs: Sanity check the root record
In the syzbot reproducer, the hfs_cat_rec for the root dir has type HFS_CDR_FIL after being read with hfs_bnode_read() in hfs_super_fill(). This indicates it should be used as an hfs_cat_file, which is 102 bytes. Only the first 70 bytes of that struct are initialized, however, because the entrylength passed into hfs_bnode_read() is still the length of a directory record. This causes uninitialized values to be used later on, when the hfs_cat_rec union is treated as the larger hfs_cat_file struct. Add a check to make sure the retrieved record has the correct type for the root directory (HFS_CDR_DIR), and make sure we load the correct number of bytes for a directory record. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=2db3c7526ba68f4ea776 Tested-by: [email protected] Tested-by: Leo Stone <[email protected]> Signed-off-by: Leo Stone <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 40384c8 commit b905baf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/hfs/super.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,13 @@ static int hfs_fill_super(struct super_block *sb, struct fs_context *fc)
349349
goto bail_no_root;
350350
res = hfs_cat_find_brec(sb, HFS_ROOT_CNID, &fd);
351351
if (!res) {
352-
if (fd.entrylength > sizeof(rec) || fd.entrylength < 0) {
352+
if (fd.entrylength != sizeof(rec.dir)) {
353353
res = -EIO;
354354
goto bail_hfs_find;
355355
}
356356
hfs_bnode_read(fd.bnode, &rec, fd.entryoffset, fd.entrylength);
357+
if (rec.type != HFS_CDR_DIR)
358+
res = -EIO;
357359
}
358360
if (res)
359361
goto bail_hfs_find;

0 commit comments

Comments
 (0)