mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: Lukas Czerner <lczerner@redhat.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 3.19.y-ckt 36/92] ext4: fix data corruption caused by unwritten and delayed extents
Date: Tue, 26 May 2015 08:40:40 -0700	[thread overview]
Message-ID: <1432654896-28478-37-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1432654896-28478-1-git-send-email-kamal@canonical.com>

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

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

From: Lukas Czerner <lczerner@redhat.com>

commit d2dc317d564a46dfc683978a2e5a4f91434e9711 upstream.

Currently it is possible to lose whole file system block worth of data
when we hit the specific interaction with unwritten and delayed extents
in status extent tree.

The problem is that when we insert delayed extent into extent status
tree the only way to get rid of it is when we write out delayed buffer.
However there is a limitation in the extent status tree implementation
so that when inserting unwritten extent should there be even a single
delayed block the whole unwritten extent would be marked as delayed.

At this point, there is no way to get rid of the delayed extents,
because there are no delayed buffers to write out. So when a we write
into said unwritten extent we will convert it to written, but it still
remains delayed.

When we try to write into that block later ext4_da_map_blocks() will set
the buffer new and delayed and map it to invalid block which causes
the rest of the block to be zeroed loosing already written data.

For now we can fix this by simply not allowing to set delayed status on
written extent in the extent status tree. Also add WARN_ON() to make
sure that we notice if this happens in the future.

This problem can be easily reproduced by running the following xfs_io.

xfs_io -f -c "pwrite -S 0xaa 4096 2048" \
          -c "falloc 0 131072" \
          -c "pwrite -S 0xbb 65536 2048" \
          -c "fsync" /mnt/test/fff

echo 3 > /proc/sys/vm/drop_caches
xfs_io -c "pwrite -S 0xdd 67584 2048" /mnt/test/fff

This can be theoretically also reproduced by at random by running fsx,
but it's not very reliable, though on machines with bigger page size
(like ppc) this can be seen more often (especially xfstest generic/127)

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 fs/ext4/extents_status.c | 8 ++++++++
 fs/ext4/inode.c          | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index e04d457..9a01213 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -705,6 +705,14 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
 
 	BUG_ON(end < lblk);
 
+	if ((status & EXTENT_STATUS_DELAYED) &&
+	    (status & EXTENT_STATUS_WRITTEN)) {
+		ext4_warning(inode->i_sb, "Inserting extent [%u/%u] as "
+				" delayed and written which can potentially "
+				" cause data loss.\n", lblk, len);
+		WARN_ON(1);
+	}
+
 	newes.es_lblk = lblk;
 	newes.es_len = len;
 	ext4_es_store_pblock_status(&newes, pblk, status);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 5653fa4..9743a38 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -534,6 +534,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
 		status = map->m_flags & EXT4_MAP_UNWRITTEN ?
 				EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
 		if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) &&
+		    !(status & EXTENT_STATUS_WRITTEN) &&
 		    ext4_find_delalloc_range(inode, map->m_lblk,
 					     map->m_lblk + map->m_len - 1))
 			status |= EXTENT_STATUS_DELAYED;
@@ -638,6 +639,7 @@ found:
 		status = map->m_flags & EXT4_MAP_UNWRITTEN ?
 				EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
 		if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) &&
+		    !(status & EXTENT_STATUS_WRITTEN) &&
 		    ext4_find_delalloc_range(inode, map->m_lblk,
 					     map->m_lblk + map->m_len - 1))
 			status |= EXTENT_STATUS_DELAYED;
-- 
1.9.1


  parent reply	other threads:[~2015-05-26 16:04 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-26 15:40 [3.19.y-ckt stable] Linux 3.19.8-ckt1 stable review Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 01/92] ext4: allocate entire range in zero range Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 02/92] x86/microcode/intel: Guard against stack overflow in the loader Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 03/92] ASoC: tfa9879: Fix return value check in tfa9879_i2c_probe() Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 04/92] ASoC: samsung: s3c24xx-i2s: Fix return value check in s3c24xx_iis_dev_probe() Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 05/92] ASoC: dapm: Enable autodisable on SOC_DAPM_SINGLE_TLV_AUTODISABLE Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 06/92] ASoC: rt5677: add register patch for PLL Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 07/92] btrfs: unlock i_mutex after attempting to delete subvolume during send Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 08/92] ALSA: hda - Fix mute-LED fixed mode Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 09/92] ALSA: hda - Add mute-LED mode control to Thinkpad Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 10/92] arm64: dma-mapping: always clear allocated buffers Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 11/92] ALSA: emu10k1: Fix card shortname string buffer overflow Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 12/92] ALSA: emux: Fix mutex deadlock at unloading Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 13/92] drm/radeon: Use drm_calloc_ab for CS relocs Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 14/92] drm/radeon: adjust pll when audio is not enabled Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 15/92] drm/radeon: add SI DPM quirk for Sapphire R9 270 Dual-X 2G GDDR5 Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 16/92] drm/radeon: fix lockup when BOs aren't part of the VM on release Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 17/92] drm/radeon: reset BOs address after clearing it Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 18/92] drm/radeon: check new address before removing old one Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 19/92] SCSI: add 1024 max sectors black list flag Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 20/92] 3w-sas: fix command completion race Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 21/92] 3w-xxxx: " Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 22/92] 3w-9xxx: " Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 23/92] uas: Allow uas_use_uas_driver to return usb-storage flags Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 24/92] uas: Add US_FL_MAX_SECTORS_240 flag Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 25/92] uas: Set max_sectors_240 quirk for ASM1053 devices Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 26/92] usb: chipidea: otg: remove mutex unlock and lock while stop and start role Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 27/92] cdc-acm: prevent infinite loop when parsing CDC headers Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 28/92] serial: xilinx: Use platform_get_irq to get irq description structure Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 29/92] serial: of-serial: Remove device_type = "serial" registration Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 30/92] tty/serial: at91: maxburst was missing for dma transfers Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 31/92] ALSA: emux: Fix mutex deadlock in OSS emulation Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 32/92] ACPI / SBS: Enable battery manager when present Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 33/92] ALSA: emu10k1: Emu10k2 32 bit DMA mode Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 34/92] ASoC: rt5677: fixed wrong DMIC ref clock Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 35/92] rbd: end I/O the entire obj_request on error Kamal Mostafa
