All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, Denis Kirjanov <kda@linux-powerpc.org>,
	"Brian Foster" <bfoster@redhat.com>,
	"Dave Chinner" <dchinner@redhat.com>,
	"Dave Chinner" <david@fromorbit.com>
Subject: [PATCH 3.16 01/16] xfs: don't BUG() on mixed direct and mapped I/O
Date: Fri, 22 Mar 2019 05:20:18 +0000	[thread overview]
Message-ID: <lsq.1553232018.256555080@decadent.org.uk> (raw)
In-Reply-To: <lsq.1553232017.771830163@decadent.org.uk>

3.16.64-rc1 review patch.  If anyone has any objections, please let me know.

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

From: Brian Foster <bfoster@redhat.com>

commit 04197b341f23b908193308b8d63d17ff23232598 upstream.

We've had reports of generic/095 causing XFS to BUG() in
__xfs_get_blocks() due to the existence of delalloc blocks on a
direct I/O read. generic/095 issues a mix of various types of I/O,
including direct and memory mapped I/O to a single file. This is
clearly not supported behavior and is known to lead to such
problems. E.g., the lack of exclusion between the direct I/O and
write fault paths means that a write fault can allocate delalloc
blocks in a region of a file that was previously a hole after the
direct read has attempted to flush/inval the file range, but before
it actually reads the block mapping. In turn, the direct read
discovers a delalloc extent and cannot proceed.

While the appropriate solution here is to not mix direct and memory
mapped I/O to the same regions of the same file, the current
BUG_ON() behavior is probably overkill as it can crash the entire
system.  Instead, localize the failure to the I/O in question by
returning an error for a direct I/O that cannot be handled safely
due to delalloc blocks. Be careful to allow the case of a direct
write to post-eof delalloc blocks. This can occur due to speculative
preallocation and is safe as post-eof blocks are not accompanied by
dirty pages in pagecache (conversely, preallocation within eof must
have been zeroed, and thus dirtied, before the inode size could have
been increased beyond said blocks).

Finally, provide an additional warning if a direct I/O write occurs
while the file is memory mapped. This may not catch all problematic
scenarios, but provides a hint that some known-to-be-problematic I/O
methods are in use.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
[bwh: Backported to 3.16:
 - Assign positive error code to error variable
 - Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 fs/xfs/xfs_aops.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -1300,6 +1300,26 @@ __xfs_get_blocks(
 	if (error)
 		goto out_unlock;
 
+	/*
+	 * The only time we can ever safely find delalloc blocks on direct I/O
+	 * is a dio write to post-eof speculative preallocation. All other
+	 * scenarios are indicative of a problem or misuse (such as mixing
+	 * direct and mapped I/O).
+	 *
+	 * The file may be unmapped by the time we get here so we cannot
+	 * reliably fail the I/O based on mapping. Instead, fail the I/O if this
+	 * is a read or a write within eof. Otherwise, carry on but warn as a
+	 * precuation if the file happens to be mapped.
+	 */
+	if (direct && imap.br_startblock == DELAYSTARTBLOCK) {
+		if (!create || offset < i_size_read(VFS_I(ip))) {
+			WARN_ON_ONCE(1);
+			error = EIO;
+			goto out_unlock;
+		}
+		WARN_ON_ONCE(mapping_mapped(VFS_I(ip)->i_mapping));
+	}
+
 	if (create &&
 	    (!nimaps ||
 	     (imap.br_startblock == HOLESTARTBLOCK ||
@@ -1383,7 +1403,6 @@ __xfs_get_blocks(
 		set_buffer_new(bh_result);
 
 	if (imap.br_startblock == DELAYSTARTBLOCK) {
-		BUG_ON(direct);
 		if (create) {
 			set_buffer_uptodate(bh_result);
 			set_buffer_mapped(bh_result);


  parent reply	other threads:[~2019-03-22  5:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22  5:20 [PATCH 3.16 00/16] 3.16.64-rc1 review Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 08/16] HID: debug: fix error handling in hid_debug_events_read() Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 07/16] can: gw: ensure DLC boundaries after CAN frame modification Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 09/16] HID: debug: improve hid_debug_event() Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 05/16] USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 15/16] KVM: nVMX: unconditionally cancel preemption timer in free_nested (CVE-2019-7221) Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 02/16] mm: cma: fix incorrect type conversion for size during dma allocation Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 14/16] kvm: fix kvm_ioctl_create_device() reference counting (CVE-2019-6974) Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 11/16] KVM: PPC: Move xics_debugfs_init out of create Ben Hutchings
2019-03-22  5:20 ` Ben Hutchings [this message]
2019-03-22  5:20 ` [PATCH 3.16 13/16] KVM: use after free in kvm_ioctl_create_device() Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 12/16] KVM: Protect device ops->create and list_add with kvm->lock Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 06/16] net/appletalk: fix minor pointer leak to userspace in SIOCFINDIPDDPRT Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 10/16] HID: debug: fix the ring buffer implementation Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 03/16] swiotlb: clean up reporting Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 04/16] sunrpc: use-after-free in svc_process_common() Ben Hutchings
2019-03-22  5:20 ` [PATCH 3.16 16/16] KVM: x86: work around leak of uninitialized stack contents (CVE-2019-7222) Ben Hutchings
2019-03-22 13:44 ` [PATCH 3.16 00/16] 3.16.64-rc1 review Guenter Roeck
2019-03-23  4:43   ` Guenter Roeck
2019-03-24 23:25     ` Ben Hutchings

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=lsq.1553232018.256555080@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=bfoster@redhat.com \
    --cc=david@fromorbit.com \
    --cc=dchinner@redhat.com \
    --cc=kda@linux-powerpc.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.