linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: David Howells <dhowells@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-afs@lists.infradead.org
Subject: [PATCH AUTOSEL 5.0 76/98] afs: Fix StoreData op marshalling
Date: Mon, 22 Apr 2019 15:41:43 -0400	[thread overview]
Message-ID: <20190422194205.10404-76-sashal@kernel.org> (raw)
In-Reply-To: <20190422194205.10404-1-sashal@kernel.org>

From: David Howells <dhowells@redhat.com>

[ Upstream commit 8c7ae38d1ce12a0eaeba655df8562552b3596c7f ]

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: 31143d5d515e ("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>
Signed-off-by: Sasha Levin (Microsoft) <sashal@kernel.org>
---
 fs/afs/fsclient.c  | 6 +++---
 fs/afs/yfsclient.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c
index ca08c83168f5..0b37867b5c20 100644
--- a/fs/afs/fsclient.c
+++ b/fs/afs/fsclient.c
@@ -1515,8 +1515,8 @@ static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
 
 	xdr_encode_AFS_StoreStatus(&bp, attr);
 
-	*bp++ = 0;				/* position of start of write */
-	*bp++ = 0;
+	*bp++ = htonl(attr->ia_size >> 32);	/* position of start of write */
+	*bp++ = htonl((u32) attr->ia_size);
 	*bp++ = 0;				/* size of write */
 	*bp++ = 0;
 	*bp++ = htonl(attr->ia_size >> 32);	/* new file length */
@@ -1564,7 +1564,7 @@ static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
 
 	xdr_encode_AFS_StoreStatus(&bp, attr);
 
-	*bp++ = 0;				/* position of start of write */
+	*bp++ = htonl(attr->ia_size);		/* position of start of write */
 	*bp++ = 0;				/* size of write */
 	*bp++ = htonl(attr->ia_size);		/* new file length */
 
diff --git a/fs/afs/yfsclient.c b/fs/afs/yfsclient.c
index 5aa57929e8c2..6e97a42d24d1 100644
--- a/fs/afs/yfsclient.c
+++ b/fs/afs/yfsclient.c
@@ -1514,7 +1514,7 @@ static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
 	bp = xdr_encode_u32(bp, 0); /* RPC flags */
 	bp = xdr_encode_YFSFid(bp, &vnode->fid);
 	bp = xdr_encode_YFS_StoreStatus(bp, attr);
-	bp = xdr_encode_u64(bp, 0);		/* position of start of write */
+	bp = xdr_encode_u64(bp, attr->ia_size);	/* position of start of write */
 	bp = xdr_encode_u64(bp, 0);		/* size of write */
 	bp = xdr_encode_u64(bp, attr->ia_size);	/* new file length */
 	yfs_check_req(call, bp);
-- 
2.19.1


  parent reply	other threads:[~2019-04-22 20:06 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-22 19:40 [PATCH AUTOSEL 5.0 01/98] arm64: dts: renesas: r8a77990: Fix SCIF5 DMA channels Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 02/98] ARM: dts: bcm283x: Fix hdmi hpd gpio pull Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 03/98] s390: limit brk randomization to 32MB Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 04/98] mt76x02: fix hdr pointer in write txwi for USB Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 05/98] mt76: mt76x2: fix external LNA gain settings Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 06/98] mt76: mt76x2: fix 2.4 GHz channel " Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 07/98] net: ieee802154: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 08/98] ieee802154: hwsim: propagate genlmsg_reply return code Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 09/98] Btrfs: fix file corruption after snapshotting due to mix of buffered/DIO writes Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 10/98] net: stmmac: don't set own bit too early for jumbo frames Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 11/98] net: stmmac: fix jumbo frame sending with non-linear skbs Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 12/98] qlcnic: Avoid potential NULL pointer dereference Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 13/98] xsk: fix umem memory leak on cleanup Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 14/98] staging: axis-fifo: add CONFIG_OF dependency Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 15/98] staging, mt7621-pci: fix build without pci support Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 16/98] netfilter: nft_set_rbtree: check for inactive element after flag mismatch Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 17/98] netfilter: bridge: set skb transport_header before entering NF_INET_PRE_ROUTING Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 18/98] netfilter: fix NETFILTER_XT_TARGET_TEE dependencies Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 19/98] netfilter: ip6t_srh: fix NULL pointer dereferences Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 20/98] netfilter: nf_tables: bogus EBUSY in helper removal from transaction Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 21/98] s390/qeth: fix race when initializing the IP address table Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 22/98] ARM: imx51: fix a leaked reference by adding missing of_node_put Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 23/98] sc16is7xx: missing unregister/delete driver on error in sc16is7xx_init() Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 24/98] serial: ar933x_uart: Fix build failure with disabled console Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 25/98] KVM: arm64: Reset the PMU in preemptible context Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 26/98] arm64: KVM: Always set ICH_HCR_EL2.EN if GICv4 is enabled Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 27/98] KVM: arm/arm64: vgic-its: Take the srcu lock when writing to guest memory Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 28/98] KVM: arm/arm64: vgic-its: Take the srcu lock when parsing the memslots Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 29/98] KVM: arm/arm64: Enforce PTE mappings at stage2 when needed Sasha Levin
