aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/kernel/skas
diff options
context:
space:
mode:
authorBodo Stroesser <bstroesser@fujitsu-siemens.com>2005-09-03 18:57:50 -0400
committerLinus Torvalds <torvalds@evo.osdl.org>2005-09-05 03:06:24 -0400
commit07bf731e4b95d7c9ea9dbacd1fc4a041120dfffb (patch)
tree25ae7f2000421d45e484abac0b7252809476c0d0 /arch/um/kernel/skas
parent8b51304ed3184826fb262c1e9d3e58b0b00fd083 (diff)
[PATCH] uml: skas0 stubs now check system call return values
Change syscall-stub's data to include a "expected retval". Stub now checks syscalls retval and aborts execution of syscall list, if retval != expected retval. run_syscall_stub prints the data of the failed syscall, using the data pointer and retval written by the stub to the beginning of the stack. one_syscall_stub is removed, to simplify code, because only some instructions are saved by one_syscall_stub, no host-syscall. Using the stub with additional data (modify_ldt via stub) is prepared also. Signed-off-by: Bodo Stroesser <bstroesser@fujitsu-siemens.com> Signed-off-by: Jeff Dike <jdike@addtoit.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/kernel/skas')
-rw-r--r--arch/um/kernel/skas/include/skas.h33
-rw-r--r--arch/um/kernel/skas/mem_user.c234
-rw-r--r--arch/um/kernel/skas/tlb.c31
3 files changed, 168 insertions, 130 deletions
diff --git a/arch/um/kernel/skas/include/skas.h b/arch/um/kernel/skas/include/skas.h
index 03c9d99e15e4..060934740f9f 100644
--- a/arch/um/kernel/skas/include/skas.h
+++ b/arch/um/kernel/skas/include/skas.h
@@ -24,14 +24,14 @@ extern void new_thread_proc(void *stack, void (*handler)(int sig));
24extern void remove_sigstack(void); 24extern void remove_sigstack(void);
25extern void new_thread_handler(int sig); 25extern void new_thread_handler(int sig);
26extern void handle_syscall(union uml_pt_regs *regs); 26extern void handle_syscall(union uml_pt_regs *regs);
27extern void *map(struct mm_id * mm_idp, unsigned long virt, 27extern int map(struct mm_id * mm_idp, unsigned long virt,
28 unsigned long len, int r, int w, int x, int phys_fd, 28 unsigned long len, int r, int w, int x, int phys_fd,
29 unsigned long long offset, int done, void *data); 29 unsigned long long offset, int done, void **data);
30extern void *unmap(struct mm_id * mm_idp, void *addr, 30extern int unmap(struct mm_id * mm_idp, void *addr, unsigned long len,
31 unsigned long len, int done, void *data); 31 int done, void **data);
32extern void *protect(struct mm_id * mm_idp, unsigned long addr, 32extern int protect(struct mm_id * mm_idp, unsigned long addr,
33 unsigned long len, int r, int w, int x, int done, 33 unsigned long len, int r, int w, int x, int done,
34 void *data); 34 void **data);
35extern void user_signal(int sig, union uml_pt_regs *regs, int pid); 35extern void user_signal(int sig, union uml_pt_regs *regs, int pid);
36extern int new_mm(int from, unsigned long stack); 36extern int new_mm(int from, unsigned long stack);
37extern int start_userspace(unsigned long stub_stack); 37extern int start_userspace(unsigned long stub_stack);
@@ -39,16 +39,11 @@ extern int copy_context_skas0(unsigned long stack, int pid);
39extern void get_skas_faultinfo(int pid, struct faultinfo * fi); 39extern void get_skas_faultinfo(int pid, struct faultinfo * fi);
40extern long execute_syscall_skas(void *r); 40extern long execute_syscall_skas(void *r);
41extern unsigned long current_stub_stack(void); 41extern unsigned long current_stub_stack(void);
42extern long run_syscall_stub(struct mm_id * mm_idp,
43 int syscall, unsigned long *args, long expected,
44 void **addr, int done);
45extern long syscall_stub_data(struct mm_id * mm_idp,
46 unsigned long *data, int data_count,
47 void **addr, void **stub_addr);
42 48
43#endif 49#endif
44
45/*
46 * Overrides for Emacs so that we follow Linus's tabbing style.
47 * Emacs will notice this stuff at the end of the file and automatically
48 * adjust the settings for this buffer only. This must remain at the end
49 * of the file.
50 * ---------------------------------------------------------------------------
51 * Local variables:
52 * c-file-style: "linux"
53 * End:
54 */
diff --git a/arch/um/kernel/skas/mem_user.c b/arch/um/kernel/skas/mem_user.c
index c976320ebe84..1d89640bd502 100644
--- a/arch/um/kernel/skas/mem_user.c
+++ b/arch/um/kernel/skas/mem_user.c
@@ -5,13 +5,14 @@
5 5
6#include <signal.h> 6#include <signal.h>
7#include <errno.h> 7#include <errno.h>
8#include <string.h>
8#include <sys/mman.h> 9#include <sys/mman.h>
9#include <sys/wait.h> 10#include <sys/wait.h>
10#include <asm/page.h> 11#include <asm/page.h>
11#include <asm/unistd.h> 12#include <asm/unistd.h>
12#include "mem_user.h" 13#include "mem_user.h"
13#include "mem.h" 14#include "mem.h"
14#include "mm_id.h" 15#include "skas.h"
15#include "user.h" 16#include "user.h"
16#include "os.h" 17#include "os.h"
17#include "proc_mm.h" 18#include "proc_mm.h"
@@ -23,56 +24,99 @@
23#include "uml-config.h" 24#include "uml-config.h"
24#include "sysdep/ptrace.h" 25#include "sysdep/ptrace.h"
25#include "sysdep/stub.h" 26#include "sysdep/stub.h"
26#include "skas.h"
27 27
28extern unsigned long syscall_stub, batch_syscall_stub, __syscall_stub_start; 28extern unsigned long batch_syscall_stub, __syscall_stub_start;
29 29
30extern void wait_stub_done(int pid, int sig, char * fname); 30extern void wait_stub_done(int pid, int sig, char * fname);
31 31
32static inline unsigned long *check_init_stack(struct mm_id * mm_idp,
33 unsigned long *stack)
34{
35 if(stack == NULL){
36 stack = (unsigned long *) mm_idp->stack + 2;
37 *stack = 0;
38 }
39 return stack;
40}
41
42extern int proc_mm;
43
32int single_count = 0; 44int single_count = 0;
45int multi_count = 0;
46int multi_op_count = 0;
33 47
34static long one_syscall_stub(struct mm_id * mm_idp, int syscall, 48static long do_syscall_stub(struct mm_id *mm_idp, void **addr)
35 unsigned long *args)
36{ 49{
50 unsigned long regs[MAX_REG_NR];
51 unsigned long *data;
52 unsigned long *syscall;
53 long ret, offset;
37 int n, pid = mm_idp->u.pid; 54 int n, pid = mm_idp->u.pid;
38 unsigned long regs[MAX_REG_NR]; 55
56 if(proc_mm)
57#warning Need to look up userspace_pid by cpu
58 pid = userspace_pid[0];
59
60 multi_count++;
39 61
40 get_safe_registers(regs); 62 get_safe_registers(regs);
41 regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE + 63 regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE +
42 ((unsigned long) &syscall_stub - 64 ((unsigned long) &batch_syscall_stub -
43 (unsigned long) &__syscall_stub_start); 65 (unsigned long) &__syscall_stub_start);
44 /* XXX Don't have a define for starting a syscall */ 66 n = ptrace_setregs(pid, regs);
45 regs[REGS_SYSCALL_NR] = syscall; 67 if(n < 0)
46 regs[REGS_SYSCALL_ARG1] = args[0]; 68 panic("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n",
47 regs[REGS_SYSCALL_ARG2] = args[1]; 69 n);
48 regs[REGS_SYSCALL_ARG3] = args[2]; 70
49 regs[REGS_SYSCALL_ARG4] = args[3]; 71 wait_stub_done(pid, 0, "do_syscall_stub");
50 regs[REGS_SYSCALL_ARG5] = args[4]; 72
51 regs[REGS_SYSCALL_ARG6] = args[5]; 73 /* When the stub stops, we find the following values on the
52 n = ptrace_setregs(pid, regs); 74 * beginning of the stack:
53 if(n < 0){ 75 * (long )return_value
54 printk("one_syscall_stub : PTRACE_SETREGS failed, " 76 * (long )offset to failed sycall-data (0, if no error)
55 "errno = %d\n", n); 77 */
56 return(n); 78 ret = *((unsigned long *) mm_idp->stack);
79 offset = *((unsigned long *) mm_idp->stack + 1);
80 if (offset) {
81 data = (unsigned long *)(mm_idp->stack +
82 offset - UML_CONFIG_STUB_DATA);
83 syscall = (unsigned long *)((unsigned long)data + data[0]);
84 printk("do_syscall_stub: syscall %ld failed, return value = "
85 "0x%lx, expected return value = 0x%lx\n",
86 syscall[0], ret, syscall[7]);
87 printk(" syscall parameters: "
88 "0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
89 syscall[1], syscall[2], syscall[3],
90 syscall[4], syscall[5], syscall[6]);
91 for(n = 1; n < data[0]/sizeof(long); n++) {
92 if(n == 1)
93 printk(" additional syscall data:");
94 if(n % 4 == 1)
95 printk("\n ");
96 printk(" 0x%lx", data[n]);
97 }
98 if(n > 1)
99 printk("\n");
57 } 100 }
101 else ret = 0;
58 102
59 wait_stub_done(pid, 0, "one_syscall_stub"); 103 *addr = check_init_stack(mm_idp, NULL);
60 104
61 return(*((unsigned long *) mm_idp->stack)); 105 return ret;
62} 106}
63 107
64int multi_count = 0; 108long run_syscall_stub(struct mm_id * mm_idp, int syscall,
65int multi_op_count = 0; 109 unsigned long *args, long expected, void **addr,
66 110 int done)
67static long many_syscall_stub(struct mm_id * mm_idp, int syscall,
68 unsigned long *args, int done, void **addr_out)
69{ 111{
70 unsigned long regs[MAX_REG_NR], *stack; 112 unsigned long *stack = check_init_stack(mm_idp, *addr);
71 int n, pid = mm_idp->u.pid; 113
114 if(done && *addr == NULL)
115 single_count++;
116
117 *stack += sizeof(long);
118 stack += *stack / sizeof(long);
72 119
73 stack = *addr_out;
74 if(stack == NULL)
75 stack = (unsigned long *) current_stub_stack();
76 *stack++ = syscall; 120 *stack++ = syscall;
77 *stack++ = args[0]; 121 *stack++ = args[0];
78 *stack++ = args[1]; 122 *stack++ = args[1];
@@ -80,53 +124,55 @@ static long many_syscall_stub(struct mm_id * mm_idp, int syscall,
80 *stack++ = args[3]; 124 *stack++ = args[3];
81 *stack++ = args[4]; 125 *stack++ = args[4];
82 *stack++ = args[5]; 126 *stack++ = args[5];
127 *stack++ = expected;
83 *stack = 0; 128 *stack = 0;
84 multi_op_count++; 129 multi_op_count++;
85 130
86 if(!done && ((((unsigned long) stack) & ~PAGE_MASK) < 131 if(!done && ((((unsigned long) stack) & ~PAGE_MASK) <
87 PAGE_SIZE - 8 * sizeof(long))){ 132 PAGE_SIZE - 10 * sizeof(long))){
88 *addr_out = stack; 133 *addr = stack;
89 return 0; 134 return 0;
90 } 135 }
91 136
92 multi_count++; 137 return do_syscall_stub(mm_idp, addr);
93 get_safe_registers(regs); 138}
94 regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE +
95 ((unsigned long) &batch_syscall_stub -
96 (unsigned long) &__syscall_stub_start);
97 regs[REGS_SP_INDEX] = UML_CONFIG_STUB_DATA;
98 139
99 n = ptrace_setregs(pid, regs); 140long syscall_stub_data(struct mm_id * mm_idp,
100 if(n < 0){ 141 unsigned long *data, int data_count,
101 printk("many_syscall_stub : PTRACE_SETREGS failed, " 142 void **addr, void **stub_addr)
102 "errno = %d\n", n); 143{
103 return(n); 144 unsigned long *stack;
104 } 145 int ret = 0;
146
147 /* If *addr still is uninitialized, it *must* contain NULL.
148 * Thus in this case do_syscall_stub correctly won't be called.
149 */
150 if((((unsigned long) *addr) & ~PAGE_MASK) >=
151 PAGE_SIZE - (10 + data_count) * sizeof(long)) {
152 ret = do_syscall_stub(mm_idp, addr);
153 /* in case of error, don't overwrite data on stack */
154 if(ret)
155 return ret;
156 }
105 157
106 wait_stub_done(pid, 0, "many_syscall_stub"); 158 stack = check_init_stack(mm_idp, *addr);
107 stack = (unsigned long *) mm_idp->stack; 159 *addr = stack;
108 160
109 *addr_out = stack; 161 *stack = data_count * sizeof(long);
110 return(*stack);
111}
112 162
113static long run_syscall_stub(struct mm_id * mm_idp, int syscall, 163 memcpy(stack + 1, data, data_count * sizeof(long));
114 unsigned long *args, void **addr, int done)
115{
116 long res;
117 164
118 if((*addr == NULL) && done) 165 *stub_addr = (void *)(((unsigned long)(stack + 1) & ~PAGE_MASK) +
119 res = one_syscall_stub(mm_idp, syscall, args); 166 UML_CONFIG_STUB_DATA);
120 else res = many_syscall_stub(mm_idp, syscall, args, done, addr);
121 167
122 return res; 168 return 0;
123} 169}
124 170
125void *map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, 171int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len,
126 int r, int w, int x, int phys_fd, unsigned long long offset, 172 int r, int w, int x, int phys_fd, unsigned long long offset,
127 int done, void *data) 173 int done, void **data)
128{ 174{
129 int prot, n; 175 int prot, ret;
130 176
131 prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | 177 prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
132 (x ? PROT_EXEC : 0); 178 (x ? PROT_EXEC : 0);
@@ -146,29 +192,27 @@ void *map(struct mm_id * mm_idp, unsigned long virt, unsigned long len,
146 .fd = phys_fd, 192 .fd = phys_fd,
147 .offset= offset 193 .offset= offset
148 } } } ); 194 } } } );
149 n = os_write_file(fd, &map, sizeof(map)); 195 ret = os_write_file(fd, &map, sizeof(map));
150 if(n != sizeof(map)) 196 if(ret != sizeof(map))
151 printk("map : /proc/mm map failed, err = %d\n", -n); 197 printk("map : /proc/mm map failed, err = %d\n", -ret);
198 else ret = 0;
152 } 199 }
153 else { 200 else {
154 long res;
155 unsigned long args[] = { virt, len, prot, 201 unsigned long args[] = { virt, len, prot,
156 MAP_SHARED | MAP_FIXED, phys_fd, 202 MAP_SHARED | MAP_FIXED, phys_fd,
157 MMAP_OFFSET(offset) }; 203 MMAP_OFFSET(offset) };
158 204
159 res = run_syscall_stub(mm_idp, STUB_MMAP_NR, args, 205 ret = run_syscall_stub(mm_idp, STUB_MMAP_NR, args, virt,
160 &data, done); 206 data, done);
161 if((void *) res == MAP_FAILED)
162 printk("mmap stub failed, errno = %d\n", res);
163 } 207 }
164 208
165 return data; 209 return ret;
166} 210}
167 211
168void *unmap(struct mm_id * mm_idp, void *addr, unsigned long len, int done, 212int unmap(struct mm_id * mm_idp, void *addr, unsigned long len, int done,
169 void *data) 213 void **data)
170{ 214{
171 int n; 215 int ret;
172 216
173 if(proc_mm){ 217 if(proc_mm){
174 struct proc_mm_op unmap; 218 struct proc_mm_op unmap;
@@ -180,29 +224,29 @@ void *unmap(struct mm_id * mm_idp, void *addr, unsigned long len, int done,
180 { .addr = 224 { .addr =
181 (unsigned long) addr, 225 (unsigned long) addr,
182 .len = len } } } ); 226 .len = len } } } );
183 n = os_write_file(fd, &unmap, sizeof(unmap)); 227 ret = os_write_file(fd, &unmap, sizeof(unmap));
184 if(n != sizeof(unmap)) 228 if(ret != sizeof(unmap))
185 printk("unmap - proc_mm write returned %d\n", n); 229 printk("unmap - proc_mm write returned %d\n", ret);
230 else ret = 0;
186 } 231 }
187 else { 232 else {
188 int res;
189 unsigned long args[] = { (unsigned long) addr, len, 0, 0, 0, 233 unsigned long args[] = { (unsigned long) addr, len, 0, 0, 0,
190 0 }; 234 0 };
191 235
192 res = run_syscall_stub(mm_idp, __NR_munmap, args, 236 ret = run_syscall_stub(mm_idp, __NR_munmap, args, 0,
193 &data, done); 237 data, done);
194 if(res < 0) 238 if(ret < 0)
195 printk("munmap stub failed, errno = %d\n", res); 239 printk("munmap stub failed, errno = %d\n", ret);
196 } 240 }
197 241
198 return data; 242 return ret;
199} 243}
200 244
201void *protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len, 245int protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
202 int r, int w, int x, int done, void *data) 246 int r, int w, int x, int done, void **data)
203{ 247{
204 struct proc_mm_op protect; 248 struct proc_mm_op protect;
205 int prot, n; 249 int prot, ret;
206 250
207 prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | 251 prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
208 (x ? PROT_EXEC : 0); 252 (x ? PROT_EXEC : 0);
@@ -217,21 +261,19 @@ void *protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
217 .len = len, 261 .len = len,
218 .prot = prot } } } ); 262 .prot = prot } } } );
219 263
220 n = os_write_file(fd, &protect, sizeof(protect)); 264 ret = os_write_file(fd, &protect, sizeof(protect));
221 if(n != sizeof(protect)) 265 if(ret != sizeof(protect))
222 panic("protect failed, err = %d", -n); 266 printk("protect failed, err = %d", -ret);
267 else ret = 0;
223 } 268 }
224 else { 269 else {
225 int res;
226 unsigned long args[] = { addr, len, prot, 0, 0, 0 }; 270 unsigned long args[] = { addr, len, prot, 0, 0, 0 };
227 271
228 res = run_syscall_stub(mm_idp, __NR_mprotect, args, 272 ret = run_syscall_stub(mm_idp, __NR_mprotect, args, 0,
229 &data, done); 273 data, done);
230 if(res < 0)
231 panic("mprotect stub failed, errno = %d\n", res);
232 } 274 }
233 275
234 return data; 276 return ret;
235} 277}
236 278
237void before_mem_skas(unsigned long unused) 279void before_mem_skas(unsigned long unused)
diff --git a/arch/um/kernel/skas/tlb.c b/arch/um/kernel/skas/tlb.c
index 4b5fd2049547..6e84963dfc29 100644
--- a/arch/um/kernel/skas/tlb.c
+++ b/arch/um/kernel/skas/tlb.c
@@ -18,30 +18,31 @@
18#include "os.h" 18#include "os.h"
19#include "tlb.h" 19#include "tlb.h"
20 20
21static void *do_ops(union mm_context *mmu, struct host_vm_op *ops, int last, 21static int do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
22 int finished, void *flush) 22 int finished, void **flush)
23{ 23{
24 struct host_vm_op *op; 24 struct host_vm_op *op;
25 int i; 25 int i, ret = 0;
26 26
27 for(i = 0; i <= last; i++){ 27 for(i = 0; i <= last && !ret; i++){
28 op = &ops[i]; 28 op = &ops[i];
29 switch(op->type){ 29 switch(op->type){
30 case MMAP: 30 case MMAP:
31 flush = map(&mmu->skas.id, op->u.mmap.addr, 31 ret = map(&mmu->skas.id, op->u.mmap.addr,
32 op->u.mmap.len, op->u.mmap.r, op->u.mmap.w, 32 op->u.mmap.len, op->u.mmap.r, op->u.mmap.w,
33 op->u.mmap.x, op->u.mmap.fd, 33 op->u.mmap.x, op->u.mmap.fd,
34 op->u.mmap.offset, finished, flush); 34 op->u.mmap.offset, finished, flush);
35 break; 35 break;
36 case MUNMAP: 36 case MUNMAP:
37 flush = unmap(&mmu->skas.id, (void *) op->u.munmap.addr, 37 ret = unmap(&mmu->skas.id,
38 op->u.munmap.len, finished, flush); 38 (void *) op->u.munmap.addr,
39 op->u.munmap.len, finished, flush);
39 break; 40 break;
40 case MPROTECT: 41 case MPROTECT:
41 flush = protect(&mmu->skas.id, op->u.mprotect.addr, 42 ret = protect(&mmu->skas.id, op->u.mprotect.addr,
42 op->u.mprotect.len, op->u.mprotect.r, 43 op->u.mprotect.len, op->u.mprotect.r,
43 op->u.mprotect.w, op->u.mprotect.x, 44 op->u.mprotect.w, op->u.mprotect.x,
44 finished, flush); 45 finished, flush);
45 break; 46 break;
46 default: 47 default:
47 printk("Unknown op type %d in do_ops\n", op->type); 48 printk("Unknown op type %d in do_ops\n", op->type);
@@ -49,7 +50,7 @@ static void *do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
49 } 50 }
50 } 51 }
51 52
52 return flush; 53 return ret;
53} 54}
54 55
55extern int proc_mm; 56extern int proc_mm;