All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Andi Kleen <andi@firstfloor.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	the arch/x86 maintainers <x86@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Paul Turner <pjt@google.com>, Andrew Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linux-foundation.org>,
	Dave Hansen <dave.hansen@intel.com>,
	Jiri Kosina <jikos@kernel.org>, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH] x86/alternatives: Fix optimize_nops() checking
Date: Wed, 10 Jan 2018 12:28:16 +0100	[thread overview]
Message-ID: <20180110112815.mgciyf5acwacphkq@pd.tnic> (raw)
In-Reply-To: <1515578735.22302.91.camel@infradead.org>

From: Borislav Petkov <bp@suse.de>
Date: Wed, 10 Jan 2018 12:14:07 +0100

We check only the first byte whether it is a NOP but if David Woodhouse
wants to do some crazy experiments with slapping NOPs in front of the
payload and having the actual instructions after it, this "optimized"
test breaks. :-)

Make sure we scan all bytes before we decide to optimize the NOPs in
there.

Reported-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: x86@kernel.org
---
 arch/x86/kernel/alternative.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 3344d3382e91..78932b283915 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -344,9 +344,11 @@ recompute_jump(struct alt_instr *a, u8 *orig_insn, u8 *repl_insn, u8 *insnbuf)
 static void __init_or_module noinline optimize_nops(struct alt_instr *a, u8 *instr)
 {
 	unsigned long flags;
+	int i;
 
-	if (instr[0] != 0x90)
-		return;
+	for (i = 0; i < a->padlen; i++)
+		if (instr[i] != 0x90)
+			return;
 
 	local_irq_save(flags);
 	add_nops(instr + (a->instrlen - a->padlen), a->padlen);
-- 
2.13.0


-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

  reply	other threads:[~2018-01-10 11:28 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10  0:31 [PATCH] x86/retpoline: Fix NOSPEC_JMP for tip Andi Kleen
2018-01-10  0:39 ` Thomas Gleixner
2018-01-10  0:39 ` Linus Torvalds
2018-01-10  0:40   ` Thomas Gleixner
2018-01-10  0:45     ` Tom Lendacky
2018-01-10  0:50       ` Thomas Gleixner
2018-01-10  1:30       ` Andi Kleen
2018-01-10  1:36         ` Andi Kleen
2018-01-10  1:50           ` Thomas Gleixner
2018-01-10  1:57             ` Andi Kleen
2018-01-10  9:05         ` David Woodhouse
2018-01-10  0:51   ` Andi Kleen
2018-01-10  1:05     ` Thomas Gleixner
2018-01-10  7:15   ` David Woodhouse
2018-01-10 10:05     ` David Woodhouse
2018-01-10 11:28       ` Borislav Petkov [this message]
2018-01-10 11:36         ` [PATCH] x86/alternatives: Fix optimize_nops() checking David Woodhouse
2018-01-10 11:45           ` Borislav Petkov
2018-01-10 11:49             ` David Woodhouse
2018-01-10 11:57               ` Borislav Petkov
2018-01-10 11:58                 ` David Woodhouse
2018-01-10 17:33         ` [tip:x86/pti] " tip-bot for Borislav Petkov
2018-01-10 18:12         ` tip-bot for Borislav Petkov
2018-01-10 18:39         ` tip-bot for Borislav Petkov
2018-01-10 19:38         ` [PATCH] " Linus Torvalds
2018-01-10 19:55           ` Thomas Gleixner
2018-01-10 20:15             ` Josh Poimboeuf
2018-01-10 20:19               ` David Woodhouse
2018-01-10 20:26               ` Linus Torvalds
2018-01-10 20:33                 ` Peter Zijlstra
2018-01-10 20:36                   ` David Woodhouse
2018-01-10 20:49                   ` Linus Torvalds
2018-01-10 20:55                 ` Borislav Petkov
2018-01-10 21:05                   ` Linus Torvalds
2018-01-10 21:08                     ` David Woodhouse
2018-01-10 21:11                       ` Linus Torvalds
2018-01-10 21:16                         ` Josh Poimboeuf
2018-01-10 21:17                         ` Linus Torvalds
2018-01-10 21:27                           ` Josh Poimboeuf
2018-01-10 21:10                     ` Borislav Petkov
2018-01-10 20:55                 ` Josh Poimboeuf
2018-01-10 20:05           ` Borislav Petkov
2018-01-10 20:20             ` Linus Torvalds
2018-01-10 20:50               ` 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=20180110112815.mgciyf5acwacphkq@pd.tnic \
    --to=bp@alien8.de \
    --cc=ak@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=dave.hansen@intel.com \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@linux-foundation.org \
    --cc=jikos@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@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 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.