erofs: fix file-backed mounts over FUSE
PATCH RESEND v3 1/1 erofs: fix file-backed mounts over FUSE
syzbot reported a null-ptr-deref in fuse_read_args_fill:
fuse_read_folio+0xb0/0x100 fs/fuse/file.c:905 filemap_read_folio+0xc6/0x2a0 mm/filemap.c:2367 do_read_cache_folio+0x263/0x5c0 mm/filemap.c:3825 read_mapping_folio include/linux/pagemap.h:1011 [inline] erofs_bread+0x34d/0x7e0 fs/erofs/data.c:41 erofs_read_superblock fs/erofs/super.c:281 [inline] erofs_fc_fill_super+0x2b9/0x2500 fs/erofs/super.c:625
Unlike most filesystems, some network filesystems and FUSE need unavoidable valid file pointers for their read I/Os [1]. Anyway, those use cases need to be supported too.
[1] https://docs.kernel.org/filesystems/vfs.html
Reported-by [email protected]
Fixes fb176750266a ("erofs: add file-backed mount support")
Tested-by [email protected]
Signed-off-by Gao Xiang <[email protected]>
---
v2: https://lore.kernel.org/r/[email protected]
Changes since v2:
- set *both* ->mapping and ->file suggested by Al.
fs/erofs/data.c | 10 ++++++---- fs/erofs/internal.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-)
fs/erofs/data.c +6 -4
@@ -38,7 +38,7 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, }if (!folio || !folio_contains (folio, index)) {erofs_put_metabuf (buf); - folio =read_mapping_folio (buf->mapping, index,NULL ); + folio =read_mapping_folio (buf->mapping, index, buf->file);if (IS_ERR (folio))return folio; }
@@ -61,9 +61,11 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb) {struct erofs_sb_info *sbi =EROFS_SB (sb); -if (erofs_is_fileio_mode (sbi)) - buf->mapping =file_inode (sbi->fdev)->i_mapping; -else if (erofs_is_fscache_mode (sb)) + buf->file =NULL ; +if (erofs_is_fileio_mode (sbi)) { + buf->file = sbi->fdev;/* some fs like FUSE needs it */ + buf->mapping = buf->file->f_mapping; + }else if (erofs_is_fscache_mode (sb)) buf->mapping = sbi->s_fscache->inode->i_mapping;else buf->mapping = sb->s_bdev->bd_mapping;
fs/erofs/internal.h +1 -0
@@ -209,6 +209,7 @@ enum erofs_kmap_type {struct erofs_buf {struct address_space *mapping; +struct file *file;struct page *page;void *base;enum erofs_kmap_type kmap_type;
Signature · 1 line
2.43.5