x86/mpx, selftests: Only check bounds-vs-shadow when we keep shadow
authorJoerg Roedel <jroedel@suse.de>
Thu, 6 Apr 2017 14:23:18 +0000 (16:23 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 12 Apr 2017 06:40:59 +0000 (08:40 +0200)
The check between the hardware state and our shadow of it is
checked in the signal handler for all bounds exceptions,
even for the ones where we don't keep the shadow up2date.
This is a problem because when no shadow is kept the handler
fails at this point and hides the real reason of the
exception.

Move the check into the code-path evaluating normal bounds
exceptions to prevent this.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kselftest@vger.kernel.org
Link: http://lkml.kernel.org/r/1491488598-27346-1-git-send-email-joro@8bytes.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
tools/testing/selftests/x86/mpx-mini-test.c

index 616ee967333933778eaf54b84c41fcce59a5e9f4..a8df159a8924829695c0e56289f4ad29a598ac22 100644 (file)
@@ -404,8 +404,6 @@ void handler(int signum, siginfo_t *si, void *vucontext)
                dprintf2("info->si_lower: %p\n", __si_bounds_lower(si));
                dprintf2("info->si_upper: %p\n", __si_bounds_upper(si));
 
-               check_siginfo_vs_shadow(si);
-
                for (i = 0; i < 8; i++)
                        dprintf3("[%d]: %p\n", i, si_addr_ptr[i]);
                switch (br_reason) {
@@ -416,6 +414,9 @@ void handler(int signum, siginfo_t *si, void *vucontext)
                        exit(5);
                case 1: /* #BR MPX bounds exception */
                        /* these are normal and we expect to see them */
+
+                       check_siginfo_vs_shadow(si);
+
                        dprintf1("bounds exception (normal): status 0x%jx at %p si_addr: %p\n",
                                status, (void *)ip, si->si_addr);
                        num_bnd_chk++;