Commit 44583d38 authored by Jeff Dike's avatar Jeff Dike

Merge uml.karaya.com:/home/jdike/linux/2.5/skas-2.5

into uml.karaya.com:/home/jdike/linux/2.5/skas-2.5-linus
parents 645dbacc 8bf1412a
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "helper.h" #include "helper.h"
#include "mconsole.h" #include "mconsole.h"
#include "os.h" #include "os.h"
#include "choose-mode.h"
#include "mode.h"
struct dog_data { struct dog_data {
int stdin; int stdin;
...@@ -63,7 +65,8 @@ int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock) ...@@ -63,7 +65,8 @@ int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock)
args = mconsole_args; args = mconsole_args;
} }
else { else {
sprintf(pid_buf, "%d", tracing_pid); /* XXX The os_getpid() is not SMP correct */
sprintf(pid_buf, "%d", CHOOSE_MODE(tracing_pid, os_getpid()));
args = pid_args; args = pid_args;
} }
......
...@@ -32,8 +32,8 @@ struct port_list { ...@@ -32,8 +32,8 @@ struct port_list {
struct port_dev { struct port_dev {
struct port_list *port; struct port_list *port;
int fd; int fd;
int helper_pid; int helper_pid;
int telnetd_pid; int telnetd_pid;
}; };
struct connection { struct connection {
...@@ -50,7 +50,7 @@ static void pipe_interrupt(int irq, void *data, struct pt_regs *regs) ...@@ -50,7 +50,7 @@ static void pipe_interrupt(int irq, void *data, struct pt_regs *regs)
struct connection *conn = data; struct connection *conn = data;
int fd; int fd;
fd = os_rcv_fd(conn->socket[0], &conn->helper_pid); fd = os_rcv_fd(conn->socket[0], &conn->helper_pid);
if(fd < 0){ if(fd < 0){
if(fd == -EAGAIN) if(fd == -EAGAIN)
return; return;
...@@ -99,7 +99,8 @@ static int port_accept(struct port_list *port) ...@@ -99,7 +99,8 @@ static int port_accept(struct port_list *port)
} }
list_add(&conn->list, &port->pending); list_add(&conn->list, &port->pending);
return(1); ret = 1;
goto out;
out_free: out_free:
kfree(conn); kfree(conn);
...@@ -274,8 +275,6 @@ void port_kern_free(void *d) ...@@ -274,8 +275,6 @@ void port_kern_free(void *d)
{ {
struct port_dev *dev = d; struct port_dev *dev = d;
if(dev->helper_pid != -1) os_kill_process(dev->helper_pid, 0);
if(dev->telnetd_pid != -1) os_kill_process(dev->telnetd_pid, 0);
kfree(dev); kfree(dev);
} }
......
...@@ -120,16 +120,6 @@ static int signal_tramp(void *arg) ...@@ -120,16 +120,6 @@ static int signal_tramp(void *arg)
return((*proc)(NULL)); return((*proc)(NULL));
} }
static void last_ditch_exit(int sig)
{
kmalloc_ok = 0;
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
uml_cleanup();
exit(1);
}
static void sleeping_process_signal(int pid, int sig) static void sleeping_process_signal(int pid, int sig)
{ {
switch(sig){ switch(sig){
...@@ -214,9 +204,6 @@ int tracer(int (*init_proc)(void *), void *sp) ...@@ -214,9 +204,6 @@ int tracer(int (*init_proc)(void *), void *sp)
signal(SIGSEGV, (sighandler_t) tracer_segv); signal(SIGSEGV, (sighandler_t) tracer_segv);
signal(SIGUSR1, signal_usr1); signal(SIGUSR1, signal_usr1);
set_handler(SIGINT, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
set_handler(SIGTERM, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
set_handler(SIGHUP, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
if(debug_trace){ if(debug_trace){
printf("Tracing thread pausing to be attached\n"); printf("Tracing thread pausing to be attached\n");
stop(); stop();
......
...@@ -110,12 +110,14 @@ unsigned long start_vm; ...@@ -110,12 +110,14 @@ unsigned long start_vm;
unsigned long end_vm; unsigned long end_vm;
int ncpus = 1; int ncpus = 1;
#ifdef CONFIG_MODE_TT
/* Pointer set in linux_main, the array itself is private to each thread, /* Pointer set in linux_main, the array itself is private to each thread,
* and changed at address space creation time so this poses no concurrency * and changed at address space creation time so this poses no concurrency
* problems. * problems.
*/ */
static char *argv1_begin = NULL; static char *argv1_begin = NULL;
static char *argv1_end = NULL; static char *argv1_end = NULL;
#endif
/* Set in early boot */ /* Set in early boot */
static int have_root __initdata = 0; static int have_root __initdata = 0;
...@@ -123,6 +125,7 @@ long physmem_size = 32 * 1024 * 1024; ...@@ -123,6 +125,7 @@ long physmem_size = 32 * 1024 * 1024;
void set_cmdline(char *cmd) void set_cmdline(char *cmd)
{ {
#ifdef CONFIG_MODE_TT
char *umid, *ptr; char *umid, *ptr;
if(CHOOSE_MODE(honeypot, 0)) return; if(CHOOSE_MODE(honeypot, 0)) return;
...@@ -139,6 +142,7 @@ void set_cmdline(char *cmd) ...@@ -139,6 +142,7 @@ void set_cmdline(char *cmd)
snprintf(ptr, (argv1_end - ptr) * sizeof(*ptr), " [%s]", cmd); snprintf(ptr, (argv1_end - ptr) * sizeof(*ptr), " [%s]", cmd);
memset(argv1_begin + strlen(argv1_begin), '\0', memset(argv1_begin + strlen(argv1_begin), '\0',
argv1_end - argv1_begin - strlen(argv1_begin)); argv1_end - argv1_begin - strlen(argv1_begin));
#endif
} }
static char *usage_string = static char *usage_string =
...@@ -199,23 +203,28 @@ static int __init mode_tt_setup(char *line, int *add) ...@@ -199,23 +203,28 @@ static int __init mode_tt_setup(char *line, int *add)
return(0); return(0);
} }
__uml_setup("mode=tt", mode_tt_setup,
"mode=tt\n"
" When both CONFIG_MODE_TT and CONFIG_MODE_SKAS are enabled, this option\n"
" forces UML to run in tt (tracing thread) mode. It is not the default\n"
" because it's slower and less secure than skas mode.\n\n"
);
#else #else
#ifdef CONFIG_MODE_SKAS #ifdef CONFIG_MODE_SKAS
#define DEFAULT_TT 0 #define DEFAULT_TT 0
static int __init mode_tt_setup(char *line, int *add)
{
printk("CONFIG_MODE_TT disabled - 'mode=tt' ignored\n");
return(0);
}
#else #else
#ifdef CONFIG_MODE_TT #ifdef CONFIG_MODE_TT
#define DEFAULT_TT 1 #define DEFAULT_TT 1
static int __init mode_tt_setup(char *line, int *add)
{
printk("CONFIG_MODE_SKAS disabled - 'mode=tt' redundant\n");
return(0);
}
#else #else
#error Either CONFIG_MODE_TT or CONFIG_MODE_SKAS must be enabled #error Either CONFIG_MODE_TT or CONFIG_MODE_SKAS must be enabled
...@@ -224,6 +233,13 @@ __uml_setup("mode=tt", mode_tt_setup, ...@@ -224,6 +233,13 @@ __uml_setup("mode=tt", mode_tt_setup,
#endif #endif
#endif #endif
__uml_setup("mode=tt", mode_tt_setup,
"mode=tt\n"
" When both CONFIG_MODE_TT and CONFIG_MODE_SKAS are enabled, this option\n"
" forces UML to run in tt (tracing thread) mode. It is not the default\n"
" because it's slower and less secure than skas mode.\n\n"
);
int mode_tt = DEFAULT_TT; int mode_tt = DEFAULT_TT;
static int __init Usage(char *line, int *add) static int __init Usage(char *line, int *add)
...@@ -307,8 +323,10 @@ int linux_main(int argc, char **argv) ...@@ -307,8 +323,10 @@ int linux_main(int argc, char **argv)
setup_machinename(system_utsname.machine); setup_machinename(system_utsname.machine);
#ifdef CONFIG_MODE_TT
argv1_begin = argv[1]; argv1_begin = argv[1];
argv1_end = &argv[1][strlen(argv[1])]; argv1_end = &argv[1][strlen(argv[1])];
#endif
set_usable_vm(uml_physmem, get_kmem_end()); set_usable_vm(uml_physmem, get_kmem_end());
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
#include "user_util.h" #include "user_util.h"
#include "kern_util.h" #include "kern_util.h"
#include "mem_user.h" #include "mem_user.h"
#include "signal_user.h"
#include "user.h" #include "user.h"
#include "init.h" #include "init.h"
#include "mode.h" #include "mode.h"
#include "choose-mode.h" #include "choose-mode.h"
#include "uml-config.h"
/* Set in set_stklim, which is called from main and __wrap_malloc. /* Set in set_stklim, which is called from main and __wrap_malloc.
* __wrap_malloc only calls it if main hasn't started. * __wrap_malloc only calls it if main hasn't started.
...@@ -32,11 +34,6 @@ char *linux_prog; ...@@ -32,11 +34,6 @@ char *linux_prog;
#define STACKSIZE (8 * 1024 * 1024) #define STACKSIZE (8 * 1024 * 1024)
#define THREAD_NAME_LEN (256) #define THREAD_NAME_LEN (256)
/* Never changed */
static char padding[THREAD_NAME_LEN] = {
[ 0 ... THREAD_NAME_LEN - 2] = ' ', '\0'
};
static void set_stklim(void) static void set_stklim(void)
{ {
struct rlimit lim; struct rlimit lim;
...@@ -66,26 +63,43 @@ static __init void do_uml_initcalls(void) ...@@ -66,26 +63,43 @@ static __init void do_uml_initcalls(void)
} }
} }
static void last_ditch_exit(int sig)
{
CHOOSE_MODE(kmalloc_ok = 0, (void) 0);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
uml_cleanup();
exit(1);
}
extern int uml_exitcode; extern int uml_exitcode;
int main(int argc, char **argv, char **envp) int main(int argc, char **argv, char **envp)
{ {
char **new_argv;
sigset_t mask; sigset_t mask;
int ret, i; int ret, i;
char **new_argv;
/* Enable all signals - in some environments, we can enter with /* Enable all signals except SIGIO - in some environments, we can
* some signals blocked * enter with some signals blocked
*/ */
sigemptyset(&mask); sigemptyset(&mask);
sigaddset(&mask, SIGIO);
if(sigprocmask(SIG_SETMASK, &mask, NULL) < 0){ if(sigprocmask(SIG_SETMASK, &mask, NULL) < 0){
perror("sigprocmask"); perror("sigprocmask");
exit(1); exit(1);
} }
#ifdef CONFIG_MODE_TT
/* Allocate memory for thread command lines */ /* Allocate memory for thread command lines */
if(argc < 2 || strlen(argv[1]) < THREAD_NAME_LEN - 1){ if(argc < 2 || strlen(argv[1]) < THREAD_NAME_LEN - 1){
char padding[THREAD_NAME_LEN] = {
[ 0 ... THREAD_NAME_LEN - 2] = ' ', '\0'
};
new_argv = malloc((argc + 2) * sizeof(char*)); new_argv = malloc((argc + 2) * sizeof(char*));
if(!new_argv) { if(!new_argv) {
perror("Allocating extended argv"); perror("Allocating extended argv");
...@@ -103,6 +117,7 @@ int main(int argc, char **argv, char **envp) ...@@ -103,6 +117,7 @@ int main(int argc, char **argv, char **envp)
perror("execing with extended args"); perror("execing with extended args");
exit(1); exit(1);
} }
#endif
linux_prog = argv[0]; linux_prog = argv[0];
...@@ -120,6 +135,10 @@ int main(int argc, char **argv, char **envp) ...@@ -120,6 +135,10 @@ int main(int argc, char **argv, char **envp)
} }
new_argv[argc] = NULL; new_argv[argc] = NULL;
set_handler(SIGINT, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
set_handler(SIGTERM, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
set_handler(SIGHUP, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
do_uml_initcalls(); do_uml_initcalls();
ret = linux_main(argc, argv); ret = linux_main(argc, argv);
...@@ -141,8 +160,10 @@ extern void *__real_malloc(int); ...@@ -141,8 +160,10 @@ extern void *__real_malloc(int);
void *__wrap_malloc(int size) void *__wrap_malloc(int size)
{ {
if(CAN_KMALLOC()) return(um_kmalloc(size)); if(CAN_KMALLOC())
else return(__real_malloc(size)); return(um_kmalloc(size));
else
return(__real_malloc(size));
} }
void *__wrap_calloc(int n, int size) void *__wrap_calloc(int n, int size)
......
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