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,
	Hari Bathini <hbathini@linux.vnet.ibm.com>,
	Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>
Subject: [PATCH 3.14 12/23] powerpc/book3s64: Fix branching to OOL handlers in relocatable kernel
Date: Sun,  5 Jun 2016 14:40:12 -0700	[thread overview]
Message-ID: <20160605213828.140281253@linuxfoundation.org> (raw)
In-Reply-To: <20160605213826.938892115@linuxfoundation.org>

3.14-stable review patch.  If anyone has any objections, please let me know.

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

From: Hari Bathini <hbathini@linux.vnet.ibm.com>

commit 8ed8ab40047a570fdd8043a40c104a57248dd3fd upstream.

Some of the interrupt vectors on 64-bit POWER server processors are only
32 bytes long (8 instructions), which is not enough for the full
first-level interrupt handler. For these we need to branch to an
out-of-line (OOL) handler. But when we are running a relocatable kernel,
interrupt vectors till __end_interrupts marker are copied down to real
address 0x100. So, branching to labels (ie. OOL handlers) outside this
section must be handled differently (see LOAD_HANDLER()), considering
relocatable kernel, which would need at least 4 instructions.

However, branching from interrupt vector means that we corrupt the
CFAR (come-from address register) on POWER7 and later processors as
mentioned in commit 1707dd16. So, EXCEPTION_PROLOG_0 (6 instructions)
that contains the part up to the point where the CFAR is saved in the
PACA should be part of the short interrupt vectors before we branch out
to OOL handlers.

But as mentioned already, there are interrupt vectors on 64-bit POWER
server processors that are only 32 bytes long (like vectors 0x4f00,
0x4f20, etc.), which cannot accomodate the above two cases at the same
time owing to space constraint. Currently, in these interrupt vectors,
we simply branch out to OOL handlers, without using LOAD_HANDLER(),
which leaves us vulnerable when running a relocatable kernel (eg. kdump
case). While this has been the case for sometime now and kdump is used
widely, we were fortunate not to see any problems so far, for three
reasons:

  1. In almost all cases, production kernel (relocatable) is used for
     kdump as well, which would mean that crashed kernel's OOL handler
     would be at the same place where we end up branching to, from short
     interrupt vector of kdump kernel.
  2. Also, OOL handler was unlikely the reason for crash in almost all
     the kdump scenarios, which meant we had a sane OOL handler from
     crashed kernel that we branched to.
  3. On most 64-bit POWER server processors, page size is large enough
     that marking interrupt vector code as executable (see commit
     429d2e83) leads to marking OOL handler code from crashed kernel,
     that sits right below interrupt vector code from kdump kernel, as
     executable as well.

Let us fix this by moving the __end_interrupts marker down past OOL
handlers to make sure that we also copy OOL handlers to real address
0x100 when running a relocatable kernel.

This fix has been tested successfully in kdump scenario, on an LPAR with
4K page size by using different default/production kernel and kdump
kernel.

Also tested by manually corrupting the OOL handlers in the first kernel
and then kdump'ing, and then causing the OOL handlers to fire - mpe.

Fixes: c1fb6816fb1b ("powerpc: Add relocation on exception vector handlers")
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/powerpc/kernel/exceptions-64s.S |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -946,11 +946,6 @@ hv_facility_unavailable_relon_trampoline
 #endif
 	STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
 
-	/* Other future vectors */
-	.align	7
-	.globl	__end_interrupts
-__end_interrupts:
-
 	.align	7
 system_call_entry_direct:
 #if defined(CONFIG_RELOCATABLE)
@@ -1304,6 +1299,17 @@ __end_handlers:
 	STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
 	STD_RELON_EXCEPTION_HV_OOL(0xf80, hv_facility_unavailable)
 
+	/*
+	 * The __end_interrupts marker must be past the out-of-line (OOL)
+	 * handlers, so that they are copied to real address 0x100 when running
+	 * a relocatable kernel. This ensures they can be reached from the short
+	 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
+	 * directly, without using LOAD_HANDLER().
+	 */
+	.align	7
+	.globl	__end_interrupts
+__end_interrupts:
+
 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
 /*
  * Data area reserved for FWNMI option.

  parent reply	other threads:[~2016-06-05 21:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-05 21:40 [PATCH 3.14 00/23] 3.14.72-stable review Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 01/23] MIPS: math-emu: Fix jalr emulation when rd == $0 Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 02/23] MIPS: Fix siginfo.h to use strict posix types Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 03/23] MIPS: ath79: make bootconsole wait for both THRE and TEMT Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 04/23] Input: uinput - handle compat ioctl for UI_SET_PHYS Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 05/23] ath5k: Change led pin configuration for compaq c700 laptop Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 06/23] aacraid: Relinquish CPU during timeout wait Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 07/23] aacraid: Fix for aac_command_thread hang Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 08/23] cpuidle: Indicate when a device has been unregistered Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 09/23] PCI: Disable all BAR sizing for devices with non-compliant BARs Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 10/23] rtlwifi: Fix logic error in enter/exit power-save mode Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 11/23] pipe: Fix buffer offset after partially failed read Greg Kroah-Hartman
2016-06-07 13:50   ` Jiri Slaby
2016-06-07 14:42     ` Ben Hutchings
2016-06-05 21:40 ` Greg Kroah-Hartman [this message]
2016-06-05 21:40 ` [PATCH 3.14 13/23] xen/events: Dont move disabled irqs Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 15/23] drm/gma500: Fix possible out of bounds read Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 16/23] drm/fb_helper: Fix references to dev->mode_config.num_connector Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 17/23] ext4: fix hang when processing corrupted orphaned inode list Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 18/23] ext4: address UBSAN warning in mb_find_order_for_block() Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 19/23] ext4: silence UBSAN in ext4_mb_init() Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 21/23] xfs: xfs_iflush_cluster fails to abort on error Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 22/23] xfs: fix inode validity check in xfs_iflush_cluster Greg Kroah-Hartman
2016-06-05 21:40 ` [PATCH 3.14 23/23] xfs: skip stale inodes " Greg Kroah-Hartman
2016-06-06 17:26 ` [PATCH 3.14 00/23] 3.14.72-stable review Shuah Khan
2016-06-08  0:21   ` Greg Kroah-Hartman
2016-06-07  3:49 ` Guenter Roeck

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=20160605213828.140281253@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=hbathini@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=mpe@ellerman.id.au \
    --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).