Skip to content

Commit 2dd0e5d

Browse files
hansendcgregkh
authored andcommitted
x86/pkeys/selftests: Fix pkey exhaustion test off-by-one
[ Upstream commit f50b487 ] In our "exhaust all pkeys" test, we make sure that there is the expected number available. Turns out that the test did not cover the execute-only key, but discussed it anyway. It did *not* discuss the test-allocated key. Now that we have a test for the mprotect(PROT_EXEC) case, this off-by-one issue showed itself. Correct the off-by- one and add the explanation for the case we missed. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Michael Ellermen <mpe@ellerman.id.au> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ram Pai <linuxram@us.ibm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180509171350.E1656B95@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 63bdea7 commit 2dd0e5d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎tools/testing/selftests/x86/protection_keys.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,12 +1163,15 @@ void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
11631163
pkey_assert(i < NR_PKEYS*2);
11641164

11651165
/*
1166-
* There are 16 pkeys supported in hardware. One is taken
1167-
* up for the default (0) and another can be taken up by
1168-
* an execute-only mapping. Ensure that we can allocate
1169-
* at least 14 (16-2).
1166+
* There are 16 pkeys supported in hardware. Three are
1167+
* allocated by the time we get here:
1168+
* 1. The default key (0)
1169+
* 2. One possibly consumed by an execute-only mapping.
1170+
* 3. One allocated by the test code and passed in via
1171+
* 'pkey' to this function.
1172+
* Ensure that we can allocate at least another 13 (16-3).
11701173
*/
1171-
pkey_assert(i >= NR_PKEYS-2);
1174+
pkey_assert(i >= NR_PKEYS-3);
11721175

11731176
for (i = 0; i < nr_allocated_pkeys; i++) {
11741177
err = sys_pkey_free(allocated_pkeys[i]);

0 commit comments

Comments
 (0)