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, "zhangyi (F)" <yi.zhang@huawei.com>,
	Theodore Tso <tytso@mit.edu>, Jan Kara <jack@suse.cz>
Subject: [PATCH 4.9 091/118] jbd2: clear dirty flag when revoking a buffer from an older transaction
Date: Fri, 22 Mar 2019 12:16:03 +0100	[thread overview]
Message-ID: <20190322111223.031212401@linuxfoundation.org> (raw)
In-Reply-To: <20190322111215.873964544@linuxfoundation.org>

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

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

From: zhangyi (F) <yi.zhang@huawei.com>

commit 904cdbd41d749a476863a0ca41f6f396774f26e4 upstream.

Now, we capture a data corruption problem on ext4 while we're truncating
an extent index block. Imaging that if we are revoking a buffer which
has been journaled by the committing transaction, the buffer's jbddirty
flag will not be cleared in jbd2_journal_forget(), so the commit code
will set the buffer dirty flag again after refile the buffer.

fsx                               kjournald2
                                  jbd2_journal_commit_transaction
jbd2_journal_revoke                commit phase 1~5...
 jbd2_journal_forget
   belongs to older transaction    commit phase 6
   jbddirty not clear               __jbd2_journal_refile_buffer
                                     __jbd2_journal_unfile_buffer
                                      test_clear_buffer_jbddirty
                                       mark_buffer_dirty

Finally, if the freed extent index block was allocated again as data
block by some other files, it may corrupt the file data after writing
cached pages later, such as during unmount time. (In general,
clean_bdev_aliases() related helpers should be invoked after
re-allocation to prevent the above corruption, but unfortunately we
missed it when zeroout the head of extra extent blocks in
ext4_ext_handle_unwritten_extents()).

This patch mark buffer as freed and set j_next_transaction to the new
transaction when it already belongs to the committing transaction in
jbd2_journal_forget(), so that commit code knows it should clear dirty
bits when it is done with the buffer.

