Skip to content

Commit 3a23787

Browse files
committed
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: syzbot+0b1279812c46e48bb0c1@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/6727bbdf.050a0220.3c8d68.0a7e.GAE@google.com Fixes: fb17675 ("erofs: add file-backed mount support") Tested-by: syzbot+0b1279812c46e48bb0c1@syzkaller.appspotmail.com Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20241114234905.1873723-1-hsiangkao@linux.alibaba.com
1 parent 90655ee commit 3a23787

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

fs/erofs/data.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset,
3838
}
3939
if (!folio || !folio_contains(folio, index)) {
4040
erofs_put_metabuf(buf);
41-
folio = read_mapping_folio(buf->mapping, index, NULL);
41+
folio = read_mapping_folio(buf->mapping, index, buf->file);
4242
if (IS_ERR(folio))
4343
return folio;
4444
}
@@ -61,9 +61,11 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb)
6161
{
6262
struct erofs_sb_info *sbi = EROFS_SB(sb);
6363

64-
if (erofs_is_fileio_mode(sbi))
65-
buf->mapping = file_inode(sbi->fdev)->i_mapping;
66-
else if (erofs_is_fscache_mode(sb))
64+
buf->file = NULL;
65+
if (erofs_is_fileio_mode(sbi)) {
66+
buf->file = sbi->fdev; /* some fs like FUSE needs it */
67+
buf->mapping = buf->file->f_mapping;
68+
} else if (erofs_is_fscache_mode(sb))
6769
buf->mapping = sbi->s_fscache->inode->i_mapping;
6870
else
6971
buf->mapping = sb->s_bdev->bd_mapping;

fs/erofs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ enum erofs_kmap_type {
209209

210210
struct erofs_buf {
211211
struct address_space *mapping;
212+
struct file *file;
212213
struct page *page;
213214
void *base;
214215
enum erofs_kmap_type kmap_type;

0 commit comments

Comments
 (0)