File-backed mounts take any regular file as the image and the same goes
for the extra devices of such a mount. erofs reads them with the
credentials of the mounter so this doesn't hand out anything the mounter
couldn't read anyway. But files on pseudo filesystems aren't images.
Refuse them just like loop does.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 fs/erofs/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index ce05557bd998..980d5fc2b576 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -158,7 +158,8 @@ static int erofs_init_device(struct erofs_buf *buf, struct 
super_block *sb,
                if (!erofs_is_fileio_mode(sbi)) {
                        dif->dax_dev = fs_dax_get_by_bdev(file_bdev(file),
                                        &dif->dax_part_off, NULL, NULL);
-               } else if (!S_ISREG(file_inode(file)->i_mode)) {
+               } else if (!S_ISREG(file_inode(file)->i_mode) ||
+                          file_is_pseudo(file)) {
                        fput(file);
                        return -EINVAL;
                }
@@ -835,6 +836,9 @@ static int erofs_file_get_tree(struct fs_context *fc)
 {
        struct erofs_sb_info *sbi = fc->s_fs_info;
 
+       if (file_is_pseudo(sbi->dif0.file))
+               return invalfc(fc, "source is on a pseudo filesystem");
+
        if (!test_opt(&sbi->opt, SUPERBLOCK_SHARE))
                return get_tree_nodev(fc, erofs_fc_fill_super);
 

-- 
2.53.0


Reply via email to