This problem can be reproduced by xfstests generic/455 easily with
seeds (3246 3247 3248 3249).

Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/jbd2/transaction.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -1568,14 +1568,21 @@ int jbd2_journal_forget (handle_t *handl
 		/* However, if the buffer is still owned by a prior
 		 * (committing) transaction, we can't drop it yet... */
 		JBUFFER_TRACE(jh, "belongs to older transaction");
-		/* ... but we CAN drop it from the new transaction if we
-		 * have also modified it since the original commit. */
+		/* ... but we CAN drop it from the new transaction through
+		 * marking the buffer as freed and set j_next_transaction to
+		 * the new transaction, so that not only the commit code
+		 * knows it should clear dirty bits when it is done with the
+		 * buffer, but also the buffer can be checkpointed only
+		 * after the new transaction commits. */
 
-		if (jh->b_next_transaction) {
-			J_ASSERT(jh->b_next_transaction == transaction);
+		set_buffer_freed(bh);
+
+		if (!jh->b_next_transaction) {
 			spin_lock(&journal->j_list_lock);
-			jh->b_next_transaction = NULL;
+			jh->b_next_transaction = transaction;
 			spin_unlock(&journal->j_list_lock);
+		} else {
+			J_ASSERT(jh->b_next_transaction == transaction);
 
 			/*
 			 * only drop a reference if this transaction modified



  parent reply	other threads:[~2019-03-22 13:00 UTC|newest]

Thread overview: 123+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 11:14 [PATCH 4.9 000/118] 4.9.165-stable review Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 001/118] media: videobuf2-v4l2: drop WARN_ON in vb2_warn_zero_bytesused() Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 002/118] 9p: use inode->i_lock to protect i_size_write() under 32-bit Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 003/118] 9p/net: fix memory leak in p9_client_create Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 004/118] ASoC: fsl_esai: fix register setting issue in RIGHT_J mode Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 005/118] iio: adc: exynos-adc: Fix NULL pointer exception on unbind Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 006/118] stm class: Fix an endless loop in channel allocation Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 007/118] crypto: caam - fixed handling of sg list Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 008/118] crypto: ahash - fix another early termination in hash walk Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 009/118] gpu: ipu-v3: Fix i.MX51 CSI control registers offset Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 010/118] gpu: ipu-v3: Fix CSI offsets for imx53 Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 011/118] s390/dasd: fix using offset into zero size array error Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 012/118] ARM: OMAP2+: Variable "reg" in function omap4_dsi_mux_pads() could be uninitialized Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 013/118] Input: cap11xx - switch to using set_brightness_blocking() Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 014/118] Input: matrix_keypad - use flush_delayed_work() Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 015/118] floppy: check_events callback should not return a negative number Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 016/118] mm/gup: fix gup_pmd_range() for dax Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 017/118] mm: page_alloc: fix ref bias in page_frag_alloc() for 1-byte allocs Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 018/118] net: hns: Fix object reference leaks in hns_dsaf_roce_reset() Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 019/118] i2c: cadence: Fix the hold bit setting Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 020/118] Input: st-keyscan - fix potential zalloc NULL dereference Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 021/118] clk: sunxi: A31: Fix wrong AHB gate number Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 022/118] ARM: 8824/1: fix a migrating irq bug when hotplug cpu Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 023/118] assoc_array: Fix shortcut creation Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 024/118] scsi: libiscsi: Fix race between iscsi_xmit_task and iscsi_complete_task Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 025/118] net: systemport: Fix reception of BPDUs Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 026/118] pinctrl: meson: meson8b: fix the sdxc_a data 1..3 pins Greg Kroah-Hartman
2019-03-22 11:14 ` [PATCH 4.9 027/118] qmi_wwan: apply SET_DTR quirk to Sierra WP7607 Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 028/118] net: mv643xx_eth: disable clk on error path in mv643xx_eth_shared_probe() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 029/118] ASoC: topology: free created components in tplg load error Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 030/118] arm64: Relax GIC version check during early boot Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 031/118] net: marvell: mvneta: fix DMA debug warning Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 032/118] tmpfs: fix link accounting when a tmpfile is linked in Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 033/118] ARCv2: lib: memcpy: fix doing prefetchw outside of buffer Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 034/118] ARC: uacces: remove lp_start, lp_end from clobber list Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 035/118] phonet: fix building with clang Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 036/118] mac80211_hwsim: propagate genlmsg_reply return code Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 037/118] net: thunderx: make CFG_DONE message to run through generic send-ack sequence Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 038/118] nfp: bpf: fix code-gen bug on BPF_ALU | BPF_XOR | BPF_K Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 039/118] nfp: bpf: fix ALU32 high bits clearance bug Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 040/118] net: set static variable an initial value in atl2_probe() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 041/118] tmpfs: fix uninitialized return value in shmem_link Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 042/118] stm class: Prevent division by zero Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 043/118] libnvdimm/label: Clear updating flag after label-set update Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 044/118] libnvdimm/pmem: Honor force_raw for legacy pmem regions Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 045/118] libnvdimm: Fix altmap reservation size calculation Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 046/118] crypto: hash - set CRYPTO_TFM_NEED_KEY if ->setkey() fails Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 047/118] crypto: arm64/aes-ccm - fix logical bug in AAD MAC handling Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 048/118] CIFS: Do not reset lease state to NONE on lease break Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 049/118] CIFS: Fix read after write for files with read caching Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 050/118] tracing: Use strncpy instead of memcpy for string keys in hist triggers Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 051/118] tracing: Do not free iter->trace in fail path of tracing_open_pipe() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 052/118] ACPI / device_sysfs: Avoid OF modalias creation for removed device Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 053/118] spi: ti-qspi: Fix mmap read when more than one CS in use Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 054/118] spi: pxa2xx: Setup maximum supported DMA transfer length Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 055/118] regulator: s2mps11: Fix steps for buck7, buck8 and LDO35 Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 056/118] regulator: s2mpa01: Fix step values for some LDOs Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 057/118] clocksource/drivers/exynos_mct: Move one-shot check from tick clear to ISR Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 058/118] clocksource/drivers/exynos_mct: Clear timer interrupt when shutdown Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 059/118] s390/virtio: handle find on invalid queue gracefully Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 060/118] scsi: virtio_scsi: dont send sc payload with tmfs Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 061/118] scsi: sd: Optimal I/O size should be a multiple of physical block size Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 062/118] scsi: target/iscsi: Avoid iscsit_release_commands_from_conn() deadlock Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 063/118] fs/devpts: always delete dcache dentry-s in dput() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 064/118] splice: dont merge into linked buffers Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 065/118] m68k: Add -ffreestanding to CFLAGS Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 066/118] btrfs: ensure that a DUP or RAID1 block group has exactly two stripes Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 067/118] Btrfs: fix corruption reading shared and compressed extents after hole punching Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 068/118] crypto: pcbc - remove bogus memcpy()s with src == dest Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 069/118] libertas_tf: dont set URB_ZERO_PACKET on IN USB transfer Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 070/118] cpufreq: tegra124: add missing of_node_put() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 071/118] cpufreq: pxa2xx: remove incorrect __init annotation Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 072/118] ext4: fix crash during online resizing Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 073/118] ext2: Fix underflow in ext2_max_size() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 074/118] clk: clk-twl6040: Fix imprecise external abort for pdmclk Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 075/118] clk: ingenic: Fix round_rate misbehaving with non-integer dividers Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 076/118] clk: ingenic: Fix doc of ingenic_cgu_div_info Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 077/118] nfit: acpi_nfit_ctl(): Check out_obj->type in the right place Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 078/118] mm: hwpoison: fix thp split handing in soft_offline_in_use_page() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 079/118] mm/vmalloc: fix size check for remap_vmalloc_range_partial() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 080/118] kernel/sysctl.c: add missing range check in do_proc_dointvec_minmax_conv Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 081/118] device property: Fix the length used in PROPERTY_ENTRY_STRING() Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 082/118] intel_th: Dont reference unassigned outputs Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 083/118] parport_pc: fix find_superio io compare code, should use equal test Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 084/118] i2c: tegra: fix maximum transfer size Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 085/118] drm/i915: Relax mmap VMA check Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 086/118] serial: uartps: Fix stuck ISR if RX disabled with non-empty FIFO Greg Kroah-Hartman
2019-03-22 11:15 ` [PATCH 4.9 087/118] serial: 8250_of: assume reg-shift of 2 for mrvl,mmp-uart Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 088/118] 8250: FIX Fourth port offset of Pericom PI7C9X7954 boards Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 089/118] serial: 8250_pci: Fix number of ports for ACCES serial cards Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 090/118] serial: 8250_pci: Have ACCES cards that use the four port Pericom PI7C9X7954 chip use the pci_pericom_setup() Greg Kroah-Hartman
2019-03-22 11:16 ` Greg Kroah-Hartman [this message]
2019-03-22 11:16 ` [PATCH 4.9 092/118] jbd2: fix compile warning when using JBUFFER_TRACE Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 093/118] powerpc/32: Clear on-stack exception marker upon exception return Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 094/118] powerpc/wii: properly disable use of BATs when requested Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 095/118] powerpc/powernv: Make opal log only readable by root Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 096/118] powerpc/83xx: Also save/restore SPRG4-7 during suspend Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 097/118] powerpc: Fix 32-bit KVM-PR lockup and host crash with MacOS guest Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 098/118] powerpc/ptrace: Simplify vr_get/set() to avoid GCC warning Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 099/118] ARM: s3c24xx: Fix boolean expressions in osiris_dvs_notify Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 100/118] dm: fix to_sector() for 32bit Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 101/118] NFS: Fix I/O request leakages Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 102/118] NFS: Fix an I/O request leakage in nfs_do_recoalesce Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 103/118] NFS: Dont recoalesce on error in nfs_pageio_complete_mirror() Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 104/118] nfsd: fix memory corruption caused by readdir Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 105/118] nfsd: fix wrong check in write_v4_end_grace() Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 106/118] PM / wakeup: Rework wakeup source timer cancellation Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 107/118] bcache: never writeback a discard operation Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 108/118] perf intel-pt: Fix CYC timestamp calculation after OVF Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 109/118] perf auxtrace: Define auxtrace record alignment Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 110/118] perf intel-pt: Fix overlap calculation for padding Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 111/118] perf intel-pt: Fix divide by zero when TSC is not available Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 112/118] md: Fix failed allocation of md_register_thread Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 113/118] rcu: Do RCU GP kthread self-wakeup from softirq and interrupt Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 114/118] media: uvcvideo: Avoid NULL pointer dereference at the end of streaming Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 115/118] drm/radeon/evergreen_cs: fix missing break in switch statement Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 116/118] KVM: nVMX: Sign extend displacements of VMX instrs mem operands Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 117/118] KVM: nVMX: Ignore limit checks on VMX instructions using flat segments Greg Kroah-Hartman
2019-03-22 11:16 ` [PATCH 4.9 118/118] KVM: X86: Fix residual mmio emulation request to userspace Greg Kroah-Hartman
2019-03-22 23:02 ` [PATCH 4.9 000/118] 4.9.165-stable review kernelci.org bot
2019-03-23  4:44 ` Guenter Roeck
2019-03-23  5:30 ` Naresh Kamboju
2019-03-24 11:55 ` Jon Hunter

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=20190322111223.031212401@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /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).