[PATCH RFC v2 40/42] erofs: refuse files on pseudo filesystems as backing files
Christian Brauner
brauner at kernel.org
Sat Nov 14 13:02:21 UTC 2026
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.
file_check_backing() also checks that the file is open for reading. So
a source file descriptor that erofs can't read from fails the mount
right away instead of on the first read.
Signed-off-by: Christian Brauner (Amutable) <brauner at kernel.org>
---
fs/erofs/super.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index ce05557bd9983..517a289b9395c 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -158,7 +158,7 @@ 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 (file_check_backing(file, FMODE_READ, 0)) {
fput(file);
return -EINVAL;
}
@@ -835,6 +835,9 @@ static int erofs_file_get_tree(struct fs_context *fc)
{
struct erofs_sb_info *sbi = fc->s_fs_info;
+ if (file_check_backing(sbi->dif0.file, FMODE_READ, 0))
+ return invalfc(fc, "source can't be used as a backing file");
+
if (!test_opt(&sbi->opt, SUPERBLOCK_SHARE))
return get_tree_nodev(fc, erofs_fc_fill_super);
--
2.53.0
More information about the Linux-security-module-archive
mailing list