Skip to content

Commit 3f4aa98

Browse files
committed
afs: Fix EOF corruption
When doing a partial writeback, afs_write_back_from_locked_page() may generate an FS.StoreData RPC request that writes out part of a file when a file has been constructed from pieces by doing seek, write, seek, write, ... as is done by ld. The FS.StoreData RPC is given the current i_size as the file length, but the server basically ignores it unless the data length is 0 (in which case it's just a truncate operation). The revised file length returned in the result of the RPC may then not reflect what we suggested - and this leads to i_size getting moved backwards - which causes issues later. Fix the client to take account of this by ignoring the returned file size unless the data version number jumped unexpectedly - in which case we're going to have to clear the pagecache and reload anyway. This can be observed when doing a kernel build on an AFS mount. The following pair of commands produce the issue: ld -m elf_x86_64 -z max-page-size=0x200000 --emit-relocs \ -T arch/x86/realmode/rm/realmode.lds \ arch/x86/realmode/rm/header.o \ arch/x86/realmode/rm/trampoline_64.o \ arch/x86/realmode/rm/stack.o \ arch/x86/realmode/rm/reboot.o \ -o arch/x86/realmode/rm/realmode.elf arch/x86/tools/relocs --realmode \ arch/x86/realmode/rm/realmode.elf \ >arch/x86/realmode/rm/realmode.relocs This results in the latter giving: Cannot read ELF section headers 0/18: Success as the realmode.elf file got corrupted. The sequence of events can also be driven with: xfs_io -t -f \ -c "pwrite -S 0x58 0 0x58" \ -c "pwrite -S 0x59 10000 1000" \ -c "close" \ /afs/example.com/scratch/a Fixes: 31143d5 ("AFS: implement basic file write support") Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 1f32ef7 commit 3f4aa98

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎fs/afs/inode.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ static void afs_apply_status(struct afs_operation *op,
168168
struct timespec64 t;
169169
umode_t mode;
170170
bool data_changed = false;
171+
bool change_size = false;
171172

172173
_enter("{%llx:%llu.%u} %s",
173174
vp->fid.vid, vp->fid.vnode, vp->fid.unique,
@@ -226,18 +227,27 @@ static void afs_apply_status(struct afs_operation *op,
226227
} else {
227228
set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
228229
}
230+
change_size = true;
229231
} else if (vnode->status.type == AFS_FTYPE_DIR) {
230232
/* Expected directory change is handled elsewhere so
231233
* that we can locally edit the directory and save on a
232234
* download.
233235
*/
234236
if (test_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
235237
data_changed = false;
238+
change_size = true;
236239
}
237240

238241
if (data_changed) {
239242
inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
240-
afs_set_i_size(vnode, status->size);
243+
244+
/* Only update the size if the data version jumped. If the
245+
* file is being modified locally, then we might have our own
246+
* idea of what the size should be that's not the same as
247+
* what's on the server.
248+
*/
249+
if (change_size)
250+
afs_set_i_size(vnode, status->size);
241251
}
242252
}
243253

0 commit comments

Comments
 (0)