License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-07-30 00:30:24 +08:00
|
|
|
/*
|
2020-06-23 15:09:05 +08:00
|
|
|
* Tests Memory Protection Keys (see Documentation/core-api/protection-keys.rst)
|
2016-07-30 00:30:24 +08:00
|
|
|
*
|
|
|
|
* There are examples in here of:
|
|
|
|
* * how to set protection keys on memory
|
2020-06-05 07:51:37 +08:00
|
|
|
* * how to set/clear bits in pkey registers (the rights register)
|
|
|
|
* * how to handle SEGV_PKUERR signals and extract pkey-relevant
|
2016-07-30 00:30:24 +08:00
|
|
|
* information from the siginfo
|
|
|
|
*
|
|
|
|
* Things to add:
|
|
|
|
* make sure KSM and KSM COW breaking works
|
|
|
|
* prefault pages in at malloc, or not
|
|
|
|
* protect MPX bounds tables with protection keys?
|
|
|
|
* make sure VMA splitting/merging is working correctly
|
|
|
|
* OOMs can destroy mm->mmap (see exit_mmap()), so make sure it is immune to pkeys
|
|
|
|
* look for pkey "leaks" where it is still set on a VMA but "freed" back to the kernel
|
|
|
|
* do a plain mprotect() to a mprotect_pkey() area and make sure the pkey sticks
|
|
|
|
*
|
|
|
|
* Compile like this:
|
|
|
|
* gcc -o protection_keys -O2 -g -std=gnu99 -pthread -Wall protection_keys.c -lrt -ldl -lm
|
|
|
|
* gcc -m32 -o protection_keys_32 -O2 -g -std=gnu99 -pthread -Wall protection_keys.c -lrt -ldl -lm
|
|
|
|
*/
|
|
|
|
#define _GNU_SOURCE
|
2020-06-05 07:51:51 +08:00
|
|
|
#define __SANE_USERSPACE_TYPES__
|
2016-07-30 00:30:24 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <linux/futex.h>
|
2020-06-05 07:52:05 +08:00
|
|
|
#include <time.h>
|
2016-07-30 00:30:24 +08:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ucontext.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/ptrace.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
#include "pkey-helpers.h"
|
|
|
|
|
|
|
|
int iteration_nr = 1;
|
|
|
|
int test_nr;
|
|
|
|
|
2020-06-05 07:51:51 +08:00
|
|
|
u64 shadow_pkey_reg;
|
2016-07-30 00:30:24 +08:00
|
|
|
int dprint_in_signal;
|
|
|
|
char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE];
|
|
|
|
|
|
|
|
void cat_into_file(char *str, char *file)
|
|
|
|
{
|
|
|
|
int fd = open(file, O_RDWR);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dprintf2("%s(): writing '%s' to '%s'\n", __func__, str, file);
|
|
|
|
/*
|
|
|
|
* these need to be raw because they are called under
|
|
|
|
* pkey_assert()
|
|
|
|
*/
|
2018-05-10 01:13:40 +08:00
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "error opening '%s'\n", str);
|
|
|
|
perror("error: ");
|
|
|
|
exit(__LINE__);
|
|
|
|
}
|
|
|
|
|
2016-07-30 00:30:24 +08:00
|
|
|
ret = write(fd, str, strlen(str));
|
|
|
|
if (ret != strlen(str)) {
|
|
|
|
perror("write to file failed");
|
|
|
|
fprintf(stderr, "filename: '%s' str: '%s'\n", file, str);
|
2018-05-10 01:13:40 +08:00
|
|
|
exit(__LINE__);
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CONTROL_TRACING > 0
|
|
|
|
static int warned_tracing;
|
|
|
|
int tracing_root_ok(void)
|
|
|
|
{
|
|
|
|
if (geteuid() != 0) {
|
|
|
|
if (!warned_tracing)
|
|
|
|
fprintf(stderr, "WARNING: not run as root, "
|
|
|
|
"can not do tracing control\n");
|
|
|
|
warned_tracing = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void tracing_on(void)
|
|
|
|
{
|
|
|
|
#if CONTROL_TRACING > 0
|
|
|
|
#define TRACEDIR "/sys/kernel/debug/tracing"
|
|
|
|
char pidstr[32];
|
|
|
|
|
|
|
|
if (!tracing_root_ok())
|
|
|
|
return;
|
|
|
|
|
|
|
|
sprintf(pidstr, "%d", getpid());
|
|
|
|
cat_into_file("0", TRACEDIR "/tracing_on");
|
|
|
|
cat_into_file("\n", TRACEDIR "/trace");
|
|
|
|
if (1) {
|
|
|
|
cat_into_file("function_graph", TRACEDIR "/current_tracer");
|
|
|
|
cat_into_file("1", TRACEDIR "/options/funcgraph-proc");
|
|
|
|
} else {
|
|
|
|
cat_into_file("nop", TRACEDIR "/current_tracer");
|
|
|
|
}
|
|
|
|
cat_into_file(pidstr, TRACEDIR "/set_ftrace_pid");
|
|
|
|
cat_into_file("1", TRACEDIR "/tracing_on");
|
|
|
|
dprintf1("enabled tracing\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void tracing_off(void)
|
|
|
|
{
|
|
|
|
#if CONTROL_TRACING > 0
|
|
|
|
if (!tracing_root_ok())
|
|
|
|
return;
|
|
|
|
cat_into_file("0", "/sys/kernel/debug/tracing/tracing_on");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void abort_hooks(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "running %s()...\n", __func__);
|
|
|
|
tracing_off();
|
|
|
|
#ifdef SLEEP_ON_ABORT
|
|
|
|
sleep(SLEEP_ON_ABORT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This attempts to have roughly a page of instructions followed by a few
|
|
|
|
* instructions that do a write, and another page of instructions. That
|
|
|
|
* way, we are pretty sure that the write is in the second page of
|
|
|
|
* instructions and has at least a page of padding behind it.
|
|
|
|
*
|
|
|
|
* *That* lets us be sure to madvise() away the write instruction, which
|
|
|
|
* will then fault, which makes sure that the fault code handles
|
|
|
|
* execute-only memory properly.
|
|
|
|
*/
|
2020-06-05 07:52:50 +08:00
|
|
|
#ifdef __powerpc64__
|
|
|
|
/* This way, both 4K and 64K alignment are maintained */
|
|
|
|
__attribute__((__aligned__(65536)))
|
|
|
|
#else
|
2016-07-30 00:30:24 +08:00
|
|
|
__attribute__((__aligned__(PAGE_SIZE)))
|
2020-06-05 07:52:50 +08:00
|
|
|
#endif
|
2016-07-30 00:30:24 +08:00
|
|
|
void lots_o_noops_around_write(int *write_to_me)
|
|
|
|
{
|
|
|
|
dprintf3("running %s()\n", __func__);
|
|
|
|
__page_o_noops();
|
|
|
|
/* Assume this happens in the second page of instructions: */
|
|
|
|
*write_to_me = __LINE__;
|
|
|
|
/* pad out by another page: */
|
|
|
|
__page_o_noops();
|
|
|
|
dprintf3("%s() done\n", __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_mem(void *dumpme, int len_bytes)
|
|
|
|
{
|
|
|
|
char *c = (void *)dumpme;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len_bytes; i += sizeof(u64)) {
|
|
|
|
u64 *ptr = (u64 *)(c + i);
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("dump[%03d][@%p]: %016llx\n", i, ptr, *ptr);
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:52:15 +08:00
|
|
|
static u32 hw_pkey_get(int pkey, unsigned long flags)
|
|
|
|
{
|
|
|
|
u64 pkey_reg = __read_pkey_reg();
|
|
|
|
|
|
|
|
dprintf1("%s(pkey=%d, flags=%lx) = %x / %d\n",
|
|
|
|
__func__, pkey, flags, 0, 0);
|
|
|
|
dprintf2("%s() raw pkey_reg: %016llx\n", __func__, pkey_reg);
|
|
|
|
|
|
|
|
return (u32) get_pkey_bits(pkey_reg, pkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hw_pkey_set(int pkey, unsigned long rights, unsigned long flags)
|
|
|
|
{
|
|
|
|
u32 mask = (PKEY_DISABLE_ACCESS|PKEY_DISABLE_WRITE);
|
|
|
|
u64 old_pkey_reg = __read_pkey_reg();
|
|
|
|
u64 new_pkey_reg;
|
|
|
|
|
|
|
|
/* make sure that 'rights' only contains the bits we expect: */
|
|
|
|
assert(!(rights & ~mask));
|
|
|
|
|
|
|
|
/* modify bits accordingly in old pkey_reg and assign it */
|
|
|
|
new_pkey_reg = set_pkey_bits(old_pkey_reg, pkey, rights);
|
|
|
|
|
|
|
|
__write_pkey_reg(new_pkey_reg);
|
|
|
|
|
|
|
|
dprintf3("%s(pkey=%d, rights=%lx, flags=%lx) = %x"
|
|
|
|
" pkey_reg now: %016llx old_pkey_reg: %016llx\n",
|
|
|
|
__func__, pkey, rights, flags, 0, __read_pkey_reg(),
|
|
|
|
old_pkey_reg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pkey_disable_set(int pkey, int flags)
|
|
|
|
{
|
|
|
|
unsigned long syscall_flags = 0;
|
|
|
|
int ret;
|
|
|
|
int pkey_rights;
|
|
|
|
u64 orig_pkey_reg = read_pkey_reg();
|
|
|
|
|
|
|
|
dprintf1("START->%s(%d, 0x%x)\n", __func__,
|
|
|
|
pkey, flags);
|
|
|
|
pkey_assert(flags & (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));
|
|
|
|
|
|
|
|
pkey_rights = hw_pkey_get(pkey, syscall_flags);
|
|
|
|
|
|
|
|
dprintf1("%s(%d) hw_pkey_get(%d): %x\n", __func__,
|
|
|
|
pkey, pkey, pkey_rights);
|
|
|
|
|
|
|
|
pkey_assert(pkey_rights >= 0);
|
|
|
|
|
|
|
|
pkey_rights |= flags;
|
|
|
|
|
|
|
|
ret = hw_pkey_set(pkey, pkey_rights, syscall_flags);
|
|
|
|
assert(!ret);
|
|
|
|
/* pkey_reg and flags have the same format */
|
|
|
|
shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, pkey, pkey_rights);
|
|
|
|
dprintf1("%s(%d) shadow: 0x%016llx\n",
|
|
|
|
__func__, pkey, shadow_pkey_reg);
|
|
|
|
|
|
|
|
pkey_assert(ret >= 0);
|
|
|
|
|
|
|
|
pkey_rights = hw_pkey_get(pkey, syscall_flags);
|
|
|
|
dprintf1("%s(%d) hw_pkey_get(%d): %x\n", __func__,
|
|
|
|
pkey, pkey, pkey_rights);
|
|
|
|
|
|
|
|
dprintf1("%s(%d) pkey_reg: 0x%016llx\n",
|
|
|
|
__func__, pkey, read_pkey_reg());
|
|
|
|
if (flags)
|
|
|
|
pkey_assert(read_pkey_reg() >= orig_pkey_reg);
|
|
|
|
dprintf1("END<---%s(%d, 0x%x)\n", __func__,
|
|
|
|
pkey, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pkey_disable_clear(int pkey, int flags)
|
|
|
|
{
|
|
|
|
unsigned long syscall_flags = 0;
|
|
|
|
int ret;
|
|
|
|
int pkey_rights = hw_pkey_get(pkey, syscall_flags);
|
|
|
|
u64 orig_pkey_reg = read_pkey_reg();
|
|
|
|
|
|
|
|
pkey_assert(flags & (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));
|
|
|
|
|
|
|
|
dprintf1("%s(%d) hw_pkey_get(%d): %x\n", __func__,
|
|
|
|
pkey, pkey, pkey_rights);
|
|
|
|
pkey_assert(pkey_rights >= 0);
|
|
|
|
|
|
|
|
pkey_rights &= ~flags;
|
|
|
|
|
|
|
|
ret = hw_pkey_set(pkey, pkey_rights, 0);
|
|
|
|
shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, pkey, pkey_rights);
|
|
|
|
pkey_assert(ret >= 0);
|
|
|
|
|
|
|
|
pkey_rights = hw_pkey_get(pkey, syscall_flags);
|
|
|
|
dprintf1("%s(%d) hw_pkey_get(%d): %x\n", __func__,
|
|
|
|
pkey, pkey, pkey_rights);
|
|
|
|
|
|
|
|
dprintf1("%s(%d) pkey_reg: 0x%016llx\n", __func__,
|
|
|
|
pkey, read_pkey_reg());
|
|
|
|
if (flags)
|
|
|
|
assert(read_pkey_reg() <= orig_pkey_reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pkey_write_allow(int pkey)
|
|
|
|
{
|
|
|
|
pkey_disable_clear(pkey, PKEY_DISABLE_WRITE);
|
|
|
|
}
|
|
|
|
void pkey_write_deny(int pkey)
|
|
|
|
{
|
|
|
|
pkey_disable_set(pkey, PKEY_DISABLE_WRITE);
|
|
|
|
}
|
|
|
|
void pkey_access_allow(int pkey)
|
|
|
|
{
|
|
|
|
pkey_disable_clear(pkey, PKEY_DISABLE_ACCESS);
|
|
|
|
}
|
|
|
|
void pkey_access_deny(int pkey)
|
|
|
|
{
|
|
|
|
pkey_disable_set(pkey, PKEY_DISABLE_ACCESS);
|
|
|
|
}
|
|
|
|
|
2018-05-14 16:56:23 +08:00
|
|
|
/* Failed address bound checks: */
|
|
|
|
#ifndef SEGV_BNDERR
|
|
|
|
# define SEGV_BNDERR 3
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SEGV_PKUERR
|
|
|
|
# define SEGV_PKUERR 4
|
|
|
|
#endif
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
static char *si_code_str(int si_code)
|
|
|
|
{
|
2017-06-27 05:36:57 +08:00
|
|
|
if (si_code == SEGV_MAPERR)
|
2016-07-30 00:30:24 +08:00
|
|
|
return "SEGV_MAPERR";
|
2017-06-27 05:36:57 +08:00
|
|
|
if (si_code == SEGV_ACCERR)
|
2016-07-30 00:30:24 +08:00
|
|
|
return "SEGV_ACCERR";
|
2017-06-27 05:36:57 +08:00
|
|
|
if (si_code == SEGV_BNDERR)
|
2016-07-30 00:30:24 +08:00
|
|
|
return "SEGV_BNDERR";
|
2017-06-27 05:36:57 +08:00
|
|
|
if (si_code == SEGV_PKUERR)
|
2016-07-30 00:30:24 +08:00
|
|
|
return "SEGV_PKUERR";
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:51:37 +08:00
|
|
|
int pkey_faults;
|
2016-07-30 00:30:24 +08:00
|
|
|
int last_si_pkey = -1;
|
|
|
|
void signal_handler(int signum, siginfo_t *si, void *vucontext)
|
|
|
|
{
|
|
|
|
ucontext_t *uctxt = vucontext;
|
|
|
|
int trapno;
|
|
|
|
unsigned long ip;
|
|
|
|
char *fpregs;
|
2020-06-05 07:52:15 +08:00
|
|
|
#if defined(__i386__) || defined(__x86_64__) /* arch */
|
2020-06-05 07:51:37 +08:00
|
|
|
u32 *pkey_reg_ptr;
|
2020-06-05 07:52:15 +08:00
|
|
|
int pkey_reg_offset;
|
|
|
|
#endif /* arch */
|
2017-11-11 08:12:31 +08:00
|
|
|
u64 siginfo_pkey;
|
2016-07-30 00:30:24 +08:00
|
|
|
u32 *si_pkey_ptr;
|
|
|
|
|
|
|
|
dprint_in_signal = 1;
|
|
|
|
dprintf1(">>>>===============SIGSEGV============================\n");
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("%s()::%d, pkey_reg: 0x%016llx shadow: %016llx\n",
|
|
|
|
__func__, __LINE__,
|
2020-06-05 07:51:37 +08:00
|
|
|
__read_pkey_reg(), shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
trapno = uctxt->uc_mcontext.gregs[REG_TRAPNO];
|
|
|
|
ip = uctxt->uc_mcontext.gregs[REG_IP_IDX];
|
2020-06-05 07:52:15 +08:00
|
|
|
fpregs = (char *) uctxt->uc_mcontext.fpregs;
|
2016-07-30 00:30:24 +08:00
|
|
|
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf2("%s() trapno: %d ip: 0x%016lx info->si_code: %s/%d\n",
|
|
|
|
__func__, trapno, ip, si_code_str(si->si_code),
|
|
|
|
si->si_code);
|
2020-06-05 07:52:15 +08:00
|
|
|
|
|
|
|
#if defined(__i386__) || defined(__x86_64__) /* arch */
|
2016-07-30 00:30:24 +08:00
|
|
|
#ifdef __i386__
|
|
|
|
/*
|
|
|
|
* 32-bit has some extra padding so that userspace can tell whether
|
|
|
|
* the XSTATE header is present in addition to the "legacy" FPU
|
|
|
|
* state. We just assume that it is here.
|
|
|
|
*/
|
|
|
|
fpregs += 0x70;
|
2020-06-05 07:52:15 +08:00
|
|
|
#endif /* i386 */
|
2020-06-05 07:51:37 +08:00
|
|
|
pkey_reg_offset = pkey_reg_xstate_offset();
|
|
|
|
pkey_reg_ptr = (void *)(&fpregs[pkey_reg_offset]);
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
/*
|
2020-06-05 07:51:37 +08:00
|
|
|
* If we got a PKEY fault, we *HAVE* to have at least one bit set in
|
2016-07-30 00:30:24 +08:00
|
|
|
* here.
|
|
|
|
*/
|
2020-06-05 07:51:37 +08:00
|
|
|
dprintf1("pkey_reg_xstate_offset: %d\n", pkey_reg_xstate_offset());
|
2016-07-30 00:30:24 +08:00
|
|
|
if (DEBUG_LEVEL > 4)
|
2020-06-05 07:51:37 +08:00
|
|
|
dump_mem(pkey_reg_ptr - 128, 256);
|
|
|
|
pkey_assert(*pkey_reg_ptr);
|
2020-06-05 07:52:15 +08:00
|
|
|
#endif /* arch */
|
|
|
|
|
|
|
|
dprintf1("siginfo: %p\n", si);
|
|
|
|
dprintf1(" fpregs: %p\n", fpregs);
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
if ((si->si_code == SEGV_MAPERR) ||
|
|
|
|
(si->si_code == SEGV_ACCERR) ||
|
|
|
|
(si->si_code == SEGV_BNDERR)) {
|
|
|
|
printf("non-PK si_code, exiting...\n");
|
|
|
|
exit(4);
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:52:15 +08:00
|
|
|
si_pkey_ptr = siginfo_get_pkey_ptr(si);
|
2018-05-10 01:13:52 +08:00
|
|
|
dprintf1("si_pkey_ptr: %p\n", si_pkey_ptr);
|
|
|
|
dump_mem((u8 *)si_pkey_ptr - 8, 24);
|
|
|
|
siginfo_pkey = *si_pkey_ptr;
|
|
|
|
pkey_assert(siginfo_pkey < NR_PKEYS);
|
|
|
|
last_si_pkey = siginfo_pkey;
|
|
|
|
|
2020-06-05 07:51:37 +08:00
|
|
|
/*
|
|
|
|
* need __read_pkey_reg() version so we do not do shadow_pkey_reg
|
|
|
|
* checking
|
|
|
|
*/
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("signal pkey_reg from pkey_reg: %016llx\n",
|
|
|
|
__read_pkey_reg());
|
|
|
|
dprintf1("pkey from siginfo: %016llx\n", siginfo_pkey);
|
2020-06-05 07:52:15 +08:00
|
|
|
#if defined(__i386__) || defined(__x86_64__) /* arch */
|
|
|
|
dprintf1("signal pkey_reg from xsave: %08x\n", *pkey_reg_ptr);
|
2020-06-05 07:51:37 +08:00
|
|
|
*(u64 *)pkey_reg_ptr = 0x00000000;
|
|
|
|
dprintf1("WARNING: set PKEY_REG=0 to allow faulting instruction to continue\n");
|
2020-06-05 07:52:15 +08:00
|
|
|
#elif defined(__powerpc64__) /* arch */
|
|
|
|
/* restore access and let the faulting instruction continue */
|
|
|
|
pkey_access_allow(siginfo_pkey);
|
|
|
|
#endif /* arch */
|
2020-06-05 07:51:37 +08:00
|
|
|
pkey_faults++;
|
2016-07-30 00:30:24 +08:00
|
|
|
dprintf1("<<<<==================================================\n");
|
|
|
|
dprint_in_signal = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wait_all_children(void)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
return waitpid(-1, &status, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sig_chld(int x)
|
|
|
|
{
|
|
|
|
dprint_in_signal = 1;
|
|
|
|
dprintf2("[%d] SIGCHLD: %d\n", getpid(), x);
|
|
|
|
dprint_in_signal = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_sigsegv_handler(void)
|
|
|
|
{
|
|
|
|
int r, rs;
|
|
|
|
struct sigaction newact;
|
|
|
|
struct sigaction oldact;
|
|
|
|
|
|
|
|
/* #PF is mapped to sigsegv */
|
|
|
|
int signum = SIGSEGV;
|
|
|
|
|
|
|
|
newact.sa_handler = 0;
|
|
|
|
newact.sa_sigaction = signal_handler;
|
|
|
|
|
|
|
|
/*sigset_t - signals to block while in the handler */
|
|
|
|
/* get the old signal mask. */
|
|
|
|
rs = sigprocmask(SIG_SETMASK, 0, &newact.sa_mask);
|
|
|
|
pkey_assert(rs == 0);
|
|
|
|
|
|
|
|
/* call sa_sigaction, not sa_handler*/
|
|
|
|
newact.sa_flags = SA_SIGINFO;
|
|
|
|
|
|
|
|
newact.sa_restorer = 0; /* void(*)(), obsolete */
|
|
|
|
r = sigaction(signum, &newact, &oldact);
|
|
|
|
r = sigaction(SIGALRM, &newact, &oldact);
|
|
|
|
pkey_assert(r == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_handlers(void)
|
|
|
|
{
|
|
|
|
signal(SIGCHLD, &sig_chld);
|
|
|
|
setup_sigsegv_handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
pid_t fork_lazy_child(void)
|
|
|
|
{
|
|
|
|
pid_t forkret;
|
|
|
|
|
|
|
|
forkret = fork();
|
|
|
|
pkey_assert(forkret >= 0);
|
|
|
|
dprintf3("[%d] fork() ret: %d\n", getpid(), forkret);
|
|
|
|
|
|
|
|
if (!forkret) {
|
|
|
|
/* in the child */
|
|
|
|
while (1) {
|
|
|
|
dprintf1("child sleeping...\n");
|
|
|
|
sleep(30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return forkret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
|
|
|
|
unsigned long pkey)
|
|
|
|
{
|
|
|
|
int sret;
|
|
|
|
|
|
|
|
dprintf2("%s(0x%p, %zx, prot=%lx, pkey=%lx)\n", __func__,
|
|
|
|
ptr, size, orig_prot, pkey);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
sret = syscall(SYS_mprotect_key, ptr, size, orig_prot, pkey);
|
|
|
|
if (errno) {
|
|
|
|
dprintf2("SYS_mprotect_key sret: %d\n", sret);
|
|
|
|
dprintf2("SYS_mprotect_key prot: 0x%lx\n", orig_prot);
|
|
|
|
dprintf2("SYS_mprotect_key failed, errno: %d\n", errno);
|
|
|
|
if (DEBUG_LEVEL >= 2)
|
|
|
|
perror("SYS_mprotect_pkey");
|
|
|
|
}
|
|
|
|
return sret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_pkey_alloc(unsigned long flags, unsigned long init_val)
|
|
|
|
{
|
|
|
|
int ret = syscall(SYS_pkey_alloc, flags, init_val);
|
|
|
|
dprintf1("%s(flags=%lx, init_val=%lx) syscall ret: %d errno: %d\n",
|
|
|
|
__func__, flags, init_val, ret, errno);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int alloc_pkey(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long init_val = 0x0;
|
|
|
|
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("%s()::%d, pkey_reg: 0x%016llx shadow: %016llx\n",
|
|
|
|
__func__, __LINE__, __read_pkey_reg(), shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
ret = sys_pkey_alloc(0, init_val);
|
|
|
|
/*
|
2020-06-05 07:51:37 +08:00
|
|
|
* pkey_alloc() sets PKEY register, so we need to reflect it in
|
|
|
|
* shadow_pkey_reg:
|
2016-07-30 00:30:24 +08:00
|
|
|
*/
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n",
|
2020-06-05 07:51:37 +08:00
|
|
|
__func__, __LINE__, ret, __read_pkey_reg(),
|
|
|
|
shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
if (ret) {
|
|
|
|
/* clear both the bits: */
|
2020-06-05 07:51:54 +08:00
|
|
|
shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, ret,
|
|
|
|
~PKEY_MASK);
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n",
|
2020-06-05 07:51:37 +08:00
|
|
|
__func__,
|
|
|
|
__LINE__, ret, __read_pkey_reg(),
|
|
|
|
shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
/*
|
|
|
|
* move the new state in from init_val
|
2020-06-05 07:51:37 +08:00
|
|
|
* (remember, we cheated and init_val == pkey_reg format)
|
2016-07-30 00:30:24 +08:00
|
|
|
*/
|
2020-06-05 07:51:54 +08:00
|
|
|
shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, ret,
|
|
|
|
init_val);
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n",
|
2020-06-05 07:51:37 +08:00
|
|
|
__func__, __LINE__, ret, __read_pkey_reg(),
|
|
|
|
shadow_pkey_reg);
|
|
|
|
dprintf1("%s()::%d errno: %d\n", __func__, __LINE__, errno);
|
2016-07-30 00:30:24 +08:00
|
|
|
/* for shadow checking: */
|
2020-06-05 07:51:37 +08:00
|
|
|
read_pkey_reg();
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n",
|
2020-06-05 07:51:37 +08:00
|
|
|
__func__, __LINE__, ret, __read_pkey_reg(),
|
|
|
|
shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_pkey_free(unsigned long pkey)
|
|
|
|
{
|
|
|
|
int ret = syscall(SYS_pkey_free, pkey);
|
|
|
|
dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I had a bug where pkey bits could be set by mprotect() but
|
|
|
|
* not cleared. This ensures we get lots of random bit sets
|
|
|
|
* and clears on the vma and pte pkey bits.
|
|
|
|
*/
|
|
|
|
int alloc_random_pkey(void)
|
|
|
|
{
|
|
|
|
int max_nr_pkey_allocs;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
int alloced_pkeys[NR_PKEYS];
|
|
|
|
int nr_alloced = 0;
|
|
|
|
int random_index;
|
|
|
|
memset(alloced_pkeys, 0, sizeof(alloced_pkeys));
|
2020-06-05 07:52:05 +08:00
|
|
|
srand((unsigned int)time(NULL));
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
/* allocate every possible key and make a note of which ones we got */
|
|
|
|
max_nr_pkey_allocs = NR_PKEYS;
|
|
|
|
for (i = 0; i < max_nr_pkey_allocs; i++) {
|
|
|
|
int new_pkey = alloc_pkey();
|
|
|
|
if (new_pkey < 0)
|
|
|
|
break;
|
|
|
|
alloced_pkeys[nr_alloced++] = new_pkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkey_assert(nr_alloced > 0);
|
|
|
|
/* select a random one out of the allocated ones */
|
|
|
|
random_index = rand() % nr_alloced;
|
|
|
|
ret = alloced_pkeys[random_index];
|
|
|
|
/* now zero it out so we don't free it next */
|
|
|
|
alloced_pkeys[random_index] = 0;
|
|
|
|
|
|
|
|
/* go through the allocated ones that we did not want and free them */
|
|
|
|
for (i = 0; i < nr_alloced; i++) {
|
|
|
|
int free_ret;
|
|
|
|
if (!alloced_pkeys[i])
|
|
|
|
continue;
|
|
|
|
free_ret = sys_pkey_free(alloced_pkeys[i]);
|
|
|
|
pkey_assert(!free_ret);
|
|
|
|
}
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("%s()::%d, ret: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n", __func__,
|
2020-06-05 07:51:37 +08:00
|
|
|
__LINE__, ret, __read_pkey_reg(), shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
|
|
|
|
unsigned long pkey)
|
|
|
|
{
|
|
|
|
int nr_iterations = random() % 100;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
while (0) {
|
|
|
|
int rpkey = alloc_random_pkey();
|
|
|
|
ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey);
|
|
|
|
dprintf1("sys_mprotect_pkey(%p, %zx, prot=0x%lx, pkey=%ld) ret: %d\n",
|
|
|
|
ptr, size, orig_prot, pkey, ret);
|
|
|
|
if (nr_iterations-- < 0)
|
|
|
|
break;
|
|
|
|
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("%s()::%d, ret: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n",
|
2020-06-05 07:51:37 +08:00
|
|
|
__func__, __LINE__, ret, __read_pkey_reg(),
|
|
|
|
shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
sys_pkey_free(rpkey);
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("%s()::%d, ret: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n",
|
2020-06-05 07:51:37 +08:00
|
|
|
__func__, __LINE__, ret, __read_pkey_reg(),
|
|
|
|
shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
|
|
|
pkey_assert(pkey < NR_PKEYS);
|
|
|
|
|
|
|
|
ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey);
|
|
|
|
dprintf1("mprotect_pkey(%p, %zx, prot=0x%lx, pkey=%ld) ret: %d\n",
|
|
|
|
ptr, size, orig_prot, pkey, ret);
|
|
|
|
pkey_assert(!ret);
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("%s()::%d, ret: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n", __func__,
|
2020-06-05 07:51:37 +08:00
|
|
|
__LINE__, ret, __read_pkey_reg(), shadow_pkey_reg);
|
2016-07-30 00:30:24 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pkey_malloc_record {
|
|
|
|
void *ptr;
|
|
|
|
long size;
|
2018-05-10 01:13:54 +08:00
|
|
|
int prot;
|
2016-07-30 00:30:24 +08:00
|
|
|
};
|
|
|
|
struct pkey_malloc_record *pkey_malloc_records;
|
2018-05-10 01:13:54 +08:00
|
|
|
struct pkey_malloc_record *pkey_last_malloc_record;
|
2016-07-30 00:30:24 +08:00
|
|
|
long nr_pkey_malloc_records;
|
2018-05-10 01:13:54 +08:00
|
|
|
void record_pkey_malloc(void *ptr, long size, int prot)
|
2016-07-30 00:30:24 +08:00
|
|
|
{
|
|
|
|
long i;
|
|
|
|
struct pkey_malloc_record *rec = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_pkey_malloc_records; i++) {
|
|
|
|
rec = &pkey_malloc_records[i];
|
|
|
|
/* find a free record */
|
|
|
|
if (rec)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!rec) {
|
|
|
|
/* every record is full */
|
|
|
|
size_t old_nr_records = nr_pkey_malloc_records;
|
|
|
|
size_t new_nr_records = (nr_pkey_malloc_records * 2 + 1);
|
|
|
|
size_t new_size = new_nr_records * sizeof(struct pkey_malloc_record);
|
|
|
|
dprintf2("new_nr_records: %zd\n", new_nr_records);
|
|
|
|
dprintf2("new_size: %zd\n", new_size);
|
|
|
|
pkey_malloc_records = realloc(pkey_malloc_records, new_size);
|
|
|
|
pkey_assert(pkey_malloc_records != NULL);
|
|
|
|
rec = &pkey_malloc_records[nr_pkey_malloc_records];
|
|
|
|
/*
|
|
|
|
* realloc() does not initialize memory, so zero it from
|
|
|
|
* the first new record all the way to the end.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < new_nr_records - old_nr_records; i++)
|
|
|
|
memset(rec + i, 0, sizeof(*rec));
|
|
|
|
}
|
|
|
|
dprintf3("filling malloc record[%d/%p]: {%p, %ld}\n",
|
|
|
|
(int)(rec - pkey_malloc_records), rec, ptr, size);
|
|
|
|
rec->ptr = ptr;
|
|
|
|
rec->size = size;
|
2018-05-10 01:13:54 +08:00
|
|
|
rec->prot = prot;
|
|
|
|
pkey_last_malloc_record = rec;
|
2016-07-30 00:30:24 +08:00
|
|
|
nr_pkey_malloc_records++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_pkey_malloc(void *ptr)
|
|
|
|
{
|
|
|
|
long i;
|
|
|
|
int ret;
|
|
|
|
dprintf3("%s(%p)\n", __func__, ptr);
|
|
|
|
for (i = 0; i < nr_pkey_malloc_records; i++) {
|
|
|
|
struct pkey_malloc_record *rec = &pkey_malloc_records[i];
|
|
|
|
dprintf4("looking for ptr %p at record[%ld/%p]: {%p, %ld}\n",
|
|
|
|
ptr, i, rec, rec->ptr, rec->size);
|
|
|
|
if ((ptr < rec->ptr) ||
|
|
|
|
(ptr >= rec->ptr + rec->size))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dprintf3("found ptr %p at record[%ld/%p]: {%p, %ld}\n",
|
|
|
|
ptr, i, rec, rec->ptr, rec->size);
|
|
|
|
nr_pkey_malloc_records--;
|
|
|
|
ret = munmap(rec->ptr, rec->size);
|
|
|
|
dprintf3("munmap ret: %d\n", ret);
|
|
|
|
pkey_assert(!ret);
|
|
|
|
dprintf3("clearing rec->ptr, rec: %p\n", rec);
|
|
|
|
rec->ptr = NULL;
|
|
|
|
dprintf3("done clearing rec->ptr, rec: %p\n", rec);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pkey_assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *malloc_pkey_with_mprotect(long size, int prot, u16 pkey)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
int ret;
|
|
|
|
|
2020-06-05 07:51:37 +08:00
|
|
|
read_pkey_reg();
|
2016-07-30 00:30:24 +08:00
|
|
|
dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__,
|
|
|
|
size, prot, pkey);
|
|
|
|
pkey_assert(pkey < NR_PKEYS);
|
|
|
|
ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
|
|
|
pkey_assert(ptr != (void *)-1);
|
|
|
|
ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey);
|
|
|
|
pkey_assert(!ret);
|
2018-05-10 01:13:54 +08:00
|
|
|
record_pkey_malloc(ptr, size, prot);
|
2020-06-05 07:51:37 +08:00
|
|
|
read_pkey_reg();
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *malloc_pkey_anon_huge(long size, int prot, u16 pkey)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__,
|
|
|
|
size, prot, pkey);
|
|
|
|
/*
|
|
|
|
* Guarantee we can fit at least one huge page in the resulting
|
|
|
|
* allocation by allocating space for 2:
|
|
|
|
*/
|
|
|
|
size = ALIGN_UP(size, HPAGE_SIZE * 2);
|
|
|
|
ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
|
|
|
pkey_assert(ptr != (void *)-1);
|
2018-05-10 01:13:54 +08:00
|
|
|
record_pkey_malloc(ptr, size, prot);
|
2016-07-30 00:30:24 +08:00
|
|
|
mprotect_pkey(ptr, size, prot, pkey);
|
|
|
|
|
|
|
|
dprintf1("unaligned ptr: %p\n", ptr);
|
|
|
|
ptr = ALIGN_PTR_UP(ptr, HPAGE_SIZE);
|
|
|
|
dprintf1(" aligned ptr: %p\n", ptr);
|
|
|
|
ret = madvise(ptr, HPAGE_SIZE, MADV_HUGEPAGE);
|
|
|
|
dprintf1("MADV_HUGEPAGE ret: %d\n", ret);
|
|
|
|
ret = madvise(ptr, HPAGE_SIZE, MADV_WILLNEED);
|
|
|
|
dprintf1("MADV_WILLNEED ret: %d\n", ret);
|
|
|
|
memset(ptr, 0, HPAGE_SIZE);
|
|
|
|
|
|
|
|
dprintf1("mmap()'d thp for pkey %d @ %p\n", pkey, ptr);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hugetlb_setup_ok;
|
2020-06-05 07:52:08 +08:00
|
|
|
#define SYSFS_FMT_NR_HUGE_PAGES "/sys/kernel/mm/hugepages/hugepages-%ldkB/nr_hugepages"
|
2016-07-30 00:30:24 +08:00
|
|
|
#define GET_NR_HUGE_PAGES 10
|
|
|
|
void setup_hugetlbfs(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int fd;
|
2020-06-05 07:52:08 +08:00
|
|
|
char buf[256];
|
|
|
|
long hpagesz_kb;
|
|
|
|
long hpagesz_mb;
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
if (geteuid() != 0) {
|
|
|
|
fprintf(stderr, "WARNING: not run as root, can not do hugetlb test\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cat_into_file(__stringify(GET_NR_HUGE_PAGES), "/proc/sys/vm/nr_hugepages");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now go make sure that we got the pages and that they
|
2020-06-05 07:52:08 +08:00
|
|
|
* are PMD-level pages. Someone might have made PUD-level
|
|
|
|
* pages the default.
|
2016-07-30 00:30:24 +08:00
|
|
|
*/
|
2020-06-05 07:52:08 +08:00
|
|
|
hpagesz_kb = HPAGE_SIZE / 1024;
|
|
|
|
hpagesz_mb = hpagesz_kb / 1024;
|
|
|
|
sprintf(buf, SYSFS_FMT_NR_HUGE_PAGES, hpagesz_kb);
|
|
|
|
fd = open(buf, O_RDONLY);
|
2016-07-30 00:30:24 +08:00
|
|
|
if (fd < 0) {
|
2020-06-05 07:52:08 +08:00
|
|
|
fprintf(stderr, "opening sysfs %ldM hugetlb config: %s\n",
|
|
|
|
hpagesz_mb, strerror(errno));
|
2016-07-30 00:30:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -1 to guarantee leaving the trailing \0 */
|
|
|
|
err = read(fd, buf, sizeof(buf)-1);
|
|
|
|
close(fd);
|
|
|
|
if (err <= 0) {
|
2020-06-05 07:52:08 +08:00
|
|
|
fprintf(stderr, "reading sysfs %ldM hugetlb config: %s\n",
|
|
|
|
hpagesz_mb, strerror(errno));
|
2016-07-30 00:30:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atoi(buf) != GET_NR_HUGE_PAGES) {
|
2020-06-05 07:52:08 +08:00
|
|
|
fprintf(stderr, "could not confirm %ldM pages, got: '%s' expected %d\n",
|
|
|
|
hpagesz_mb, buf, GET_NR_HUGE_PAGES);
|
2016-07-30 00:30:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hugetlb_setup_ok = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *malloc_pkey_hugetlb(long size, int prot, u16 pkey)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
int flags = MAP_ANONYMOUS|MAP_PRIVATE|MAP_HUGETLB;
|
|
|
|
|
|
|
|
if (!hugetlb_setup_ok)
|
|
|
|
return PTR_ERR_ENOTSUP;
|
|
|
|
|
|
|
|
dprintf1("doing %s(%ld, %x, %x)\n", __func__, size, prot, pkey);
|
|
|
|
size = ALIGN_UP(size, HPAGE_SIZE * 2);
|
|
|
|
pkey_assert(pkey < NR_PKEYS);
|
|
|
|
ptr = mmap(NULL, size, PROT_NONE, flags, -1, 0);
|
|
|
|
pkey_assert(ptr != (void *)-1);
|
|
|
|
mprotect_pkey(ptr, size, prot, pkey);
|
|
|
|
|
2018-05-10 01:13:54 +08:00
|
|
|
record_pkey_malloc(ptr, size, prot);
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *malloc_pkey_mmap_dax(long size, int prot, u16 pkey)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__,
|
|
|
|
size, prot, pkey);
|
|
|
|
pkey_assert(pkey < NR_PKEYS);
|
|
|
|
fd = open("/dax/foo", O_RDWR);
|
|
|
|
pkey_assert(fd >= 0);
|
|
|
|
|
|
|
|
ptr = mmap(0, size, prot, MAP_SHARED, fd, 0);
|
|
|
|
pkey_assert(ptr != (void *)-1);
|
|
|
|
|
|
|
|
mprotect_pkey(ptr, size, prot, pkey);
|
|
|
|
|
2018-05-10 01:13:54 +08:00
|
|
|
record_pkey_malloc(ptr, size, prot);
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
dprintf1("mmap()'d for pkey %d @ %p\n", pkey, ptr);
|
|
|
|
close(fd);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *(*pkey_malloc[])(long size, int prot, u16 pkey) = {
|
|
|
|
|
|
|
|
malloc_pkey_with_mprotect,
|
2020-06-05 07:52:39 +08:00
|
|
|
malloc_pkey_with_mprotect_subpage,
|
2016-07-30 00:30:24 +08:00
|
|
|
malloc_pkey_anon_huge,
|
|
|
|
malloc_pkey_hugetlb
|
|
|
|
/* can not do direct with the pkey_mprotect() API:
|
|
|
|
malloc_pkey_mmap_direct,
|
|
|
|
malloc_pkey_mmap_dax,
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
void *malloc_pkey(long size, int prot, u16 pkey)
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
static int malloc_type;
|
|
|
|
int nr_malloc_types = ARRAY_SIZE(pkey_malloc);
|
|
|
|
|
|
|
|
pkey_assert(pkey < NR_PKEYS);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
pkey_assert(malloc_type < nr_malloc_types);
|
|
|
|
|
|
|
|
ret = pkey_malloc[malloc_type](size, prot, pkey);
|
|
|
|
pkey_assert(ret != (void *)-1);
|
|
|
|
|
|
|
|
malloc_type++;
|
|
|
|
if (malloc_type >= nr_malloc_types)
|
|
|
|
malloc_type = (random()%nr_malloc_types);
|
|
|
|
|
|
|
|
/* try again if the malloc_type we tried is unsupported */
|
|
|
|
if (ret == PTR_ERR_ENOTSUP)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintf3("%s(%ld, prot=%x, pkey=%x) returning: %p\n", __func__,
|
|
|
|
size, prot, pkey, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:51:37 +08:00
|
|
|
int last_pkey_faults;
|
2018-05-10 01:13:46 +08:00
|
|
|
#define UNKNOWN_PKEY -2
|
2020-06-05 07:51:37 +08:00
|
|
|
void expected_pkey_fault(int pkey)
|
2016-07-30 00:30:24 +08:00
|
|
|
{
|
2020-06-05 07:51:37 +08:00
|
|
|
dprintf2("%s(): last_pkey_faults: %d pkey_faults: %d\n",
|
|
|
|
__func__, last_pkey_faults, pkey_faults);
|
2016-07-30 00:30:24 +08:00
|
|
|
dprintf2("%s(%d): last_si_pkey: %d\n", __func__, pkey, last_si_pkey);
|
2020-06-05 07:51:37 +08:00
|
|
|
pkey_assert(last_pkey_faults + 1 == pkey_faults);
|
2018-05-10 01:13:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For exec-only memory, we do not know the pkey in
|
|
|
|
* advance, so skip this check.
|
|
|
|
*/
|
|
|
|
if (pkey != UNKNOWN_PKEY)
|
|
|
|
pkey_assert(last_si_pkey == pkey);
|
|
|
|
|
2020-06-05 07:52:15 +08:00
|
|
|
#if defined(__i386__) || defined(__x86_64__) /* arch */
|
2016-07-30 00:30:24 +08:00
|
|
|
/*
|
2020-06-05 07:51:37 +08:00
|
|
|
* The signal handler shold have cleared out PKEY register to let the
|
2016-07-30 00:30:24 +08:00
|
|
|
* test program continue. We now have to restore it.
|
|
|
|
*/
|
2020-06-05 07:51:37 +08:00
|
|
|
if (__read_pkey_reg() != 0)
|
2020-06-05 07:52:15 +08:00
|
|
|
#else /* arch */
|
|
|
|
if (__read_pkey_reg() != shadow_pkey_reg)
|
|
|
|
#endif /* arch */
|
2016-07-30 00:30:24 +08:00
|
|
|
pkey_assert(0);
|
|
|
|
|
2020-06-05 07:51:37 +08:00
|
|
|
__write_pkey_reg(shadow_pkey_reg);
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf1("%s() set pkey_reg=%016llx to restore state after signal "
|
2020-06-05 07:51:37 +08:00
|
|
|
"nuked it\n", __func__, shadow_pkey_reg);
|
|
|
|
last_pkey_faults = pkey_faults;
|
2016-07-30 00:30:24 +08:00
|
|
|
last_si_pkey = -1;
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:51:37 +08:00
|
|
|
#define do_not_expect_pkey_fault(msg) do { \
|
|
|
|
if (last_pkey_faults != pkey_faults) \
|
|
|
|
dprintf0("unexpected PKey fault: %s\n", msg); \
|
|
|
|
pkey_assert(last_pkey_faults == pkey_faults); \
|
2018-05-10 01:13:38 +08:00
|
|
|
} while (0)
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
int test_fds[10] = { -1 };
|
|
|
|
int nr_test_fds;
|
|
|
|
void __save_test_fd(int fd)
|
|
|
|
{
|
|
|
|
pkey_assert(fd >= 0);
|
|
|
|
pkey_assert(nr_test_fds < ARRAY_SIZE(test_fds));
|
|
|
|
test_fds[nr_test_fds] = fd;
|
|
|
|
nr_test_fds++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_test_read_fd(void)
|
|
|
|
{
|
|
|
|
int test_fd = open("/etc/passwd", O_RDONLY);
|
|
|
|
__save_test_fd(test_fd);
|
|
|
|
return test_fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void close_test_fds(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_test_fds; i++) {
|
|
|
|
if (test_fds[i] < 0)
|
|
|
|
continue;
|
|
|
|
close(test_fds[i]);
|
|
|
|
test_fds[i] = -1;
|
|
|
|
}
|
|
|
|
nr_test_fds = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define barrier() __asm__ __volatile__("": : :"memory")
|
|
|
|
__attribute__((noinline)) int read_ptr(int *ptr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Keep GCC from optimizing this away somehow
|
|
|
|
*/
|
|
|
|
barrier();
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:52:43 +08:00
|
|
|
void test_pkey_alloc_free_attach_pkey0(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int i, err;
|
|
|
|
int max_nr_pkey_allocs;
|
|
|
|
int alloced_pkeys[NR_PKEYS];
|
|
|
|
int nr_alloced = 0;
|
|
|
|
long size;
|
|
|
|
|
|
|
|
pkey_assert(pkey_last_malloc_record);
|
|
|
|
size = pkey_last_malloc_record->size;
|
|
|
|
/*
|
|
|
|
* This is a bit of a hack. But mprotect() requires
|
|
|
|
* huge-page-aligned sizes when operating on hugetlbfs.
|
|
|
|
* So, make sure that we use something that's a multiple
|
|
|
|
* of a huge page when we can.
|
|
|
|
*/
|
|
|
|
if (size >= HPAGE_SIZE)
|
|
|
|
size = HPAGE_SIZE;
|
|
|
|
|
|
|
|
/* allocate every possible key and make sure key-0 never got allocated */
|
|
|
|
max_nr_pkey_allocs = NR_PKEYS;
|
|
|
|
for (i = 0; i < max_nr_pkey_allocs; i++) {
|
|
|
|
int new_pkey = alloc_pkey();
|
|
|
|
pkey_assert(new_pkey != 0);
|
|
|
|
|
|
|
|
if (new_pkey < 0)
|
|
|
|
break;
|
|
|
|
alloced_pkeys[nr_alloced++] = new_pkey;
|
|
|
|
}
|
|
|
|
/* free all the allocated keys */
|
|
|
|
for (i = 0; i < nr_alloced; i++) {
|
|
|
|
int free_ret;
|
|
|
|
|
|
|
|
if (!alloced_pkeys[i])
|
|
|
|
continue;
|
|
|
|
free_ret = sys_pkey_free(alloced_pkeys[i]);
|
|
|
|
pkey_assert(!free_ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attach key-0 in various modes */
|
|
|
|
err = sys_mprotect_pkey(ptr, size, PROT_READ, 0);
|
|
|
|
pkey_assert(!err);
|
|
|
|
err = sys_mprotect_pkey(ptr, size, PROT_WRITE, 0);
|
|
|
|
pkey_assert(!err);
|
|
|
|
err = sys_mprotect_pkey(ptr, size, PROT_EXEC, 0);
|
|
|
|
pkey_assert(!err);
|
|
|
|
err = sys_mprotect_pkey(ptr, size, PROT_READ|PROT_WRITE, 0);
|
|
|
|
pkey_assert(!err);
|
|
|
|
err = sys_mprotect_pkey(ptr, size, PROT_READ|PROT_WRITE|PROT_EXEC, 0);
|
|
|
|
pkey_assert(!err);
|
|
|
|
}
|
|
|
|
|
2016-07-30 00:30:24 +08:00
|
|
|
void test_read_of_write_disabled_region(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int ptr_contents;
|
|
|
|
|
|
|
|
dprintf1("disabling write access to PKEY[1], doing read\n");
|
|
|
|
pkey_write_deny(pkey);
|
|
|
|
ptr_contents = read_ptr(ptr);
|
|
|
|
dprintf1("*ptr: %d\n", ptr_contents);
|
|
|
|
dprintf1("\n");
|
|
|
|
}
|
|
|
|
void test_read_of_access_disabled_region(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int ptr_contents;
|
|
|
|
|
|
|
|
dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", pkey, ptr);
|
2020-06-05 07:51:37 +08:00
|
|
|
read_pkey_reg();
|
2016-07-30 00:30:24 +08:00
|
|
|
pkey_access_deny(pkey);
|
|
|
|
ptr_contents = read_ptr(ptr);
|
|
|
|
dprintf1("*ptr: %d\n", ptr_contents);
|
2020-06-05 07:51:37 +08:00
|
|
|
expected_pkey_fault(pkey);
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
2020-06-05 07:52:29 +08:00
|
|
|
|
|
|
|
void test_read_of_access_disabled_region_with_page_already_mapped(int *ptr,
|
|
|
|
u16 pkey)
|
|
|
|
{
|
|
|
|
int ptr_contents;
|
|
|
|
|
|
|
|
dprintf1("disabling access to PKEY[%02d], doing read @ %p\n",
|
|
|
|
pkey, ptr);
|
|
|
|
ptr_contents = read_ptr(ptr);
|
|
|
|
dprintf1("reading ptr before disabling the read : %d\n",
|
|
|
|
ptr_contents);
|
|
|
|
read_pkey_reg();
|
|
|
|
pkey_access_deny(pkey);
|
|
|
|
ptr_contents = read_ptr(ptr);
|
|
|
|
dprintf1("*ptr: %d\n", ptr_contents);
|
|
|
|
expected_pkey_fault(pkey);
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:52:32 +08:00
|
|
|
void test_write_of_write_disabled_region_with_page_already_mapped(int *ptr,
|
|
|
|
u16 pkey)
|
|
|
|
{
|
|
|
|
*ptr = __LINE__;
|
|
|
|
dprintf1("disabling write access; after accessing the page, "
|
|
|
|
"to PKEY[%02d], doing write\n", pkey);
|
|
|
|
pkey_write_deny(pkey);
|
|
|
|
*ptr = __LINE__;
|
|
|
|
expected_pkey_fault(pkey);
|
|
|
|
}
|
|
|
|
|
2016-07-30 00:30:24 +08:00
|
|
|
void test_write_of_write_disabled_region(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
dprintf1("disabling write access to PKEY[%02d], doing write\n", pkey);
|
|
|
|
pkey_write_deny(pkey);
|
|
|
|
*ptr = __LINE__;
|
2020-06-05 07:51:37 +08:00
|
|
|
expected_pkey_fault(pkey);
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
|
|
|
void test_write_of_access_disabled_region(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
dprintf1("disabling access to PKEY[%02d], doing write\n", pkey);
|
|
|
|
pkey_access_deny(pkey);
|
|
|
|
*ptr = __LINE__;
|
2020-06-05 07:51:37 +08:00
|
|
|
expected_pkey_fault(pkey);
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
2020-06-05 07:52:36 +08:00
|
|
|
|
|
|
|
void test_write_of_access_disabled_region_with_page_already_mapped(int *ptr,
|
|
|
|
u16 pkey)
|
|
|
|
{
|
|
|
|
*ptr = __LINE__;
|
|
|
|
dprintf1("disabling access; after accessing the page, "
|
|
|
|
" to PKEY[%02d], doing write\n", pkey);
|
|
|
|
pkey_access_deny(pkey);
|
|
|
|
*ptr = __LINE__;
|
|
|
|
expected_pkey_fault(pkey);
|
|
|
|
}
|
|
|
|
|
2016-07-30 00:30:24 +08:00
|
|
|
void test_kernel_write_of_access_disabled_region(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int test_fd = get_test_read_fd();
|
|
|
|
|
|
|
|
dprintf1("disabling access to PKEY[%02d], "
|
|
|
|
"having kernel read() to buffer\n", pkey);
|
|
|
|
pkey_access_deny(pkey);
|
|
|
|
ret = read(test_fd, ptr, 1);
|
|
|
|
dprintf1("read ret: %d\n", ret);
|
|
|
|
pkey_assert(ret);
|
|
|
|
}
|
|
|
|
void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int test_fd = get_test_read_fd();
|
|
|
|
|
|
|
|
pkey_write_deny(pkey);
|
|
|
|
ret = read(test_fd, ptr, 100);
|
|
|
|
dprintf1("read ret: %d\n", ret);
|
|
|
|
if (ret < 0 && (DEBUG_LEVEL > 0))
|
|
|
|
perror("verbose read result (OK for this to be bad)");
|
|
|
|
pkey_assert(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int pipe_ret, vmsplice_ret;
|
|
|
|
struct iovec iov;
|
|
|
|
int pipe_fds[2];
|
|
|
|
|
|
|
|
pipe_ret = pipe(pipe_fds);
|
|
|
|
|
|
|
|
pkey_assert(pipe_ret == 0);
|
|
|
|
dprintf1("disabling access to PKEY[%02d], "
|
|
|
|
"having kernel vmsplice from buffer\n", pkey);
|
|
|
|
pkey_access_deny(pkey);
|
|
|
|
iov.iov_base = ptr;
|
|
|
|
iov.iov_len = PAGE_SIZE;
|
|
|
|
vmsplice_ret = vmsplice(pipe_fds[1], &iov, 1, SPLICE_F_GIFT);
|
|
|
|
dprintf1("vmsplice() ret: %d\n", vmsplice_ret);
|
|
|
|
pkey_assert(vmsplice_ret == -1);
|
|
|
|
|
|
|
|
close(pipe_fds[0]);
|
|
|
|
close(pipe_fds[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int ignored = 0xdada;
|
|
|
|
int futex_ret;
|
|
|
|
int some_int = __LINE__;
|
|
|
|
|
|
|
|
dprintf1("disabling write to PKEY[%02d], "
|
|
|
|
"doing futex gunk in buffer\n", pkey);
|
|
|
|
*ptr = some_int;
|
|
|
|
pkey_write_deny(pkey);
|
|
|
|
futex_ret = syscall(SYS_futex, ptr, FUTEX_WAIT, some_int-1, NULL,
|
|
|
|
&ignored, ignored);
|
|
|
|
if (DEBUG_LEVEL > 0)
|
|
|
|
perror("futex");
|
|
|
|
dprintf1("futex() ret: %d\n", futex_ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assumes that all pkeys other than 'pkey' are unallocated */
|
|
|
|
void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Note: 0 is the default pkey, so don't mess with it */
|
|
|
|
for (i = 1; i < NR_PKEYS; i++) {
|
|
|
|
if (pkey == i)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dprintf1("trying get/set/free to non-allocated pkey: %2d\n", i);
|
|
|
|
err = sys_pkey_free(i);
|
|
|
|
pkey_assert(err);
|
|
|
|
|
|
|
|
err = sys_pkey_free(i);
|
|
|
|
pkey_assert(err);
|
|
|
|
|
|
|
|
err = sys_mprotect_pkey(ptr, PAGE_SIZE, PROT_READ, i);
|
|
|
|
pkey_assert(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assumes that all pkeys other than 'pkey' are unallocated */
|
|
|
|
void test_pkey_syscalls_bad_args(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int bad_pkey = NR_PKEYS+99;
|
|
|
|
|
|
|
|
/* pass a known-invalid pkey in: */
|
|
|
|
err = sys_mprotect_pkey(ptr, PAGE_SIZE, PROT_READ, bad_pkey);
|
|
|
|
pkey_assert(err);
|
|
|
|
}
|
|
|
|
|
2019-01-03 05:56:57 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-07-30 00:30:24 +08:00
|
|
|
/* Assumes that all pkeys other than 'pkey' are unallocated */
|
|
|
|
void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int allocated_pkeys[NR_PKEYS] = {0};
|
|
|
|
int nr_allocated_pkeys = 0;
|
|
|
|
int i;
|
|
|
|
|
2019-01-03 05:56:57 +08:00
|
|
|
for (i = 0; i < NR_PKEYS*3; i++) {
|
2016-07-30 00:30:24 +08:00
|
|
|
int new_pkey;
|
|
|
|
dprintf1("%s() alloc loop: %d\n", __func__, i);
|
|
|
|
new_pkey = alloc_pkey();
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf4("%s()::%d, err: %d pkey_reg: 0x%016llx"
|
|
|
|
" shadow: 0x%016llx\n",
|
2020-06-05 07:51:37 +08:00
|
|
|
__func__, __LINE__, err, __read_pkey_reg(),
|
|
|
|
shadow_pkey_reg);
|
|
|
|
read_pkey_reg(); /* for shadow checking */
|
2016-07-30 00:30:24 +08:00
|
|
|
dprintf2("%s() errno: %d ENOSPC: %d\n", __func__, errno, ENOSPC);
|
|
|
|
if ((new_pkey == -1) && (errno == ENOSPC)) {
|
|
|
|
dprintf2("%s() failed to allocate pkey after %d tries\n",
|
|
|
|
__func__, nr_allocated_pkeys);
|
2019-01-03 05:56:57 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Ensure the number of successes never
|
|
|
|
* exceeds the number of keys supported
|
|
|
|
* in the hardware.
|
|
|
|
*/
|
|
|
|
pkey_assert(nr_allocated_pkeys < NR_PKEYS);
|
|
|
|
allocated_pkeys[nr_allocated_pkeys++] = new_pkey;
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
2019-01-03 05:56:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that allocation state is properly
|
|
|
|
* preserved across fork().
|
|
|
|
*/
|
|
|
|
if (i == NR_PKEYS*2)
|
|
|
|
become_child();
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dprintf3("%s()::%d\n", __func__, __LINE__);
|
|
|
|
|
|
|
|
/*
|
2020-06-05 07:52:22 +08:00
|
|
|
* On x86:
|
2018-05-10 01:13:50 +08:00
|
|
|
* There are 16 pkeys supported in hardware. Three are
|
|
|
|
* allocated by the time we get here:
|
|
|
|
* 1. The default key (0)
|
|
|
|
* 2. One possibly consumed by an execute-only mapping.
|
|
|
|
* 3. One allocated by the test code and passed in via
|
|
|
|
* 'pkey' to this function.
|
|
|
|
* Ensure that we can allocate at least another 13 (16-3).
|
2020-06-05 07:52:22 +08:00
|
|
|
*
|
|
|
|
* On powerpc:
|
|
|
|
* There are either 5, 28, 29 or 32 pkeys supported in
|
|
|
|
* hardware depending on the page size (4K or 64K) and
|
|
|
|
* platform (powernv or powervm). Four are allocated by
|
|
|
|
* the time we get here. These include pkey-0, pkey-1,
|
|
|
|
* exec-only pkey and the one allocated by the test code.
|
|
|
|
* Ensure that we can allocate the remaining.
|
2016-07-30 00:30:24 +08:00
|
|
|
*/
|
2020-06-05 07:52:22 +08:00
|
|
|
pkey_assert(i >= (NR_PKEYS - get_arch_reserved_keys() - 1));
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
for (i = 0; i < nr_allocated_pkeys; i++) {
|
|
|
|
err = sys_pkey_free(allocated_pkeys[i]);
|
|
|
|
pkey_assert(!err);
|
2020-06-05 07:51:37 +08:00
|
|
|
read_pkey_reg(); /* for shadow checking */
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-10 01:13:56 +08:00
|
|
|
/*
|
|
|
|
* pkey 0 is special. It is allocated by default, so you do not
|
|
|
|
* have to call pkey_alloc() to use it first. Make sure that it
|
|
|
|
* is usable.
|
|
|
|
*/
|
|
|
|
void test_mprotect_with_pkey_0(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
long size;
|
|
|
|
int prot;
|
|
|
|
|
|
|
|
assert(pkey_last_malloc_record);
|
|
|
|
size = pkey_last_malloc_record->size;
|
|
|
|
/*
|
|
|
|
* This is a bit of a hack. But mprotect() requires
|
|
|
|
* huge-page-aligned sizes when operating on hugetlbfs.
|
|
|
|
* So, make sure that we use something that's a multiple
|
|
|
|
* of a huge page when we can.
|
|
|
|
*/
|
|
|
|
if (size >= HPAGE_SIZE)
|
|
|
|
size = HPAGE_SIZE;
|
|
|
|
prot = pkey_last_malloc_record->prot;
|
|
|
|
|
|
|
|
/* Use pkey 0 */
|
|
|
|
mprotect_pkey(ptr, size, prot, 0);
|
|
|
|
|
|
|
|
/* Make sure that we can set it back to the original pkey. */
|
|
|
|
mprotect_pkey(ptr, size, prot, pkey);
|
|
|
|
}
|
|
|
|
|
2016-07-30 00:30:24 +08:00
|
|
|
void test_ptrace_of_child(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
__attribute__((__unused__)) int peek_result;
|
|
|
|
pid_t child_pid;
|
|
|
|
void *ignored = 0;
|
|
|
|
long ret;
|
|
|
|
int status;
|
|
|
|
/*
|
|
|
|
* This is the "control" for our little expermient. Make sure
|
|
|
|
* we can always access it when ptracing.
|
|
|
|
*/
|
|
|
|
int *plain_ptr_unaligned = malloc(HPAGE_SIZE);
|
|
|
|
int *plain_ptr = ALIGN_PTR_UP(plain_ptr_unaligned, PAGE_SIZE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fork a child which is an exact copy of this process, of course.
|
|
|
|
* That means we can do all of our tests via ptrace() and then plain
|
|
|
|
* memory access and ensure they work differently.
|
|
|
|
*/
|
|
|
|
child_pid = fork_lazy_child();
|
|
|
|
dprintf1("[%d] child pid: %d\n", getpid(), child_pid);
|
|
|
|
|
|
|
|
ret = ptrace(PTRACE_ATTACH, child_pid, ignored, ignored);
|
|
|
|
if (ret)
|
|
|
|
perror("attach");
|
|
|
|
dprintf1("[%d] attach ret: %ld %d\n", getpid(), ret, __LINE__);
|
|
|
|
pkey_assert(ret != -1);
|
|
|
|
ret = waitpid(child_pid, &status, WUNTRACED);
|
|
|
|
if ((ret != child_pid) || !(WIFSTOPPED(status))) {
|
|
|
|
fprintf(stderr, "weird waitpid result %ld stat %x\n",
|
|
|
|
ret, status);
|
|
|
|
pkey_assert(0);
|
|
|
|
}
|
|
|
|
dprintf2("waitpid ret: %ld\n", ret);
|
|
|
|
dprintf2("waitpid status: %d\n", status);
|
|
|
|
|
|
|
|
pkey_access_deny(pkey);
|
|
|
|
pkey_write_deny(pkey);
|
|
|
|
|
|
|
|
/* Write access, untested for now:
|
|
|
|
ret = ptrace(PTRACE_POKEDATA, child_pid, peek_at, data);
|
|
|
|
pkey_assert(ret != -1);
|
|
|
|
dprintf1("poke at %p: %ld\n", peek_at, ret);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to access the pkey-protected "ptr" via ptrace:
|
|
|
|
*/
|
|
|
|
ret = ptrace(PTRACE_PEEKDATA, child_pid, ptr, ignored);
|
|
|
|
/* expect it to work, without an error: */
|
|
|
|
pkey_assert(ret != -1);
|
|
|
|
/* Now access from the current task, and expect an exception: */
|
|
|
|
peek_result = read_ptr(ptr);
|
2020-06-05 07:51:37 +08:00
|
|
|
expected_pkey_fault(pkey);
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to access the NON-pkey-protected "plain_ptr" via ptrace:
|
|
|
|
*/
|
|
|
|
ret = ptrace(PTRACE_PEEKDATA, child_pid, plain_ptr, ignored);
|
|
|
|
/* expect it to work, without an error: */
|
|
|
|
pkey_assert(ret != -1);
|
|
|
|
/* Now access from the current task, and expect NO exception: */
|
|
|
|
peek_result = read_ptr(plain_ptr);
|
2020-06-05 07:51:37 +08:00
|
|
|
do_not_expect_pkey_fault("read plain pointer after ptrace");
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
ret = ptrace(PTRACE_DETACH, child_pid, ignored, 0);
|
|
|
|
pkey_assert(ret != -1);
|
|
|
|
|
|
|
|
ret = kill(child_pid, SIGKILL);
|
|
|
|
pkey_assert(ret != -1);
|
|
|
|
|
|
|
|
wait(&status);
|
|
|
|
|
|
|
|
free(plain_ptr_unaligned);
|
|
|
|
}
|
|
|
|
|
2018-05-10 01:13:47 +08:00
|
|
|
void *get_pointer_to_instructions(void)
|
2016-07-30 00:30:24 +08:00
|
|
|
{
|
|
|
|
void *p1;
|
|
|
|
|
|
|
|
p1 = ALIGN_PTR_UP(&lots_o_noops_around_write, PAGE_SIZE);
|
|
|
|
dprintf3("&lots_o_noops: %p\n", &lots_o_noops_around_write);
|
|
|
|
/* lots_o_noops_around_write should be page-aligned already */
|
|
|
|
assert(p1 == &lots_o_noops_around_write);
|
|
|
|
|
|
|
|
/* Point 'p1' at the *second* page of the function: */
|
|
|
|
p1 += PAGE_SIZE;
|
|
|
|
|
2018-05-10 01:13:47 +08:00
|
|
|
/*
|
|
|
|
* Try to ensure we fault this in on next touch to ensure
|
|
|
|
* we get an instruction fault as opposed to a data one
|
|
|
|
*/
|
2016-07-30 00:30:24 +08:00
|
|
|
madvise(p1, PAGE_SIZE, MADV_DONTNEED);
|
2018-05-10 01:13:47 +08:00
|
|
|
|
|
|
|
return p1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_executing_on_unreadable_memory(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
void *p1;
|
|
|
|
int scratch;
|
|
|
|
int ptr_contents;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
p1 = get_pointer_to_instructions();
|
2016-07-30 00:30:24 +08:00
|
|
|
lots_o_noops_around_write(&scratch);
|
|
|
|
ptr_contents = read_ptr(p1);
|
|
|
|
dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents);
|
|
|
|
|
|
|
|
ret = mprotect_pkey(p1, PAGE_SIZE, PROT_EXEC, (u64)pkey);
|
|
|
|
pkey_assert(!ret);
|
|
|
|
pkey_access_deny(pkey);
|
|
|
|
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf2("pkey_reg: %016llx\n", read_pkey_reg());
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this is an *instruction* fault
|
|
|
|
*/
|
|
|
|
madvise(p1, PAGE_SIZE, MADV_DONTNEED);
|
|
|
|
lots_o_noops_around_write(&scratch);
|
2020-06-05 07:51:37 +08:00
|
|
|
do_not_expect_pkey_fault("executing on PROT_EXEC memory");
|
2020-06-05 07:52:12 +08:00
|
|
|
expect_fault_on_read_execonly_key(p1, pkey);
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
|
|
|
|
2018-05-10 01:13:48 +08:00
|
|
|
void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
void *p1;
|
|
|
|
int scratch;
|
|
|
|
int ptr_contents;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dprintf1("%s() start\n", __func__);
|
|
|
|
|
|
|
|
p1 = get_pointer_to_instructions();
|
|
|
|
lots_o_noops_around_write(&scratch);
|
|
|
|
ptr_contents = read_ptr(p1);
|
|
|
|
dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents);
|
|
|
|
|
|
|
|
/* Use a *normal* mprotect(), not mprotect_pkey(): */
|
|
|
|
ret = mprotect(p1, PAGE_SIZE, PROT_EXEC);
|
|
|
|
pkey_assert(!ret);
|
|
|
|
|
2020-06-05 07:51:51 +08:00
|
|
|
dprintf2("pkey_reg: %016llx\n", read_pkey_reg());
|
2018-05-10 01:13:48 +08:00
|
|
|
|
|
|
|
/* Make sure this is an *instruction* fault */
|
|
|
|
madvise(p1, PAGE_SIZE, MADV_DONTNEED);
|
|
|
|
lots_o_noops_around_write(&scratch);
|
2020-06-05 07:51:37 +08:00
|
|
|
do_not_expect_pkey_fault("executing on PROT_EXEC memory");
|
2020-06-05 07:52:12 +08:00
|
|
|
expect_fault_on_read_execonly_key(p1, UNKNOWN_PKEY);
|
2018-05-10 01:13:48 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the memory back to non-PROT_EXEC. Should clear the
|
|
|
|
* exec-only pkey off the VMA and allow it to be readable
|
|
|
|
* again. Go to PROT_NONE first to check for a kernel bug
|
|
|
|
* that did not clear the pkey when doing PROT_NONE.
|
|
|
|
*/
|
|
|
|
ret = mprotect(p1, PAGE_SIZE, PROT_NONE);
|
|
|
|
pkey_assert(!ret);
|
|
|
|
|
|
|
|
ret = mprotect(p1, PAGE_SIZE, PROT_READ|PROT_EXEC);
|
|
|
|
pkey_assert(!ret);
|
|
|
|
ptr_contents = read_ptr(p1);
|
2020-06-05 07:51:37 +08:00
|
|
|
do_not_expect_pkey_fault("plain read on recently PROT_EXEC area");
|
2018-05-10 01:13:48 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 00:30:24 +08:00
|
|
|
void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey)
|
|
|
|
{
|
|
|
|
int size = PAGE_SIZE;
|
|
|
|
int sret;
|
|
|
|
|
2020-06-05 07:52:25 +08:00
|
|
|
if (cpu_has_pkeys()) {
|
2016-07-30 00:30:24 +08:00
|
|
|
dprintf1("SKIP: %s: no CPU support\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sret = syscall(SYS_mprotect_key, ptr, size, PROT_READ, pkey);
|
|
|
|
pkey_assert(sret < 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void (*pkey_tests[])(int *ptr, u16 pkey) = {
|
|
|
|
test_read_of_write_disabled_region,
|
|
|
|
test_read_of_access_disabled_region,
|
2020-06-05 07:52:29 +08:00
|
|
|
test_read_of_access_disabled_region_with_page_already_mapped,
|
2016-07-30 00:30:24 +08:00
|
|
|
test_write_of_write_disabled_region,
|
2020-06-05 07:52:32 +08:00
|
|
|
test_write_of_write_disabled_region_with_page_already_mapped,
|
2016-07-30 00:30:24 +08:00
|
|
|
test_write_of_access_disabled_region,
|
2020-06-05 07:52:36 +08:00
|
|
|
test_write_of_access_disabled_region_with_page_already_mapped,
|
2016-07-30 00:30:24 +08:00
|
|
|
test_kernel_write_of_access_disabled_region,
|
|
|
|
test_kernel_write_of_write_disabled_region,
|
|
|
|
test_kernel_gup_of_access_disabled_region,
|
|
|
|
test_kernel_gup_write_to_write_disabled_region,
|
|
|
|
test_executing_on_unreadable_memory,
|
2018-05-10 01:13:48 +08:00
|
|
|
test_implicit_mprotect_exec_only_memory,
|
2018-05-10 01:13:56 +08:00
|
|
|
test_mprotect_with_pkey_0,
|
2016-07-30 00:30:24 +08:00
|
|
|
test_ptrace_of_child,
|
|
|
|
test_pkey_syscalls_on_non_allocated_pkey,
|
|
|
|
test_pkey_syscalls_bad_args,
|
|
|
|
test_pkey_alloc_exhaust,
|
2020-06-05 07:52:43 +08:00
|
|
|
test_pkey_alloc_free_attach_pkey0,
|
2016-07-30 00:30:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void run_tests_once(void)
|
|
|
|
{
|
|
|
|
int *ptr;
|
|
|
|
int prot = PROT_READ|PROT_WRITE;
|
|
|
|
|
|
|
|
for (test_nr = 0; test_nr < ARRAY_SIZE(pkey_tests); test_nr++) {
|
|
|
|
int pkey;
|
2020-06-05 07:51:37 +08:00
|
|
|
int orig_pkey_faults = pkey_faults;
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
dprintf1("======================\n");
|
|
|
|
dprintf1("test %d preparing...\n", test_nr);
|
|
|
|
|
|
|
|
tracing_on();
|
|
|
|
pkey = alloc_random_pkey();
|
|
|
|
dprintf1("test %d starting with pkey: %d\n", test_nr, pkey);
|
|
|
|
ptr = malloc_pkey(PAGE_SIZE, prot, pkey);
|
|
|
|
dprintf1("test %d starting...\n", test_nr);
|
|
|
|
pkey_tests[test_nr](ptr, pkey);
|
|
|
|
dprintf1("freeing test memory: %p\n", ptr);
|
|
|
|
free_pkey_malloc(ptr);
|
|
|
|
sys_pkey_free(pkey);
|
|
|
|
|
2020-06-05 07:51:37 +08:00
|
|
|
dprintf1("pkey_faults: %d\n", pkey_faults);
|
|
|
|
dprintf1("orig_pkey_faults: %d\n", orig_pkey_faults);
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
tracing_off();
|
|
|
|
close_test_fds();
|
|
|
|
|
2016-12-28 00:17:21 +08:00
|
|
|
printf("test %2d PASSED (iteration %d)\n", test_nr, iteration_nr);
|
2016-07-30 00:30:24 +08:00
|
|
|
dprintf1("======================\n\n");
|
|
|
|
}
|
|
|
|
iteration_nr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pkey_setup_shadow(void)
|
|
|
|
{
|
2020-06-05 07:51:37 +08:00
|
|
|
shadow_pkey_reg = __read_pkey_reg();
|
2016-07-30 00:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
int nr_iterations = 22;
|
2020-06-05 07:52:25 +08:00
|
|
|
int pkeys_supported = is_pkeys_supported();
|
2016-07-30 00:30:24 +08:00
|
|
|
|
|
|
|
setup_handlers();
|
|
|
|
|
2020-06-05 07:52:25 +08:00
|
|
|
printf("has pkeys: %d\n", pkeys_supported);
|
2016-07-30 00:30:24 +08:00
|
|
|
|
2020-06-05 07:52:25 +08:00
|
|
|
if (!pkeys_supported) {
|
2016-07-30 00:30:24 +08:00
|
|
|
int size = PAGE_SIZE;
|
|
|
|
int *ptr;
|
|
|
|
|
|
|
|
printf("running PKEY tests for unsupported CPU/OS\n");
|
|
|
|
|
|
|
|
ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
|
|
|
assert(ptr != (void *)-1);
|
|
|
|
test_mprotect_pkey_on_unsupported_cpu(ptr, 1);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pkey_setup_shadow();
|
2020-06-05 07:51:51 +08:00
|
|
|
printf("startup pkey_reg: %016llx\n", read_pkey_reg());
|
2016-07-30 00:30:24 +08:00
|
|
|
setup_hugetlbfs();
|
|
|
|
|
|
|
|
while (nr_iterations-- > 0)
|
|
|
|
run_tests_once();
|
|
|
|
|
|
|
|
printf("done (all tests OK)\n");
|
|
|
|
return 0;
|
|
|
|
}
|