From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Michael Zimmer" <michael@swarm64.com>,
"Theodore Ts'o" <tytso@mit.edu>, "Jan Kara" <jack@suse.cz>
Subject: [PATCH 3.2 051/106] ext4: fix data corruption for mmap writes
Date: Sat, 09 Sep 2017 22:47:39 +0100 [thread overview]
Message-ID: <lsq.1504993659.668992091@decadent.org.uk> (raw)
In-Reply-To: <lsq.1504993659.376385113@decadent.org.uk>
3.2.93-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <jack@suse.cz>
commit a056bdaae7a181f7dcc876cfab2f94538e508709 upstream.
mpage_submit_page() can race with another process growing i_size and
writing data via mmap to the written-back page. As mpage_submit_page()
samples i_size too early, it may happen that ext4_bio_write_page()
zeroes out too large tail of the page and thus corrupts user data.
Fix the problem by sampling i_size only after the page has been
write-protected in page tables by clear_page_dirty_for_io() call.
Reported-by: Michael Zimmer <michael@swarm64.com>
Fixes: cb20d5188366f04d96d2e07b1240cc92170ade40
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
[bwh: Backported to 3.2: The writeback path is very different here and
it needs to read i_size long before calling clear_page_dirty_for_io().
So read it twice and skip the page if it changed.]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
fs/ext4/inode.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1344,7 +1344,6 @@ static int mpage_da_submit_io(struct mpa
int ret = 0, err, nr_pages, i;
struct inode *inode = mpd->inode;
struct address_space *mapping = inode->i_mapping;
- loff_t size = i_size_read(inode);
unsigned int len, block_start;
struct buffer_head *bh, *page_bufs = NULL;
int journal_data = ext4_should_journal_data(inode);
@@ -1370,6 +1369,7 @@ static int mpage_da_submit_io(struct mpa
for (i = 0; i < nr_pages; i++) {
int commit_write = 0, skip_page = 0;
struct page *page = pvec.pages[i];
+ loff_t size = i_size_read(inode);
index = page->index;
if (index > end)
@@ -1443,11 +1443,31 @@ static int mpage_da_submit_io(struct mpa
if (skip_page)
goto skip_page;
+ clear_page_dirty_for_io(page);
+ /*
+ * We have to be very careful here! Nothing protects
+ * writeback path against i_size changes and the page
+ * can be writeably mapped into page tables. So an
+ * application can be growing i_size and writing data
+ * through mmap while writeback runs.
+ * clear_page_dirty_for_io() write-protects our page in
+ * page tables and the page cannot get written to again
+ * until we release page lock. So only after
+ * clear_page_dirty_for_io() we are safe to sample
+ * i_size for ext4_bio_write_page() to zero-out tail of
+ * the written page. We rely on the barrier provided by
+ * TestClearPageDirty in clear_page_dirty_for_io() to
+ * make sure i_size is really sampled only after page
+ * tables are updated.
+ */
+ if (size != i_size_read(inode)) {
+ set_page_dirty(page);
+ goto skip_page;
+ }
+
if (commit_write)
/* mark the buffer_heads as dirty & uptodate */
block_commit_write(page, 0, len);
-
- clear_page_dirty_for_io(page);
/*
* Delalloc doesn't support data journalling,
* but eventually maybe we'll lift this
next prev parent reply other threads:[~2017-09-09 22:44 UTC|newest]
Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-09 21:47 [PATCH 3.2 000/106] 3.2.93-rc1 review Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 074/106] MIPS: kprobes: flush_insn_slot should flush only if probe initialised Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 010/106] tcp: eliminate negative reordering in tcp_clean_rtx_queue Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 084/106] xfrm: NULL dereference on allocation failure Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 057/106] alarmtimer: Prevent overflow of relative timers Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 041/106] crypto: gcm - wait for crypto op not signal safe Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 008/106] USB: serial: io_ti: fix div-by-zero in set_termios Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 067/106] perf probe: Fix examples section of documentation Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 069/106] perf script: Fix documentation errors Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 046/106] dmaengine: ep93xx: Always start from BASE0 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 090/106] rtnetlink: add IFLA_GROUP to ifla_policy Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 072/106] perf script python: Remove dups in documentation examples Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 023/106] of: fdt: add missing allocation-failure check Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 070/106] perf script python: Fix wrong code snippets in documentation Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 038/106] osf_wait4(): fix infoleak Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 086/106] swap: cond_resched in swap_cgroup_prepare() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 040/106] i2c: i2c-tiny-usb: fix buffer not being DMA capable Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 066/106] drm/vmwgfx: Handle vmalloc() failure in vmw_local_fifo_reserve() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 030/106] USB: xhci: fix lock-inversion problem Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 001/106] xfrm: fix stack access out of bounds with CONFIG_XFRM_SUB_POLICY Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 045/106] drm/gma500/psb: Actually use VBT mode when it is found Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 034/106] powerpc/mm: Fix virt_addr_valid() etc. on 64-bit hash Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 080/106] configfs: Fix race between create_link and configfs_rmdir Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 059/106] [media] rc-core: race condition during ir_raw_event_register() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 047/106] netfilter: ctnetlink: fix incorrect nf_ct_put during hash resize Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 061/106] ipv6: Fix leak in ipv6_gso_segment() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 048/106] ASoC: Fix use-after-free at card unregistration Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 014/106] USB: iowarrior: fix info ioctl on big-endian hosts Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 031/106] usb: musb: tusb6010_omap: Do not reset the other direction's packet size Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 083/106] xfrm: Oops on error in pfkey_msg2xfrm_state() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 063/106] [media] vb2: fix plane index sanity check in vb2_plane_cookie() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 064/106] [media] vb2: Fix an off by one error in 'vb2_plane_vaddr' Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 029/106] usb: host: xhci: simplify irq handler return Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 088/106] Input: i8042 - add Fujitsu Lifebook AH544 to notimeout list Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 018/106] USB: usbip: fix nonconforming hub descriptor Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 058/106] alarmtimer: Rate limit periodic intervals Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 043/106] block: fix an error code in add_partition() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 050/106] net: ethernet: ax88796: don't call free_irq without request_irq first Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 077/106] ufs: set correct ->s_maxsize Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 002/106] af_key: Fix slab-out-of-bounds in pfkey_compile_policy Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 036/106] KVM: x86: fix use of uninitialized memory as segment descriptor in emulator Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 060/106] net: add kfree_skb_list() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 009/106] ahci: Acer SA5-271 SSD Not Detected Fix Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 026/106] usb: xhci: apply XHCI_PME_STUCK_QUIRK to Intel Apollo Lake Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 005/106] USB: serial: ftdi_sio: fix setting latency for unprivileged users Ben Hutchings
2017-09-09 21:47 ` Ben Hutchings [this message]
2017-09-09 21:47 ` [PATCH 3.2 082/106] selinux: fix double free in selinux_parse_opts_str() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 056/106] drivers: char: mem: Fix wraparound check to allow mappings up to the end Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 085/106] powerpc/kprobes: Pause function_graph tracing during jprobes handling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 037/106] KVM: x86: zero base3 of unusable segments Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 044/106] libceph: NULL deref on crush_decode() error path Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 068/106] perf script: Fix outdated comment for perf-trace-python Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 062/106] net: ping: do not abuse udp_poll() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 039/106] ext4: keep existing extra fields when inode expands Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 065/106] net: ethoc: enable NAPI before poll may be scheduled Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 091/106] ipv6: avoid unregistering inet6_dev for loopback Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 035/106] KVM: X86: Fix read out-of-bounds vulnerability in kvm pio emulation Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 003/106] tcp: avoid fragmenting peculiar skbs in SACK Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 076/106] fix ufs_isblockset() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 007/106] USB: serial: mct_u232: fix big-endian baud-rate handling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 071/106] perf script python: Updated trace_unhandled() signature Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 089/106] drm/radeon: add a quirk for Toshiba Satellite L20-183 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 019/106] USB: hub: fix SS hub-descriptor handling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 028/106] usb: host: xhci-mem: allocate zeroed Scratchpad Buffer Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 025/106] xhci: workaround for hosts missing CAS bit Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 011/106] USB: ene_usb6250: fix DMA to the stack Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 022/106] mac80211: strictly check mesh address extension mode Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 004/106] net: irda: irda-usb: fix firmware name on big-endian hosts Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 020/106] USB: hub: fix non-SS hub-descriptor handling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 021/106] USB: hub: fix SS max number of ports Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 055/106] ipv6: xfrm: Handle errors reported by xfrm6_find_1stfragopt() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 081/106] usb: xhci: ASMedia ASM1042A chipset need shorts TX quirk Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 075/106] KEYS: fix dereferencing NULL payload with nonzero length Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 078/106] excessive checks in ufs_write_failed() and ufs_evict_inode() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 079/106] KVM: async_pf: avoid async pf injection when in guest mode Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 053/106] net: phy: fix marvell phy status reading Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 032/106] drivers: char: mem: Check for address space wraparound with mmap() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 073/106] KVM: cpuid: Fix read/write out-of-bounds vulnerability in cpuid emulation Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 024/106] tracing/kprobes: Enforce kprobes teardown after testing Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 052/106] ext4: fix fdatasync(2) after extent manipulation operations Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 015/106] usb: r8a66597-hcd: decrease timeout Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 016/106] usb: r8a66597-hcd: select a different endpoint on timeout Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 017/106] USB: gadget: dummy_hcd: fix hub-descriptor removable fields Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 042/106] ALSA: hda - apply STAC_9200_DELL_M22 quirk for Dell Latitude D430 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 054/106] usb: gadget: f_mass_storage: Serialize wake and sleep execution Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 013/106] uwb: fix device quirk on big-endian hosts Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 012/106] USB: core: replace %p with %pK Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 006/106] USB: serial: ir-usb: fix big-endian baud-rate debug printk Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 087/106] signal: Only reschedule timers on signals timers have sent Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 033/106] watchdog: pcwd_usb: fix NULL-deref at probe Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 049/106] scsi: qla2xxx: don't disable a not previously enabled PCI device Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 027/106] xhci: apply PME_STUCK_QUIRK and MISSING_CAS quirk for Denverton Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 105/106] Sanitize 'move_pages()' permission checks Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 093/106] autofs: sanity check status reported with AUTOFS_DEV_IOCTL_FAIL Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 100/106] xen: fix bio vec merging Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 106/106] net: phy: marvell: Limit errata to 88m1101 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 098/106] tcp: initialize rcv_mss to TCP_MIN_MSS instead of 0 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 094/106] lib/cmdline.c: fix get_options() overflow while parsing ranges Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 102/106] mm: fix move/migrate_pages() race on task struct Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 096/106] MIPS: Fix IRQ tracing & lockdep when rescheduling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 092/106] powerpc/64: Initialise thread_info for emergency stacks Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 104/106] mm: fix NULL ptr dereference in move_pages Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 101/106] ptrace: use fsuid, fsgid, effective creds for fs access checks Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 099/106] xfrm: policy: check policy direction value Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 095/106] net: prevent sign extension in dev_get_stats() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 103/106] mm: fix NULL ptr dereference in migrate_pages Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 097/106] tracing/kprobes: Allow to create probe with a module name starting with a digit Ben Hutchings
2017-09-10 14:31 ` [PATCH 3.2 000/106] 3.2.93-rc1 review Guenter Roeck
2017-09-10 18:46 ` 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.1504993659.668992091@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=michael@swarm64.com \
--cc=stable@vger.kernel.org \
--cc=tytso@mit.edu \
/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
Powered by JetHome