Skip to content

Commit 9748f2f

Browse files
Sheng Yonghsiangkao
authored andcommitted
erofs: avoid using multiple devices with different type
For multiple devices, both primary and extra devices should be the same type. `erofs_init_device` has already guaranteed that if the primary is a file-backed device, extra devices should also be regular files. However, if the primary is a block device while the extra device is a file-backed device, `erofs_init_device` will get an ENOTBLK, which is not treated as an error in `erofs_fc_get_tree`, and that leads to an UAF: erofs_fc_get_tree get_tree_bdev_flags(erofs_fc_fill_super) erofs_read_superblock erofs_init_device // sbi->dif0 is not inited yet, // return -ENOTBLK deactivate_locked_super free(sbi) if (err is -ENOTBLK) sbi->dif0.file = filp_open() // sbi UAF So if -ENOTBLK is hitted in `erofs_init_device`, it means the primary device must be a block device, and the extra device is not a block device. The error can be converted to -EINVAL. Fixes: fb17675 ("erofs: add file-backed mount support") Signed-off-by: Sheng Yong <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Hongbo Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 510de83 commit 9748f2f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/erofs/super.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
165165
filp_open(dif->path, O_RDONLY | O_LARGEFILE, 0) :
166166
bdev_file_open_by_path(dif->path,
167167
BLK_OPEN_READ, sb->s_type, NULL);
168-
if (IS_ERR(file))
168+
if (IS_ERR(file)) {
169+
if (file == ERR_PTR(-ENOTBLK))
170+
return -EINVAL;
169171
return PTR_ERR(file);
172+
}
170173

171174
if (!erofs_is_fileio_mode(sbi)) {
172175
dif->dax_dev = fs_dax_get_by_bdev(file_bdev(file),

0 commit comments

Comments
 (0)