Received: by 10.223.185.116 with SMTP id b49csp1379990wrg; Wed, 21 Feb 2018 17:59:42 -0800 (PST) X-Google-Smtp-Source: AH8x226w4Zvo14kdGn4i/vGNzLWJ+KHjibcly/CRAk9KOyey9PBsooo9JUOkB2RxTkpeeICUHPp/ X-Received: by 10.99.121.131 with SMTP id u125mr4305611pgc.263.1519264782131; Wed, 21 Feb 2018 17:59:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519264782; cv=none; d=google.com; s=arc-20160816; b=XgyNMubBC2w/FJu+WdPJtatBHVotzLo/fCr/GtERHhxEvdc9GF0P8Dnv47Q4USBNLj N4GkYW6QUGVwdJo3RDg7+wIqVLkrsl6npBqo5dmBNwN8Qs+yOlMKhR90d4r8ZRDzM0YZ pUm0OejnsKHIFjuHcswv84bhDv7gQfISF99ZGPcwHHWQIUvkvvjNfNhjmZFp59BwzhFD po9xyEdZXpyLP8kqUCFhx1oXpuvs/o6Odjmtn+arUKOdSMx4/ZQVdj7FopGg3bitPume 7V0kE0q9vIwajmB2yt2OBHDZdWCcl93UY67KdWUHfm6YDis6hp6+5CxrFAKW5JZMFBZw iQew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=0daHP3bgBhNQCdLx+BzTO0i3LtWh8jC5KL66pBUzkJ4=; b=aof1zr8kwQmC/k6//+/Nrp4xla6lhVJz75jBhXNMRLHGmK2nfevhRoBuEPB5zOv+l3 EbAuoh3g6Z2Vt/wNaUMswNrZRIxPVYflIC6wo/p2SGApZnjOzV7ND4zjS1ObarA8row+ F1rg4QTRZKx7XuxZcmrT1N9CwjusUWlVnQbQMrAncjDXsepwjgSw8gzxC0KZ8o0hV7PS GHpcR0M6dnXM7SRwENx6Bz6qQDoWieOBjz6FPuO4UudJtURE+lmxwpRMuQOGA0+991LF RIOPDhMIQ8ZC1QFMO4t5W+jTRmogIvBatjPcScRfH7USprrR2cq65p9aztg0L5fgQmGJ i1Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=DDPJqtbe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w8si11994721pfk.17.2018.02.21.17.59.27; Wed, 21 Feb 2018 17:59:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=DDPJqtbe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752336AbeBVB6P (ORCPT + 99 others); Wed, 21 Feb 2018 20:58:15 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:39976 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751771AbeBVB50 (ORCPT ); Wed, 21 Feb 2018 20:57:26 -0500 Received: by mail-qk0-f193.google.com with SMTP id n198so4628473qke.7; Wed, 21 Feb 2018 17:57:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=0daHP3bgBhNQCdLx+BzTO0i3LtWh8jC5KL66pBUzkJ4=; b=DDPJqtbeMzmW+ptS6AKh5Rl9xg4L7TV6q1dyKVnOa9YcKUdmIl61ry7+mzEbUK27Bh eblHWjDtZGesFwltoYAMbtioNwYtng0YLInaWt91RHpati3EjxFccjqU5WMw8Pc5R7Kz FfsI+IXp1h5pPji2R12f6jqL1+9a3GlWb4VFoon3/WTLxItkFrO2lMbnfhXfqrj0Vxxm Swhd7mLcK0PZxcl2C1ayV/ycYmBBUvaJcqL1YkXe7yIVJKrI8ClCJ67OXYYfjalAPs74 cNxvQgQmBl0g+g4uyDeDb4vuZLJdYACN84pKxFw3Oc+/Iy5BToICG//0K8X5lS/+ChE8 Llpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=0daHP3bgBhNQCdLx+BzTO0i3LtWh8jC5KL66pBUzkJ4=; b=UXL5LLWPqNWLMgMCIX4NPoclUhw032FK9B4dGc7LjObr97pOPB7D/3KMr/z0TW5CJT /bDlUPK+m3GykBsBcHkClXda/voCumoBPKkbJ2IpSEw0QHmczzRxpTQGmiKHrv9rPy+5 EqlsT629qBlaDB53NKyaxyoG8M08eYeI7hWPuUwXBRDPG3Yne5Q3Vyrs5O2hSMxayd3T AQNhA3gX9RtUge5rV70agSIxvu8ZBpmaa1XdFYp93sSVqUoShRRyr+EITypOwmSnZ8UJ NRSkmqkCtdUSo8bGCgmPuSwPaldrV1RYkt4UKWd7ZhrIn85HBQ4BZjiK12FX/3vssUeP LIIA== X-Gm-Message-State: APf1xPDs037+AhZcm13L/9pLzGVhU/UQVt6LuzMl25QANkKo/tOXSN2i 7zy12YvbCBIpYey2/j/mtPTqjH3E X-Received: by 10.55.113.69 with SMTP id m66mr4097818qkc.84.1519264645402; Wed, 21 Feb 2018 17:57:25 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id n29sm14182630qtf.18.2018.02.21.17.57.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 17:57:25 -0800 (PST) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, akpm@linux-foundation.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com, arnd@arndb.de Subject: [PATCH v12 20/22] selftests/vm: testcases must restore pkey-permissions Date: Wed, 21 Feb 2018 17:55:39 -0800 Message-Id: <1519264541-7621-21-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> References: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Generally the signal handler restores the state of the pkey register before returning. However there are times when the read/write operation can legitamely fail without invoking the signal handler. Eg: A sys_read() operaton to a write-protected page should be disallowed. In such a case the state of the pkey register is not restored to its original state. The test case is responsible for restoring the key register state to its original value. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai --- tools/testing/selftests/vm/protection_keys.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 437ee74..42c068a 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1003,6 +1003,7 @@ void test_read_of_write_disabled_region(int *ptr, u16 pkey) ptr_contents = read_ptr(ptr); dprintf1("*ptr: %d\n", ptr_contents); dprintf1("\n"); + pkey_write_allow(pkey); } void test_read_of_access_disabled_region(int *ptr, u16 pkey) { @@ -1082,6 +1083,7 @@ void test_kernel_write_of_access_disabled_region(int *ptr, u16 pkey) ret = read(test_fd, ptr, 1); dprintf1("read ret: %d\n", ret); pkey_assert(ret); + pkey_access_allow(pkey); } void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) { @@ -1094,6 +1096,7 @@ void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) if (ret < 0 && (DEBUG_LEVEL > 0)) perror("verbose read result (OK for this to be bad)"); pkey_assert(ret); + pkey_write_allow(pkey); } void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) @@ -1113,6 +1116,7 @@ void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) vmsplice_ret = vmsplice(pipe_fds[1], &iov, 1, SPLICE_F_GIFT); dprintf1("vmsplice() ret: %d\n", vmsplice_ret); pkey_assert(vmsplice_ret == -1); + pkey_access_allow(pkey); close(pipe_fds[0]); close(pipe_fds[1]); @@ -1133,6 +1137,7 @@ void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) if (DEBUG_LEVEL > 0) perror("futex"); dprintf1("futex() ret: %d\n", futex_ret); + pkey_write_allow(pkey); } /* Assumes that all pkeys other than 'pkey' are unallocated */ -- 1.7.1