0255-x86-alternatives-Fix-optimize_nops-checking.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Borislav Petkov <[email protected]>
  3. Date: Wed, 10 Jan 2018 12:28:16 +0100
  4. Subject: [PATCH] x86/alternatives: Fix optimize_nops() checking
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. The alternatives code checks only the first byte whether it is a NOP, but
  10. with NOPs in front of the payload and having actual instructions after it
  11. breaks the "optimized' test.
  12. Make sure to scan all bytes before deciding to optimize the NOPs in there.
  13. Reported-by: David Woodhouse <[email protected]>
  14. Signed-off-by: Borislav Petkov <[email protected]>
  15. Signed-off-by: Thomas Gleixner <[email protected]>
  16. Cc: Tom Lendacky <[email protected]>
  17. Cc: Andi Kleen <[email protected]>
  18. Cc: Tim Chen <[email protected]>
  19. Cc: Peter Zijlstra <[email protected]>
  20. Cc: Jiri Kosina <[email protected]>
  21. Cc: Dave Hansen <[email protected]>
  22. Cc: Andi Kleen <[email protected]>
  23. Cc: Andrew Lutomirski <[email protected]>
  24. Cc: Linus Torvalds <[email protected]>
  25. Cc: Greg Kroah-Hartman <[email protected]>
  26. Cc: Paul Turner <[email protected]>
  27. Link: https://lkml.kernel.org/r/[email protected]
  28. (cherry picked from commit 612e8e9350fd19cae6900cf36ea0c6892d1a0dca)
  29. Signed-off-by: Andy Whitcroft <[email protected]>
  30. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  31. (cherry picked from commit dc241f68557ee1929a92b9ec6f7a1294bbbd4f00)
  32. Signed-off-by: Fabian Grünbichler <[email protected]>
  33. ---
  34. arch/x86/kernel/alternative.c | 7 +++++--
  35. 1 file changed, 5 insertions(+), 2 deletions(-)
  36. diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
  37. index 32e14d137416..5dc05755a044 100644
  38. --- a/arch/x86/kernel/alternative.c
  39. +++ b/arch/x86/kernel/alternative.c
  40. @@ -344,9 +344,12 @@ recompute_jump(struct alt_instr *a, u8 *orig_insn, u8 *repl_insn, u8 *insnbuf)
  41. static void __init_or_module noinline optimize_nops(struct alt_instr *a, u8 *instr)
  42. {
  43. unsigned long flags;
  44. + int i;
  45. - if (instr[0] != 0x90)
  46. - return;
  47. + for (i = 0; i < a->padlen; i++) {
  48. + if (instr[i] != 0x90)
  49. + return;
  50. + }
  51. local_irq_save(flags);
  52. add_nops(instr + (a->instrlen - a->padlen), a->padlen);
  53. --
  54. 2.14.2