linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, NeilBrown <neilb@suse.com>,
	Anna Schumaker <Anna.Schumaker@Netapp.com>
Subject: [PATCH 4.12 10/31] NFS: invalidate file size when taking a lock.
Date: Thu,  3 Aug 2017 16:17:40 -0700	[thread overview]
Message-ID: <20170803231737.641411637@linuxfoundation.org> (raw)
In-Reply-To: <20170803231737.202188456@linuxfoundation.org>

4.12-stable review patch.  If anyone has any objections, please let me know.

------------------

From: NeilBrown <neilb@suse.com>

commit 442ce0499c0535f8972b68fa1fda357357a5c953 upstream.

Prior to commit ca0daa277aca ("NFS: Cache aggressively when file is open
for writing"), NFS would revalidate, or invalidate, the file size when
taking a lock.  Since that commit it only invalidates the file content.

If the file size is changed on the server while wait for the lock, the
client will have an incorrect understanding of the file size and could
corrupt data.  This particularly happens when writing beyond the
(supposed) end of file and can be easily be demonstrated with
posix_fallocate().

If an application opens an empty file, waits for a write lock, and then
calls posix_fallocate(), glibc will determine that the underlying
filesystem doesn't support fallocate (assuming version 4.1 or earlier)
and will write out a '0' byte at the end of each 4K page in the region
being fallocated that is after the end of the file.
NFS will (usually) detect that these writes are beyond EOF and will
expand them to cover the whole page, and then will merge the pages.
Consequently, NFS will write out large blocks of zeroes beyond where it
thought EOF was.  If EOF had moved, the pre-existing part of the file
will be over-written.  Locking should have protected against this,
but it doesn't.

This patch restores the use of nfs_zap_caches() which invalidated the
cached attributes.  When posix_fallocate() asks for the file size, the
request will go to the server and get a correct answer.

Fixes: ca0daa277aca ("NFS: Cache aggressively when file is open for writing")
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/nfs/file.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -750,7 +750,7 @@ do_setlk(struct file *filp, int cmd, str
 	 */
 	nfs_sync_mapping(filp->f_mapping);
 	if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
-		nfs_zap_mapping(inode, filp->f_mapping);
+		nfs_zap_caches(inode);
 out:
 	return status;
 }

  parent reply	other threads:[~2017-08-03 23:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-03 23:17 [PATCH 4.12 00/31] 4.12.5-stable review Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 01/31] jfs: Dont clear SGID when inheriting ACLs Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 03/31] ALSA: hda - Add missing NVIDIA GPU codec IDs to patch table Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 04/31] ALSA: hda - Add mute led support for HP ProBook 440 G4 Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 05/31] parisc: Prevent TLB speculation on flushed pages on CPUs that only support equivalent aliases Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 06/31] parisc: Extend disabled preemption in copy_user_page Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 07/31] parisc: Suspend lockup detectors before system halt Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 08/31] powerpc/pseries: Fix of_node_put() underflow during reconfig remove Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 09/31] mmc: sunxi: Keep default timing phase settings for new timing mode Greg Kroah-Hartman
2017-08-03 23:17 ` Greg Kroah-Hartman [this message]
2017-08-03 23:17 ` [PATCH 4.12 11/31] NFSv4.1: Fix a race where CB_NOTIFY_LOCK fails to wake a waiter Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 12/31] scripts/dtc: dtx_diff - update include dts paths to match build Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 13/31] crypto: brcm - Fix SHA3-512 algorithm failure Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 14/31] crypto: brcm - remove BCM_PDC_MBOX dependency in Kconfig Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 15/31] crypto: authencesn - Fix digest_null crash Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 16/31] KVM: PPC: Book3S HV: Enable TM before accessing TM registers Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 17/31] KVM: PPC: Book3S HV: Fix host crash on changing HPT size Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 18/31] dm integrity: fix inefficient allocation of journal space Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 19/31] dm integrity: test for corrupted disk format during table load Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 20/31] md: remove idx from struct resync_pages Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 21/31] md/raid1: fix writebehind bio clone Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 22/31] md/raid5: add thread_group worker async_tx_issue_pending_all Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 23/31] drm/vmwgfx: Fix gcc-7.1.1 warning Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 24/31] drm/vmwgfx: Limit max desktop dimensions to 8Kx8K Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 25/31] drm/nouveau/disp/nv50-: bump max chans to 21 Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 26/31] drm/nouveau/bar/gf100: fix access to upper half of BAR2 Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 28/31] isdn/i4l: fix buffer overflow Greg Kroah-Hartman
2017-08-03 23:17 ` [PATCH 4.12 29/31] ipmi/watchdog: fix watchdog timeout set on reboot Greg Kroah-Hartman
2017-08-03 23:18 ` [PATCH 4.12 30/31] dentry name snapshots Greg Kroah-Hartman
2017-08-03 23:18 ` [PATCH 4.12 31/31] mmc: tmio-mmc: fix bad pointer math Greg Kroah-Hartman
2017-08-04  4:53 ` [PATCH 4.12 00/31] 4.12.5-stable review Guenter Roeck
2017-08-04 16:27   ` Greg Kroah-Hartman
2017-08-04 20:55 ` Shuah Khan
2017-08-04 21:46   ` Greg Kroah-Hartman

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=20170803231737.641411637@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=Anna.Schumaker@Netapp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=stable@vger.kernel.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).