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, Jan Kara <jack@suse.cz>,
	"zhangyi (F)" <yi.zhang@huawei.com>, Theodore Tso <tytso@mit.edu>,
	stable@kernel.org, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.4 015/113] jbd2: do not clear the BH_Mapped flag when forgetting a metadata buffer
Date: Thu, 27 Feb 2020 14:35:31 +0100	[thread overview]
Message-ID: <20200227132214.157539071@linuxfoundation.org> (raw)
In-Reply-To: <20200227132211.791484803@linuxfoundation.org>

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

[ Upstream commit c96dceeabf765d0b1b1f29c3bf50a5c01315b820 ]

Commit 904cdbd41d74 ("jbd2: clear dirty flag when revoking a buffer from
an older transaction") set the BH_Freed flag when forgetting a metadata
buffer which belongs to the committing transaction, it indicate the
committing process clear dirty bits when it is done with the buffer. But
it also clear the BH_Mapped flag at the same time, which may trigger
below NULL pointer oops when block_size < PAGE_SIZE.

rmdir 1             kjournald2                 mkdir 2
                    jbd2_journal_commit_transaction
		    commit transaction N
jbd2_journal_forget
set_buffer_freed(bh1)
                    jbd2_journal_commit_transaction
                     commit transaction N+1
                     ...
                     clear_buffer_mapped(bh1)
                                               ext4_getblk(bh2 ummapped)
                                               ...
                                               grow_dev_page
                                                init_page_buffers
                                                 bh1->b_private=NULL
                                                 bh2->b_private=NULL
                     jbd2_journal_put_journal_head(jh1)
                      __journal_remove_journal_head(hb1)
		       jh1 is NULL and trigger oops

*) Dir entry block bh1 and bh2 belongs to one page, and the bh2 has
   already been unmapped.

For the metadata buffer we forgetting, we should always keep the mapped
flag and clear the dirty flags is enough, so this patch pick out the
these buffers and keep their BH_Mapped flag.

Link: https://lore.kernel.org/r/20200213063821.30455-3-yi.zhang@huawei.com
Fixes: 904cdbd41d74 ("jbd2: clear dirty flag when revoking a buffer from an older transaction")
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/jbd2/commit.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 3bf86d912b76f..7fe61edb1bb9e 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -996,12 +996,29 @@ void jbd2_journal_commit_transaction(journal_t *journal)
 		 * pagesize and it is attached to the last partial page.
 		 */
 		if (buffer_freed(bh) && !jh->b_next_transaction) {
+			struct address_space *mapping;
+
 			clear_buffer_freed(bh);
 			clear_buffer_jbddirty(bh);
-			clear_buffer_mapped(bh);
-			clear_buffer_new(bh);
-			clear_buffer_req(bh);
-			bh->b_bdev = NULL;
+
+			/*
+			 * Block device buffers need to stay mapped all the
+			 * time, so it is enough to clear buffer_jbddirty and
+			 * buffer_freed bits. For the file mapping buffers (i.e.
+			 * journalled data) we need to unmap buffer and clear
+			 * more bits. We also need to be careful about the check
+			 * because the data page mapping can get cleared under
+			 * out hands, which alse need not to clear more bits
+			 * because the page and buffers will be freed and can
+			 * never be reused once we are done with them.
+			 */
+			mapping = READ_ONCE(bh->b_page->mapping);
+			if (mapping && !sb_is_blkdev_sb(mapping->host->i_sb)) {
+				clear_buffer_mapped(bh);
+				clear_buffer_new(bh);
+				clear_buffer_req(bh);
+				bh->b_bdev = NULL;
+			}
 		}
 
 		if (buffer_jbddirty(bh)) {
-- 
2.20.1




  parent reply	other threads:[~2020-02-27 13:41 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27 13:35 [PATCH 4.4 000/113] 4.4.215-stable review Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 001/113] x86/vdso: Use RDPID in preference to LSL when available Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 002/113] KVM: x86: emulate RDPID Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 003/113] ALSA: hda: Use scnprintf() for printing texts for sysfs/procfs Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 004/113] ecryptfs: fix a memory leak bug in parse_tag_1_packet() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 005/113] ecryptfs: fix a memory leak bug in ecryptfs_init_messaging() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 006/113] ALSA: usb-audio: Apply sample rate quirk for Audioengine D1 Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 007/113] ubifs: Fix deadlock in concurrent bulk-read and writepage Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 008/113] ext4: fix checksum errors with indexed dirs Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 009/113] Btrfs: fix race between using extent maps and merging them Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 010/113] btrfs: log message when rw remount is attempted with unclean tree-log Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 011/113] padata: Remove broken queue flushing Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 012/113] s390/time: Fix clk type in get_tod_clock Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 013/113] hwmon: (pmbus/ltc2978) Fix PMBus polling of MFR_COMMON definitions Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 014/113] jbd2: move the clearing of b_modified flag to the journal_unmap_buffer() Greg Kroah-Hartman
