Skip to content

Commit 416a8b2

Browse files
committed
erofs: ensure regular inodes for file-backed mounts
Only regular inodes are allowed for file-backed mounts, not directories (as seen in the original syzbot case) or special inodes. Also ensure that .read_folio() is implemented on the underlying fs for the primary device. Fixes: fb17675 ("erofs: add file-backed mount support") Reported-by: syzbot+001306cd9c92ce0df23f@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/00000000000011bdde0622498ee3@google.com Tested-by: syzbot+001306cd9c92ce0df23f@syzkaller.appspotmail.com Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20240917130803.32418-1-hsiangkao@linux.alibaba.com
1 parent 9852d85 commit 416a8b2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

fs/erofs/super.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,14 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
191191
if (IS_ERR(file))
192192
return PTR_ERR(file);
193193

194-
dif->file = file;
195-
if (!erofs_is_fileio_mode(sbi))
194+
if (!erofs_is_fileio_mode(sbi)) {
196195
dif->dax_dev = fs_dax_get_by_bdev(file_bdev(file),
197196
&dif->dax_part_off, NULL, NULL);
197+
} else if (!S_ISREG(file_inode(file)->i_mode)) {
198+
fput(file);
199+
return -EINVAL;
200+
}
201+
dif->file = file;
198202
}
199203

200204
dif->blocks = le32_to_cpu(dis->blocks);
@@ -714,7 +718,10 @@ static int erofs_fc_get_tree(struct fs_context *fc)
714718
if (IS_ERR(sbi->fdev))
715719
return PTR_ERR(sbi->fdev);
716720

717-
return get_tree_nodev(fc, erofs_fc_fill_super);
721+
if (S_ISREG(file_inode(sbi->fdev)->i_mode) &&
722+
sbi->fdev->f_mapping->a_ops->read_folio)
723+
return get_tree_nodev(fc, erofs_fc_fill_super);
724+
fput(sbi->fdev);
718725
}
719726
#endif
720727
return ret;

0 commit comments

Comments
 (0)