Commit d744dcad authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Ingo Molnar

selftests/x86/ldt_gdt: Add infrastructure to test set_thread_area()

Much of the test design could apply to set_thread_area() (i.e. GDT),
not just modify_ldt().  Add set_thread_area() to the
install_valid_mode() helper.
Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bpetkov@suse.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/02c23f8fba5547007f741dc24c3926e5284ede02.1509794321.git.luto@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent d60ad744
...@@ -137,30 +137,51 @@ static void check_valid_segment(uint16_t index, int ldt, ...@@ -137,30 +137,51 @@ static void check_valid_segment(uint16_t index, int ldt,
} }
} }
static bool install_valid_mode(const struct user_desc *desc, uint32_t ar, static bool install_valid_mode(const struct user_desc *d, uint32_t ar,
bool oldmode) bool oldmode, bool ldt)
{ {
int ret = syscall(SYS_modify_ldt, oldmode ? 1 : 0x11, struct user_desc desc = *d;
desc, sizeof(*desc)); int ret;
if (ret < -1)
errno = -ret; if (!ldt) {
#ifndef __i386__
/* No point testing set_thread_area in a 64-bit build */
return false;
#endif
if (!gdt_entry_num)
return false;
desc.entry_number = gdt_entry_num;
ret = syscall(SYS_set_thread_area, &desc);
} else {
ret = syscall(SYS_modify_ldt, oldmode ? 1 : 0x11,
&desc, sizeof(desc));
if (ret < -1)
errno = -ret;
if (ret != 0 && errno == ENOSYS) {
printf("[OK]\tmodify_ldt returned -ENOSYS\n");
return false;
}
}
if (ret == 0) { if (ret == 0) {
uint32_t limit = desc->limit; uint32_t limit = desc.limit;
if (desc->limit_in_pages) if (desc.limit_in_pages)
limit = (limit << 12) + 4095; limit = (limit << 12) + 4095;
check_valid_segment(desc->entry_number, 1, ar, limit, true); check_valid_segment(desc.entry_number, ldt, ar, limit, true);
return true; return true;
} else if (errno == ENOSYS) {
printf("[OK]\tmodify_ldt returned -ENOSYS\n");
return false;
} else { } else {
if (desc->seg_32bit) { if (desc.seg_32bit) {
printf("[FAIL]\tUnexpected modify_ldt failure %d\n", printf("[FAIL]\tUnexpected %s failure %d\n",
ldt ? "modify_ldt" : "set_thread_area",
errno); errno);
nerrs++; nerrs++;
return false; return false;
} else { } else {
printf("[OK]\tmodify_ldt rejected 16 bit segment\n"); printf("[OK]\t%s rejected 16 bit segment\n",
ldt ? "modify_ldt" : "set_thread_area");
return false; return false;
} }
} }
...@@ -168,7 +189,7 @@ static bool install_valid_mode(const struct user_desc *desc, uint32_t ar, ...@@ -168,7 +189,7 @@ static bool install_valid_mode(const struct user_desc *desc, uint32_t ar,
static bool install_valid(const struct user_desc *desc, uint32_t ar) static bool install_valid(const struct user_desc *desc, uint32_t ar)
{ {
return install_valid_mode(desc, ar, false); return install_valid_mode(desc, ar, false, true);
} }
static void install_invalid(const struct user_desc *desc, bool oldmode) static void install_invalid(const struct user_desc *desc, bool oldmode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment