Re: Cramfs: "unable to handle kernel paging request" when reading a file from a fuzzed FS image
From: Anatoly Trosinenko
Date: Wed Oct 31 2018 - 09:07:10 EST
Tested in fresh torvalds/master branch. Thank you!
Best regards
Anatoly
ÐÐ, 29 ÐÐÑ. 2018 Ð. Ð 19:03, Nicolas Pitre <nicolas.pitre@xxxxxxxxxx>:
>
> On Mon, 29 Oct 2018, Anatoly Trosinenko wrote:
>
> > > How do I populate /vtmp? Mine is empty at this point. I imagine I
> > > should put the cramfs image somewhere on the host, but I'm not that
> > > familiar withkvm.
> >
> > Oops, forgot to say, it is the /tmp/kvm-xfstests-$USER directory on
> > the host (it will be created when you first launch kvm-xfstests and it
> > is "live", i.e. like NFS, not like "pack to ext4 image then boot and
> > mount").
>
> OK, I reproduced it. The fix is as follows:
>
> diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
> index f408994fc6..6e000392e4 100644
> --- a/fs/cramfs/inode.c
> +++ b/fs/cramfs/inode.c
> @@ -202,7 +202,8 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset,
> continue;
> blk_offset = (blocknr - buffer_blocknr[i]) << PAGE_SHIFT;
> blk_offset += offset;
> - if (blk_offset + len > BUFFER_SIZE)
> + if (blk_offset > BUFFER_SIZE ||
> + blk_offset + len > BUFFER_SIZE)
> continue;
> return read_buffers[i] + blk_offset;
> }
>
> User space will get a bunch of zeroes rather than an explicit error in
> this case. There is just so many ways to corrupt a cramfs image without
> detecting it afterwards that I don't think it is worth doing more than
> making sure the system won't be compromized.
>
> > > Hmmm... It doesn't show up on my test system.
> >
> > Mounted it on my host Ubuntu 18.10 amd64, executed `cat /mnt/xyz` and
> > it was "Killed". Maybe it is something freshly added or
> > arch-dependent...
>
> It actually depends on whether there is something mapped immediately
> next to the cramfs cache buffer.
>
> In any case, this is a nice catch. Thank you for reporting it.
>
>
> Nicolas