All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Thomas Gleixner <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: bp@alien8.de, mingo@kernel.org, rjones@redhat.com, hpa@zytor.com,
	tglx@linutronix.de, linux-kernel@vger.kernel.org,
	cebbert.lkml@gmail.com
Subject: [tip:x86/urgent] x86/alternatives: Make optimize_nops() interrupt safe and synced
Date: Thu, 3 Sep 2015 12:30:47 -0700	[thread overview]
Message-ID: <tip-66c117d7fa2ae429911e60d84bf31a90b2b96189@git.kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.11.1509031232340.15006@nanos>

Commit-ID:  66c117d7fa2ae429911e60d84bf31a90b2b96189
Gitweb:     http://git.kernel.org/tip/66c117d7fa2ae429911e60d84bf31a90b2b96189
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Thu, 3 Sep 2015 12:34:55 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 3 Sep 2015 21:27:47 +0200

x86/alternatives: Make optimize_nops() interrupt safe and synced

Richard reported the following crash:

[    0.036000] BUG: unable to handle kernel paging request at 55501e06
[    0.036000] IP: [<c0aae48b>] common_interrupt+0xb/0x38
[    0.036000] Call Trace:
[    0.036000]  [<c0409c80>] ? add_nops+0x90/0xa0
[    0.036000]  [<c040a054>] apply_alternatives+0x274/0x630

Chuck decoded:

 "  0:   8d 90 90 83 04 24       lea    0x24048390(%eax),%edx
    6:   80 fc 0f                cmp    $0xf,%ah
    9:   a8 0f                   test   $0xf,%al
 >> b:   a0 06 1e 50 55          mov    0x55501e06,%al
   10:   57                      push   %edi
   11:   56                      push   %esi

 Interrupt 0x30 occurred while the alternatives code was replacing the
 initial 0x90,0x90,0x90 NOPs (from the ASM_CLAC macro) with the
 optimized version, 0x8d,0x76,0x00. Only the first byte has been
 replaced so far, and it makes a mess out of the insn decoding."

optimize_nops() is buggy in two aspects:

- It's not disabling interrupts across the modification
- It's lacking a sync_core() call

Add both.

Fixes: 4fd4b6e5537c 'x86/alternatives: Use optimized NOPs for padding'
Reported-and-tested-by: "Richard W.M. Jones" <rjones@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard W.M. Jones <rjones@redhat.com>
Cc: Chuck Ebbert <cebbert.lkml@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/alpine.DEB.2.11.1509031232340.15006@nanos
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/alternative.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index c42827e..25f9093 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -338,10 +338,15 @@ done:
 
 static void __init_or_module optimize_nops(struct alt_instr *a, u8 *instr)
 {
+	unsigned long flags;
+
 	if (instr[0] != 0x90)
 		return;
 
+	local_irq_save(flags);
 	add_nops(instr + (a->instrlen - a->padlen), a->padlen);
+	sync_core();
+	local_irq_restore(flags);
 
 	DUMP_BYTES(instr, a->instrlen, "%p: [%d:%d) optimized NOPs: ",
 		   instr, a->instrlen - a->padlen, a->padlen);

  parent reply	other threads:[~2015-09-03 19:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-31  2:37 [BUG 4.2-rc8] Interrupt occurs while apply_alternatives() is patching the handler Chuck Ebbert
2015-09-01  6:20 ` Richard W.M. Jones
2015-09-02  9:11   ` Thomas Gleixner
2015-09-02 19:05     ` Richard W.M. Jones
2015-09-03  7:53       ` Richard W.M. Jones
2015-09-03  8:50     ` Borislav Petkov
2015-09-03 10:41       ` Thomas Gleixner
2015-09-03 12:43         ` Josh Boyer
2015-09-03 13:01           ` Thomas Gleixner
2015-09-03 15:48         ` Richard W.M. Jones
2015-09-03 19:30         ` tip-bot for Thomas Gleixner [this message]
2015-09-04  7:40         ` Richard W.M. Jones
2015-09-04 12:02         ` Borislav Petkov
2015-09-04 13:37           ` Thomas Gleixner
2015-09-05 15:25             ` Borislav Petkov

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=tip-66c117d7fa2ae429911e60d84bf31a90b2b96189@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bp@alien8.de \
    --cc=cebbert.lkml@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=rjones@redhat.com \
    --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.