2006-01-19 01:42:46 +00:00
|
|
|
/*
|
2005-04-16 22:20:36 +00:00
|
|
|
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
|
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "linux/sched.h"
|
|
|
|
#include "linux/slab.h"
|
|
|
|
#include "linux/ptrace.h"
|
|
|
|
#include "linux/proc_fs.h"
|
|
|
|
#include "linux/file.h"
|
|
|
|
#include "linux/errno.h"
|
|
|
|
#include "linux/init.h"
|
|
|
|
#include "asm/uaccess.h"
|
|
|
|
#include "asm/atomic.h"
|
|
|
|
#include "kern_util.h"
|
|
|
|
#include "skas.h"
|
|
|
|
#include "os.h"
|
|
|
|
#include "user_util.h"
|
|
|
|
#include "tlb.h"
|
|
|
|
#include "kern.h"
|
|
|
|
#include "mode.h"
|
|
|
|
#include "registers.h"
|
|
|
|
|
2005-09-17 02:27:43 +00:00
|
|
|
void switch_to_skas(void *prev, void *next)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct task_struct *from, *to;
|
|
|
|
|
|
|
|
from = prev;
|
|
|
|
to = next;
|
|
|
|
|
|
|
|
/* XXX need to check runqueues[cpu].idle */
|
|
|
|
if(current->pid == 0)
|
|
|
|
switch_timers(0);
|
|
|
|
|
2006-01-19 01:42:46 +00:00
|
|
|
switch_threads(&from->thread.mode.skas.switch_buf,
|
2005-04-16 22:20:36 +00:00
|
|
|
to->thread.mode.skas.switch_buf);
|
|
|
|
|
|
|
|
if(current->pid == 0)
|
|
|
|
switch_timers(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void schedule_tail(struct task_struct *prev);
|
|
|
|
|
|
|
|
void new_thread_handler(int sig)
|
|
|
|
{
|
|
|
|
int (*fn)(void *), n;
|
|
|
|
void *arg;
|
|
|
|
|
|
|
|
fn = current->thread.request.u.thread.proc;
|
|
|
|
arg = current->thread.request.u.thread.arg;
|
2006-01-19 01:42:46 +00:00
|
|
|
os_usr1_signal(1);
|
|
|
|
thread_wait(¤t->thread.mode.skas.switch_buf,
|
2005-04-16 22:20:36 +00:00
|
|
|
current->thread.mode.skas.fork_buf);
|
|
|
|
|
|
|
|
if(current->thread.prev_sched != NULL)
|
|
|
|
schedule_tail(current->thread.prev_sched);
|
|
|
|
current->thread.prev_sched = NULL;
|
|
|
|
|
|
|
|
/* The return value is 1 if the kernel thread execs a process,
|
|
|
|
* 0 if it just exits
|
|
|
|
*/
|
|
|
|
n = run_kernel_thread(fn, arg, ¤t->thread.exec_buf);
|
2005-06-08 22:48:13 +00:00
|
|
|
if(n == 1){
|
|
|
|
/* Handle any immediate reschedules or signals */
|
|
|
|
interrupt_end();
|
2005-04-16 22:20:36 +00:00
|
|
|
userspace(¤t->thread.regs.regs);
|
2005-06-08 22:48:13 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
else do_exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void new_thread_proc(void *stack, void (*handler)(int sig))
|
|
|
|
{
|
|
|
|
init_new_thread_stack(stack, handler);
|
|
|
|
os_usr1_process(os_getpid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_thread_skas(struct task_struct *task)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void fork_handler(int sig)
|
|
|
|
{
|
2006-01-19 01:42:46 +00:00
|
|
|
os_usr1_signal(1);
|
|
|
|
thread_wait(¤t->thread.mode.skas.switch_buf,
|
2005-04-16 22:20:36 +00:00
|
|
|
current->thread.mode.skas.fork_buf);
|
|
|
|
|
|
|
|
force_flush_all();
|
|
|
|
if(current->thread.prev_sched == NULL)
|
|
|
|
panic("blech");
|
|
|
|
|
|
|
|
schedule_tail(current->thread.prev_sched);
|
|
|
|
current->thread.prev_sched = NULL;
|
|
|
|
|
2006-01-19 01:42:46 +00:00
|
|
|
/* Handle any immediate reschedules or signals */
|
2005-06-08 22:48:13 +00:00
|
|
|
interrupt_end();
|
2005-04-16 22:20:36 +00:00
|
|
|
userspace(¤t->thread.regs.regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
|
2006-01-19 01:42:46 +00:00
|
|
|
unsigned long stack_top, struct task_struct * p,
|
2005-04-16 22:20:36 +00:00
|
|
|
struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
void (*handler)(int);
|
|
|
|
|
|
|
|
if(current->thread.forking){
|
2005-06-25 21:55:21 +00:00
|
|
|
memcpy(&p->thread.regs.regs.skas, ®s->regs.skas,
|
2005-04-16 22:20:36 +00:00
|
|
|
sizeof(p->thread.regs.regs.skas));
|
|
|
|
REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0);
|
|
|
|
if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp;
|
|
|
|
|
|
|
|
handler = fork_handler;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
init_thread_registers(&p->thread.regs.regs);
|
|
|
|
p->thread.request.u.thread = current->thread.request.u.thread;
|
|
|
|
handler = new_thread_handler;
|
|
|
|
}
|
|
|
|
|
2006-01-12 09:05:48 +00:00
|
|
|
new_thread(task_stack_page(p), &p->thread.mode.skas.switch_buf,
|
2005-04-16 22:20:36 +00:00
|
|
|
&p->thread.mode.skas.fork_buf, handler);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2006-01-19 01:42:39 +00:00
|
|
|
int new_mm(unsigned long stack)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-01-19 01:42:39 +00:00
|
|
|
int fd;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
|
|
|
|
if(fd < 0)
|
|
|
|
return(fd);
|
|
|
|
|
2005-11-07 08:58:55 +00:00
|
|
|
if(skas_needs_stub)
|
2005-09-03 22:57:49 +00:00
|
|
|
map_stub_pages(fd, CONFIG_STUB_CODE, CONFIG_STUB_DATA, stack);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_idle_skas(void)
|
|
|
|
{
|
|
|
|
cpu_tasks[current_thread->cpu].pid = os_getpid();
|
|
|
|
default_idle();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void start_kernel(void);
|
|
|
|
|
|
|
|
static int start_kernel_proc(void *unused)
|
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
block_signals();
|
|
|
|
pid = os_getpid();
|
|
|
|
|
|
|
|
cpu_tasks[0].pid = pid;
|
|
|
|
cpu_tasks[0].task = current;
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
cpu_online_map = cpumask_of_cpu(0);
|
|
|
|
#endif
|
|
|
|
start_kernel();
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
[PATCH] uml: skas0 - separate kernel address space on stock hosts
UML has had two modes of operation - an insecure, slow mode (tt mode) in
which the kernel is mapped into every process address space which requires
no host kernel modifications, and a secure, faster mode (skas mode) in
which the UML kernel is in a separate host address space, which requires a
patch to the host kernel.
This patch implements something very close to skas mode for hosts which
don't support skas - I'm calling this skas0. It provides the security of
the skas host patch, and some of the performance gains.
The two main things that are provided by the skas patch, /proc/mm and
PTRACE_FAULTINFO, are implemented in a way that require no host patch.
For the remote address space changing stuff (mmap, munmap, and mprotect),
we set aside two pages in the process above its stack, one of which
contains a little bit of code which can call mmap et al.
To update the address space, the system call information (system call
number and arguments) are written to the stub page above the code. The
%esp is set to the beginning of the data, the %eip is set the the start of
the stub, and it repeatedly pops the information into its registers and
makes the system call until it sees a system call number of zero. This is
to amortize the cost of the context switch across multiple address space
updates.
When the updates are done, it SIGSTOPs itself, and the kernel process
continues what it was doing.
For a PTRACE_FAULTINFO replacement, we set up a SIGSEGV handler in the
child, and let it handle segfaults rather than nullifying them. The
handler is in the same page as the mmap stub. The second page is used as
the stack. The handler reads cr2 and err from the sigcontext, sticks them
at the base of the stack in a faultinfo struct, and SIGSTOPs itself. The
kernel then reads the faultinfo and handles the fault.
A complication on x86_64 is that this involves resetting the registers to
the segfault values when the process is inside the kill system call. This
breaks on x86_64 because %rcx will contain %rip because you tell SYSRET
where to return to by putting the value in %rcx. So, this corrupts $rcx on
return from the segfault. To work around this, I added an
arch_finish_segv, which on x86 does nothing, but which on x86_64 ptraces
the child back through the sigreturn. This causes %rcx to be restored by
sigreturn and avoids the corruption. Ultimately, I think I will replace
this with the trick of having it send itself a blocked signal which will be
unblocked by the sigreturn. This will allow it to be stopped just after
the sigreturn, and PTRACE_SYSCALLed without all the back-and-forth of
PTRACE_SYSCALLing it through sigreturn.
This runs on a stock host, so theoretically (and hopefully), tt mode isn't
needed any more. We need to make sure that this is better in every way
than tt mode, though. I'm concerned about the speed of address space
updates and page fault handling, since they involve extra round-trips to
the child. We can amortize the round-trip cost for large address space
updates by writing all of the operations to the data page and having the
child execute them all at the same time. This will help fork and exec, but
not page faults, since they involve only one page.
I can't think of any way to help page faults, except to add something like
PTRACE_FAULTINFO to the host. There is PTRACE_SIGINFO, but UML doesn't use
siginfo for SIGSEGV (or anything else) because there isn't enough
information in the siginfo struct to handle page faults (the faulting
operation type is missing). Adding that would make PTRACE_SIGINFO a usable
equivalent to PTRACE_FAULTINFO.
As for the code itself:
- The system call stub is in arch/um/kernel/sys-$(SUBARCH)/stub.S. It is
put in its own section of the binary along with stub_segv_handler in
arch/um/kernel/skas/process.c. This is manipulated with run_syscall_stub
in arch/um/kernel/skas/mem_user.c. syscall_stub will execute any system
call at all, but it's only used for mmap, munmap, and mprotect.
- The x86_64 stub calls sigreturn by hand rather than allowing the normal
sigreturn to happen, because the normal sigreturn is a SA_RESTORER in
UML's address space provided by libc. Needless to say, this is not
available in the child's address space. Also, it does a couple of odd
pops before that which restore the stack to the state it was in at the
time the signal handler was called.
- There is a new field in the arch mmu_context, which is now a union.
This is the pid to be manipulated rather than the /proc/mm file
descriptor. Code which deals with this now checks proc_mm to see whether
it should use the usual skas code or the new code.
- userspace_tramp is now used to create a new host process for every UML
process, rather than one per UML processor. It checks proc_mm and
ptrace_faultinfo to decide whether to map in the pages above its stack.
- start_userspace now makes CLONE_VM conditional on proc_mm since we need
separate address spaces now.
- switch_mm_skas now just sets userspace_pid[0] to the new pid rather
than PTRACE_SWITCH_MM. There is an addition to userspace which updates
its idea of the pid being manipulated each time around the loop. This is
important on exec, when the pid will change underneath userspace().
- The stub page has a pte, but it can't be mapped in using tlb_flush
because it is part of tlb_flush. This is why it's required for it to be
mapped in by userspace_tramp.
Other random things:
- The stub section in uml.lds.S is page aligned. This page is written
out to the backing vm file in setup_physmem because it is mapped from
there into user processes.
- There's some confusion with TASK_SIZE now that there are a couple of
extra pages that the process can't use. TASK_SIZE is considered by the
elf code to be the usable process memory, which is reasonable, so it is
decreased by two pages. This confuses the definition of
USER_PGDS_IN_LAST_PML4, making it too small because of the rounding down
of the uneven division. So we round it to the nearest PGDIR_SIZE rather
than the lower one.
- I added a missing PT_SYSCALL_ARG6_OFFSET macro.
- um_mmu.h was made into a userspace-usable file.
- proc_mm and ptrace_faultinfo are globals which say whether the host
supports these features.
- There is a bad interaction between the mm.nr_ptes check at the end of
exit_mmap, stack randomization, and skas0. exit_mmap will stop freeing
pages at the PGDIR_SIZE boundary after the last vma. If the stack isn't
on the last page table page, the last pte page won't be freed, as it
should be since the stub ptes are there, and exit_mmap will BUG because
there is an unfreed page. To get around this, TASK_SIZE is set to the
next lowest PGDIR_SIZE boundary and mm->nr_ptes is decremented after the
calls to init_stub_pte. This ensures that we know the process stack (and
all other process mappings) will be below the top page table page, and
thus we know that mm->nr_ptes will be one too many, and can be
decremented.
Things that need fixing:
- We may need better assurrences that the stub code is PIC.
- The stub pte is set up in init_new_context_skas.
- alloc_pgdir is probably the right place.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-08 00:56:49 +00:00
|
|
|
extern int userspace_pid[];
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
int start_uml_skas(void)
|
|
|
|
{
|
[PATCH] uml: skas0 - separate kernel address space on stock hosts
UML has had two modes of operation - an insecure, slow mode (tt mode) in
which the kernel is mapped into every process address space which requires
no host kernel modifications, and a secure, faster mode (skas mode) in
which the UML kernel is in a separate host address space, which requires a
patch to the host kernel.
This patch implements something very close to skas mode for hosts which
don't support skas - I'm calling this skas0. It provides the security of
the skas host patch, and some of the performance gains.
The two main things that are provided by the skas patch, /proc/mm and
PTRACE_FAULTINFO, are implemented in a way that require no host patch.
For the remote address space changing stuff (mmap, munmap, and mprotect),
we set aside two pages in the process above its stack, one of which
contains a little bit of code which can call mmap et al.
To update the address space, the system call information (system call
number and arguments) are written to the stub page above the code. The
%esp is set to the beginning of the data, the %eip is set the the start of
the stub, and it repeatedly pops the information into its registers and
makes the system call until it sees a system call number of zero. This is
to amortize the cost of the context switch across multiple address space
updates.
When the updates are done, it SIGSTOPs itself, and the kernel process
continues what it was doing.
For a PTRACE_FAULTINFO replacement, we set up a SIGSEGV handler in the
child, and let it handle segfaults rather than nullifying them. The
handler is in the same page as the mmap stub. The second page is used as
the stack. The handler reads cr2 and err from the sigcontext, sticks them
at the base of the stack in a faultinfo struct, and SIGSTOPs itself. The
kernel then reads the faultinfo and handles the fault.
A complication on x86_64 is that this involves resetting the registers to
the segfault values when the process is inside the kill system call. This
breaks on x86_64 because %rcx will contain %rip because you tell SYSRET
where to return to by putting the value in %rcx. So, this corrupts $rcx on
return from the segfault. To work around this, I added an
arch_finish_segv, which on x86 does nothing, but which on x86_64 ptraces
the child back through the sigreturn. This causes %rcx to be restored by
sigreturn and avoids the corruption. Ultimately, I think I will replace
this with the trick of having it send itself a blocked signal which will be
unblocked by the sigreturn. This will allow it to be stopped just after
the sigreturn, and PTRACE_SYSCALLed without all the back-and-forth of
PTRACE_SYSCALLing it through sigreturn.
This runs on a stock host, so theoretically (and hopefully), tt mode isn't
needed any more. We need to make sure that this is better in every way
than tt mode, though. I'm concerned about the speed of address space
updates and page fault handling, since they involve extra round-trips to
the child. We can amortize the round-trip cost for large address space
updates by writing all of the operations to the data page and having the
child execute them all at the same time. This will help fork and exec, but
not page faults, since they involve only one page.
I can't think of any way to help page faults, except to add something like
PTRACE_FAULTINFO to the host. There is PTRACE_SIGINFO, but UML doesn't use
siginfo for SIGSEGV (or anything else) because there isn't enough
information in the siginfo struct to handle page faults (the faulting
operation type is missing). Adding that would make PTRACE_SIGINFO a usable
equivalent to PTRACE_FAULTINFO.
As for the code itself:
- The system call stub is in arch/um/kernel/sys-$(SUBARCH)/stub.S. It is
put in its own section of the binary along with stub_segv_handler in
arch/um/kernel/skas/process.c. This is manipulated with run_syscall_stub
in arch/um/kernel/skas/mem_user.c. syscall_stub will execute any system
call at all, but it's only used for mmap, munmap, and mprotect.
- The x86_64 stub calls sigreturn by hand rather than allowing the normal
sigreturn to happen, because the normal sigreturn is a SA_RESTORER in
UML's address space provided by libc. Needless to say, this is not
available in the child's address space. Also, it does a couple of odd
pops before that which restore the stack to the state it was in at the
time the signal handler was called.
- There is a new field in the arch mmu_context, which is now a union.
This is the pid to be manipulated rather than the /proc/mm file
descriptor. Code which deals with this now checks proc_mm to see whether
it should use the usual skas code or the new code.
- userspace_tramp is now used to create a new host process for every UML
process, rather than one per UML processor. It checks proc_mm and
ptrace_faultinfo to decide whether to map in the pages above its stack.
- start_userspace now makes CLONE_VM conditional on proc_mm since we need
separate address spaces now.
- switch_mm_skas now just sets userspace_pid[0] to the new pid rather
than PTRACE_SWITCH_MM. There is an addition to userspace which updates
its idea of the pid being manipulated each time around the loop. This is
important on exec, when the pid will change underneath userspace().
- The stub page has a pte, but it can't be mapped in using tlb_flush
because it is part of tlb_flush. This is why it's required for it to be
mapped in by userspace_tramp.
Other random things:
- The stub section in uml.lds.S is page aligned. This page is written
out to the backing vm file in setup_physmem because it is mapped from
there into user processes.
- There's some confusion with TASK_SIZE now that there are a couple of
extra pages that the process can't use. TASK_SIZE is considered by the
elf code to be the usable process memory, which is reasonable, so it is
decreased by two pages. This confuses the definition of
USER_PGDS_IN_LAST_PML4, making it too small because of the rounding down
of the uneven division. So we round it to the nearest PGDIR_SIZE rather
than the lower one.
- I added a missing PT_SYSCALL_ARG6_OFFSET macro.
- um_mmu.h was made into a userspace-usable file.
- proc_mm and ptrace_faultinfo are globals which say whether the host
supports these features.
- There is a bad interaction between the mm.nr_ptes check at the end of
exit_mmap, stack randomization, and skas0. exit_mmap will stop freeing
pages at the PGDIR_SIZE boundary after the last vma. If the stack isn't
on the last page table page, the last pte page won't be freed, as it
should be since the stub ptes are there, and exit_mmap will BUG because
there is an unfreed page. To get around this, TASK_SIZE is set to the
next lowest PGDIR_SIZE boundary and mm->nr_ptes is decremented after the
calls to init_stub_pte. This ensures that we know the process stack (and
all other process mappings) will be below the top page table page, and
thus we know that mm->nr_ptes will be one too many, and can be
decremented.
Things that need fixing:
- We may need better assurrences that the stub code is PIC.
- The stub pte is set up in init_new_context_skas.
- alloc_pgdir is probably the right place.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-08 00:56:49 +00:00
|
|
|
if(proc_mm)
|
|
|
|
userspace_pid[0] = start_userspace(0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
init_new_thread_signals(1);
|
|
|
|
|
|
|
|
init_task.thread.request.u.thread.proc = start_kernel_proc;
|
|
|
|
init_task.thread.request.u.thread.arg = NULL;
|
2006-01-12 09:05:48 +00:00
|
|
|
return(start_idle_thread(task_stack_page(&init_task),
|
2005-04-16 22:20:36 +00:00
|
|
|
&init_task.thread.mode.skas.switch_buf,
|
|
|
|
&init_task.thread.mode.skas.fork_buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
int external_pid_skas(struct task_struct *task)
|
|
|
|
{
|
|
|
|
#warning Need to look up userspace_pid by cpu
|
|
|
|
return(userspace_pid[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int thread_pid_skas(struct task_struct *task)
|
|
|
|
{
|
|
|
|
#warning Need to look up userspace_pid by cpu
|
|
|
|
return(userspace_pid[0]);
|
|
|
|
}
|
[PATCH] uml: skas0 - separate kernel address space on stock hosts
UML has had two modes of operation - an insecure, slow mode (tt mode) in
which the kernel is mapped into every process address space which requires
no host kernel modifications, and a secure, faster mode (skas mode) in
which the UML kernel is in a separate host address space, which requires a
patch to the host kernel.
This patch implements something very close to skas mode for hosts which
don't support skas - I'm calling this skas0. It provides the security of
the skas host patch, and some of the performance gains.
The two main things that are provided by the skas patch, /proc/mm and
PTRACE_FAULTINFO, are implemented in a way that require no host patch.
For the remote address space changing stuff (mmap, munmap, and mprotect),
we set aside two pages in the process above its stack, one of which
contains a little bit of code which can call mmap et al.
To update the address space, the system call information (system call
number and arguments) are written to the stub page above the code. The
%esp is set to the beginning of the data, the %eip is set the the start of
the stub, and it repeatedly pops the information into its registers and
makes the system call until it sees a system call number of zero. This is
to amortize the cost of the context switch across multiple address space
updates.
When the updates are done, it SIGSTOPs itself, and the kernel process
continues what it was doing.
For a PTRACE_FAULTINFO replacement, we set up a SIGSEGV handler in the
child, and let it handle segfaults rather than nullifying them. The
handler is in the same page as the mmap stub. The second page is used as
the stack. The handler reads cr2 and err from the sigcontext, sticks them
at the base of the stack in a faultinfo struct, and SIGSTOPs itself. The
kernel then reads the faultinfo and handles the fault.
A complication on x86_64 is that this involves resetting the registers to
the segfault values when the process is inside the kill system call. This
breaks on x86_64 because %rcx will contain %rip because you tell SYSRET
where to return to by putting the value in %rcx. So, this corrupts $rcx on
return from the segfault. To work around this, I added an
arch_finish_segv, which on x86 does nothing, but which on x86_64 ptraces
the child back through the sigreturn. This causes %rcx to be restored by
sigreturn and avoids the corruption. Ultimately, I think I will replace
this with the trick of having it send itself a blocked signal which will be
unblocked by the sigreturn. This will allow it to be stopped just after
the sigreturn, and PTRACE_SYSCALLed without all the back-and-forth of
PTRACE_SYSCALLing it through sigreturn.
This runs on a stock host, so theoretically (and hopefully), tt mode isn't
needed any more. We need to make sure that this is better in every way
than tt mode, though. I'm concerned about the speed of address space
updates and page fault handling, since they involve extra round-trips to
the child. We can amortize the round-trip cost for large address space
updates by writing all of the operations to the data page and having the
child execute them all at the same time. This will help fork and exec, but
not page faults, since they involve only one page.
I can't think of any way to help page faults, except to add something like
PTRACE_FAULTINFO to the host. There is PTRACE_SIGINFO, but UML doesn't use
siginfo for SIGSEGV (or anything else) because there isn't enough
information in the siginfo struct to handle page faults (the faulting
operation type is missing). Adding that would make PTRACE_SIGINFO a usable
equivalent to PTRACE_FAULTINFO.
As for the code itself:
- The system call stub is in arch/um/kernel/sys-$(SUBARCH)/stub.S. It is
put in its own section of the binary along with stub_segv_handler in
arch/um/kernel/skas/process.c. This is manipulated with run_syscall_stub
in arch/um/kernel/skas/mem_user.c. syscall_stub will execute any system
call at all, but it's only used for mmap, munmap, and mprotect.
- The x86_64 stub calls sigreturn by hand rather than allowing the normal
sigreturn to happen, because the normal sigreturn is a SA_RESTORER in
UML's address space provided by libc. Needless to say, this is not
available in the child's address space. Also, it does a couple of odd
pops before that which restore the stack to the state it was in at the
time the signal handler was called.
- There is a new field in the arch mmu_context, which is now a union.
This is the pid to be manipulated rather than the /proc/mm file
descriptor. Code which deals with this now checks proc_mm to see whether
it should use the usual skas code or the new code.
- userspace_tramp is now used to create a new host process for every UML
process, rather than one per UML processor. It checks proc_mm and
ptrace_faultinfo to decide whether to map in the pages above its stack.
- start_userspace now makes CLONE_VM conditional on proc_mm since we need
separate address spaces now.
- switch_mm_skas now just sets userspace_pid[0] to the new pid rather
than PTRACE_SWITCH_MM. There is an addition to userspace which updates
its idea of the pid being manipulated each time around the loop. This is
important on exec, when the pid will change underneath userspace().
- The stub page has a pte, but it can't be mapped in using tlb_flush
because it is part of tlb_flush. This is why it's required for it to be
mapped in by userspace_tramp.
Other random things:
- The stub section in uml.lds.S is page aligned. This page is written
out to the backing vm file in setup_physmem because it is mapped from
there into user processes.
- There's some confusion with TASK_SIZE now that there are a couple of
extra pages that the process can't use. TASK_SIZE is considered by the
elf code to be the usable process memory, which is reasonable, so it is
decreased by two pages. This confuses the definition of
USER_PGDS_IN_LAST_PML4, making it too small because of the rounding down
of the uneven division. So we round it to the nearest PGDIR_SIZE rather
than the lower one.
- I added a missing PT_SYSCALL_ARG6_OFFSET macro.
- um_mmu.h was made into a userspace-usable file.
- proc_mm and ptrace_faultinfo are globals which say whether the host
supports these features.
- There is a bad interaction between the mm.nr_ptes check at the end of
exit_mmap, stack randomization, and skas0. exit_mmap will stop freeing
pages at the PGDIR_SIZE boundary after the last vma. If the stack isn't
on the last page table page, the last pte page won't be freed, as it
should be since the stub ptes are there, and exit_mmap will BUG because
there is an unfreed page. To get around this, TASK_SIZE is set to the
next lowest PGDIR_SIZE boundary and mm->nr_ptes is decremented after the
calls to init_stub_pte. This ensures that we know the process stack (and
all other process mappings) will be below the top page table page, and
thus we know that mm->nr_ptes will be one too many, and can be
decremented.
Things that need fixing:
- We may need better assurrences that the stub code is PIC.
- The stub pte is set up in init_new_context_skas.
- alloc_pgdir is probably the right place.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-08 00:56:49 +00:00
|
|
|
|
|
|
|
void kill_off_processes_skas(void)
|
|
|
|
{
|
|
|
|
if(proc_mm)
|
|
|
|
#warning need to loop over userspace_pids in kill_off_processes_skas
|
|
|
|
os_kill_ptraced_process(userspace_pid[0], 1);
|
|
|
|
else {
|
|
|
|
struct task_struct *p;
|
|
|
|
int pid, me;
|
|
|
|
|
|
|
|
me = os_getpid();
|
|
|
|
for_each_process(p){
|
|
|
|
if(p->mm == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pid = p->mm->context.skas.id.u.pid;
|
|
|
|
os_kill_ptraced_process(pid, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long current_stub_stack(void)
|
|
|
|
{
|
|
|
|
if(current->mm == NULL)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
return(current->mm->context.skas.id.stack);
|
|
|
|
}
|