linux-stable/fs/afs
David Howells f5ea303502 afs: Fix accidental truncation when storing data
[ Upstream commit 03275585ca ]

When an AFS FS.StoreData RPC call is made, amongst other things it is
given the resultant file size to be.  On the server, this is processed
by truncating the file to new size and then writing the data.

Now, kafs has a lock (vnode->io_lock) that serves to serialise
operations against a specific vnode (ie.  inode), but the parameters for
the op are set before the lock is taken.  This allows two writebacks
(say sync and kswapd) to race - and if writes are ongoing the writeback
for a later write could occur before the writeback for an earlier one if
the latter gets interrupted.

Note that afs_writepages() cannot take i_mutex and only takes a shared
lock on vnode->validate_lock.

Also note that the server does the truncation and the write inside a
lock, so there's no problem at that end.

Fix this by moving the calculation for the proposed new i_size inside
the vnode->io_lock.  Also reset the iterator (which we might have read
from) and update the mtime setting there.

Fixes: bd80d8a80e ("afs: Use ITER_XARRAY for writing")
Reported-by: Marc Dionne <marc.dionne@auristor.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeffrey Altman <jaltman@auristor.com>
Reviewed-by: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
cc: linux-fsdevel@vger.kernel.org
Link: https://lore.kernel.org/r/3526895.1687960024@warthog.procyon.org.uk/
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-07-19 16:22:06 +02:00
..
addr_list.c
afs.h
afs_cm.h
afs_fs.h
afs_vl.h
callback.c netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context 2022-06-09 13:55:00 -07:00
cell.c afs: Use refcount_t rather than atomic_t 2022-08-02 18:10:11 +01:00
cmservice.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
dir.c afs: Fix setting of mtime when creating a file/dir/symlink 2023-06-14 11:15:16 +02:00
dir_edit.c netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context 2022-06-09 13:55:00 -07:00
dir_silly.c netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context 2022-06-09 13:55:00 -07:00
dynroot.c netfs: Further cleanups after struct netfs_inode wrapper introduced 2022-06-10 20:55:21 +01:00
file.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
flock.c afs: Use the operation issue time instead of the reply time for callbacks 2022-09-01 11:44:13 +01:00
fs_operation.c netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context 2022-06-09 13:55:00 -07:00
fs_probe.c afs: Fix lost servers_outstanding count 2022-12-31 13:33:08 +01:00
fsclient.c afs: Use the operation issue time instead of the reply time for callbacks 2022-09-01 11:44:13 +01:00
inode.c afs: Fix getattr to report server i_size on dirs, not local size 2023-05-11 23:03:38 +09:00
internal.h use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
Kconfig afs: Convert afs to use the new fscache API 2022-01-07 13:44:47 +00:00
main.c afs: Convert afs to use the new fscache API 2022-01-07 13:44:47 +00:00
Makefile afs: Convert afs to use the new fscache API 2022-01-07 13:44:47 +00:00
misc.c afs: Return -EAGAIN, not -EREMOTEIO, when a file already locked 2022-09-06 21:33:01 -04:00
mntpt.c afs: Remove check of PageError 2022-06-29 08:51:06 -04:00
proc.c afs: Use refcount_t rather than atomic_t 2022-08-02 18:10:11 +01:00
protocol_afs.h
protocol_uae.h
protocol_yfs.h
rotate.c afs: Adjust ACK interpretation to try and cope with NAT 2022-05-22 21:03:02 +01:00
rxrpc.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
security.c afs: Prefer struct_size over open coded arithmetic 2022-04-26 10:20:00 -05:00
server.c afs: Fix server->active leak in afs_put_server 2022-11-30 10:02:37 -08:00
server_list.c
super.c netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context 2022-06-09 13:55:00 -07:00
vl_alias.c
vl_list.c afs: Use refcount_t rather than atomic_t 2022-08-02 18:10:11 +01:00
vl_probe.c afs: Fix vlserver probe RTT handling 2023-06-21 16:01:02 +02:00
vl_rotate.c
vlclient.c
volume.c afs: Use refcount_t rather than atomic_t 2022-08-02 18:10:11 +01:00
write.c afs: Fix accidental truncation when storing data 2023-07-19 16:22:06 +02:00
xattr.c
xdr_fs.h
yfsclient.c afs: Use the operation issue time instead of the reply time for callbacks 2022-09-01 11:44:13 +01:00