Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 6 | #include "linux/stddef.h" |
| 7 | #include "linux/fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include "linux/smp_lock.h" |
| 9 | #include "linux/ptrace.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 10 | #include "linux/sched.h" |
| 11 | #include "asm/current.h" |
| 12 | #include "asm/processor.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "asm/uaccess.h" |
Jeff Dike | 54ae36f | 2007-10-16 01:27:33 -0700 | [diff] [blame] | 14 | #include "as-layout.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include "mem_user.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 16 | #include "skas.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include "os.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | void flush_thread(void) |
| 20 | { |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 21 | void *data = NULL; |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 22 | int ret; |
| 23 | |
Paolo 'Blaisorblade' Giarrusso | aa6758d | 2006-03-31 02:30:22 -0800 | [diff] [blame] | 24 | arch_flush_thread(¤t->thread.arch); |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 25 | |
Jeff Dike | 3963333 | 2008-02-04 22:31:01 -0800 | [diff] [blame^] | 26 | ret = unmap(¤t->mm->context.id, 0, STUB_START, 0, &data); |
| 27 | ret = ret || unmap(¤t->mm->context.id, STUB_END, |
| 28 | TASK_SIZE - STUB_END, 1, &data); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 29 | if (ret) { |
| 30 | printk(KERN_ERR "flush_thread - clearing address space failed, " |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 31 | "err = %d\n", ret); |
| 32 | force_sig(SIGKILL, current); |
| 33 | } |
| 34 | |
Jeff Dike | 6c738ff | 2007-10-16 01:27:06 -0700 | [diff] [blame] | 35 | __switch_mm(¤t->mm->context.id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp) |
| 39 | { |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 40 | set_fs(USER_DS); |
| 41 | PT_REGS_IP(regs) = eip; |
| 42 | PT_REGS_SP(regs) = esp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 45 | #ifdef CONFIG_TTY_LOG |
| 46 | extern void log_exec(char **argv, void *tty); |
| 47 | #endif |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | static long execve1(char *file, char __user * __user *argv, |
Paolo 'Blaisorblade' Giarrusso | 42947cb | 2006-02-01 03:06:29 -0800 | [diff] [blame] | 50 | char __user *__user *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 52 | long error; |
Jeff Dike | f979522 | 2007-02-10 01:44:03 -0800 | [diff] [blame] | 53 | #ifdef CONFIG_TTY_LOG |
Peter Zijlstra | 24ec839 | 2006-12-08 02:36:04 -0800 | [diff] [blame] | 54 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Alan Cox | b1fc0b1 | 2006-09-25 23:33:08 -0700 | [diff] [blame] | 56 | mutex_lock(&tty_mutex); |
Peter Zijlstra | 24ec839 | 2006-12-08 02:36:04 -0800 | [diff] [blame] | 57 | tty = get_current_tty(); |
| 58 | if (tty) |
| 59 | log_exec(argv, tty); |
Alan Cox | b1fc0b1 | 2006-09-25 23:33:08 -0700 | [diff] [blame] | 60 | mutex_unlock(&tty_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #endif |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 62 | error = do_execve(file, argv, env, ¤t->thread.regs); |
| 63 | if (error == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | task_lock(current); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 65 | current->ptrace &= ~PT_DTRACE; |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 66 | #ifdef SUBARCH_EXECVE1 |
| 67 | SUBARCH_EXECVE1(¤t->thread.regs.regs); |
| 68 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | task_unlock(current); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 70 | } |
| 71 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | long um_execve(char *file, char __user *__user *argv, char __user *__user *env) |
| 75 | { |
| 76 | long err; |
| 77 | |
| 78 | err = execve1(file, argv, env); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 79 | if (!err) |
Jeff Dike | fab95c5 | 2007-10-16 01:27:05 -0700 | [diff] [blame] | 80 | UML_LONGJMP(current->thread.exec_buf, 1); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 81 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 84 | long sys_execve(char __user *file, char __user *__user *argv, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | char __user *__user *env) |
| 86 | { |
| 87 | long error; |
| 88 | char *filename; |
| 89 | |
| 90 | lock_kernel(); |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 91 | filename = getname(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | error = PTR_ERR(filename); |
| 93 | if (IS_ERR(filename)) goto out; |
| 94 | error = execve1(filename, argv, env); |
| 95 | putname(filename); |
| 96 | out: |
| 97 | unlock_kernel(); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 98 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |