]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
selftests/x86/ldt_gdt: Robustify against set_thread_area() and LAR oddities
authorAndy Lutomirski <luto@kernel.org>
Sat, 4 Nov 2017 11:19:49 +0000 (04:19 -0700)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Sat, 6 Jan 2018 12:23:00 +0000 (13:23 +0100)
CVE-2017-5754

Bits 19:16 of LAR's result are undefined, and some upcoming
improvements to the test case seem to trigger this.  Mask off those
bits to avoid spurious failures.

commit 5b781c7e317f ("x86/tls: Forcibly set the accessed bit in TLS
segments") adds a valid case in which LAR's output doesn't quite
agree with set_thread_area()'s input.  This isn't triggered in the
test as is, but it will be if we start calling set_thread_area()
with the accessed bit clear.  Work around this discrepency.

I've added a Fixes tag so that -stable can pick this up if neccesary.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bpetkov@suse.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 5b781c7e317f ("x86/tls: Forcibly set the accessed bit in TLS segments")
Link: http://lkml.kernel.org/r/b82f3f89c034b53580970ac865139fd8863f44e2.1509794321.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
(cherry picked from commit d60ad744c9741586010d4bea286f09a063a90fbd)
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
tools/testing/selftests/x86/ldt_gdt.c

index b9a22f18566ae27eef76b22590448e2725b15e12..b2c54f4673f25243bfe381ab3c83ac8816a52ca5 100644 (file)
@@ -114,7 +114,15 @@ static void check_valid_segment(uint16_t index, int ldt,
                return;
        }
 
-       if (ar != expected_ar) {
+       /* The SDM says "bits 19:16 are undefined".  Thanks. */
+       ar &= ~0xF0000;
+
+       /*
+        * NB: Different Linux versions do different things with the
+        * accessed bit in set_thread_area().
+        */
+       if (ar != expected_ar &&
+           (ldt || ar != (expected_ar | AR_ACCESSED))) {
                printf("[FAIL]\t%s entry %hu has AR 0x%08X but expected 0x%08X\n",
                       (ldt ? "LDT" : "GDT"), index, ar, expected_ar);
                nerrs++;