Skip to content

Commit 81b21c0

Browse files
Tetsuo Handabrauner
authored andcommitted
fs: hfsplus: remove WARN_ON() from hfsplus_cat_{read,write}_inode()
syzbot is hitting WARN_ON() in hfsplus_cat_{read,write}_inode(), for crafted filesystem image can contain bogus length. There conditions are not kernel bugs that can justify kernel to panic. Reported-by: syzbot <syzbot+e2787430e752a92b8750@syzkaller.appspotmail.com> Link: https://syzkaller.appspot.com/bug?extid=e2787430e752a92b8750 Reported-by: syzbot <syzbot+4913dca2ea6e4d43f3f1@syzkaller.appspotmail.com> Link: https://syzkaller.appspot.com/bug?extid=4913dca2ea6e4d43f3f1 Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com> Message-Id: <15308173-5252-d6a3-ae3b-e96d46cb6f41@I-love.SAKURA.ne.jp> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 4ea2a8d commit 81b21c0

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

fs/hfsplus/inode.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,11 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
511511
if (type == HFSPLUS_FOLDER) {
512512
struct hfsplus_cat_folder *folder = &entry.folder;
513513

514-
WARN_ON(fd->entrylength < sizeof(struct hfsplus_cat_folder));
514+
if (fd->entrylength < sizeof(struct hfsplus_cat_folder)) {
515+
pr_err("bad catalog folder entry\n");
516+
res = -EIO;
517+
goto out;
518+
}
515519
hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
516520
sizeof(struct hfsplus_cat_folder));
517521
hfsplus_get_perms(inode, &folder->permissions, 1);
@@ -531,7 +535,11 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
531535
} else if (type == HFSPLUS_FILE) {
532536
struct hfsplus_cat_file *file = &entry.file;
533537

534-
WARN_ON(fd->entrylength < sizeof(struct hfsplus_cat_file));
538+
if (fd->entrylength < sizeof(struct hfsplus_cat_file)) {
539+
pr_err("bad catalog file entry\n");
540+
res = -EIO;
541+
goto out;
542+
}
535543
hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
536544
sizeof(struct hfsplus_cat_file));
537545

@@ -562,6 +570,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
562570
pr_err("bad catalog entry used to create inode\n");
563571
res = -EIO;
564572
}
573+
out:
565574
return res;
566575
}
567576

@@ -570,6 +579,7 @@ int hfsplus_cat_write_inode(struct inode *inode)
570579
struct inode *main_inode = inode;
571580
struct hfs_find_data fd;
572581
hfsplus_cat_entry entry;
582+
int res = 0;
573583

574584
if (HFSPLUS_IS_RSRC(inode))
575585
main_inode = HFSPLUS_I(inode)->rsrc_inode;
@@ -588,7 +598,11 @@ int hfsplus_cat_write_inode(struct inode *inode)
588598
if (S_ISDIR(main_inode->i_mode)) {
589599
struct hfsplus_cat_folder *folder = &entry.folder;
590600

591-
WARN_ON(fd.entrylength < sizeof(struct hfsplus_cat_folder));
601+
if (fd.entrylength < sizeof(struct hfsplus_cat_folder)) {
602+
pr_err("bad catalog folder entry\n");
603+
res = -EIO;
604+
goto out;
605+
}
592606
hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
593607
sizeof(struct hfsplus_cat_folder));
594608
/* simple node checks? */
@@ -613,7 +627,11 @@ int hfsplus_cat_write_inode(struct inode *inode)
613627
} else {
614628
struct hfsplus_cat_file *file = &entry.file;
615629

616-
WARN_ON(fd.entrylength < sizeof(struct hfsplus_cat_file));
630+
if (fd.entrylength < sizeof(struct hfsplus_cat_file)) {
631+
pr_err("bad catalog file entry\n");
632+
res = -EIO;
633+
goto out;
634+
}
617635
hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
618636
sizeof(struct hfsplus_cat_file));
619637
hfsplus_inode_write_fork(inode, &file->data_fork);
@@ -634,7 +652,7 @@ int hfsplus_cat_write_inode(struct inode *inode)
634652
set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags);
635653
out:
636654
hfs_find_exit(&fd);
637-
return 0;
655+
return res;
638656
}
639657

640658
int hfsplus_fileattr_get(struct dentry *dentry, struct fileattr *fa)

0 commit comments

Comments
 (0)