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