linux-kernel.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, Denis Kirjanov <kda@linux-powerpc.org>,
	"David Sterba" <dsterba@suse.com>,
	"Filipe Manana" <fdmanana@suse.com>,
	"Anand Jain" <anand.jain@oracle.com>,
	"Nikolay Borisov" <nborisov@suse.com>
Subject: [PATCH 3.16 28/72] Btrfs: fix use-after-free when using the tree modification log
Date: Sun, 08 Dec 2019 13:53:12 +0000	[thread overview]
Message-ID: <lsq.1575813165.522399963@decadent.org.uk> (raw)
In-Reply-To: <lsq.1575813164.154362148@decadent.org.uk>

3.16.79-rc1 review patch.  If anyone has any objections, please let me know.

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

From: Filipe Manana <fdmanana@suse.com>

commit efad8a853ad2057f96664328a0d327a05ce39c76 upstream.

At ctree.c:get_old_root(), we are accessing a root's header owner field
after we have freed the respective extent buffer. This results in an
use-after-free that can lead to crashes, and when CONFIG_DEBUG_PAGEALLOC
is set, results in a stack trace like the following:

  [ 3876.799331] stack segment: 0000 [#1] SMP DEBUG_PAGEALLOC PTI
  [ 3876.799363] CPU: 0 PID: 15436 Comm: pool Not tainted 5.3.0-rc3-btrfs-next-54 #1
  [ 3876.799385] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-0-ga698c8995f-prebuilt.qemu.org 04/01/2014
  [ 3876.799433] RIP: 0010:btrfs_search_old_slot+0x652/0xd80 [btrfs]
  (...)
  [ 3876.799502] RSP: 0018:ffff9f08c1a2f9f0 EFLAGS: 00010286
  [ 3876.799518] RAX: ffff8dd300000000 RBX: ffff8dd85a7a9348 RCX: 000000038da26000
  [ 3876.799538] RDX: 0000000000000000 RSI: ffffe522ce368980 RDI: 0000000000000246
  [ 3876.799559] RBP: dae1922adadad000 R08: 0000000008020000 R09: ffffe522c0000000
  [ 3876.799579] R10: ffff8dd57fd788c8 R11: 000000007511b030 R12: ffff8dd781ddc000
  [ 3876.799599] R13: ffff8dd9e6240578 R14: ffff8dd6896f7a88 R15: ffff8dd688cf90b8
  [ 3876.799620] FS:  00007f23ddd97700(0000) GS:ffff8dda20200000(0000) knlGS:0000000000000000
  [ 3876.799643] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  [ 3876.799660] CR2: 00007f23d4024000 CR3: 0000000710bb0005 CR4: 00000000003606f0
  [ 3876.799682] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
  [ 3876.799703] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
  [ 3876.799723] Call Trace:
  [ 3876.799735]  ? do_raw_spin_unlock+0x49/0xc0
  [ 3876.799749]  ? _raw_spin_unlock+0x24/0x30
  [ 3876.799779]  resolve_indirect_refs+0x1eb/0xc80 [btrfs]
  [ 3876.799810]  find_parent_nodes+0x38d/0x1180 [btrfs]
  [ 3876.799841]  btrfs_check_shared+0x11a/0x1d0 [btrfs]
  [ 3876.799870]  ? extent_fiemap+0x598/0x6e0 [btrfs]
  [ 3876.799895]  extent_fiemap+0x598/0x6e0 [btrfs]
  [ 3876.799913]  do_vfs_ioctl+0x45a/0x700
  [ 3876.799926]  ksys_ioctl+0x70/0x80
  [ 3876.799938]  ? trace_hardirqs_off_thunk+0x1a/0x20
  [ 3876.799953]  __x64_sys_ioctl+0x16/0x20
  [ 3876.799965]  do_syscall_64+0x62/0x220
  [ 3876.799977]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
  [ 3876.799993] RIP: 0033:0x7f23e0013dd7
  (...)
  [ 3876.800056] RSP: 002b:00007f23ddd96ca8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
  [ 3876.800078] RAX: ffffffffffffffda RBX: 00007f23d80210f8 RCX: 00007f23e0013dd7
  [ 3876.800099] RDX: 00007f23d80210f8 RSI: 00000000c020660b RDI: 0000000000000003
  [ 3876.800626] RBP: 000055fa2a2a2440 R08: 0000000000000000 R09: 00007f23ddd96d7c
  [ 3876.801143] R10: 00007f23d8022000 R11: 0000000000000246 R12: 00007f23ddd96d80
  [ 3876.801662] R13: 00007f23ddd96d78 R14: 00007f23d80210f0 R15: 00007f23ddd96d80
  (...)
  [ 3876.805107] ---[ end trace e53161e179ef04f9 ]---

Fix that by saving the root's header owner field into a local variable
before freeing the root's extent buffer, and then use that local variable
when needed.

Fixes: 30b0463a9394d9 ("Btrfs: fix accessing the root pointer in tree mod log functions")
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 fs/btrfs/ctree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1411,6 +1411,7 @@ get_old_root(struct btrfs_root *root, u6
 	struct tree_mod_elem *tm;
 	struct extent_buffer *eb = NULL;
 	struct extent_buffer *eb_root;
+	u64 eb_root_owner = 0;
 	struct extent_buffer *old;
 	struct tree_mod_root *old_root = NULL;
 	u64 old_generation = 0;
@@ -1445,6 +1446,7 @@ get_old_root(struct btrfs_root *root, u6
 			free_extent_buffer(old);
 		}
 	} else if (old_root) {
+		eb_root_owner = btrfs_header_owner(eb_root);
 		btrfs_tree_read_unlock(eb_root);
 		free_extent_buffer(eb_root);
 		eb = alloc_dummy_extent_buffer(logical, root->nodesize);
@@ -1462,7 +1464,7 @@ get_old_root(struct btrfs_root *root, u6
 	if (old_root) {
 		btrfs_set_header_bytenr(eb, eb->start);
 		btrfs_set_header_backref_rev(eb, BTRFS_MIXED_BACKREF_REV);
-		btrfs_set_header_owner(eb, btrfs_header_owner(eb_root));
+		btrfs_set_header_owner(eb, eb_root_owner);
 		btrfs_set_header_level(eb, old_root->level);
 		btrfs_set_header_generation(eb, old_generation);
 	}


  parent reply	other threads:[~2019-12-08 13:57 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-08 13:52 [PATCH 3.16 00/72] 3.16.79-rc1 review Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 01/72] ASoC: Define a set of DAPM pre/post-up events Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 02/72] ASoC: sgtl5000: fix VAG power up timing Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 03/72] ASoC: sgtl5000: Improve VAG power and mute control Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 04/72] leds: leds-lp5562 allow firmware files up to the maximum length Ben Hutchings
