All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	linux-acpi@vger.kernel.org, Borislav Petkov <bp@alien8.de>,
	Len Brown <lenb@kernel.org>, Thomas Gleixner <tglx@linutronix.de>,
	Jiri Slaby <jslaby@suse.cz>
Subject: [patch added to 3.12-stable] ftrace/x86: Fix triple fault with graph tracing and suspend-to-ram
Date: Wed,  3 May 2017 14:23:27 +0200	[thread overview]
Message-ID: <20170503122327.12095-49-jslaby@suse.cz> (raw)
In-Reply-To: <20170503122327.12095-1-jslaby@suse.cz>

From: Josh Poimboeuf <jpoimboe@redhat.com>

This patch has been added to the 3.12 stable tree. If you have any
objections, please let us know.

===============

commit 34a477e5297cbaa6ecc6e17c042a866e1cbe80d6 upstream.

On x86-32, with CONFIG_FIRMWARE and multiple CPUs, if you enable function
graph tracing and then suspend to RAM, it will triple fault and reboot when
it resumes.

The first fault happens when booting a secondary CPU:

startup_32_smp()
  load_ucode_ap()
    prepare_ftrace_return()
      ftrace_graph_is_dead()
        (accesses 'kill_ftrace_graph')

The early head_32.S code calls into load_ucode_ap(), which has an an
ftrace hook, so it calls prepare_ftrace_return(), which calls
ftrace_graph_is_dead(), which tries to access the global
'kill_ftrace_graph' variable with a virtual address, causing a fault
because the CPU is still in real mode.

The fix is to add a check in prepare_ftrace_return() to make sure it's
running in protected mode before continuing.  The check makes sure the
stack pointer is a virtual kernel address.  It's a bit of a hack, but
it's not very intrusive and it works well enough.

For reference, here are a few other (more difficult) ways this could
have potentially been fixed:

- Move startup_32_smp()'s call to load_ucode_ap() down to *after* paging
  is enabled.  (No idea what that would break.)

- Track down load_ucode_ap()'s entire callee tree and mark all the
  functions 'notrace'.  (Probably not realistic.)

- Pause graph tracing in ftrace_suspend_notifier_call() or bringup_cpu()
  or __cpu_up(), and ensure that the pause facility can be queried from
  real mode.

Reported-by: Paul Menzel <pmenzel@molgen.mpg.de>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: "Rafael J . Wysocki" <rjw@rjwysocki.net>
Cc: linux-acpi@vger.kernel.org
Cc: Borislav Petkov <bp@alien8.de>
Cc: Len Brown <lenb@kernel.org>
Link: http://lkml.kernel.org/r/5c1272269a580660703ed2eccf44308e790c7a98.1492123841.git.jpoimboe@redhat.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 arch/x86/kernel/ftrace.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index f8ab203fb676..b8162154e615 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -735,6 +735,18 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
 	unsigned long return_hooker = (unsigned long)
 				&return_to_handler;
 
+	/*
+	 * When resuming from suspend-to-ram, this function can be indirectly
+	 * called from early CPU startup code while the CPU is in real mode,
+	 * which would fail miserably.  Make sure the stack pointer is a
+	 * virtual address.
+	 *
+	 * This check isn't as accurate as virt_addr_valid(), but it should be
+	 * good enough for this purpose, and it's fast.
+	 */
+	if (unlikely((long)__builtin_frame_address(0) >= 0))
+		return;
+
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
 		return;
 
-- 
2.12.2


      parent reply	other threads:[~2017-05-03 12:23 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-03 12:22 [patch added to 3.12-stable] rtc: tegra: Implement clock handling Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] mm: Tighten x86 /dev/mem with zeroing reads Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] virtio-console: avoid DMA from stack Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] pegasus: Use heap buffers for all register access Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] rtl8150: " Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] catc: Combine failure cleanup code in catc_probe() Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] catc: Use heap buffer for memory size test Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] net: ipv6: check route protocol when deleting routes Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] KEYS: Disallow keyrings beginning with '.' to be joined as session keyrings Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] KEYS: Change the name of the dead type to ".dead" to prevent user access Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] KEYS: fix keyctl_set_reqkey_keyring() to not leak thread keyrings Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] tracing: Allocate the snapshot buffer before enabling probe Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] ring-buffer: Have ring_buffer_iter_empty() return true when empty Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] cifs: Do not send echoes before Negotiate is complete Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] CIFS: remove bad_network_name flag Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] Drivers: hv: don't leak memory in vmbus_establish_gpadl() Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] Drivers: hv: get rid of timeout in vmbus_open() Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] Input: elantech - add Fujitsu Lifebook E547 to force crc_enabled Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] ACPI / power: Avoid maybe-uninitialized warning Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] ubi/upd: Always flush after prepared for an update Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] x86/mce/AMD: Give a name to MCA bank 3 when accessed with legacy MSRs Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] kvm: arm/arm64: Fix locking for kvm_free_stage2_pgd Jiri Slaby
2017-05-03 12:39   ` Suzuki K Poulose
2017-05-03 13:21     ` Jiri Slaby
2017-05-03 13:31       ` Suzuki K Poulose
2017-05-03 12:23 ` [patch added to 3.12-stable] block: fix del_gendisk() vs blkdev_ioctl crash Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] powerpc: Reject binutils 2.24 when building little endian Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ping: implement proper locking Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net/packet: fix overflow in check for tp_frame_nr Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net/packet: fix overflow in check for tp_reserve Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] netfilter: arp_tables: fix invoking 32bit "iptable -P INPUT ACCEPT" failed in 64bit kernel Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] tty: nozomi: avoid a harmless gcc warning Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] hostap: avoid uninitialized variable use in hfa384x_get_rid Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] gfs2: avoid uninitialized variable warning Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net: neigh: guard against NULL solicit() method Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net: phy: handle state correctly in phy_stop_machine Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] l2tp: take reference on sessions being dumped Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net: ipv4: fix multipath RTM_GETROUTE behavior when iif is given Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] sctp: listen on the sock only when it's state is listening or closed Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ip6mr: fix notification device destruction Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ipv6: check raw payload size correctly in ioctl Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ext4: check if in-inode xattr is corrupted in ext4_expand_extra_isize_ea() Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] md:raid1: fix a dead loop when read from a WriteMostly disk Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] MIPS: Fix crash registers on non-crashing CPUs Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] RDS: Fix the atomicity for congestion map update Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] xen/x86: don't lose event interrupts Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ALSA: seq: Don't break snd_use_lock_sync() loop by timeout Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] MIPS: KGDB: Use kernel context for sleeping threads Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] p9_client_readdir() fix Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] Input: i8042 - add Clevo P650RS to the i8042 reset list Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] nfsd: check for oversized NFSv2/v3 arguments Jiri Slaby
2017-05-03 12:23 ` Jiri Slaby [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=20170503122327.12095-49-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=bp@alien8.de \
    --cc=jpoimboe@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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.