From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751295AbdBWWhA (ORCPT ); Thu, 23 Feb 2017 17:37:00 -0500 Received: from resqmta-po-01v.sys.comcast.net ([96.114.154.160]:57308 "EHLO resqmta-po-01v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751195AbdBWWg6 (ORCPT ); Thu, 23 Feb 2017 17:36:58 -0500 Reply-To: shuah@kernel.org Subject: Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys References: <20170223222603.A022ED65@viggo.jf.intel.com> <20170223222604.D3AE8473@viggo.jf.intel.com> To: Dave Hansen , linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-kselftest@vger.kernel.org, Shuah Khan From: Shuah Khan Message-ID: <806cc744-98a2-7575-30bc-a703b75a9640@kernel.org> Date: Thu, 23 Feb 2017 15:36:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20170223222604.D3AE8473@viggo.jf.intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfNowPJbZkO2a8rcdNGISRKu5ZE1NR2k4AlXcHzjlmE24AazBdKQTEsPfdmnShPzlkgAd8+Xr4W119UTISDMJ45PehBjW38BbfJ0wih6oYHcilS72M7Eq VYa6L9H8+QYckjTSWYn6K7eJWVDsCg6bFDdKSznZqBJ1dIu2GGzkS7G/siqFWAJsCVGY7ei2O5oQHz4qy2tkZaTkDu0zsXNiM4L3u5ENzaTiHvd+2PIWtqi+ 1ZaWOQjFTd9E1HtMQqXKijbG6SkmMAXn+UVxngkj8z8r72N1cpkvamfWfcwcqrIXwCgo3Ncob9hXDDTX5HsXoElqahZpEIfBPFPNZ6Vkowg= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/23/2017 03:26 PM, Dave Hansen wrote: > Shuah, I assume you'll take this patch in through the selftests tree. Yes I can do that. -- Shuah > > -- > From: Dave Hansen > > 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 > ec: Kirill A. Shutemov > Cc: Shuah Khan > 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:21:05.168391529 -0800 > +++ b/tools/testing/selftests/x86/protection_keys.c 2017-02-23 14:23:03.244671815 -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(); > + > + /* 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, > }; > _ > >