From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752785AbeAJSop (ORCPT + 1 other); Wed, 10 Jan 2018 13:44:45 -0500 Received: from terminus.zytor.com ([65.50.211.136]:52029 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751787AbeAJSon (ORCPT ); Wed, 10 Jan 2018 13:44:43 -0500 Date: Wed, 10 Jan 2018 10:39:50 -0800 From: tip-bot for Borislav Petkov Message-ID: Cc: ak@linux.intel.com, tglx@linutronix.de, dave.hansen@intel.com, andi@firstfloor.org, dwmw2@infradead.org, hpa@zytor.com, peterz@infradead.org, gregkh@linux-foundation.org, tim.c.chen@linux.intel.com, linux-kernel@vger.kernel.org, jikos@kernel.org, mingo@kernel.org, bp@suse.de, pjt@google.com, torvalds@linux-foundation.org, thomas.lendacky@amd.com, luto@kernel.org Reply-To: ak@linux.intel.com, dave.hansen@intel.com, tglx@linutronix.de, hpa@zytor.com, peterz@infradead.org, andi@firstfloor.org, dwmw2@infradead.org, tim.c.chen@linux.intel.com, gregkh@linux-foundation.org, linux-kernel@vger.kernel.org, jikos@kernel.org, mingo@kernel.org, thomas.lendacky@amd.com, bp@suse.de, torvalds@linux-foundation.org, pjt@google.com, luto@kernel.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: 612e8e9350fd19cae6900cf36ea0c6892d1a0dca 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: 612e8e9350fd19cae6900cf36ea0c6892d1a0dca Gitweb: https://git.kernel.org/tip/612e8e9350fd19cae6900cf36ea0c6892d1a0dca Author: Borislav Petkov AuthorDate: Wed, 10 Jan 2018 12:28:16 +0100 Committer: Thomas Gleixner CommitDate: Wed, 10 Jan 2018 19:36:22 +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);