mirror of https://lore.kernel.org/lkml/
 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,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Abdul Haleem" <abdhalee@linux.vnet.ibm.com>
Subject: [PATCH 3.2 092/106] powerpc/64: Initialise thread_info for emergency stacks
Date: Sat, 09 Sep 2017 22:47:40 +0100	[thread overview]
Message-ID: <lsq.1504993660.610201577@decadent.org.uk> (raw)
In-Reply-To: <lsq.1504993659.376385113@decadent.org.uk>

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

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

From: Nicholas Piggin <npiggin@gmail.com>

commit 34f19ff1b5a0d11e46df479623d6936460105c9f upstream.

Emergency stacks have their thread_info mostly uninitialised, which in
particular means garbage preempt_count values.

Emergency stack code runs with interrupts disabled entirely, and is
used very rarely, so this has been unnoticed so far. It was found by a
proposed new powerpc watchdog that takes a soft-NMI directly from the
masked_interrupt handler and using the emergency stack. That crashed
at BUG_ON(in_nmi()) in nmi_enter(). preempt_count()s were found to be
garbage.

To fix this, zero the entire THREAD_SIZE allocation, and initialize
the thread_info.

Reported-by: Abdul Haleem <abdhalee@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Move it all into setup_64.c, use a function not a macro. Fix
      crashes on Cell by setting preempt_count to 0 not HARDIRQ_OFFSET]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
