aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cachefiles/rdwr.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2015-11-04 10:20:42 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2015-11-11 02:11:02 -0500
commit102f4d900c9c8f5ed89ae4746d493fe3ebd7ba64 (patch)
tree1478b45629f2cd2a499a4b06f9938c2ad3ed0942 /fs/cachefiles/rdwr.c
parent95201a40604791bc4a2e8d066429be89fb82b46d (diff)
FS-Cache: Handle a write to the page immediately beyond the EOF marker
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] Cc: stable@vger.kernel.org # v2.6.31+; earlier - that + backport of a17754f (at least) Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/cachefiles/rdwr.c')
-rw-r--r--fs/cachefiles/rdwr.c67
1 files changed, 37 insertions, 30 deletions
diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index e76c2452ac40..7a6b02f72787 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -899,6 +899,15 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
899 cache = container_of(object->fscache.cache, 899 cache = container_of(object->fscache.cache,
900 struct cachefiles_cache, cache); 900 struct cachefiles_cache, cache);
901 901
902 pos = (loff_t)page->index << PAGE_SHIFT;
903
904 /* We mustn't write more data than we have, so we have to beware of a
905 * partial page at EOF.
906 */
907 eof = object->fscache.store_limit_l;
908 if (pos >= eof)
909 goto error;
910
902 /* write the page to the backing filesystem and let it store it in its 911 /* write the page to the backing filesystem and let it store it in its
903 * own time */ 912 * own time */
904 path.mnt = cache->mnt; 913 path.mnt = cache->mnt;
@@ -906,40 +915,38 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
906 file = dentry_open(&path, O_RDWR | O_LARGEFILE, cache->cache_cred); 915 file = dentry_open(&path, O_RDWR | O_LARGEFILE, cache->cache_cred);
907 if (IS_ERR(file)) { 916 if (IS_ERR(file)) {
908 ret = PTR_ERR(file); 917 ret = PTR_ERR(file);
909 } else { 918 goto error_2;
910 pos = (loff_t) page->index << PAGE_SHIFT;
911
912 /* we mustn't write more data than we have, so we have
913 * to beware of a partial page at EOF */
914 eof = object->fscache.store_limit_l;
915 len = PAGE_SIZE;
916 if (eof & ~PAGE_MASK) {
917 ASSERTCMP(pos, <, eof);
918 if (eof - pos < PAGE_SIZE) {
919 _debug("cut short %llx to %llx",
920 pos, eof);
921 len = eof - pos;
922 ASSERTCMP(pos + len, ==, eof);
923 }
924 }
925
926 data = kmap(page);
927 ret = __kernel_write(file, data, len, &pos);
928 kunmap(page);
929 if (ret != len)
930 ret = -EIO;
931 fput(file);
932 } 919 }
933 920
934 if (ret < 0) { 921 len = PAGE_SIZE;
935 if (ret == -EIO) 922 if (eof & ~PAGE_MASK) {
936 cachefiles_io_error_obj( 923 if (eof - pos < PAGE_SIZE) {
937 object, "Write page to backing file failed"); 924 _debug("cut short %llx to %llx",
938 ret = -ENOBUFS; 925 pos, eof);
926 len = eof - pos;
927 ASSERTCMP(pos + len, ==, eof);
928 }
939 } 929 }
940 930
941 _leave(" = %d", ret); 931 data = kmap(page);
942 return ret; 932 ret = __kernel_write(file, data, len, &pos);
933 kunmap(page);
934 fput(file);
935 if (ret != len)
936 goto error_eio;
937
938 _leave(" = 0");
939 return 0;
940
941error_eio:
942 ret = -EIO;
943error_2:
944 if (ret == -EIO)
945 cachefiles_io_error_obj(object,
946 "Write page to backing file failed");
947error:
948 _leave(" = -ENOBUFS [%d]", ret);
949 return -ENOBUFS;
943} 950}
944 951
945/* 952/*