From patchwork Mon Feb 17 12:09:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucas A. M. Magalhaes" X-Patchwork-Id: 38124 X-Patchwork-Delegate: fweimer@redhat.com Received: (qmail 107702 invoked by alias); 17 Feb 2020 12:10:01 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 107679 invoked by uid 89); 17 Feb 2020 12:10:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=approaches, HContent-Transfer-Encoding:8bit X-HELO: mx0a-001b2d01.pphosted.com From: "Lucas A. M. Magalhaes" To: libc-alpha@sourceware.org Cc: fweimer@redhat.com Subject: [PATCH v4] Fix tst-pkey expectations on pkey_get [BZ #23202] Date: Mon, 17 Feb 2020 09:09:52 -0300 Message-Id: <20200217120952.5219-1-lamm@linux.ibm.com> In-Reply-To: <871rqwyoxl.fsf@oldenburg2.str.redhat.com> References: <871rqwyoxl.fsf@oldenburg2.str.redhat.com> MIME-Version: 1.0 From the GNU C Library manual the pkey_set can receive a combination of PKEY_DISABLE_WRITE and PKEY_DISABLE_ACCESS. However PKEY_DISABLE_ACCESS is more restrictive than PKEY_DISABLE_WRITE and includes its behavior. The test expects that after setting (PKEY_DISABLE_WRITE|PKEY_DISABLE_ACCESS) pkey_get should return the same. This may not be true as PKEY_DISABLE_ACCESS will succeed in describe the state of the key in this case. The pkey behavior during signal handling is different between x86 and POWER. This change make the test compatible with both architectures. --- Hi, in V4: - Fix comments. in V3: - Commit message changes. - Add comments. in V2: - Fix signal handling expectations to accept x86 and POWER behavior. sysdeps/unix/sysv/linux/tst-pkey.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sysdeps/unix/sysv/linux/tst-pkey.c b/sysdeps/unix/sysv/linux/tst-pkey.c index 4ea1bc4f9a..cba40c73de 100644 --- a/sysdeps/unix/sysv/linux/tst-pkey.c +++ b/sysdeps/unix/sysv/linux/tst-pkey.c @@ -37,7 +37,7 @@ static pthread_barrier_t barrier; /* The keys used for testing. These have been allocated with access rights set based on their array index. */ -enum { key_count = 4 }; +enum { key_count = 3 }; static int keys[key_count]; static volatile int *pages[key_count]; @@ -111,14 +111,16 @@ check_page_access (int page, bool write) } static volatile sig_atomic_t sigusr1_handler_ran; - -/* Used to check that access is revoked in signal handlers. */ +/* Used to check the behavior in signal handlers. In x86 all access are + revoked during signal handling. In PowerPC the key permissions are + inherited by the interrupted thread. This test accept both approaches. */ static void sigusr1_handler (int signum) { TEST_COMPARE (signum, SIGUSR1); for (int i = 0; i < key_count; ++i) - TEST_COMPARE (pkey_get (keys[i]), PKEY_DISABLE_ACCESS); + TEST_VERIFY (pkey_get (keys[i]) == PKEY_DISABLE_ACCESS + || pkey_get (keys[i]) == i); sigusr1_handler_ran = 1; }