Skip to content

Commit

Permalink
[PATCH] uml: maintain own LDT entries
Browse files Browse the repository at this point in the history
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: Bodo Stroesser <[email protected]>
Signed-off-by: Jeff Dike <[email protected]>
Cc: Paolo Giarrusso <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Bodo Stroesser authored and Linus Torvalds committed Nov 7, 2005
1 parent e763b79 commit 858259c
Show file tree
Hide file tree
Showing 13 changed files with 724 additions and 141 deletions.
2 changes: 2 additions & 0 deletions arch/um/kernel/skas/include/mmu-skas.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

#include "linux/config.h"
#include "mm_id.h"
#include "asm/ldt.h"

struct mmu_context_skas {
struct mm_id id;
unsigned long last_page_table;
#ifdef CONFIG_3_LEVEL_PGTABLES
unsigned long last_pmd;
#endif
uml_ldt_t ldt;
};

extern void switch_mm_skas(struct mm_id * mm_idp);
Expand Down
3 changes: 2 additions & 1 deletion arch/um/kernel/skas/include/skas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion arch/um/kernel/skas/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 27 additions & 17 deletions arch/um/kernel/skas/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions arch/um/kernel/skas/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion arch/um/kernel/skas/process_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
75 changes: 70 additions & 5 deletions arch/um/os-Linux/start_up.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion arch/um/scripts/Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 858259c

Please sign in to comment.