linux/fs/afs
David Howells 8c7ae38d1c afs: Fix StoreData op marshalling
The marshalling of AFS.StoreData, AFS.StoreData64 and YFS.StoreData64 calls
generated by ->setattr() ops for the purpose of expanding a file is
incorrect due to older documentation incorrectly describing the way the RPC
'FileLength' parameter is meant to work.

The older documentation says that this is the length the file is meant to
end up at the end of the operation; however, it was never implemented this
way in any of the servers, but rather the file is truncated down to this
before the write operation is effected, and never expanded to it (and,
indeed, it was renamed to 'TruncPos' in 2014).

Fix this by setting the position parameter to the new file length and doing
a zero-lengh write there.

The bug causes Xwayland to SIGBUS due to unexpected non-expansion of a file
it then mmaps.  This can be tested by giving the following test program a
filename in an AFS directory:

	#include <stdio.h>
	#include <stdlib.h>
	#include <unistd.h>
	#include <fcntl.h>
	#include <sys/mman.h>
	int main(int argc, char *argv[])
	{
		char *p;
		int fd;
		if (argc != 2) {
			fprintf(stderr,
				"Format: test-trunc-mmap <file>\n");
			exit(2);
		}
		fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC);
		if (fd < 0) {
			perror(argv[1]);
			exit(1);
		}
		if (ftruncate(fd, 0x140008) == -1) {
			perror("ftruncate");
			exit(1);
		}
		p = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
			 MAP_SHARED, fd, 0);
		if (p == MAP_FAILED) {
			perror("mmap");
			exit(1);
		}
		p[0] = 'a';
		if (munmap(p, 4096) < 0) {
			perror("munmap");
			exit(1);
		}
		if (close(fd) < 0) {
			perror("close");
			exit(1);
		}
		exit(0);
	}

Fixes: 31143d5d51 ("AFS: implement basic file write support")
Reported-by: Jonathan Billings <jsbillin@umich.edu>
Tested-by: Jonathan Billings <jsbillin@umich.edu>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-03-28 08:54:20 -07:00
..
addr_list.c afs: Probe multiple fileservers simultaneously 2018-10-24 00:41:09 +01:00
afs_cm.h afs: support the CB.ProbeUuid RPC op 2008-04-29 08:06:26 -07:00
afs_fs.h afs: Prospectively look up extra files when doing a single lookup 2018-04-09 21:12:31 +01:00
afs_vl.h afs: Make use of the YFS service upgrade to fully support IPv6 2017-11-13 15:38:19 +00:00
afs.h afs: Expand data structure fields to support YFS 2018-10-24 00:41:08 +01:00
cache.c afs: Increase to 64-bit volume ID and 96-bit vnode ID for YFS 2018-10-24 00:41:08 +01:00
callback.c afs: Implement YFS support in the fs client 2018-10-24 00:41:08 +01:00
cell.c afs: Fix manually set volume location server list 2019-02-25 11:59:07 -08:00
cmservice.c afs: Probe multiple fileservers simultaneously 2018-10-24 00:41:09 +01:00
dir_edit.c afs: Locally edit directory data for mkdir/create/unlink/... 2018-04-09 21:54:48 +01:00
dir.c afs: Use d_instantiate() rather than d_add() and don't d_drop() 2018-11-29 21:08:14 -05:00
dynroot.c afs: Increase to 64-bit volume ID and 96-bit vnode ID for YFS 2018-10-24 00:41:08 +01:00
file.c fs: don't open code lru_to_page() 2019-01-04 13:13:48 -08:00
flock.c afs: Fix key refcounting in file locking code 2019-01-17 15:17:28 +00:00
fs_probe.c fs/: remove caller signal_pending branch predictions 2019-01-04 13:13:48 -08:00
fsclient.c afs: Fix StoreData op marshalling 2019-03-28 08:54:20 -07:00
inode.c afs: Fix key refcounting in file locking code 2019-01-17 15:17:28 +00:00
internal.h afs: Use fs_context to pass parameters over automount 2019-02-28 03:29:39 -05:00
Kconfig afs: Allow dumping of server cursor on operation failure 2018-10-24 00:41:09 +01:00
main.c afs: Fix cell proc list 2018-10-12 13:18:57 +02:00
Makefile afs: Probe multiple fileservers simultaneously 2018-10-24 00:41:09 +01:00
misc.c afs: Fix missing net error handling 2018-11-29 21:08:14 -05:00
mntpt.c afs: Use fs_context to pass parameters over automount 2019-02-28 03:29:39 -05:00
netdevices.c afs: Implement network namespacing 2018-05-23 12:01:15 +01:00
proc.c afs: Probe multiple fileservers simultaneously 2018-10-24 00:41:09 +01:00
protocol_yfs.h afs: Set correct lock type for the yfs CreateFile 2019-01-10 17:12:05 +00:00
rotate.c afs: Fix missing net error handling 2018-11-29 21:08:14 -05:00
rxrpc.c afs: Fix race in async call refcounting 2019-01-17 15:17:28 +00:00
security.c afs: Fix callback handling 2018-10-24 00:41:09 +01:00
server_list.c afs: Use struct_size() in kzalloc() 2019-01-10 17:12:05 +00:00
server.c afs: Probe multiple fileservers simultaneously 2018-10-24 00:41:09 +01:00
super.c Merge branch 'work.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-03-12 14:08:19 -07:00
vl_list.c afs: Probe multiple fileservers simultaneously 2018-10-24 00:41:09 +01:00
vl_probe.c fs/: remove caller signal_pending branch predictions 2019-01-04 13:13:48 -08:00
vl_rotate.c afs: Fix missing net error handling 2018-11-29 21:08:14 -05:00
vlclient.c afs: Probe multiple fileservers simultaneously 2018-10-24 00:41:09 +01:00
volume.c afs: Add fs_context support 2019-02-28 03:29:38 -05:00
write.c afs: Increase to 64-bit volume ID and 96-bit vnode ID for YFS 2018-10-24 00:41:08 +01:00
xattr.c afs: Increase to 64-bit volume ID and 96-bit vnode ID for YFS 2018-10-24 00:41:08 +01:00
xdr_fs.h afs: Adjust the directory XDR structures 2018-04-09 21:54:48 +01:00
yfsclient.c afs: Fix StoreData op marshalling 2019-03-28 08:54:20 -07:00