Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753062AbeAJSSm (ORCPT + 1 other); Wed, 10 Jan 2018 13:18:42 -0500 Received: from terminus.zytor.com ([65.50.211.136]:38577 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752790AbeAJSSj (ORCPT ); Wed, 10 Jan 2018 13:18:39 -0500 Date: Wed, 10 Jan 2018 10:12:49 -0800 From: tip-bot for Borislav Petkov Message-ID: Cc: thomas.lendacky@amd.com, gregkh@linux-foundation.org, ak@linux.intel.com, jikos@kernel.org, tim.c.chen@linux.intel.com, mingo@kernel.org, dave.hansen@intel.com, torvalds@linux-foundation.org, peterz@infradead.org, dwmw2@infradead.org, luto@kernel.org, pjt@google.com, bp@suse.de, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, andi@firstfloor.org Reply-To: luto@kernel.org, pjt@google.com, bp@suse.de, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, andi@firstfloor.org, thomas.lendacky@amd.com, gregkh@linux-foundation.org, ak@linux.intel.com, tim.c.chen@linux.intel.com, mingo@kernel.org, jikos@kernel.org, dave.hansen@intel.com, torvalds@linux-foundation.org, peterz@infradead.org, dwmw2@infradead.org In-Reply-To: <20180110112815.mgciyf5acwacphkq@pd.tnic> References: <20180110112815.mgciyf5acwacphkq@pd.tnic> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/alternatives: Fix optimize_nops() checking Git-Commit-ID: 0795e94c2eacd888c88e2ad2321368b6b0fcb20a X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Commit-ID: 0795e94c2eacd888c88e2ad2321368b6b0fcb20a Gitweb: https://git.kernel.org/tip/0795e94c2eacd888c88e2ad2321368b6b0fcb20a Author: Borislav Petkov AuthorDate: Wed, 10 Jan 2018 12:28:16 +0100 Committer: Thomas Gleixner CommitDate: Wed, 10 Jan 2018 19:09:08 +0100 x86/alternatives: Fix optimize_nops() checking The alternatives code checks only the first byte whether it is a NOP, but with NOPs in front of the payload and having actual instructions after it breaks the "optimized' test. Make sure to scan all bytes before deciding to optimize the NOPs in there. Reported-by: David Woodhouse Signed-off-by: Borislav Petkov Signed-off-by: Thomas Gleixner Cc: Tom Lendacky Cc: Andi Kleen Cc: Tim Chen Cc: Peter Zijlstra Cc: Jiri Kosina Cc: Dave Hansen Cc: Andi Kleen Cc: Andrew Lutomirski Cc: Linus Torvalds Cc: Greg Kroah-Hartman Cc: Paul Turner Link: https://lkml.kernel.org/r/20180110112815.mgciyf5acwacphkq@pd.tnic --- arch/x86/kernel/alternative.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 3344d33..e0b97e4 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -344,9 +344,12 @@ done: 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);