Skip to content

Commit 4aead50

Browse files
konisakpm00
authored andcommitted
nilfs2: reject invalid file types when reading inodes
To prevent inodes with invalid file types from tripping through the vfs and causing malfunctions or assertion failures, add a missing sanity check when reading an inode from a block device. If the file type is not valid, treat it as a filesystem error. Link: https://lkml.kernel.org/r/20250710134952.29862-1-konishi.ryusuke@gmail.com Fixes: 05fe58f ("nilfs2: inode operations") Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> Reported-by: syzbot+895c23f6917da440ed0d@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=895c23f6917da440ed0d Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 7563fcb commit 4aead50

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

fs/nilfs2/inode.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,18 @@ static int __nilfs_read_inode(struct super_block *sb,
472472
inode->i_op = &nilfs_symlink_inode_operations;
473473
inode_nohighmem(inode);
474474
inode->i_mapping->a_ops = &nilfs_aops;
475-
} else {
475+
} else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
476+
S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
476477
inode->i_op = &nilfs_special_inode_operations;
477478
init_special_inode(
478479
inode, inode->i_mode,
479480
huge_decode_dev(le64_to_cpu(raw_inode->i_device_code)));
481+
} else {
482+
nilfs_error(sb,
483+
"invalid file type bits in mode 0%o for inode %lu",
484+
inode->i_mode, ino);
485+
err = -EIO;
486+
goto failed_unmap;
480487
}
481488
nilfs_ifile_unmap_inode(raw_inode);
482489
brelse(bh);

0 commit comments

Comments
 (0)