Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1587209

[PATCH] [v2] selftests, x86, pkeys: test with random, unallocated protection keys

Path csiph.com!news.mixmin.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod
From Dave Hansen <dave.hansen@linux.intel.com>
Newsgroups linux.kernel
Subject [PATCH] [v2] selftests, x86, pkeys: test with random, unallocated protection keys
Date Fri, 24 Feb 2017 01:30:02 +0100
Message-ID <tebVM-py-3@gated-at.bofh.it> (permalink)
X-Extloop1 1
X-Ironport-Av E=Sophos;i="5.35,199,1484035200"; d="scan'208";a="1134144214"
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 69
Organization linux.* mail to news gateway
X-Original-Cc x86@kernel.org, Dave Hansen <dave.hansen@linux.intel.com>, kirill.shutemov@linux.intel.com, shuah@kernel.org, linux-kselftest@vger.kernel.org
X-Original-Date Thu, 23 Feb 2017 16:23:39 -0800
X-Original-Message-ID <20170224002339.672BEF68@viggo.jf.intel.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1587209

Show key headers only | View raw



Changes from v1:
 * Also generate random negative numbers for protection key

--
From: Dave Hansen <dave.hansen@linux.intel.com>

The kernel pkeys code had a minor bug where it did some large shifts
to an integer which is undefined behavior in C.  It didn't cause any
real harm, but it is screwy behavior that the kernel should have
rejected.

Add a test case for this.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: x86@kernel.org
---

 b/tools/testing/selftests/x86/protection_keys.c |   25 ++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-better-selftests-of-random-pkey tools/testing/selftests/x86/protection_keys.c
--- a/tools/testing/selftests/x86/protection_keys.c~pkeys-better-selftests-of-random-pkey	2017-02-23 14:24:34.323744591 -0800
+++ b/tools/testing/selftests/x86/protection_keys.c	2017-02-23 16:14:06.101005910 -0800
@@ -1123,6 +1123,30 @@ void test_pkey_syscalls_on_non_allocated
 }
 
 /* Assumes that all pkeys other than 'pkey' are unallocated */
+void test_pkey_syscalls_on_non_allocated_random_pkey(int *ptr, u16 pkey)
+{
+	int err;
+	int nr_tests = 0;
+
+	while (nr_tests < 1000) {
+		int test_pkey = rand() - RAND_MAX/2;
+
+		/* do not test with the pkey we know is good */
+		if (pkey == test_pkey)
+			continue;
+
+		dprintf1("trying free/mprotect bad pkey: %2d\n", test_pkey);
+		err = sys_pkey_free(test_pkey);
+		pkey_assert(err);
+
+		err = sys_mprotect_pkey(ptr, PAGE_SIZE, PROT_READ, test_pkey);
+		pkey_assert(err);
+
+		nr_tests++;
+	}
+}
+
+/* Assumes that all pkeys other than 'pkey' are unallocated */
 void test_pkey_syscalls_bad_args(int *ptr, u16 pkey)
 {
 	int err;
@@ -1320,6 +1344,7 @@ void (*pkey_tests[])(int *ptr, u16 pkey)
 	test_executing_on_unreadable_memory,
 	test_ptrace_of_child,
 	test_pkey_syscalls_on_non_allocated_pkey,
+	test_pkey_syscalls_on_non_allocated_random_pkey,
 	test_pkey_syscalls_bad_args,
 	test_pkey_alloc_exhaust,
 };
_

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] [v2] selftests, x86, pkeys: test with random, unallocated protection keys Dave Hansen <dave.hansen@linux.intel.com> - 2017-02-24 01:30 +0100
  Re: [PATCH] [v2] selftests, x86, pkeys: test with random,  unallocated protection keys "Kirill A. Shutemov" <kirill@shutemov.name> - 2017-02-24 14:40 +0100

csiph-web