0113-selftests-x86-ldt_gdt-Robustify-against-set_thread_a.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. From bd7ec1093f8a0a743215207ebc14cc6947ea23a0 Mon Sep 17 00:00:00 2001
  2. From: Andy Lutomirski <[email protected]>
  3. Date: Sat, 4 Nov 2017 04:19:49 -0700
  4. Subject: [PATCH 113/242] selftests/x86/ldt_gdt: Robustify against
  5. set_thread_area() and LAR oddities
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. Bits 19:16 of LAR's result are undefined, and some upcoming
  11. improvements to the test case seem to trigger this. Mask off those
  12. bits to avoid spurious failures.
  13. commit 5b781c7e317f ("x86/tls: Forcibly set the accessed bit in TLS
  14. segments") adds a valid case in which LAR's output doesn't quite
  15. agree with set_thread_area()'s input. This isn't triggered in the
  16. test as is, but it will be if we start calling set_thread_area()
  17. with the accessed bit clear. Work around this discrepency.
  18. I've added a Fixes tag so that -stable can pick this up if neccesary.
  19. Signed-off-by: Andy Lutomirski <[email protected]>
  20. Cc: Borislav Petkov <[email protected]>
  21. Cc: Linus Torvalds <[email protected]>
  22. Cc: Peter Zijlstra <[email protected]>
  23. Cc: Thomas Gleixner <[email protected]>
  24. Fixes: 5b781c7e317f ("x86/tls: Forcibly set the accessed bit in TLS segments")
  25. Link: http://lkml.kernel.org/r/b82f3f89c034b53580970ac865139fd8863f44e2.1509794321.git.luto@kernel.org
  26. Signed-off-by: Ingo Molnar <[email protected]>
  27. (cherry picked from commit d60ad744c9741586010d4bea286f09a063a90fbd)
  28. Signed-off-by: Andy Whitcroft <[email protected]>
  29. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  30. (cherry picked from commit d4c2ffcf3efe0d9610919fd48f5a1a5e38c28c07)
  31. Signed-off-by: Fabian Grünbichler <[email protected]>
  32. ---
  33. tools/testing/selftests/x86/ldt_gdt.c | 10 +++++++++-
  34. 1 file changed, 9 insertions(+), 1 deletion(-)
  35. diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c
  36. index b9a22f18566a..b2c54f4673f2 100644
  37. --- a/tools/testing/selftests/x86/ldt_gdt.c
  38. +++ b/tools/testing/selftests/x86/ldt_gdt.c
  39. @@ -114,7 +114,15 @@ static void check_valid_segment(uint16_t index, int ldt,
  40. return;
  41. }
  42. - if (ar != expected_ar) {
  43. + /* The SDM says "bits 19:16 are undefined". Thanks. */
  44. + ar &= ~0xF0000;
  45. +
  46. + /*
  47. + * NB: Different Linux versions do different things with the
  48. + * accessed bit in set_thread_area().
  49. + */
  50. + if (ar != expected_ar &&
  51. + (ldt || ar != (expected_ar | AR_ACCESSED))) {
  52. printf("[FAIL]\t%s entry %hu has AR 0x%08X but expected 0x%08X\n",
  53. (ldt ? "LDT" : "GDT"), index, ar, expected_ar);
  54. nerrs++;
  55. --
  56. 2.14.2