FS-Cache: Handle a write to the page immediately beyond the EOF marker
authorDavid Howells <dhowells@redhat.com>
Wed, 4 Nov 2015 15:20:42 +0000 (15:20 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 27 Nov 2015 12:48:24 +0000 (12:48 +0000)
commitcf1857234d83095c437e2cc8346e5a2783667cf1
tree9c9c27e0814919d71c88e6b6e86e036af66dcbc2
parent8f2746bba547a5dc23edf74b6006a0a593dfc08f
FS-Cache: Handle a write to the page immediately beyond the EOF marker

commit 102f4d900c9c8f5ed89ae4746d493fe3ebd7ba64 upstream.

Handle a write being requested to the page immediately beyond the EOF
marker on a cache object.  Currently this gets an assertion failure in
CacheFiles because the EOF marker is used there to encode information about
a partial page at the EOF - which could lead to an unknown blank spot in
the file if we extend the file over it.

The problem is actually in fscache where we check the index of the page
being written against store_limit.  store_limit is set to the number of
pages that we're allowed to store by fscache_set_store_limit() - which
means it's one more than the index of the last page we're allowed to store.
The problem is that we permit writing to a page with an index _equal_ to
the store limit - when we should reject that case.

Whilst we're at it, change the triggered assertion in CacheFiles to just
return -ENOBUFS instead.

The assertion failure looks something like this:

CacheFiles: Assertion failed
1000 < 7b1 is false
------------[ cut here ]------------
kernel BUG at fs/cachefiles/rdwr.c:962!
...
RIP: 0010:[<ffffffffa02c9e83>]  [<ffffffffa02c9e83>] cachefiles_write_page+0x273/0x2d0 [cachefiles]

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
[bwh: Backported to 3.2: we don't have __kernel_write() so keep using the
 open-coded equivalent]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/cachefiles/rdwr.c
fs/fscache/page.c