2020-02-27 13:35 ` Greg Kroah-Hartman [this message]
2020-02-27 13:35 ` [PATCH 4.4 016/113] btrfs: print message when tree-log replay starts Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 017/113] scsi: qla2xxx: fix a potential NULL pointer dereference Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 018/113] Revert "KVM: VMX: Add non-canonical check on writes to RTIT address MSRs" Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 019/113] drm/gma500: Fixup fbdev stolen size usage evaluation Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 020/113] brcmfmac: Fix use after free in brcmf_sdio_readframes() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 021/113] gianfar: Fix TX timestamping with a stacked DSA driver Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 022/113] pinctrl: sh-pfc: sh7264: Fix CAN function GPIOs Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 023/113] media: i2c: mt9v032: fix enum mbus codes and frame sizes Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 024/113] media: sti: bdisp: fix a possible sleep-in-atomic-context bug in bdisp_device_run() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 025/113] efi/x86: Map the entire EFI vendor string before copying it Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 026/113] MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 027/113] uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 028/113] usb: gadget: udc: fix possible sleep-in-atomic-context bugs in gr_probe() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 029/113] nfs: NFS_SWAP should depend on SWAP Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 030/113] jbd2: clear JBD2_ABORT flag before journal_reset to update log tail info when load journal Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 031/113] tracing: Fix very unlikely race of registering two stat tracers Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 032/113] ext4, jbd2: ensure panic when aborting with zero errno Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 033/113] kconfig: fix broken dependency in randconfig-generated .config Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 034/113] clk: qcom: rcg2: Dont crash if our parent cant be found; return an error Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 035/113] drm/amdgpu: remove 4 set but not used variable in amdgpu_atombios_get_connector_info_from_object_table Greg Kroah-Hartman
2020-03-11  9:07   ` nobuhiro1.iwamatsu
2020-03-16 10:53     ` Greg KH
2020-02-27 13:35 ` [PATCH 4.4 036/113] regulator: rk808: Lower log level on optional GPIOs being not available Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 037/113] NFC: port100: Convert cpu_to_le16(le16_to_cpu(E1) + E2) to use le16_add_cpu() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 038/113] reiserfs: Fix spurious unlock in reiserfs_fill_super() error handling Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 039/113] ALSA: usx2y: Adjust indentation in snd_usX2Y_hwdep_dsp_status Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 040/113] b43legacy: Fix -Wcast-function-type Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 041/113] ipw2x00: " Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 042/113] iwlegacy: " Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 043/113] rtlwifi: rtl_pci: " Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 044/113] orinoco: avoid assertion in case of NULL pointer Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 045/113] ACPICA: Disassembler: create buffer fields in ACPI_PARSE_LOAD_PASS1 Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 046/113] scsi: aic7xxx: Adjust indentation in ahc_find_syncrate Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 047/113] ARM: dts: r8a7779: Add device node for ARM global timer Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 048/113] x86/vdso: Provide missing include file Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 049/113] pinctrl: sh-pfc: sh7269: Fix CAN function GPIOs Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 050/113] ALSA: sh: Fix compile warning wrt const Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 051/113] tools lib api fs: Fix gcc9 stringop-truncation compilation error Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 052/113] usbip: Fix unsafe unaligned pointer usage Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 053/113] soc/tegra: fuse: Correct straps address for older Tegra124 device trees Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 054/113] rcu: Use WRITE_ONCE() for assignments to ->pprev for hlist_nulls Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 055/113] Input: edt-ft5x06 - work around first register access error Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 056/113] wan: ixp4xx_hss: fix compile-testing on 64-bit Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 057/113] ASoC: atmel: fix build error with CONFIG_SND_ATMEL_SOC_DMA=m Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 058/113] PCI: Dont disable bridge BARs when assigning bus resources Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 059/113] driver core: Print device when resources present in really_probe() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 060/113] drm/nouveau: Fix copy-paste error in nouveau_fence_wait_uevent_handler Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 061/113] drm/vmwgfx: prevent memory leak in vmw_cmdbuf_res_add Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 062/113] iommu/arm-smmu-v3: Use WRITE_ONCE() when changing validity of an STE Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 063/113] scsi: iscsi: Dont destroy session if there are outstanding connections Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 064/113] cmd64x: potential buffer overflow in cmd64x_program_timings() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 065/113] ide: serverworks: potential overflow in svwks_set_pio_mode() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 066/113] remoteproc: Initialize rproc_class before use Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 067/113] s390/ftrace: generate traced function stack frame Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 068/113] ALSA: hda - Add docking station support for Lenovo Thinkpad T420s Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 069/113] jbd2: switch to use jbd2_journal_abort() when failed to submit the commit record Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 070/113] ARM: 8951/1: Fix Kexec compilation issue Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 071/113] hostap: Adjust indentation in prism2_hostapd_add_sta Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 072/113] iwlegacy: ensure loop counter addr does not wrap and cause an infinite loop Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 073/113] drm/nouveau/disp/nv50-: prevent oops when no channel method map provided Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 074/113] trigger_next should increase position index Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 075/113] radeon: insert 10ms sleep in dce5_crtc_load_lut Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 076/113] ocfs2: fix a NULL pointer dereference when call ocfs2_update_inode_fsync_trans() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 077/113] lib/scatterlist.c: adjust indentation in __sg_alloc_table Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 078/113] reiserfs: prevent NULL pointer dereference in reiserfs_insert_item() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 079/113] bcache: explicity type cast in bset_bkey_last() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 080/113] irqchip/gic-v3-its: Reference to its_invall_cmd descriptor when building INVALL Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 081/113] microblaze: Prevent the overflow of the start Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 082/113] brd: check and limit max_part par Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 083/113] selinux: ensure we cleanup the internal AVC counters on error in avc_update() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 084/113] enic: prevent waking up stopped tx queues over watchdog reset Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 085/113] floppy: check FDC index for errors before assigning it Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 086/113] staging: android: ashmem: Disallow ashmem memory from being remapped Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 087/113] staging: vt6656: fix sign of rx_dbm to bb_pre_ed_rssi Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 088/113] usb: uas: fix a plug & unplug racing Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 089/113] USB: Fix novation SourceControl XL after suspend Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 090/113] USB: hub: Dont record a connect-change event during reset-resume Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 091/113] staging: rtl8188eu: Fix potential security hole Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 092/113] staging: rtl8188eu: Fix potential overuse of kernel memory Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 093/113] x86/mce/amd: Fix kobject lifetime Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 094/113] tty: serial: imx: setup the correct sg entry for tx dma Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 095/113] Revert "ipc,sem: remove uneeded sem_undo_list lock usage in exit_sem()" Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 096/113] xhci: apply XHCI_PME_STUCK_QUIRK to Intel Comet Lake platforms Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 097/113] VT_RESIZEX: get rid of field-by-field copyin Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 098/113] vt: vt_ioctl: fix race in VT_RESIZEX Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 099/113] KVM: nVMX: Dont emulate instructions in guest mode Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 100/113] netfilter: xt_bpf: add overflow checks Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 101/113] ext4: fix a data race in EXT4_I(inode)->i_disksize Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 102/113] ext4: add cond_resched() to __ext4_find_entry() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 103/113] KVM: nVMX: Refactor IO bitmap checks into helper function Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 104/113] KVM: nVMX: Check IO instruction VM-exit conditions Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 105/113] KVM: apic: avoid calculating pending eoi from an uninitialized val Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 106/113] Btrfs: fix btrfs_wait_ordered_range() so that it waits for all ordered extents Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 107/113] scsi: Revert "RDMA/isert: Fix a recently introduced regression related to logout" Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 108/113] scsi: Revert "target: iscsi: Wait for all commands to finish before freeing a session" Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 109/113] ecryptfs: replace BUG_ON with error handling code Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 110/113] ALSA: rawmidi: Avoid bit fields for state flags Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 111/113] ALSA: seq: Avoid concurrent access to queue flags Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 112/113] ALSA: seq: Fix concurrent access to queue current tick/time Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 113/113] xen: Enable interrupts when calling _cond_resched() Greg Kroah-Hartman
2020-02-27 15:52 ` [PATCH 4.4 000/113] 4.4.215-stable review Chris Paterson
2020-02-27 18:50 ` Jon Hunter
2020-02-27 19:37 ` Guenter Roeck
2020-02-28 11:11 ` Naresh Kamboju

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=20200227132214.157539071@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@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).