2019-04-23  9:27   ` Suzuki K Poulose
2019-05-02 12:50     ` Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 30/98] usb: dwc3: pci: add support for Comet Lake PCH ID Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 31/98] usb: gadget: net2280: Fix overrun of OUT messages Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 32/98] usb: gadget: net2280: Fix net2280_dequeue() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 33/98] usb: gadget: net2272: Fix net2272_dequeue() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 34/98] ARM: dts: pfla02: increase phy reset duration Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 35/98] i2c: i801: Add support for Intel Comet Lake Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 36/98] KVM: arm/arm64: Fix handling of stage2 huge mappings Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 37/98] net: ks8851: Dequeue RX packets explicitly Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 38/98] net: ks8851: Reassert reset pin if chip ID check fails Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 39/98] net: ks8851: Delay requesting IRQ until opened Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 40/98] net: ks8851: Set initial carrier state to down Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 41/98] staging: rtl8188eu: Fix potential NULL pointer dereference of kcalloc Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 42/98] staging: rtlwifi: rtl8822b: fix to avoid potential NULL pointer dereference Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 43/98] staging: rtl8712: uninitialized memory in read_bbreg_hdl() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 44/98] staging: rtlwifi: Fix potential NULL pointer dereference of kzalloc Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 45/98] net: phy: Add DP83825I to the DP83822 driver Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 46/98] net: macb: Add null check for PCLK and HCLK Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 47/98] net/sched: don't dereference a->goto_chain to read the chain index Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 48/98] ARM: dts: imx6qdl: Fix typo in imx6qdl-icore-rqs.dtsi Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 49/98] drm/tegra: hub: Fix dereference before check Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 50/98] NFS: Fix a typo in nfs_init_timeout_values() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 51/98] net: xilinx: fix possible object reference leak Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 52/98] net: ibm: " Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 53/98] net: ethernet: ti: " Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 54/98] drm: Fix drm_release() and device unplug Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 55/98] gpio: aspeed: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 56/98] drm/meson: Fix invalid pointer in meson_drv_unbind() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 57/98] drm/meson: Uninstall IRQ handler Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 58/98] ARM: davinci: fix build failure with allnoconfig Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 59/98] sbitmap: order READ/WRITE freed instance and setting clear bit Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 60/98] staging: vc04_services: Fix an error code in vchiq_probe() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 61/98] libceph: fix breakage caused by multipage bvecs Sasha Levin
2019-04-23  8:28   ` Ilya Dryomov
2019-05-02 12:51     ` Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 62/98] scsi: mpt3sas: Fix kernel panic during expander reset Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 63/98] scsi: aacraid: Insure we don't access PCIe space during AER/EEH Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 64/98] scsi: qla4xxx: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 65/98] usb: usb251xb: fix to avoid " Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 66/98] leds: trigger: netdev: fix refcnt leak on interface rename Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 67/98] SUNRPC: fix uninitialized variable warning Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 68/98] x86/realmode: Don't leak the trampoline kernel address Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 69/98] usb: u132-hcd: fix resource leak Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 70/98] tty: fix NULL pointer issue when tty_port ops is not set Sasha Levin
2019-04-22 20:40   ` Greg Kroah-Hartman
2019-05-02 12:53     ` Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 71/98] ceph: fix use-after-free on symlink traversal Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 72/98] scsi: zfcp: reduce flood of fcrscn1 trace records on multi-element RSCN Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 73/98] x86/mm: Don't exceed the valid physical address space Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 74/98] libata: fix using DMA buffers on stack Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 75/98] kbuild: skip parsing pre sub-make code for recursion Sasha Levin
2019-04-22 19:41 ` Sasha Levin [this message]
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 77/98] gpio: of: Check propname before applying "cs-gpios" quirks Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 78/98] gpio: of: Check for "spi-cs-high" in child instead of parent node Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 79/98] KVM: nVMX: Do not inherit quadrant and invalid for the root shadow EPT Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 80/98] KVM: SVM: Workaround errata#1096 (insn_len maybe zero on SMAP violation) Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 81/98] kvm/x86: Move MSR_IA32_ARCH_CAPABILITIES to array emulated_msrs Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 82/98] x86/kvm/hyper-v: avoid spurious pending stimer on vCPU init Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 83/98] KVM: selftests: assert on exit reason in CR4/cpuid sync test Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 84/98] KVM: selftests: explicitly disable PIE for tests Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 85/98] KVM: selftests: disable stack protector for all KVM tests Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 86/98] KVM: selftests: complete IO before migrating guest state Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 87/98] gpio: of: Fix of_gpiochip_add() error path Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 88/98] nvme-multipath: relax ANA state check Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 89/98] nvmet: fix building bvec from sg list Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 90/98] nvmet: fix error flow during ns enable Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 91/98] perf cs-etm: Add missing case value Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 92/98] perf machine: Update kernel map address and re-order properly Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 93/98] kconfig/[mn]conf: handle backspace (^H) key Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 94/98] iommu/amd: Reserve exclusion range in iova-domain Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 95/98] kasan: fix variable 'tag' set but not used warning Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 96/98] ptrace: take into account saved_sigmask in PTRACE{GET,SET}SIGMASK Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 97/98] leds: pca9532: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 98/98] leds: trigger: netdev: use memcpy in device_name_store Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190422194205.10404-76-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).