Commit 858259cf authored by Bodo Stroesser's avatar Bodo Stroesser Committed by Linus Torvalds

[PATCH] uml: maintain own LDT entries

Patch imlements full LDT handling in SKAS:
 * UML holds it's own LDT table, used to deliver data on
   modify_ldt(READ)
 * UML disables the default_ldt, inherited from the host (SKAS3)
   or resets LDT entries, set by host's clib and inherited in
   SKAS0
 * A new global variable skas_needs_stub is inserted, that
   can be used to decide, whether stub-pages must be supported
   or not.
 * Uses the syscall-stub to replace missing PTRACE_LDT (therefore,
   write_ldt_entry needs to be modified)
Signed-off-by: default avatarBodo Stroesser <bstroesser@fujitsu-siemens.com>
Signed-off-by: default avatarJeff Dike <jdike@addtoit.com>
Cc: Paolo Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e763b793
......@@ -8,6 +8,7 @@
#include "linux/config.h"
#include "mm_id.h"
#include "asm/ldt.h"
struct mmu_context_skas {
struct mm_id id;
......@@ -15,6 +16,7 @@ struct mmu_context_skas {
#ifdef CONFIG_3_LEVEL_PGTABLES
unsigned long last_pmd;
#endif
uml_ldt_t ldt;
};
extern void switch_mm_skas(struct mm_id * mm_idp);
......
......@@ -10,7 +10,8 @@
#include "sysdep/ptrace.h"
extern int userspace_pid[];
extern int proc_mm, ptrace_faultinfo;
extern int proc_mm, ptrace_faultinfo, ptrace_ldt;
extern int skas_needs_stub;
extern void switch_threads(void *me, void *next);
extern void thread_wait(void *sw, void *fb);
......
......@@ -20,7 +20,7 @@ unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out,
*task_size_out = CONFIG_HOST_TASK_SIZE;
#else
*host_size_out = top;
if (proc_mm && ptrace_faultinfo)
if (!skas_needs_stub)
*task_size_out = top;
else *task_size_out = CONFIG_STUB_START & PGDIR_MASK;
#endif
......
......@@ -15,6 +15,7 @@
#include "asm/mmu.h"
#include "asm/pgalloc.h"
#include "asm/pgtable.h"
#include "asm/ldt.h"
#include "os.h"
#include "skas.h"
......@@ -74,13 +75,12 @@ static int init_stub_pte(struct mm_struct *mm, unsigned long proc,
int init_new_context_skas(struct task_struct *task, struct mm_struct *mm)
{
struct mm_struct *cur_mm = current->mm;
struct mm_id *cur_mm_id = &cur_mm->context.skas.id;
struct mm_id *mm_id = &mm->context.skas.id;
struct mmu_context_skas *from_mm = NULL;
struct mmu_context_skas *to_mm = &mm->context.skas;
unsigned long stack = 0;
int from, ret = -ENOMEM;
int from_fd, ret = -ENOMEM;
if(!proc_mm || !ptrace_faultinfo){
if(skas_needs_stub){
stack = get_zeroed_page(GFP_KERNEL);
if(stack == 0)
goto out;
......@@ -102,33 +102,43 @@ int init_new_context_skas(struct task_struct *task, struct mm_struct *mm)
mm->nr_ptes--;
}
mm_id->stack = stack;
to_mm->id.stack = stack;
if(current->mm != NULL && current->mm != &init_mm)
from_mm = &current->mm->context.skas;
if(proc_mm){
if((cur_mm != NULL) && (cur_mm != &init_mm))
from = cur_mm_id->u.mm_fd;
else from = -1;
if(from_mm)
from_fd = from_mm->id.u.mm_fd;
else from_fd = -1;
ret = new_mm(from, stack);
ret = new_mm(from_fd, stack);
if(ret < 0){
printk("init_new_context_skas - new_mm failed, "
"errno = %d\n", ret);
goto out_free;
}
mm_id->u.mm_fd = ret;
to_mm->id.u.mm_fd = ret;
}
else {
if((cur_mm != NULL) && (cur_mm != &init_mm))
mm_id->u.pid = copy_context_skas0(stack,
cur_mm_id->u.pid);
else mm_id->u.pid = start_userspace(stack);
if(from_mm)
to_mm->id.u.pid = copy_context_skas0(stack,
from_mm->id.u.pid);
else to_mm->id.u.pid = start_userspace(stack);
}
ret = init_new_ldt(to_mm, from_mm);
if(ret < 0){
printk("init_new_context_skas - init_ldt"
" failed, errno = %d\n", ret);
goto out_free;
}
return 0;
out_free:
if(mm_id->stack != 0)
free_page(mm_id->stack);
if(to_mm->id.stack != 0)
free_page(to_mm->id.stack);
out:
return ret;
}
......
......@@ -381,9 +381,9 @@ int copy_context_skas0(unsigned long new_stack, int pid)
}
/*
* This is used only, if proc_mm is available, while PTRACE_FAULTINFO
* isn't. Opening /proc/mm creates a new mm_context, which lacks the stub-pages
* Thus, we map them using /proc/mm-fd
* This is used only, if stub pages are needed, while proc_mm is
* availabl. Opening /proc/mm creates a new mm_context, which lacks
* the stub-pages. Thus, we map them using /proc/mm-fd
*/
void map_stub_pages(int fd, unsigned long code,
unsigned long data, unsigned long stack)
......
......@@ -145,7 +145,7 @@ int new_mm(int from, unsigned long stack)
"err = %d\n", -n);
}
if(!ptrace_faultinfo)
if(skas_needs_stub)
map_stub_pages(fd, CONFIG_STUB_CODE, CONFIG_STUB_DATA, stack);
return(fd);
......
......@@ -135,7 +135,9 @@ static int stop_ptraced_child(int pid, void *stack, int exitcode,
}
int ptrace_faultinfo = 1;
int ptrace_ldt = 1;
int proc_mm = 1;
int skas_needs_stub = 0;
static int __init skas0_cmd_param(char *str, int* add)
{
......@@ -352,14 +354,26 @@ __uml_setup("noptracefaultinfo", noptracefaultinfo_cmd_param,
" it. To support PTRACE_FAULTINFO, the host needs to be patched\n"
" using the current skas3 patch.\n\n");
static int __init noptraceldt_cmd_param(char *str, int* add)
{
ptrace_ldt = 0;
return 0;
}
__uml_setup("noptraceldt", noptraceldt_cmd_param,
"noptraceldt\n"
" Turns off usage of PTRACE_LDT, even if host supports it.\n"
" To support PTRACE_LDT, the host needs to be patched using\n"
" the current skas3 patch.\n\n");
#ifdef UML_CONFIG_MODE_SKAS
static inline void check_skas3_ptrace_support(void)
static inline void check_skas3_ptrace_faultinfo(void)
{
struct ptrace_faultinfo fi;
void *stack;
int pid, n;
printf("Checking for the skas3 patch in the host...");
printf(" - PTRACE_FAULTINFO...");
pid = start_ptraced_child(&stack);
n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
......@@ -381,9 +395,49 @@ static inline void check_skas3_ptrace_support(void)
stop_ptraced_child(pid, stack, 1, 1);
}
int can_do_skas(void)
static inline void check_skas3_ptrace_ldt(void)
{
#ifdef PTRACE_LDT
void *stack;
int pid, n;
unsigned char ldtbuf[40];
struct ptrace_ldt ldt_op = (struct ptrace_ldt) {
.func = 2, /* read default ldt */
.ptr = ldtbuf,
.bytecount = sizeof(ldtbuf)};
printf(" - PTRACE_LDT...");
pid = start_ptraced_child(&stack);
n = ptrace(PTRACE_LDT, pid, 0, (unsigned long) &ldt_op);
if (n < 0) {
if(errno == EIO)
printf("not found\n");
else {
perror("not found");
}
ptrace_ldt = 0;
}
else {
if(ptrace_ldt)
printf("found\n");
else
printf("found, but use is disabled\n");
}
stop_ptraced_child(pid, stack, 1, 1);
#else
/* PTRACE_LDT might be disabled via cmdline option.
* We want to override this, else we might use the stub
* without real need
*/
ptrace_ldt = 1;
#endif
}
static inline void check_skas3_proc_mm(void)
{
printf("Checking for /proc/mm...");
printf(" - /proc/mm...");
if (os_access("/proc/mm", OS_ACC_W_OK) < 0) {
proc_mm = 0;
printf("not found\n");
......@@ -394,8 +448,19 @@ int can_do_skas(void)
else
printf("found\n");
}
}
int can_do_skas(void)
{
printf("Checking for the skas3 patch in the host:\n");
check_skas3_proc_mm();
check_skas3_ptrace_faultinfo();
check_skas3_ptrace_ldt();
if(!proc_mm || !ptrace_faultinfo || !ptrace_ldt)
skas_needs_stub = 1;
check_skas3_ptrace_support();
return 1;
}
#else
......
......@@ -26,8 +26,13 @@ define unprofile
$(patsubst -pg,,$(patsubst -fprofile-arcs -ftest-coverage,,$(1)))
endef
# cmd_make_link checks to see if the $(foo-dir) variable starts with a /. If
# so, it's considered to be a path relative to $(srcdir) rather than
# $(srcdir)/arch/$(SUBARCH). This is because x86_64 wants to get ldt.c from
# arch/um/sys-i386 rather than arch/i386 like the other borrowed files. So,
# it sets $(ldt.c-dir) to /arch/um/sys-i386.
quiet_cmd_make_link = SYMLINK $@
cmd_make_link = ln -sf $(srctree)/arch/$(SUBARCH)/$($(notdir $@)-dir)/$(notdir $@) $@
cmd_make_link = rm -f $@; ln -sf $(srctree)$(if $(filter-out /%,$($(notdir $@)-dir)),/arch/$(SUBARCH))/$($(notdir $@)-dir)/$(notdir $@) $@
# this needs to be before the foreach, because targets does not accept
# complete paths like $(obj)/$(f). To make sure this works, use a := assignment
......
This diff is collapsed.
......@@ -5,7 +5,7 @@
#
#XXX: why into lib-y?
lib-y = bitops.o bugs.o csum-partial.o delay.o fault.o mem.o memcpy.o \
lib-y = bitops.o bugs.o csum-partial.o delay.o fault.o ldt.o mem.o memcpy.o \
ptrace.o ptrace_user.o sigcontext.o signal.o stub.o \
stub_segv.o syscalls.o syscall_table.o sysrq.o thunk.o
......@@ -14,7 +14,7 @@ obj-$(CONFIG_MODULES) += module.o um_module.o
USER_OBJS := ptrace_user.o sigcontext.o
SYMLINKS = bitops.c csum-copy.S csum-partial.c csum-wrappers.c memcpy.S \
SYMLINKS = bitops.c csum-copy.S csum-partial.c csum-wrappers.c ldt.c memcpy.S \
thunk.S module.c
include arch/um/scripts/Makefile.rules
......@@ -23,6 +23,7 @@ bitops.c-dir = lib
csum-copy.S-dir = lib
csum-partial.c-dir = lib
csum-wrappers.c-dir = lib
ldt.c-dir = /arch/um/sys-i386
memcpy.S-dir = lib
thunk.S-dir = lib
module.c-dir = kernel
......
......@@ -28,81 +28,6 @@ asmlinkage long sys_uname64(struct new_utsname __user * name)
return err ? -EFAULT : 0;
}
#ifdef CONFIG_MODE_TT
extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
long sys_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
{
/* XXX This should check VERIFY_WRITE depending on func, check this
* in i386 as well.
*/
if (!access_ok(VERIFY_READ, ptr, bytecount))
return -EFAULT;
return(modify_ldt(func, ptr, bytecount));
}
#endif
#ifdef CONFIG_MODE_SKAS
extern int userspace_pid[];
#include "skas_ptrace.h"
long sys_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
{
struct ptrace_ldt ldt;
void *buf;
int res, n;
buf = kmalloc(bytecount, GFP_KERNEL);
if(buf == NULL)
return(-ENOMEM);
res = 0;
switch(func){
case 1:
case 0x11:
res = copy_from_user(buf, ptr, bytecount);
break;
}
if(res != 0){
res = -EFAULT;
goto out;
}
ldt = ((struct ptrace_ldt) { .func = func,
.ptr = buf,
.bytecount = bytecount });
#warning Need to look up userspace_pid by cpu
res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
if(res < 0)
goto out;
switch(func){
case 0:
case 2:
n = res;
res = copy_to_user(ptr, buf, n);
if(res != 0)
res = -EFAULT;
else
res = n;
break;
}
out:
kfree(buf);
return(res);
}
#endif
long sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
{
return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
ptr, bytecount));
}
#ifdef CONFIG_MODE_TT
extern long arch_prctl(int code, unsigned long addr);
......
/*
* Copyright (C) 2004 Fujitsu Siemens Computers GmbH
* Licensed under the GPL
*
* Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
*/
#ifndef __ASM_LDT_I386_H
#define __ASM_LDT_I386_H
#include "asm/semaphore.h"
#include "asm/arch/ldt.h"
struct mmu_context_skas;
extern void ldt_host_info(void);
extern long init_new_ldt(struct mmu_context_skas * to_mm,
struct mmu_context_skas * from_mm);
extern void free_ldt(struct mmu_context_skas * mm);
#define LDT_PAGES_MAX \
((LDT_ENTRIES * LDT_ENTRY_SIZE)/PAGE_SIZE)
#define LDT_ENTRIES_PER_PAGE \
(PAGE_SIZE/LDT_ENTRY_SIZE)
#define LDT_DIRECT_ENTRIES \
((LDT_PAGES_MAX*sizeof(void *))/LDT_ENTRY_SIZE)
struct ldt_entry {
__u32 a;
__u32 b;
};
typedef struct uml_ldt {
int entry_count;
struct semaphore semaphore;
union {
struct ldt_entry * pages[LDT_PAGES_MAX];
struct ldt_entry entries[LDT_DIRECT_ENTRIES];
};
} uml_ldt_t;
/*
* macros stolen from include/asm-i386/desc.h
*/
#define LDT_entry_a(info) \
((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
#define LDT_entry_b(info) \
(((info)->base_addr & 0xff000000) | \
(((info)->base_addr & 0x00ff0000) >> 16) | \
((info)->limit & 0xf0000) | \
(((info)->read_exec_only ^ 1) << 9) | \
((info)->contents << 10) | \
(((info)->seg_not_present ^ 1) << 15) | \
((info)->seg_32bit << 22) | \
((info)->limit_in_pages << 23) | \
((info)->useable << 20) | \
0x7000)
#define LDT_empty(info) (\
(info)->base_addr == 0 && \
(info)->limit == 0 && \
(info)->contents == 0 && \
(info)->read_exec_only == 1 && \
(info)->seg_32bit == 0 && \
(info)->limit_in_pages == 0 && \
(info)->seg_not_present == 1 && \
(info)->useable == 0 )
#endif
/*
* Copyright (C) 2004 Fujitsu Siemens Computers GmbH
* Licensed under the GPL
*
* Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
*/
#ifndef __ASM_LDT_I386_H
#define __ASM_LDT_I386_H
#include "asm/semaphore.h"
#include "asm/arch/ldt.h"
struct mmu_context_skas;
extern void ldt_host_info(void);
extern long init_new_ldt(struct mmu_context_skas * to_mm,
struct mmu_context_skas * from_mm);
extern void free_ldt(struct mmu_context_skas * mm);
#define LDT_PAGES_MAX \
((LDT_ENTRIES * LDT_ENTRY_SIZE)/PAGE_SIZE)
#define LDT_ENTRIES_PER_PAGE \
(PAGE_SIZE/LDT_ENTRY_SIZE)
#define LDT_DIRECT_ENTRIES \
((LDT_PAGES_MAX*sizeof(void *))/LDT_ENTRY_SIZE)
struct ldt_entry {
__u32 a;
__u32 b;
};
typedef struct uml_ldt {
int entry_count;
struct semaphore semaphore;
union {
struct ldt_entry * pages[LDT_PAGES_MAX];
struct ldt_entry entries[LDT_DIRECT_ENTRIES];
};
} uml_ldt_t;
/*
* macros stolen from include/asm-i386/desc.h
*/
#define LDT_entry_a(info) \
((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
#define LDT_entry_b(info) \
(((info)->base_addr & 0xff000000) | \
(((info)->base_addr & 0x00ff0000) >> 16) | \
((info)->limit & 0xf0000) | \
(((info)->read_exec_only ^ 1) << 9) | \
((info)->contents << 10) | \
(((info)->seg_not_present ^ 1) << 15) | \
((info)->seg_32bit << 22) | \
((info)->limit_in_pages << 23) | \
((info)->useable << 20) | \
0x7000)
#define LDT_empty(info) (\
(info)->base_addr == 0 && \
(info)->limit == 0 && \
(info)->contents == 0 && \
(info)->read_exec_only == 1 && \
(info)->seg_32bit == 0 && \
(info)->limit_in_pages == 0 && \
(info)->seg_not_present == 1 && \
(info)->useable == 0 )
#endif
#ifndef __UM_LDT_H
#define __UM_LDT_H
......
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