All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Qu Wenruo <wqu@suse.com>, Jungyeon Yoon <jungyeon.yoon@gmail.com>,
	David Sterba <dsterba@suse.com>, Sasha Levin <sashal@kernel.org>,
	linux-btrfs@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 60/60] btrfs: extent-tree: Make sure we only allocate extents from block groups with the same type
Date: Sun, 22 Sep 2019 14:59:33 -0400	[thread overview]
Message-ID: <20190922185934.4305-60-sashal@kernel.org> (raw)
In-Reply-To: <20190922185934.4305-1-sashal@kernel.org>

From: Qu Wenruo <wqu@suse.com>

[ Upstream commit 2a28468e525f3924efed7f29f2bc5a2926e7e19a ]

[BUG]
With fuzzed image and MIXED_GROUPS super flag, we can hit the following
BUG_ON():

  kernel BUG at fs/btrfs/delayed-ref.c:491!
  invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
  CPU: 0 PID: 1849 Comm: sync Tainted: G           O      5.2.0-custom #27
  RIP: 0010:update_existing_head_ref.cold+0x44/0x46 [btrfs]
  Call Trace:
   add_delayed_ref_head+0x20c/0x2d0 [btrfs]
   btrfs_add_delayed_tree_ref+0x1fc/0x490 [btrfs]
   btrfs_free_tree_block+0x123/0x380 [btrfs]
   __btrfs_cow_block+0x435/0x500 [btrfs]
   btrfs_cow_block+0x110/0x240 [btrfs]
   btrfs_search_slot+0x230/0xa00 [btrfs]
   ? __lock_acquire+0x105e/0x1e20
   btrfs_insert_empty_items+0x67/0xc0 [btrfs]
   alloc_reserved_file_extent+0x9e/0x340 [btrfs]
   __btrfs_run_delayed_refs+0x78e/0x1240 [btrfs]
   ? kvm_clock_read+0x18/0x30
   ? __sched_clock_gtod_offset+0x21/0x50
   btrfs_run_delayed_refs.part.0+0x4e/0x180 [btrfs]
   btrfs_run_delayed_refs+0x23/0x30 [btrfs]
   btrfs_commit_transaction+0x53/0x9f0 [btrfs]
   btrfs_sync_fs+0x7c/0x1c0 [btrfs]
   ? __ia32_sys_fdatasync+0x20/0x20
   sync_fs_one_sb+0x23/0x30
   iterate_supers+0x95/0x100
   ksys_sync+0x62/0xb0
   __ia32_sys_sync+0xe/0x20
   do_syscall_64+0x65/0x240
   entry_SYSCALL_64_after_hwframe+0x49/0xbe

[CAUSE]
This situation is caused by several factors:
- Fuzzed image
  The extent tree of this fs missed one backref for extent tree root.
  So we can allocated space from that slot.

- MIXED_BG feature
  Super block has MIXED_BG flag.

- No mixed block groups exists
  All block groups are just regular ones.

This makes data space_info->block_groups[] contains metadata block
groups.  And when we reserve space for data, we can use space in
metadata block group.

Then we hit the following file operations:

- fallocate
  We need to allocate data extents.
  find_free_extent() choose to use the metadata block to allocate space
  from, and choose the space of extent tree root, since its backref is
  missing.

  This generate one delayed ref head with is_data = 1.

- extent tree update
  We need to update extent tree at run_delayed_ref time.

  This generate one delayed ref head with is_data = 0, for the same
  bytenr of old extent tree root.

Then we trigger the BUG_ON().

[FIX]
The quick fix here is to check block_group->flags before using it.

The problem can only happen for MIXED_GROUPS fs. Regular filesystems
won't have space_info with DATA|METADATA flag, and no way to hit the
bug.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203255
Reported-by: Jungyeon Yoon <jungyeon.yoon@gmail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/btrfs/extent-tree.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 7938c48c72ff0..f3a2512344743 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -7571,6 +7571,14 @@ static noinline int find_free_extent(struct btrfs_root *orig_root,
 			 */
 			if ((flags & extra) && !(block_group->flags & extra))
 				goto loop;
+
+			/*
+			 * This block group has different flags than we want.
+			 * It's possible that we have MIXED_GROUP flag but no
+			 * block group is mixed.  Just skip such block group.
+			 */
+			btrfs_release_block_group(block_group, delalloc);
+			continue;
 		}
 
 have_block_group:
