diff options
author | Andy Lutomirski <luto@kernel.org> | 2015-04-23 09:36:06 -0700 |
---|---|---|
committer | Andy Lutomirski <luto@kernel.org> | 2015-04-23 09:36:06 -0700 |
commit | 1c496dbfe2643b3fbdcc32ec1023bf9c312cfd53 (patch) | |
tree | c3abcfbef604dacc6590ff28addfdb238c937705 | |
parent | 628f134de4b404d8290c64c513ea119159cf23d5 (diff) | |
download | misc-tests-1c496dbfe2643b3fbdcc32ec1023bf9c312cfd53.tar.gz |
sysret_ss_attrs: New test, WIP
Signed-off-by: Andy Lutomirski <luto@kernel.org>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | sysret_ss_attrs.c | 67 |
2 files changed, 68 insertions, 1 deletions
@@ -4,7 +4,7 @@ SIMPLE_C_TARGETS := dump-vsyscall context_switch_latency kernel_pf user_visible_ SIMPLE_CC_TARGETS := evil-clock-test -SPLIT_C_TARGETS := dump-vdso dump-vvar syscall_exit_regs dump_all_pmcs ntflag +SPLIT_C_TARGETS := dump-vdso dump-vvar syscall_exit_regs dump_all_pmcs ntflag sysret_ss_attrs SPLIT_CC_TARGETS := timing_test test_vsyscall test_vdso_parser ALL_TARGETS := $(SIMPLE_C_TARGETS) $(SIMPLE_CC_TARGETS) $(SPLIT_C_TARGETS:%=%_64) $(SPLIT_CC_TARGETS:%=%_64) $(SPLIT_C_TARGETS:%=%_32) $(SPLIT_CC_TARGETS:%=%_32) syscall32_from_64 segregs diff --git a/sysret_ss_attrs.c b/sysret_ss_attrs.c new file mode 100644 index 0000000..fa81ce2 --- /dev/null +++ b/sysret_ss_attrs.c @@ -0,0 +1,67 @@ +#define _GNU_SOURCE + +#include <sys/time.h> +#include <time.h> +#include <stdlib.h> +#include <sys/syscall.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/mman.h> +#include <sys/signal.h> +#include <sys/ucontext.h> +#include <asm/ldt.h> +#include <err.h> +#include <setjmp.h> +#include <stddef.h> +#include <stdbool.h> +#include <sys/ptrace.h> +#include <sys/user.h> +#include <pthread.h> + +static unsigned short GDT3(int idx) +{ + return (idx << 3) | 3; +} + +static void *threadproc(void *ctx) +{ + struct user_desc desc = { + .entry_number = -1, + .base_addr = 0, + .limit = 1, + .seg_32bit = 1, + .contents = 0, /* Data, grow-up */ + .read_exec_only = 0, + .limit_in_pages = 0, + .seg_not_present = 0, + .useable = 0, + }; + + if (syscall(SYS_set_thread_area, &desc) != 0) + err(1, "set_thread_area"); + + asm volatile ( + "mov %%ax, %%ss\n\t" + "1:\n\t" + "movl $0xbfffffff, %%eax\n\t" + "int $0x80\n\t" + "jmp 1b" + : : "a" (GDT3(desc.entry_number)) + ); + return NULL; +} + +int main() +{ + pthread_t thread; + if (pthread_create(&thread, 0, threadproc, 0) != 0) + err(1, "pthread_create"); + + while (1) { + usleep(1); + } + + return 0; +} |