a2cf7d
commit 8d42bf859a289944749d9f978c076cd318119867
a2cf7d
Author: Lucas A. M. Magalhaes <lamm@linux.ibm.com>
a2cf7d
Date:   Mon Feb 17 09:09:52 2020 -0300
a2cf7d
a2cf7d
    Fix tst-pkey expectations on pkey_get [BZ #23202]
a2cf7d
    
a2cf7d
    From the GNU C Library manual, the pkey_set can receive a combination of
a2cf7d
    PKEY_DISABLE_WRITE and PKEY_DISABLE_ACCESS.  However PKEY_DISABLE_ACCESS
a2cf7d
    is more restrictive than PKEY_DISABLE_WRITE and includes its behavior.
a2cf7d
    
a2cf7d
    The test expects that after setting
a2cf7d
    (PKEY_DISABLE_WRITE|PKEY_DISABLE_ACCESS) pkey_get should return the
a2cf7d
    same.  This may not be true as PKEY_DISABLE_ACCESS will succeed in
a2cf7d
    describing the state of the key in this case.
a2cf7d
    
a2cf7d
    The pkey behavior during signal handling is different between x86 and
a2cf7d
    POWER.  This change make the test compatible with both architectures.
a2cf7d
    
a2cf7d
    Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
a2cf7d
a2cf7d
diff --git a/sysdeps/unix/sysv/linux/tst-pkey.c b/sysdeps/unix/sysv/linux/tst-pkey.c
a2cf7d
index 5f721d4444490945..600b6f0098def773 100644
a2cf7d
--- a/sysdeps/unix/sysv/linux/tst-pkey.c
a2cf7d
+++ b/sysdeps/unix/sysv/linux/tst-pkey.c
a2cf7d
@@ -37,7 +37,7 @@ static pthread_barrier_t barrier;
a2cf7d
 
a2cf7d
 /* The keys used for testing.  These have been allocated with access
a2cf7d
    rights set based on their array index.  */
a2cf7d
-enum { key_count = 4 };
a2cf7d
+enum { key_count = 3 };
a2cf7d
 static int keys[key_count];
a2cf7d
 static volatile int *pages[key_count];
a2cf7d
 
a2cf7d
@@ -111,14 +111,16 @@ check_page_access (int page, bool write)
a2cf7d
 }
a2cf7d
 
a2cf7d
 static volatile sig_atomic_t sigusr1_handler_ran;
a2cf7d
-
a2cf7d
-/* Used to check that access is revoked in signal handlers.  */
a2cf7d
+/* Used to check the behavior in signal handlers.  In x86 all access are
a2cf7d
+   revoked during signal handling.  In PowerPC the key permissions are
a2cf7d
+   inherited by the interrupted thread. This test accept both approaches.  */
a2cf7d
 static void
a2cf7d
 sigusr1_handler (int signum)
a2cf7d
 {
a2cf7d
   TEST_COMPARE (signum, SIGUSR1);
a2cf7d
   for (int i = 0; i < key_count; ++i)
a2cf7d
-    TEST_COMPARE (pkey_get (keys[i]), PKEY_DISABLE_ACCESS);
a2cf7d
+    TEST_VERIFY (pkey_get (keys[i]) == PKEY_DISABLE_ACCESS
a2cf7d
+                 || pkey_get (keys[i]) == i);
a2cf7d
   sigusr1_handler_ran = 1;
a2cf7d
 }
a2cf7d