[bwh: Backported to 3.2:
 - There's only one emergency stack
 - No need to call klp_init_thread_info()
 - Add the ti variable in emergency_stack_init()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 arch/powerpc/kernel/setup_64.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -509,6 +509,23 @@ static void __init exc_lvl_early_init(vo
 #endif
 
 /*
+ * Emergency stacks are used for a range of things, from asynchronous
+ * NMIs (system reset, machine check) to synchronous, process context.
+ * We set preempt_count to zero, even though that isn't necessarily correct. To
+ * get the right value we'd need to copy it from the previous thread_info, but
+ * doing that might fault causing more problems.
+ * TODO: what to do with accounting?
+ */
+static void emerg_stack_init_thread_info(struct thread_info *ti, int cpu)
+{
+	ti->task = NULL;
+	ti->cpu = cpu;
+	ti->preempt_count = 0;
+	ti->local_flags = 0;
+	ti->flags = 0;
+}
+
+/*
  * Stack space used when we detect a bad kernel stack pointer, and
  * early in SMP boots before relocation is enabled.
  */
@@ -525,12 +542,20 @@ static void __init emergency_stack_init(
 	 * Since we use these as temporary stacks during secondary CPU
 	 * bringup, we need to get at them in real mode. This means they
 	 * must also be within the RMO region.
+	 *
+	 * The IRQ stacks allocated elsewhere in this file are zeroed and
+	 * initialized in kernel/irq.c. These are initialized here in order
+	 * to have emergency stacks available as early as possible.
 	 */
 	limit = min(safe_stack_limit(), ppc64_rma_size);
 
 	for_each_possible_cpu(i) {
 		unsigned long sp;
+		struct thread_info *ti;
 		sp  = memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit);
+		ti = __va(sp);
+		memset(ti, 0, THREAD_SIZE);
+		emerg_stack_init_thread_info(ti, i);
 		sp += THREAD_SIZE;
 		paca[i].emergency_sp = __va(sp);
 	}

  parent reply	other threads:[~2017-09-09 22:52 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-09 21:47 [PATCH 3.2 000/106] 3.2.93-rc1 review Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 006/106] USB: serial: ir-usb: fix big-endian baud-rate debug printk Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 049/106] scsi: qla2xxx: don't disable a not previously enabled PCI device Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 087/106] signal: Only reschedule timers on signals timers have sent Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 027/106] xhci: apply PME_STUCK_QUIRK and MISSING_CAS quirk for Denverton Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 033/106] watchdog: pcwd_usb: fix NULL-deref at probe Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 013/106] uwb: fix device quirk on big-endian hosts Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 054/106] usb: gadget: f_mass_storage: Serialize wake and sleep execution Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 042/106] ALSA: hda - apply STAC_9200_DELL_M22 quirk for Dell Latitude D430 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 012/106] USB: core: replace %p with %pK Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 016/106] usb: r8a66597-hcd: select a different endpoint on timeout Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 015/106] usb: r8a66597-hcd: decrease timeout Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 017/106] USB: gadget: dummy_hcd: fix hub-descriptor removable fields Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 079/106] KVM: async_pf: avoid async pf injection when in guest mode Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 053/106] net: phy: fix marvell phy status reading Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 073/106] KVM: cpuid: Fix read/write out-of-bounds vulnerability in cpuid emulation Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 032/106] drivers: char: mem: Check for address space wraparound with mmap() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 052/106] ext4: fix fdatasync(2) after extent manipulation operations Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 024/106] tracing/kprobes: Enforce kprobes teardown after testing Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 078/106] excessive checks in ufs_write_failed() and ufs_evict_inode() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 075/106] KEYS: fix dereferencing NULL payload with nonzero length Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 004/106] net: irda: irda-usb: fix firmware name on big-endian hosts Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 021/106] USB: hub: fix SS max number of ports Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 020/106] USB: hub: fix non-SS hub-descriptor handling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 081/106] usb: xhci: ASMedia ASM1042A chipset need shorts TX quirk Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 055/106] ipv6: xfrm: Handle errors reported by xfrm6_find_1stfragopt() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 028/106] usb: host: xhci-mem: allocate zeroed Scratchpad Buffer Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 019/106] USB: hub: fix SS hub-descriptor handling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 022/106] mac80211: strictly check mesh address extension mode Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 025/106] xhci: workaround for hosts missing CAS bit Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 011/106] USB: ene_usb6250: fix DMA to the stack Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 089/106] drm/radeon: add a quirk for Toshiba Satellite L20-183 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 071/106] perf script python: Updated trace_unhandled() signature Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 035/106] KVM: X86: Fix read out-of-bounds vulnerability in kvm pio emulation Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 076/106] fix ufs_isblockset() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 003/106] tcp: avoid fragmenting peculiar skbs in SACK Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 007/106] USB: serial: mct_u232: fix big-endian baud-rate handling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 091/106] ipv6: avoid unregistering inet6_dev for loopback Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 039/106] ext4: keep existing extra fields when inode expands Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 065/106] net: ethoc: enable NAPI before poll may be scheduled Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 068/106] perf script: Fix outdated comment for perf-trace-python Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 062/106] net: ping: do not abuse udp_poll() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 037/106] KVM: x86: zero base3 of unusable segments Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 044/106] libceph: NULL deref on crush_decode() error path Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 085/106] powerpc/kprobes: Pause function_graph tracing during jprobes handling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 051/106] ext4: fix data corruption for mmap writes Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 082/106] selinux: fix double free in selinux_parse_opts_str() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 056/106] drivers: char: mem: Fix wraparound check to allow mappings up to the end Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 005/106] USB: serial: ftdi_sio: fix setting latency for unprivileged users Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 026/106] usb: xhci: apply XHCI_PME_STUCK_QUIRK to Intel Apollo Lake Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 009/106] ahci: Acer SA5-271 SSD Not Detected Fix Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 060/106] net: add kfree_skb_list() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 002/106] af_key: Fix slab-out-of-bounds in pfkey_compile_policy Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 050/106] net: ethernet: ax88796: don't call free_irq without request_irq first Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 077/106] ufs: set correct ->s_maxsize Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 036/106] KVM: x86: fix use of uninitialized memory as segment descriptor in emulator Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 043/106] block: fix an error code in add_partition() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 064/106] [media] vb2: Fix an off by one error in 'vb2_plane_vaddr' Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 063/106] [media] vb2: fix plane index sanity check in vb2_plane_cookie() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 029/106] usb: host: xhci: simplify irq handler return Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 058/106] alarmtimer: Rate limit periodic intervals Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 018/106] USB: usbip: fix nonconforming hub descriptor Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 088/106] Input: i8042 - add Fujitsu Lifebook AH544 to notimeout list Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 083/106] xfrm: Oops on error in pfkey_msg2xfrm_state() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 031/106] usb: musb: tusb6010_omap: Do not reset the other direction's packet size Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 047/106] netfilter: ctnetlink: fix incorrect nf_ct_put during hash resize Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 059/106] [media] rc-core: race condition during ir_raw_event_register() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 048/106] ASoC: Fix use-after-free at card unregistration Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 061/106] ipv6: Fix leak in ipv6_gso_segment() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 014/106] USB: iowarrior: fix info ioctl on big-endian hosts Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 045/106] drm/gma500/psb: Actually use VBT mode when it is found Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 034/106] powerpc/mm: Fix virt_addr_valid() etc. on 64-bit hash Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 080/106] configfs: Fix race between create_link and configfs_rmdir Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 040/106] i2c: i2c-tiny-usb: fix buffer not being DMA capable Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 066/106] drm/vmwgfx: Handle vmalloc() failure in vmw_local_fifo_reserve() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 030/106] USB: xhci: fix lock-inversion problem Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 001/106] xfrm: fix stack access out of bounds with CONFIG_XFRM_SUB_POLICY Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 023/106] of: fdt: add missing allocation-failure check Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 070/106] perf script python: Fix wrong code snippets in documentation Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 086/106] swap: cond_resched in swap_cgroup_prepare() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 038/106] osf_wait4(): fix infoleak Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 046/106] dmaengine: ep93xx: Always start from BASE0 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 072/106] perf script python: Remove dups in documentation examples Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 090/106] rtnetlink: add IFLA_GROUP to ifla_policy Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 067/106] perf probe: Fix examples section of documentation Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 069/106] perf script: Fix documentation errors Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 041/106] crypto: gcm - wait for crypto op not signal safe Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 008/106] USB: serial: io_ti: fix div-by-zero in set_termios Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 074/106] MIPS: kprobes: flush_insn_slot should flush only if probe initialised Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 010/106] tcp: eliminate negative reordering in tcp_clean_rtx_queue Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 084/106] xfrm: NULL dereference on allocation failure Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 057/106] alarmtimer: Prevent overflow of relative timers Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 097/106] tracing/kprobes: Allow to create probe with a module name starting with a digit Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 103/106] mm: fix NULL ptr dereference in migrate_pages Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 095/106] net: prevent sign extension in dev_get_stats() Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 099/106] xfrm: policy: check policy direction value Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 101/106] ptrace: use fsuid, fsgid, effective creds for fs access checks Ben Hutchings
2017-09-09 21:47 ` Ben Hutchings [this message]
2017-09-09 21:47 ` [PATCH 3.2 096/106] MIPS: Fix IRQ tracing & lockdep when rescheduling Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 104/106] mm: fix NULL ptr dereference in move_pages Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 102/106] mm: fix move/migrate_pages() race on task struct Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 094/106] lib/cmdline.c: fix get_options() overflow while parsing ranges Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 098/106] tcp: initialize rcv_mss to TCP_MIN_MSS instead of 0 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 100/106] xen: fix bio vec merging Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 106/106] net: phy: marvell: Limit errata to 88m1101 Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 093/106] autofs: sanity check status reported with AUTOFS_DEV_IOCTL_FAIL Ben Hutchings
2017-09-09 21:47 ` [PATCH 3.2 105/106] Sanitize 'move_pages()' permission checks Ben Hutchings
2017-09-10 14:31 ` [PATCH 3.2 000/106] 3.2.93-rc1 review Guenter Roeck
2017-09-10 18:46   ` 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.1504993660.610201577@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=abdhalee@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.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

Powered by JetHome