diff mbox series

[4/5] afs: Zero bytes after 'oldsize' if we're expanding the file

Message ID 20230202204428.3267832-5-willy@infradead.org (mailing list archive)
State New
Headers show
Series Fix a minor POSIX conformance problem | expand

Commit Message

Matthew Wilcox (Oracle) Feb. 2, 2023, 8:44 p.m. UTC
POSIX requires that "If the file size is increased, the extended area
shall appear as if it were zero-filled".  It is possible to use mmap to
write past EOF and that data will become visible instead of zeroes.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/afs/inode.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

David Howells Feb. 27, 2023, 1:49 p.m. UTC | #1
Matthew Wilcox (Oracle) <willy@infradead.org> wrote:

> POSIX requires that "If the file size is increased, the extended area
> shall appear as if it were zero-filled".  It is possible to use mmap to
> write past EOF and that data will become visible instead of zeroes.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

That seems to work.  Do you want me to pass it on to Linus?  If not:

Acked-by: David Howells <dhowells@redhat.com>
Matthew Wilcox (Oracle) Feb. 27, 2023, 2:09 p.m. UTC | #2
On Mon, Feb 27, 2023 at 01:49:27PM +0000, David Howells wrote:
> Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
> 
> > POSIX requires that "If the file size is increased, the extended area
> > shall appear as if it were zero-filled".  It is possible to use mmap to
> > write past EOF and that data will become visible instead of zeroes.
> > 
> > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> 
> That seems to work.  Do you want me to pass it on to Linus?  If not:
> 
> Acked-by: David Howells <dhowells@redhat.com>

I'll send a patch series with all of this; it doesn't seem terribly
urgent.  Do you think there's a similar problem for AFS that Brian
noted with the generic patch?
David Howells Feb. 27, 2023, 2:20 p.m. UTC | #3
Matthew Wilcox <willy@infradead.org> wrote:

> I'll send a patch series with all of this; it doesn't seem terribly
> urgent.  Do you think there's a similar problem for AFS that Brian
> noted with the generic patch?

Do you have a link I can look at?

David
David Howells Feb. 27, 2023, 2:49 p.m. UTC | #4
Matthew Wilcox <willy@infradead.org> wrote:

> I'll send a patch series with all of this; it doesn't seem terribly
> urgent.  Do you think there's a similar problem for AFS that Brian
> noted with the generic patch?

Probably not.  To avoid deadlocking itself, afs uses a mutex to prevent
writepages racing with truncate (vnode->validate_lock).

	commit ec0fa0b659144d9c68204d23f627b6a65fa53e50
	afs: Fix deadlock between writeback and truncate

the afs_setattr_edit_file() call that changes i_size and partially clears the
pagecache is applied to the local inode before the mutex is dropped.

David
diff mbox series

Patch

diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 6d3a3dbe4928..92e2ba7625de 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -854,6 +854,8 @@  static void afs_setattr_edit_file(struct afs_operation *op)
 
 		if (size < i_size)
 			truncate_pagecache(inode, size);
+		else
+			truncate_pagecache(inode, i_size);
 		if (size != i_size)
 			fscache_resize_cookie(afs_vnode_cache(vp->vnode),
 					      vp->scb.status.size);