-- 
2.20.1


      parent reply	other threads:[~2019-09-22 19:01 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-22 18:58 [PATCH AUTOSEL 4.9 01/60] ALSA: hda: Flush interrupts on disabling Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 02/60] regulator: lm363x: Fix off-by-one n_voltages for lm3632 ldo_vpos/ldo_vneg Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 03/60] ASoC: sgtl5000: Fix charge pump source assignment Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 04/60] dmaengine: bcm2835: Print error in case setting DMA mask fails Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 05/60] leds: leds-lp5562 allow firmware files up to the maximum length Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 06/60] media: dib0700: fix link error for dibx000_i2c_set_speed Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 07/60] media: exynos4-is: fix leaked of_node references Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 08/60] media: hdpvr: Add device num check and handling Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 09/60] sched/fair: Fix imbalance due to CPU affinity Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 10/60] sched/core: Fix CPU controller for !RT_GROUP_SCHED Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 11/60] x86/reboot: Always use NMI fallback when shutdown via reboot vector IPI fails Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 12/60] x86/apic: Soft disable APIC before initializing it Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 13/60] ALSA: hda - Show the fatal CORB/RIRB error more clearly Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 14/60] ALSA: i2c: ak4xxx-adda: Fix a possible null pointer dereference in build_adc_controls() Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 15/60] media: iguanair: add sanity checks Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 16/60] base: soc: Export soc_device_register/unregister APIs Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 17/60] ALSA: usb-audio: Skip bSynchAddress endpoint check if it is invalid Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 18/60] ia64:unwind: fix double free for mod->arch.init_unw_table Sasha Levin
2019-09-22 18:58   ` Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 19/60] EDAC/altera: Use the proper type for the IRQ status bits Sasha Levin
2019-09-22 18:58   ` Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 20/60] md: don't call spare_active in md_reap_sync_thread if all member devices can't work Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 21/60] md: don't set In_sync if array is frozen Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 22/60] efi: cper: print AER info of PCIe fatal error Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 23/60] media: gspca: zero usb_buf on error Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 24/60] dmaengine: iop-adma: use correct printk format strings Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 25/60] media: omap3isp: Don't set streaming state on random subdevs Sasha Levin
2019-09-22 18:58 ` [PATCH AUTOSEL 4.9 26/60] net: lpc-enet: fix printk format strings Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 27/60] ARM: dts: imx7d: cl-som-imx7: make ethernet work again Sasha Levin
2019-09-22 18:59   ` Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 28/60] media: radio/si470x: kill urb on error Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 29/60] media: hdpvr: add terminating 0 at end of string Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 30/60] media: dvb-core: fix a memory leak bug Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 31/60] PM / devfreq: passive: Use non-devm notifiers Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 32/60] PM / devfreq: exynos-bus: Correct clock enable sequence Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 33/60] media: saa7146: add cleanup in hexium_attach() Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 34/60] media: cpia2_usb: fix memory leaks Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 35/60] media: saa7134: fix terminology around saa7134_i2c_eeprom_md7134_gate() Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 36/60] media: ov9650: add a sanity check Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 37/60] ACPI / CPPC: do not require the _PSD method Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 38/60] arm64: kpti: ensure patched kernel text is fetched from PoU Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 39/60] nvmet: fix data units read and written counters in SMART log Sasha Levin
2019-09-22 18:59   ` Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 40/60] iommu/amd: Silence warnings under memory pressure Sasha Levin
2019-09-22 18:59   ` Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 41/60] libtraceevent: Change users plugin directory Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 42/60] ARM: dts: exynos: Mark LDO10 as always-on on Peach Pit/Pi Chromebooks Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 43/60] ACPI: custom_method: fix memory leaks Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 44/60] ACPI / PCI: fix acpi_pci_irq_enable() memory leak Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 45/60] hwmon: (acpi_power_meter) Change log level for 'unsafe software power cap' Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 46/60] md/raid1: fail run raid1 array when active disk less than one Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 47/60] dmaengine: ti: edma: Do not reset reserved paRAM slots Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 48/60] kprobes: Prohibit probing on BUG() and WARN() address Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 49/60] s390/crypto: xts-aes-s390 fix extra run-time crypto self tests finding Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 50/60] irqchip/gic-v3-its: Fix LPI release for Multi-MSI devices Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 51/60] x86/platform/uv: Fix kmalloc() NULL check routine Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 52/60] ASoC: dmaengine: Make the pcm->name equal to pcm->id if the name is not set Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 53/60] mmc: sdhci: Fix incorrect switch to HS mode Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 54/60] media: technisat-usb2: break out of loop at end of buffer Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 55/60] libertas: Add missing sentinel at end of if_usb.c fw_table Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 56/60] e1000e: add workaround for possible stalled packet Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 57/60] drm/amd/powerplay/smu7: enforce minimal VBITimeout (v2) Sasha Levin
2019-09-22 18:59   ` Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 58/60] media: ttusb-dec: Fix info-leak in ttusb_dec_send_command() Sasha Levin
2019-09-22 18:59 ` [PATCH AUTOSEL 4.9 59/60] ALSA: hda/realtek - Blacklist PC beep for Lenovo ThinkCentre M73/93 Sasha Levin
2019-09-22 18:59 ` Sasha Levin [this message]

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=20190922185934.4305-60-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dsterba@suse.com \
    --cc=jungyeon.yoon@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wqu@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.