]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
afs: Fix afs_write_end() to handle len > page size
authorDavid Howells <dhowells@redhat.com>
Mon, 14 Jun 2021 13:13:41 +0000 (14:13 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 26 Nov 2021 21:23:49 +0000 (21:23 +0000)
It is possible for the len argument to afs_write_end() to overrun the end
of the page (len is used to key the size of the page in afs_write_start()
when compound pages become a regular thing).

Fix afs_write_end() to correctly trim the write length so that it doesn't
exceed the end of the page.

Fixes: 3003bbd0697b ("afs: Use the netfs_write_begin() helper")
Reported-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Jeff Layton <jlayton@kernel.org>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Al Viro <viro@zeniv.linux.org.uk>
cc: Matthew Wilcox <willy@infradead.org>
cc: linux-afs@lists.infradead.org
Link: https://lore.kernel.org/r/162367682522.460125.5652091227576721609.stgit@warthog.procyon.org.uk/
fs/afs/write.c

index 8e4e87d6685587cce289a0842e95234aa49b9f3d..9db3ddb1c45b787ad98d1e27c9274740b4b53f08 100644 (file)
@@ -120,6 +120,7 @@ int afs_write_end(struct file *file, struct address_space *mapping,
        _enter("{%llx:%llu},{%lx}",
               vnode->fid.vid, vnode->fid.vnode, folio_index(folio));
 
+       len = min_t(size_t, len, folio_size(folio) - from);
        if (!folio_test_uptodate(folio)) {
                if (copied < len) {
                        copied = 0;