Messages in this thread Patch in this message | | | Date | Wed, 10 Jan 2018 12:28:16 +0100 | From | Borislav Petkov <> | Subject | [PATCH] x86/alternatives: Fix optimize_nops() checking |
| |
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.
| |