Received: by 10.223.176.46 with SMTP id f43csp3256114wra; Mon, 22 Jan 2018 10:55:16 -0800 (PST) X-Google-Smtp-Source: AH8x224tvfrGv2ArdpLmpCvmPNwTjdqD4O0lQCew39LStRi+XHvgw8bQiL23mIIqQ6iPt0E7tHEU X-Received: by 10.107.78.10 with SMTP id c10mr9638901iob.238.1516647316184; Mon, 22 Jan 2018 10:55:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516647316; cv=none; d=google.com; s=arc-20160816; b=F763zT/IFrGi9ideAgR9TzClfyqhhXlGQu0bPpbdztF2KKNviIiMt2c4/SjGVyWpyY NVLQCI2V3ffzNrqRea2/abaStN+teiwN58W+SnbsjZYWvLq3WdP1evuhlUdvU6XKzlzJ y4Y3jq+DSzFPlzhGGhXkdIb1hyE+LZti6kAhMt9P+KXednCT9UVhp7oOrdrn/sxOxdUg LmdW2EMRkt/DMHpAoF0quybUeY5xC6PYs23dXws+iUUnW+2juOrRPYkDOPWuza1bpaZD jZrQG/ReBvV4fJusUYoJae7Td0sIXlxkCXfBT9MrkB4BdNLnhJxd2wvfRkf2Y6aF8Hzv KfZg== 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=Adk4qI4A8r5SeTcScPcVSNcRK+/lGrTDPHJxHULfwfg=; b=WTgx9r2Hhy6djoe8Vi5VFJXlQf8jK0vlZ8qSrbG5yKDPV9z+puyUed981DaLP8sAaa 9XFw48MbyI9yCB5MRJOBQGYp9AXlzS5ASnqA3T0C4ftCo7ET7NXbJERJsZWQfaJDyKXY 2eQu20iU7oCGQuWUt51GcvLvTDtINp1hzNBCFLGM+OnMyYO5iToYz87YWjt+ocaN/8/R ZJ9NCdatFhopIgema3Sh0atDonOiq0xjwJSA6v0jh8aheYek52ldnRLYSPhdXvg1XZcP /oQDXDi6FP9BvtyKU82fJTixI7B+oXAWG+wlAm2YFgaE1fUP+J3/JG9cVX47Uvj4XjL7 9bKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=spcOl1/Z; 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 f185si6624955ith.3.2018.01.22.10.55.03; Mon, 22 Jan 2018 10:55:16 -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=spcOl1/Z; 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 S1751599AbeAVSxy (ORCPT + 99 others); Mon, 22 Jan 2018 13:53:54 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:41685 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751542AbeAVSxt (ORCPT ); Mon, 22 Jan 2018 13:53:49 -0500 Received: by mail-qt0-f195.google.com with SMTP id i1so23466924qtj.8; Mon, 22 Jan 2018 10:53:48 -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=Adk4qI4A8r5SeTcScPcVSNcRK+/lGrTDPHJxHULfwfg=; b=spcOl1/Z/be4mLIe/ORXuULwsCnlM8curz9Vf6CApQ00eHayGPM/3ZxJ5XZgOBxyKT TCi9Cb64zbadpmlQp+fQwGiLQ73FnAj1YPturjATthYJqrRQ9Y5gR9/gvC/Ee4Qn4UkF 6aGQS3GA+1BPVJzna76bVQB1T8Iyg4Pq7znB85NWWPgf9podERxg6pR39BapKdGsiMUE kkWuBhcYNutM1RgfkMVW+y6vghP1Al0JA4k/iNFA0jYOq2pRCQjNlXPBoSV+JEj8e1Th F5GctAMmxVX15jZrzoKVa7kEfMYL5g07oG2bQcQMDRioaqaL6OjUabjwq84ZCbihIfm6 TeqQ== 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=Adk4qI4A8r5SeTcScPcVSNcRK+/lGrTDPHJxHULfwfg=; b=BEZk7fN+us/4yLbojJcPISBNnhHiIqyaFIuoO2vSdf1yManNntd5sfwAYMR+QCjj7r pWsG9IlZgszBL30JtYLWduICYoCdvSUfuHIuAFJUQT1ztmQr92jcr73p1+ZqT4Zo8DFi 6ViK14muxAMirx8RUJwu9VsvvviaO/BNDqDeoywzevrexUNcGDHsXE6V1rb3VXYU1mej duSrp/usc1ZJrhgDXN4+z6LvmA1MowiVXL+tcDquRNJwdIgVqNceehy9+YrvvktXtjt8 DsGzXp0dq2pIYbrO999pSaqNqQBTU8JYfUxWKFaD1mQ6eQueDxRnre5WGePiC1ORfbEI nANA== X-Gm-Message-State: AKwxyteRtWt0up25NG82sCTuHEPHBnzy7X2C7Cqfpxh5B5ufqcIvIk2s EWTz7BlhTJ8XSAPP4rTPRvk= X-Received: by 10.237.48.225 with SMTP id 88mr12899922qtf.340.1516647228631; Mon, 22 Jan 2018 10:53:48 -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 o20sm10790061qkl.14.2018.01.22.10.53.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 10:53:48 -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 v10 20/24] selftests/vm: testcases must restore pkey-permissions Date: Mon, 22 Jan 2018 10:52:13 -0800 Message-Id: <1516647137-11174-21-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> References: <1516647137-11174-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. 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 3e9e36d..5783587 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