Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

afs: Fix accidental truncation when storing data

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: bd80d8a80e12 ("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>

authored by

David Howells and committed by
Linus Torvalds
03275585 538140ca

+5 -3
+5 -3
fs/afs/write.c
··· 413 413 afs_op_set_vnode(op, 0, vnode); 414 414 op->file[0].dv_delta = 1; 415 415 op->file[0].modification = true; 416 - op->store.write_iter = iter; 417 416 op->store.pos = pos; 418 417 op->store.size = size; 419 - op->store.i_size = max(pos + size, vnode->netfs.remote_i_size); 420 418 op->store.laundering = laundering; 421 - op->mtime = vnode->netfs.inode.i_mtime; 422 419 op->flags |= AFS_OPERATION_UNINTR; 423 420 op->ops = &afs_store_data_operation; 424 421 425 422 try_next_key: 426 423 afs_begin_vnode_operation(op); 424 + 425 + op->store.write_iter = iter; 426 + op->store.i_size = max(pos + size, vnode->netfs.remote_i_size); 427 + op->mtime = vnode->netfs.inode.i_mtime; 428 + 427 429 afs_wait_for_operation(op); 428 430 429 431 switch (op->error) {