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: [email protected] Closes: https://lore.kernel.org/r/[email protected] Tested-by: [email protected] Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9852d85 commit 416a8b2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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)