Thread (85 messages) 85 messages, 4 authors, 2021-12-14
STALE1651d REVIEWED: 4 (4M)
Revisions (3)
  1. v1 [diff vs current]
  2. v2 current
  3. v4 [diff vs current]

[PATCH v2 56/67] afs: Fix afs_write_end() to handle len > page size

From: David Howells <dhowells@redhat.com>
Date: 2021-12-09 17:08:44
Also in: ceph-devel, linux-cifs, linux-fsdevel, lkml
Subsystem: afs filesystem, filesystems (vfs and infrastructure), the rest · Maintainers: David Howells, Marc Dionne, Alexander Viro, Christian Brauner, Linus Torvalds

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/ (local) # v1
Link: https://lore.kernel.org/r/163819660464.215744.4576104569408497052.stgit@warthog.procyon.org.uk/ (local) # v1
---

 fs/afs/write.c |    1 +
 1 file changed, 1 insertion(+)
diff --git a/fs/afs/write.c b/fs/afs/write.c
index 8e4e87d66855..9db3ddb1c45b 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -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;

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help