Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1587148 > unrolled thread
| Started by | Dave Hansen <dave.hansen@linux.intel.com> |
|---|---|
| First post | 2017-02-23 23:30 +0100 |
| Last post | 2017-02-24 01:20 +0100 |
| Articles | 6 — 4 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys Dave Hansen <dave.hansen@linux.intel.com> - 2017-02-23 23:30 +0100
Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys Shuah Khan <shuah@kernel.org> - 2017-02-23 23:40 +0100
Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys Ingo Molnar <mingo@kernel.org> - 2017-02-24 08:50 +0100
Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys Shuah Khan <shuah@kernel.org> - 2017-02-24 16:00 +0100
Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys Ingo Molnar <mingo@kernel.org> - 2017-02-25 10:20 +0100
Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys "Kirill A. Shutemov" <kirill@shutemov.name> - 2017-02-24 01:20 +0100
| From | Dave Hansen <dave.hansen@linux.intel.com> |
|---|---|
| Date | 2017-02-23 23:30 +0100 |
| Subject | [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys |
| Message-ID | <tea3E-7vC-7@gated-at.bofh.it> |
Shuah, I assume you'll take this patch in through the selftests tree.
--
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>
ec: 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: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,
};
_
[toc] | [next] | [standalone]
| From | Shuah Khan <shuah@kernel.org> |
|---|---|
| Date | 2017-02-23 23:40 +0100 |
| Subject | Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys |
| Message-ID | <teadj-7yI-7@gated-at.bofh.it> |
| In reply to | #1587148 |
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 <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>
> ec: 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: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,
> };
> _
>
>
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2017-02-24 08:50 +0100 |
| Subject | Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys |
| Message-ID | <teiNz-5pl-13@gated-at.bofh.it> |
| In reply to | #1587153 |
* Shuah Khan <shuah@kernel.org> wrote: > 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. No, let's not do that please, we have a fix and a self-tests update, I'd like them to be next in the Git space. I'll apply the testcase too when applying the pkeys fix, ok? Thanks, Ingo
[toc] | [prev] | [next] | [standalone]
| From | Shuah Khan <shuah@kernel.org> |
|---|---|
| Date | 2017-02-24 16:00 +0100 |
| Subject | Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys |
| Message-ID | <tepvH-1C7-9@gated-at.bofh.it> |
| In reply to | #1587326 |
On 02/24/2017 12:45 AM, Ingo Molnar wrote: > > * Shuah Khan <shuah@kernel.org> wrote: > >> 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. > > No, let's not do that please, we have a fix and a self-tests update, I'd like them > to be next in the Git space. > > I'll apply the testcase too when applying the pkeys fix, ok? > > Thanks, > > Ingo > > Yup. I noticed the first patch has to go through x86 tree, Sounds good to me. Please take both through. I am sending pull request for 4.11-rc1 today. I have a few pkeys patches in there. Hope there won't be any conflicts. thanks, -- Shuah
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2017-02-25 10:20 +0100 |
| Subject | Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys |
| Message-ID | <teGGd-5Fx-7@gated-at.bofh.it> |
| In reply to | #1587700 |
* Shuah Khan <shuah@kernel.org> wrote: > On 02/24/2017 12:45 AM, Ingo Molnar wrote: > > > > * Shuah Khan <shuah@kernel.org> wrote: > > > >> 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. > > > > No, let's not do that please, we have a fix and a self-tests update, I'd like them > > to be next in the Git space. > > > > I'll apply the testcase too when applying the pkeys fix, ok? > > > > Thanks, > > > > Ingo > > > > > > > Yup. I noticed the first patch has to go through x86 tree, Sounds good > to me. Please take both through. I am sending pull request for 4.11-rc1 > today. I have a few pkeys patches in there. Hope there won't be any > conflicts. Ok, I'll wait for your changes to hit upstream, to not create unnecessary conflicts. Thanks, Ingo
[toc] | [prev] | [next] | [standalone]
| From | "Kirill A. Shutemov" <kirill@shutemov.name> |
|---|---|
| Date | 2017-02-24 01:20 +0100 |
| Subject | Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys |
| Message-ID | <tebM6-lC-15@gated-at.bofh.it> |
| In reply to | #1587148 |
On Thu, Feb 23, 2017 at 02:26:04PM -0800, Dave Hansen wrote:
>
>
> Shuah, I assume you'll take this patch in through the selftests tree.
>
> --
> 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>
> ec: 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: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();
rand(3) doesn't generate negative numbers. Would be good to cover this
case too.
int test_pkey = rand() - RAND_MAX/2;
?
Otherwise looks good to me.
--
Kirill A. Shutemov
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web