2019-12-14  8:37   ` Pavel Machek
2019-12-14 18:44     ` Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 05/72] media: dib0700: fix link error for dibx000_i2c_set_speed Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 06/72] fbdev: ssd1307fb: return proper error code if write command fails Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 07/72] video: ssd1307fb: Start page range at page_offset Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 08/72] libertas_tf: Use correct channel range in lbtf_geo_init Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 09/72] x86/reboot: Always use NMI fallback when shutdown via reboot vector IPI fails Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 10/72] video: of: display_timing: Add of_node_put() in of_get_display_timing() Ben Hutchings
2019-12-09 21:19   ` Doug Anderson
2019-12-10 13:27     ` Thierry Reding
2019-12-10 15:52       ` Ben Hutchings
2019-12-10 15:31     ` Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 11/72] ALSA: aoa: onyx: always initialize register read value Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 12/72] efi: cper: print AER info of PCIe fatal error Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 13/72] ext4: set error return correctly when ext4_htree_store_dirent fails Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 14/72] ARM: zynq: Use memcpy_toio instead of memcpy on smp bring-up Ben Hutchings
2019-12-08 13:52 ` [PATCH 3.16 15/72] media: tm6000: double free if usb disconnect while streaming Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 16/72] powerpc/rtas: use device model APIs and serialization during LPM Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 17/72] can: mcp251x: mcp251x_hw_reset(): allow more time after a reset Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 18/72] HID: hidraw: Fix invalid read in hidraw_ioctl Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 19/72] ext4: fix warning inside ext4_convert_unwritten_extents_endio Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 20/72] media: sn9c20x: Add MSI MS-1039 laptop to flip_dmi_table Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 21/72] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword() Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 22/72] /dev/mem: Bail out upon SIGKILL Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 23/72] USB: usbcore: Fix slab-out-of-bounds bug during device reset Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 24/72] Smack: Don't ignore other bprm->unsafe flags if LSM_UNSAFE_PTRACE is set Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 25/72] smack: use GFP_NOFS while holding inode_smack::smk_lock Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 26/72] HID: prodikeys: Fix general protection fault during probe Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 27/72] parisc: Disable HP HSC-PCI Cards to prevent kernel crash Ben Hutchings
2019-12-08 13:53 ` Ben Hutchings [this message]
2019-12-08 13:53 ` [PATCH 3.16 29/72] btrfs: Relinquish CPUs in btrfs_compare_trees Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 30/72] KVM: mmio: cleanup kvm_set_mmio_spte_mask Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 31/72] KVM: x86: Manually calculate reserved bits when loading PDPTRS Ben Hutchings
2019-12-09 15:49   ` Sean Christopherson
2019-12-10 16:16     ` Ben Hutchings
2019-12-10 16:27       ` Sean Christopherson
2019-12-08 13:53 ` [PATCH 3.16 32/72] cfg80211: Purge frame registrations on iftype change Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 33/72] configfs: fix a deadlock in configfs_symlink() Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 34/72] powerpc/pseries: correctly track irq state in default idle Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 35/72] hypfs: Fix error number left in struct pointer member Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 36/72] hwrng: core - don't wait on add_early_randomness() Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 37/72] ALSA: hda - Add laptop imic fixup for ASUS M9V laptop Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 38/72] sch_netem: fix a divide by zero in tabledist() Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 39/72] net/phy: fix DP83865 10 Mbps HDX loopback disable function Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 40/72] s390/topology: avoid firing events before kobjs are created Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 41/72] s390/cio: avoid calling strlen on null pointer Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 42/72] s390/cio: exclude subchannels with no parent from pseudo check Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 43/72] thermal: Fix use-after-free when unregistering thermal zone device Ben Hutchings
2019-12-08 16:22   ` Ido Schimmel
2019-12-08 18:09     ` Ben Hutchings
2019-12-09  1:40       ` Zhang Rui
2019-12-08 13:53 ` [PATCH 3.16 44/72] CIFS: fix max ea value size Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 45/72] fuse: fix missing unlock_page in fuse_writepage() Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 46/72] CIFS: Fix oplock handling for SMB 2.1+ protocols Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 47/72] i2c: riic: Clear NACK in tend isr Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 48/72] ANDROID: binder: remove waitqueue when thread exits Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 49/72] media: b2c2-flexcop-usb: add sanity checking Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 50/72] cfg80211: add and use strongly typed element iteration macros Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 51/72] nl80211: validate beacon head Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 52/72] wimax: i2400: fix memory leak Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 53/72] wimax: i2400: Fix memory leak in i2400m_op_rfkill_sw_toggle Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 54/72] can: gs_usb: gs_can_open(): prevent memory leak Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 55/72] mwifiex: pcie: Fix memory leak in mwifiex_pcie_alloc_cmdrsp_buf Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 56/72] mwifiex: pcie: Fix memory leak in mwifiex_pcie_init_evt_ring Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 57/72] crypto: user - Fix crypto_alg_match race Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 58/72] crypto: user - fix memory leak in crypto_report Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 59/72] scsi: bfa: release allocated memory in case of error Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 60/72] appletalk: Fix potential NULL pointer dereference in unregister_snap_client Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 61/72] appletalk: Set error code if register_snap_client failed Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 62/72] KVM: x86: fix out-of-bounds write in KVM_GET_EMULATED_CPUID (CVE-2019-19332) Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 63/72] USB: adutux: remove redundant variable minor Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 64/72] USB: adutux: fix use-after-free on disconnect Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 65/72] Input: ff-memless - kill timer in destroy() Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 66/72] HID: hiddev: do cleanup in failure of opening a device Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 67/72] HID: hiddev: avoid opening a disconnected device Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 68/72] usb: iowarrior: fix deadlock on disconnect Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 69/72] USB: iowarrior: fix use-after-free " Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 70/72] HID: Fix assumption that devices have inputs Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 71/72] media: ttusb-dec: Fix info-leak in ttusb_dec_send_command() Ben Hutchings
2019-12-08 13:53 ` [PATCH 3.16 72/72] can: peak_usb: fix slab info leak Ben Hutchings
2019-12-08 14:49 ` [PATCH 3.16 00/72] 3.16.79-rc1 review Guenter Roeck
2019-12-08 15:09   ` 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=lsq.1575813165.522399963@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=anand.jain@oracle.com \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=kda@linux-powerpc.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nborisov@suse.com \
    --cc=stable@vger.kernel.org \
    /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).