LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
hpa@zytor.com, x86@kernel.org, peterz@infradead.org,
mpe@ellerman.id.au, will.deacon@arm.com, luto@kernel.org,
jroedel@suse.de
Subject: [PATCH 2/2] x86/selftests/pkeys: fork() to check for state being preserved
Date: Fri, 26 Oct 2018 12:51:47 -0700 [thread overview]
Message-ID: <20181026195147.78D4C275@viggo.jf.intel.com> (raw)
In-Reply-To: <20181026195146.9C7C1136@viggo.jf.intel.com>
From: Dave Hansen <dave.hansen@linux.intel.com>
There was a bug where the per-mm pkey state was not being preserved
across fork() in the child. fork() is performed in the pkey
selftests, but all of our pkey activity is performed in the parent.
The child does not perform any actions sensitive to pkey state.
To make the test more sensitive to these kinds of bugs, add a
fork() where we let the parent exit, and continue execution in
the child.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Joerg Roedel <jroedel@suse.de>
---
b/tools/testing/selftests/x86/protection_keys.c | 30 ++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff -puN tools/testing/selftests/x86/protection_keys.c~x86-pkeys-no-init-at-fork-selftests tools/testing/selftests/x86/protection_keys.c
--- a/tools/testing/selftests/x86/protection_keys.c~x86-pkeys-no-init-at-fork-selftests 2018-10-26 09:26:51.970102217 -0700
+++ b/tools/testing/selftests/x86/protection_keys.c 2018-10-26 09:26:51.974102217 -0700
@@ -1133,6 +1133,21 @@ void test_pkey_syscalls_bad_args(int *pt
pkey_assert(err);
}
+void become_child(void)
+{
+ pid_t forkret;
+
+ forkret = fork();
+ pkey_assert(forkret >= 0);
+ dprintf3("[%d] fork() ret: %d\n", getpid(), forkret);
+
+ if (!forkret) {
+ /* in the child */
+ return;
+ }
+ exit(0);
+}
+
/* Assumes that all pkeys other than 'pkey' are unallocated */
void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
{
@@ -1141,7 +1156,7 @@ void test_pkey_alloc_exhaust(int *ptr, u
int nr_allocated_pkeys = 0;
int i;
- for (i = 0; i < NR_PKEYS*2; i++) {
+ for (i = 0; i < NR_PKEYS*3; i++) {
int new_pkey;
dprintf1("%s() alloc loop: %d\n", __func__, i);
new_pkey = alloc_pkey();
@@ -1152,10 +1167,17 @@ void test_pkey_alloc_exhaust(int *ptr, u
if ((new_pkey == -1) && (errno == ENOSPC)) {
dprintf2("%s() failed to allocate pkey after %d tries\n",
__func__, nr_allocated_pkeys);
- break;
+ } else {
+ pkey_assert(nr_allocated_pkeys < NR_PKEYS);
+ allocated_pkeys[nr_allocated_pkeys++] = new_pkey;
}
- pkey_assert(nr_allocated_pkeys < NR_PKEYS);
- allocated_pkeys[nr_allocated_pkeys++] = new_pkey;
+
+ /*
+ * Make sure that allocation state is properly
+ * preserved across fork().
+ */
+ if (i == NR_PKEYS*2)
+ become_child();
}
dprintf3("%s()::%d\n", __func__, __LINE__);
_
next prev parent reply other threads:[~2018-10-26 19:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-26 19:51 [PATCH 1/2] x86/pkeys: copy pkey state at fork() Dave Hansen
2018-10-26 19:51 ` Dave Hansen [this message]
2018-10-26 19:59 ` Dave Hansen
2018-10-26 21:39 ` Daniel Micay
2018-10-26 22:12 ` Andy Lutomirski
2018-10-26 22:56 ` Daniel Micay
2018-10-29 6:36 ` Ingo Molnar
2018-10-29 8:55 ` Daniel Micay
2018-11-20 21:14 ` Kees Cook
2019-01-09 0:56 ` Kees Cook
2019-01-02 21:56 [PATCH 0/2] x86/mm/pkeys: fix user-visible pkey state destruction " Dave Hansen
2019-01-02 21:56 ` [PATCH 2/2] x86/selftests/pkeys: fork() to check for state being preserved Dave Hansen
[not found] ` <20190103135225.4929F217D9@mail.kernel.org>
2019-01-03 18:57 ` Dave Hansen
2019-01-10 19:16 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181026195147.78D4C275@viggo.jf.intel.com \
--to=dave.hansen@linux.intel.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jroedel@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
--cc=x86@kernel.org \
--subject='Re: [PATCH 2/2] x86/selftests/pkeys: fork() to check for state being preserved' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).