stable.vger.kernel.org archive mirror
 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, alan@lxorguk.ukuu.org.uk,
	Dmitry Monakhov <dmonakhov@openvz.org>,
	"Theodore Tso" <tytso@mit.edu>
Subject: [ 035/105] ext4: race-condition protection for ext4_convert_unwritten_extents_endio
Date: Sun, 28 Oct 2012 23:16:11 +0000	[thread overview]
Message-ID: <20121028231547.747971375@decadent.org.uk> (raw)
In-Reply-To: <20121028231536.970033833@decadent.org.uk>

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

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

From: Dmitry Monakhov <dmonakhov@openvz.org>

commit dee1f973ca341c266229faa5a1a5bb268bed3531 upstream.

We assumed that at the time we call ext4_convert_unwritten_extents_endio()
extent in question is fully inside [map.m_lblk, map->m_len] because
it was already split during submission.  But this may not be true due to
a race between writeback vs fallocate.

If extent in question is larger than requested we will split it again.
Special precautions should being done if zeroout required because
[map.m_lblk, map->m_len] already contains valid data.

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 fs/ext4/extents.c |   57 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 46 insertions(+), 11 deletions(-)

--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2715,6 +2715,9 @@ static int ext4_ext_zeroout(struct inode
 #define EXT4_EXT_MARK_UNINIT1	0x2  /* mark first half uninitialized */
 #define EXT4_EXT_MARK_UNINIT2	0x4  /* mark second half uninitialized */
 
+#define EXT4_EXT_DATA_VALID1	0x8  /* first half contains valid data */
+#define EXT4_EXT_DATA_VALID2	0x10 /* second half contains valid data */
+
 /*
  * ext4_split_extent_at() splits an extent at given block.
  *
@@ -2750,6 +2753,9 @@ static int ext4_split_extent_at(handle_t
 	unsigned int ee_len, depth;
 	int err = 0;
 
+	BUG_ON((split_flag & (EXT4_EXT_DATA_VALID1 | EXT4_EXT_DATA_VALID2)) ==
+	       (EXT4_EXT_DATA_VALID1 | EXT4_EXT_DATA_VALID2));
+
 	ext_debug("ext4_split_extents_at: inode %lu, logical"
 		"block %llu\n", inode->i_ino, (unsigned long long)split);
 
@@ -2808,7 +2814,14 @@ static int ext4_split_extent_at(handle_t
 
 	err = ext4_ext_insert_extent(handle, inode, path, &newex, flags);
 	if (err == -ENOSPC && (EXT4_EXT_MAY_ZEROOUT & split_flag)) {
-		err = ext4_ext_zeroout(inode, &orig_ex);
+		if (split_flag & (EXT4_EXT_DATA_VALID1|EXT4_EXT_DATA_VALID2)) {
+			if (split_flag & EXT4_EXT_DATA_VALID1)
+				err = ext4_ext_zeroout(inode, ex2);
+			else
+				err = ext4_ext_zeroout(inode, ex);
+		} else
+			err = ext4_ext_zeroout(inode, &orig_ex);
+
 		if (err)
 			goto fix_extent_len;
 		/* update the extent length and mark as initialized */
@@ -2861,12 +2874,13 @@ static int ext4_split_extent(handle_t *h
 	uninitialized = ext4_ext_is_uninitialized(ex);
 
 	if (map->m_lblk + map->m_len < ee_block + ee_len) {
-		split_flag1 = split_flag & EXT4_EXT_MAY_ZEROOUT ?
-			      EXT4_EXT_MAY_ZEROOUT : 0;
+		split_flag1 = split_flag & EXT4_EXT_MAY_ZEROOUT;
 		flags1 = flags | EXT4_GET_BLOCKS_PRE_IO;
 		if (uninitialized)
 			split_flag1 |= EXT4_EXT_MARK_UNINIT1 |
 				       EXT4_EXT_MARK_UNINIT2;
+		if (split_flag & EXT4_EXT_DATA_VALID2)
+			split_flag1 |= EXT4_EXT_DATA_VALID1;
 		err = ext4_split_extent_at(handle, inode, path,
 				map->m_lblk + map->m_len, split_flag1, flags1);
 		if (err)
@@ -2879,8 +2893,8 @@ static int ext4_split_extent(handle_t *h
 		return PTR_ERR(path);
 
 	if (map->m_lblk >= ee_block) {
-		split_flag1 = split_flag & EXT4_EXT_MAY_ZEROOUT ?
-			      EXT4_EXT_MAY_ZEROOUT : 0;
+		split_flag1 = split_flag & (EXT4_EXT_MAY_ZEROOUT |
+					    EXT4_EXT_DATA_VALID2);
 		if (uninitialized)
 			split_flag1 |= EXT4_EXT_MARK_UNINIT1;
 		if (split_flag & EXT4_EXT_MARK_UNINIT2)
@@ -3158,26 +3172,47 @@ static int ext4_split_unwritten_extents(
 
 	split_flag |= ee_block + ee_len <= eof_block ? EXT4_EXT_MAY_ZEROOUT : 0;
 	split_flag |= EXT4_EXT_MARK_UNINIT2;
-
+	if (flags & EXT4_GET_BLOCKS_CONVERT)
+		split_flag |= EXT4_EXT_DATA_VALID2;
 	flags |= EXT4_GET_BLOCKS_PRE_IO;
 	return ext4_split_extent(handle, inode, path, map, split_flag, flags);
 }
 
 static int ext4_convert_unwritten_extents_endio(handle_t *handle,
-					      struct inode *inode,
-					      struct ext4_ext_path *path)
+						struct inode *inode,
+						struct ext4_map_blocks *map,
+						struct ext4_ext_path *path)
 {
 	struct ext4_extent *ex;
+	ext4_lblk_t ee_block;
+	unsigned int ee_len;
 	int depth;
 	int err = 0;
 
 	depth = ext_depth(inode);
 	ex = path[depth].p_ext;
+	ee_block = le32_to_cpu(ex->ee_block);
+	ee_len = ext4_ext_get_actual_len(ex);
 
 	ext_debug("ext4_convert_unwritten_extents_endio: inode %lu, logical"
 		"block %llu, max_blocks %u\n", inode->i_ino,
-		(unsigned long long)le32_to_cpu(ex->ee_block),
-		ext4_ext_get_actual_len(ex));
+		  (unsigned long long)ee_block, ee_len);
+
+	/* If extent is larger than requested then split is required */
+	if (ee_block != map->m_lblk || ee_len > map->m_len) {
+		err = ext4_split_unwritten_extents(handle, inode, map, path,
+						   EXT4_GET_BLOCKS_CONVERT);
+		if (err < 0)
+			goto out;
+		ext4_ext_drop_refs(path);
+		path = ext4_ext_find_extent(inode, map->m_lblk, path);
+		if (IS_ERR(path)) {
+			err = PTR_ERR(path);
+			goto out;
+		}
+		depth = ext_depth(inode);
+		ex = path[depth].p_ext;
+	}
 
 	err = ext4_ext_get_access(handle, inode, path + depth);
 	if (err)
@@ -3479,7 +3514,7 @@ ext4_ext_handle_uninitialized_extents(ha
 	}
 	/* IO end_io complete, convert the filled extent to written */
 	if ((flags & EXT4_GET_BLOCKS_CONVERT)) {
-		ret = ext4_convert_unwritten_extents_endio(handle, inode,
+		ret = ext4_convert_unwritten_extents_endio(handle, inode, map,
 							path);
 		if (ret >= 0) {
 			ext4_update_inode_fsync_trans(handle, inode, 1);



  parent reply	other threads:[~2012-10-28 23:16 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-28 23:15 [ 000/105] 3.2.33-stable review Ben Hutchings
2012-10-28 23:15 ` [ 001/105] netfilter: ipset: avoid use of kernel-only types Ben Hutchings
2012-10-28 23:15 ` [ 002/105] samsung-laptop: dont handle backlight if handled by acpi/video Ben Hutchings
2012-10-28 23:15 ` [ 003/105] samsung-laptop: make the dmi check less strict (part 2) Ben Hutchings
2012-10-28 23:15 ` [ 004/105] jbd: Fix assertion failure in commit code due to lacking transaction credits Ben Hutchings
2012-10-28 23:15 ` [ 005/105] mtd: nand: allow NAND_NO_SUBPAGE_WRITE to be set from driver Ben Hutchings
2012-10-28 23:15 ` [ 006/105] ALSA: hda - Fix oops caused by recent commit "Fix internal mic for Lenovo Ideapad U300s" Ben Hutchings
2012-10-28 23:15 ` [ 007/105] e1000: fix vlan processing regression Ben Hutchings
2012-10-28 23:15 ` [ 008/105] SUNRPC: Set alloc_slot for backchannel tcp ops Ben Hutchings
2012-10-28 23:15 ` [ 009/105] drm/i915: dont pwrite tiled objects through the gtt Ben Hutchings
2012-10-28 23:15 ` [ 010/105] drm/i915: no lvds quirk for Zotac ZDBOX SD ID12/ID13 Ben Hutchings
2012-10-28 23:15 ` [ 011/105] sparc64: fix ptrace interaction with force_successful_syscall_return() Ben Hutchings
2012-10-28 23:15 ` [ 012/105] sparc64: Like x86 we should check current->mm during perf backtrace generation Ben Hutchings
2012-10-28 23:15 ` [ 013/105] sparc64: Fix bit twiddling in sparc_pmu_enable_event() Ben Hutchings
2012-10-28 23:15 ` [ 014/105] sparc64: do not clobber personality flags in sys_sparc64_personality() Ben Hutchings
2012-10-28 23:15 ` [ 015/105] sparc64: Be less verbose during vmemmap population Ben Hutchings
2012-10-28 23:15 ` [ 016/105] [media] au0828: fix case where STREAMOFF being called on stopped stream causes BUG() Ben Hutchings
2012-10-28 23:15 ` [ 017/105] net: Fix skb_under_panic oops in neigh_resolve_output Ben Hutchings
2012-10-28 23:15 ` [ 018/105] skge: Add DMA mask quirk for Marvell 88E8001 on ASUS P5NSLI motherboard Ben Hutchings
2012-10-28 23:15 ` [ 019/105] vlan: dont deliver frames for unknown vlans to protocols Ben Hutchings
2012-10-28 23:15 ` [ 020/105] RDS: fix rds-ping spinlock recursion Ben Hutchings
2012-10-28 23:15 ` [ 021/105] tcp: resets are misrouted Ben Hutchings
2012-10-28 23:15 ` [ 022/105] staging: comedi: amplc_pc236: fix invalid register access during detach Ben Hutchings
2012-10-28 23:15 ` [ 023/105] nfsd4: fix nfs4 stateid leak Ben Hutchings
2012-10-28 23:16 ` [ 024/105] viafb: dont touch clock state on OLPC XO-1.5 Ben Hutchings
2012-10-28 23:16 ` [ 025/105] module: taint kernel when lve module is loaded Ben Hutchings
2012-10-28 23:16 ` [ 026/105] ACPI: EC: Make the GPE storm threshold a module parameter Ben Hutchings
2012-10-29  0:04   ` Jonathan Nieder
2012-10-28 23:16 ` [ 027/105] ACPI: EC: Add a quirk for CLEVO M720T/M730T laptop Ben Hutchings
2012-10-28 23:16 ` [ 028/105] ARM: vfp: fix saving d16-d31 vfp registers on v6+ kernels Ben Hutchings
2012-10-28 23:16 ` [ 029/105] [SCSI] scsi_debug: Fix off-by-one bug when unmapping region Ben Hutchings
2012-10-28 23:16 ` [ 030/105] [SCSI] storvsc: Account for in-transit packets in the RESET path Ben Hutchings
2012-10-28 23:16 ` [ 031/105] timers: Fix endless looping between cascade() and internal_add_timer() Ben Hutchings
2012-10-28 23:16 ` [ 032/105] timekeeping: Cast raw_interval to u64 to avoid shift overflow Ben Hutchings
2012-10-28 23:16 ` [ 033/105] video/udlfb: fix line counting in fb_write Ben Hutchings
2012-10-28 23:16 ` [ 034/105] tmpfs,ceph,gfs2,isofs,reiserfs,xfs: fix fh_len checking Ben Hutchings
2012-10-28 23:16 ` Ben Hutchings [this message]
2012-10-28 23:16 ` [ 036/105] ALSA: hda - Fix memory leaks at error path in patch_cirrus.c Ben Hutchings
2012-10-28 23:16 ` [ 037/105] nohz: Fix idle ticks in cpu summary line of /proc/stat Ben Hutchings
2012-10-28 23:16 ` [ 038/105] ALSA: hda - do not detect jack on internal speakers for Realtek Ben Hutchings
2012-10-28 23:16 ` [ 039/105] pktgen: fix crash when generating IPv6 packets Ben Hutchings
2012-10-28 23:16 ` [ 040/105] md/raid10: use correct limit variable Ben Hutchings
2012-10-28 23:16 ` [ 041/105] Bluetooth: SMP: Fix setting unknown auth_req bits Ben Hutchings
2012-10-28 23:16 ` [ 042/105] mips,kgdb: fix recursive page fault with CONFIG_KPROBES Ben Hutchings
2012-10-28 23:16 ` [ 043/105] xen/bootup: allow read_tscp call for Xen PV guests Ben Hutchings
2012-10-28 23:16 ` [ 044/105] xen/bootup: allow {read|write}_cr8 pvops call Ben Hutchings
2012-10-28 23:16 ` [ 045/105] pcmcia: sharpsl: dont discard sharpsl_pcmcia_ops Ben Hutchings
2012-10-28 23:16 ` [ 046/105] oprofile, x86: Fix wrapping bug in op_x86_get_ctrl() Ben Hutchings
2012-10-28 23:16 ` [ 047/105] drm/radeon: Dont destroy I2C Bus Rec in radeon_ext_tmds_enc_destroy() Ben Hutchings
2012-10-28 23:16 ` [ 048/105] mac80211: check if key has TKIP type before updating IV Ben Hutchings
2012-10-28 23:16 ` [ 049/105] bcma: fix unregistration of cores Ben Hutchings
2012-10-28 23:16 ` [ 050/105] net/wireless: ipw2200: Fix panic occurring in ipw_handle_promiscuous_tx() Ben Hutchings
2012-10-28 23:16 ` [ 051/105] iwlwifi: fix 6000 series channel switch command Ben Hutchings
2012-10-28 23:16 ` [ 052/105] cgroup: notify_on_release may not be triggered in some cases Ben Hutchings
2012-10-28 23:16 ` [ 053/105] ALSA: hda - Always check array bounds in alc_get_line_out_pfx Ben Hutchings
2012-10-28 23:16 ` [ 054/105] NLM: nlm_lookup_file() may return NLMv4-specific error codes Ben Hutchings
2012-10-28 23:16 ` [ 055/105] SUNRPC: Prevent kernel stack corruption on long values of flush Ben Hutchings
2012-10-28 23:16 ` [ 056/105] USB: cdc-acm: fix pipe type of write endpoint Ben Hutchings
2012-10-28 23:16 ` [ 057/105] usb: acm: fix the computation of the number of data bits Ben Hutchings
2012-10-28 23:16 ` [ 058/105] usb: host: xhci: New system added for Compliance Mode Patch on SN65LVPE502CP Ben Hutchings
2012-10-28 23:16 ` [ 059/105] USB: option: blacklist net interface on ZTE devices Ben Hutchings
2012-10-28 23:16 ` [ 060/105] USB: option: add more " Ben Hutchings
2012-10-28 23:16 ` [ 061/105] s390: fix linker script for 31 bit builds Ben Hutchings
2012-10-28 23:16 ` [ 062/105] xen/x86: dont corrupt %eip when returning from a signal handler Ben Hutchings
2012-10-28 23:16 ` [ 063/105] ALSA: hda - add dock support for Thinkpad T430 Ben Hutchings
2012-10-28 23:16 ` [ 064/105] kernel/sys.c: fix stack memory content leak via UNAME26 Ben Hutchings
2012-10-28 23:16 ` [ 065/105] ARM: 7559/1: smp: switch away from the idmap before updating init_mm.mm_count Ben Hutchings
2012-10-28 23:16 ` [ 066/105] usb hub: send clear_tt_buffer_complete events when canceling TT clear work Ben Hutchings
2012-10-28 23:16 ` [ 067/105] cpufreq / powernow-k8: Remove usage of smp_processor_id() in preemptible code Ben Hutchings
2012-10-28 23:16 ` [ 068/105] arch/tile: avoid generating .eh_frame information in modules Ben Hutchings
2012-10-28 23:16 ` [ 069/105] amd64_edac:__amd64_set_scrub_rate(): avoid overindexing scrubrates[] Ben Hutchings
2012-10-28 23:16 ` [ 070/105] SUNRPC: Clear the connect flag when socket state is TCP_CLOSE_WAIT Ben Hutchings
2012-10-28 23:16 ` [ 071/105] Revert "SUNRPC: Ensure we close the socket on EPIPE errors too..." Ben Hutchings
2012-10-28 23:16 ` [ 072/105] SUNRPC: Prevent races in xs_abort_connection() Ben Hutchings
2012-10-28 23:16 ` [ 073/105] SUNRPC: Get rid of the xs_error_report socket callback Ben Hutchings
2012-10-28 23:16 ` [ 074/105] Revert "ath9k_hw: Updated AR9003 tx gain table for 5GHz" Ben Hutchings
2012-10-28 23:16 ` [ 075/105] USB: serial: Fix memory leak in sierra_release() Ben Hutchings
2012-10-28 23:16 ` [ 076/105] usb-storage: add unusual_devs entry for Casio EX-N1 digital camera Ben Hutchings
2012-10-28 23:16 ` [ 077/105] Drivers: hv: Cleanup error handling in vmbus_open() Ben Hutchings
2012-10-28 23:16 ` [ 078/105] sysfs: sysfs_pathname/sysfs_add_one: Use strlcat() instead of strcat() Ben Hutchings
2012-10-28 23:16 ` [ 079/105] vhost: fix mergeable bufs on BE hosts Ben Hutchings
2012-10-28 23:16 ` [ 080/105] USB: whiteheat: fix memory leak in error path Ben Hutchings
2012-10-28 23:16 ` [ 081/105] USB: opticon: fix DMA from stack Ben Hutchings
2012-10-28 23:16 ` [ 082/105] USB: opticon: fix memory leak in error path Ben Hutchings
2012-10-28 23:16 ` [ 083/105] USB: mct_u232: fix broken close Ben Hutchings
2012-10-28 23:17 ` [ 084/105] USB: sierra: fix memory leak in attach error path Ben Hutchings
2012-10-28 23:17 ` [ 085/105] USB: sierra: fix memory leak in probe " Ben Hutchings
2012-10-28 23:17 ` [ 086/105] USB: mos7840: fix urb leak at release Ben Hutchings
2012-10-28 23:17 ` [ 087/105] USB: mos7840: fix port-device leak in error path Ben Hutchings
2012-10-28 23:17 ` [ 088/105] USB: mos7840: remove NULL-urb submission Ben Hutchings
2012-10-28 23:17 ` [ 089/105] USB: mos7840: remove invalid disconnect handling Ben Hutchings
2012-10-28 23:17 ` [ 090/105] ehci: fix Lucid nohandoff pci quirk to be more generic with BIOS versions Ben Hutchings
2012-10-28 23:17 ` [ 091/105] ehci: Add yet-another Lucid nohandoff pci quirk Ben Hutchings
2012-10-28 23:17 ` [ 092/105] xhci: Fix potential NULL ptr deref in command cancellation Ben Hutchings
2012-10-28 23:17 ` [ 093/105] freezer: exec should clear PF_NOFREEZE along with PF_KTHREAD Ben Hutchings
2012-10-28 23:17 ` [ 094/105] mm: fix XFS oops due to dirty pages without buffers on s390 Ben Hutchings
2012-10-28 23:17 ` [ 095/105] genalloc: stop crashing the system when destroying a pool Ben Hutchings
2012-10-28 23:17 ` [ 096/105] drivers/rtc/rtc-imxdi.c: add missing spin lock initialization Ben Hutchings
2012-10-28 23:17 ` [ 097/105] gen_init_cpio: avoid stack overflow when expanding Ben Hutchings
2012-10-28 23:17 ` [ 098/105] fs/compat_ioctl.c: VIDEO_SET_SPU_PALETTE missing error check Ben Hutchings
2012-10-28 23:17 ` [ 099/105] Revert "lockd: use rpc clients cl_nodename for id encoding" Ben Hutchings
2012-10-28 23:17 ` [ 100/105] netfilter: nf_conntrack: fix racy timer handling with reliable events Ben Hutchings
2012-10-28 23:17 ` [ 101/105] tpm: Propagate error from tpm_transmit to fix a timeout hang Ben Hutchings
2012-10-28 23:17 ` [ 102/105] usb: gadget: at91_udc: fix dt support Ben Hutchings
2012-10-29  6:21   ` Fabio Porcedda
2012-10-29 14:41     ` Ben Hutchings
2012-10-28 23:17 ` [ 103/105] ALSA: ac97 - Fix missing NULL check in snd_ac97_cvol_new() Ben Hutchings
2012-10-28 23:17 ` [ 104/105] ALSA: emu10k1: add chip details for E-mu 1010 PCIe card Ben Hutchings
2012-10-28 23:17 ` [ 105/105] Add CDC-ACM support for the CX93010-2x UCMxx USB Modem Ben Hutchings
2012-10-29  2:24 ` [ 000/105] 3.2.33-stable review 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=20121028231547.747971375@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=dmonakhov@openvz.org \
    --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;
as well as URLs for NNTP newsgroup(s).