2015-05-26 15:40 ` Kamal Mostafa [this message]
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 37/92] ext4: move check under lock scope to close a race Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 38/92] powerpc/pseries: Correct cpu affinity for dlpar added cpus Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 39/92] powerpc/powernv: Restore non-volatile CRs after nap Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 40/92] efivarfs: Ensure VariableName is NUL-terminated Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 41/92] x86/efi: Store upper bits of command line buffer address in ext_cmd_line_ptr Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 42/92] blk-mq: fix race between timeout and CPU hotplug Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 43/92] blk-mq: fix CPU hotplug handling Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 44/92] writeback: use |1 instead of +1 to protect against div by zero Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 45/92] ARM: mvebu: armada-xp-openblocks-ax3-4: Disable internal RTC Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 46/92] ARM: dts: imx23-olinuxino: Fix polarity of LED GPIO Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 47/92] ARM: dts: imx23-olinuxino: Fix dr_mode of usb0 Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 48/92] ARM: dts: imx6: phyFLEX: USB VBUS control is active-high Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 49/92] ARM: dts: imx25: Add #pwm-cells to pwm4 Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 50/92] ARM: dts: imx28: Fix AUART4 TX-DMA interrupt name Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 51/92] [media] marvell-ccic: fix Y'CbCr ordering Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 52/92] gpio: sysfs: fix memory leaks and device hotplug Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 53/92] ACPI / SBS: Add 5 us delay to fix SBS hangs on MacBook Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 54/92] ACPI / PNP: add two IDs to list for PNPACPI device enumeration Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 55/92] ARM: OMAP2+: Fix omap off idle power consumption creeping up Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 56/92] ARM: dts: OMAP3-N900: Add microphone bias voltages Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 57/92] drm/radeon: disable semaphores for UVD V1 (v2) Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 58/92] x86/spinlocks: Fix regression in spinlock contention detection Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 59/92] RDMA/CMA: Canonize IPv4 on IPV6 sockets properly Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 60/92] drm/i915: Assume dual channel LVDS if pixel clock necessitates it Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 61/92] drm/i915: Add missing MacBook Pro models with dual channel LVDS Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 62/92] efi: Fix error handling in add_sysfs_runtime_map_entry() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 63/92] Revert "dm crypt: fix deadlock when async crypto algorithm returns -EBUSY" Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 64/92] xen/events: Clear cpu_evtchn_mask before resuming Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 65/92] xen/xenbus: Update xenbus event channel on resume Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 66/92] xen/console: Update console " Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 67/92] xen/events: Set irq_info->evtchn before binding the channel to CPU in __startup_pirq() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 68/92] mm/memory-failure: call shake_page() when error hits thp tail page Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 69/92] mm: soft-offline: fix num_poisoned_pages counting on concurrent events Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 70/92] nilfs2: fix sanity check of btree level in nilfs_btree_root_broken() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 71/92] ocfs2: dlm: fix race between purge and get lock resource Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 72/92] drm/i915/dp: there is no audio on port A Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 73/92] drm/amdkfd: allow unregister process with queues Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 74/92] drm/radeon: fix userptr BO unpin bug v3 Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 75/92] drm/radeon: make VCE handle check more strict Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 76/92] drm/radeon: make UVD handle checking " Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 77/92] drm/radeon: more strictly validate the UVD codec Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 78/92] path_openat(): fix double fput() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 79/92] mnt: Fix fs_fully_visible to verify the root directory is visible Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 80/92] drm: Zero out invalid vblank timestamp in drm_update_vblank_count Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 81/92] ARM: ux500: Move GPIO regulator for SD-card into board DTSs Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 82/92] ARM: ux500: Enable GPIO regulator for SD-card for HREF boards Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 83/92] ARM: ux500: Enable GPIO regulator for SD-card for snowball Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 84/92] xen-pciback: Add name prefix to global 'permissive' variable Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 85/92] mmc: core: add missing pm event in mmc_pm_notify to fix hib restore Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 86/92] ARM: dts: am57xx-beagle-x15: Fix IRQ type for mcp7941x Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 87/92] mmc: sh_mmcif: Fix timeout value for command request Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 88/92] mmc: card: Don't access RPMB partitions for normal read/write Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 89/92] pinctrl: Don't just pretend to protect pinctrl_maps, do it for real Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 90/92] arm64: add missing PAGE_ALIGN() to __dma_free() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 91/92] vhost/scsi: potential memory corruption Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 92/92] md/raid0: fix restore to sector variable in raid0_make_request Kamal Mostafa

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=1432654896-28478-37-git-send-email-kamal@canonical.com \
    --to=kamal@canonical.com \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=lczerner@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®