aboutsummaryrefslogtreecommitdiffstats
path: root/arch
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
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')
-rw-r--r--arch/um/include/tlb.h6
-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
-rw-r--r--arch/um/kernel/tlb.c163
-rw-r--r--arch/um/kernel/tt/tlb.c27
-rw-r--r--arch/um/sys-i386/stub.S42
-rw-r--r--arch/um/sys-x86_64/stub.S50
8 files changed, 348 insertions, 238 deletions
diff --git a/arch/um/include/tlb.h b/arch/um/include/tlb.h
index 2deefb99c63..45d7da6c3b2 100644
--- a/arch/um/include/tlb.h
+++ b/arch/um/include/tlb.h
@@ -38,9 +38,9 @@ extern void mprotect_kernel_vm(int w);
38extern void force_flush_all(void); 38extern void force_flush_all(void);
39extern void fix_range_common(struct mm_struct *mm, unsigned long start_addr, 39extern void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
40 unsigned long end_addr, int force, 40 unsigned long end_addr, int force,
41 void *(*do_ops)(union mm_context *, 41 int (*do_ops)(union mm_context *,
42 struct host_vm_op *, int, int, 42 struct host_vm_op *, int, int,
43 void *)); 43 void **));
44extern int flush_tlb_kernel_range_common(unsigned long start, 44extern int flush_tlb_kernel_range_common(unsigned long start,
45 unsigned long end); 45 unsigned long end);
46 46
diff --git a/arch/um/kernel/skas/include/skas.h b/arch/um/kernel/skas/include/skas.h
index 03c9d99e15e..060934740f9 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 c976320ebe8..1d89640bd50 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 4b5fd204954..6e84963dfc2 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;
diff --git a/arch/um/kernel/tlb.c b/arch/um/kernel/tlb.c
index 7d914bb6b00..80ed6188e8a 100644
--- a/arch/um/kernel/tlb.c
+++ b/arch/um/kernel/tlb.c
@@ -16,115 +16,117 @@
16#include "os.h" 16#include "os.h"
17 17
18static int add_mmap(unsigned long virt, unsigned long phys, unsigned long len, 18static int add_mmap(unsigned long virt, unsigned long phys, unsigned long len,
19 int r, int w, int x, struct host_vm_op *ops, int index, 19 int r, int w, int x, struct host_vm_op *ops, int *index,
20 int last_filled, union mm_context *mmu, void **flush, 20 int last_filled, union mm_context *mmu, void **flush,
21 void *(*do_ops)(union mm_context *, struct host_vm_op *, 21 int (*do_ops)(union mm_context *, struct host_vm_op *,
22 int, int, void *)) 22 int, int, void **))
23{ 23{
24 __u64 offset; 24 __u64 offset;
25 struct host_vm_op *last; 25 struct host_vm_op *last;
26 int fd; 26 int fd, ret = 0;
27 27
28 fd = phys_mapping(phys, &offset); 28 fd = phys_mapping(phys, &offset);
29 if(index != -1){ 29 if(*index != -1){
30 last = &ops[index]; 30 last = &ops[*index];
31 if((last->type == MMAP) && 31 if((last->type == MMAP) &&
32 (last->u.mmap.addr + last->u.mmap.len == virt) && 32 (last->u.mmap.addr + last->u.mmap.len == virt) &&
33 (last->u.mmap.r == r) && (last->u.mmap.w == w) && 33 (last->u.mmap.r == r) && (last->u.mmap.w == w) &&
34 (last->u.mmap.x == x) && (last->u.mmap.fd == fd) && 34 (last->u.mmap.x == x) && (last->u.mmap.fd == fd) &&
35 (last->u.mmap.offset + last->u.mmap.len == offset)){ 35 (last->u.mmap.offset + last->u.mmap.len == offset)){
36 last->u.mmap.len += len; 36 last->u.mmap.len += len;
37 return index; 37 return 0;
38 } 38 }
39 } 39 }
40 40
41 if(index == last_filled){ 41 if(*index == last_filled){
42 *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); 42 ret = (*do_ops)(mmu, ops, last_filled, 0, flush);
43 index = -1; 43 *index = -1;
44 } 44 }
45 45
46 ops[++index] = ((struct host_vm_op) { .type = MMAP, 46 ops[++*index] = ((struct host_vm_op) { .type = MMAP,
47 .u = { .mmap = { 47 .u = { .mmap = {
48 .addr = virt, 48 .addr = virt,
49 .len = len, 49 .len = len,
50 .r = r, 50 .r = r,
51 .w = w, 51 .w = w,
52 .x = x, 52 .x = x,
53 .fd = fd, 53 .fd = fd,
54 .offset = offset } 54 .offset = offset }
55 } }); 55 } });
56 return index; 56 return ret;
57} 57}
58 58
59static int add_munmap(unsigned long addr, unsigned long len, 59static int add_munmap(unsigned long addr, unsigned long len,
60 struct host_vm_op *ops, int index, int last_filled, 60 struct host_vm_op *ops, int *index, int last_filled,
61 union mm_context *mmu, void **flush, 61 union mm_context *mmu, void **flush,
62 void *(*do_ops)(union mm_context *, struct host_vm_op *, 62 int (*do_ops)(union mm_context *, struct host_vm_op *,
63 int, int, void *)) 63 int, int, void **))
64{ 64{
65 struct host_vm_op *last; 65 struct host_vm_op *last;
66 int ret = 0;
66 67
67 if(index != -1){ 68 if(*index != -1){
68 last = &ops[index]; 69 last = &ops[*index];
69 if((last->type == MUNMAP) && 70 if((last->type == MUNMAP) &&
70 (last->u.munmap.addr + last->u.mmap.len == addr)){ 71 (last->u.munmap.addr + last->u.mmap.len == addr)){
71 last->u.munmap.len += len; 72 last->u.munmap.len += len;
72 return index; 73 return 0;
73 } 74 }
74 } 75 }
75 76
76 if(index == last_filled){ 77 if(*index == last_filled){
77 *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); 78 ret = (*do_ops)(mmu, ops, last_filled, 0, flush);
78 index = -1; 79 *index = -1;
79 } 80 }
80 81
81 ops[++index] = ((struct host_vm_op) { .type = MUNMAP, 82 ops[++*index] = ((struct host_vm_op) { .type = MUNMAP,
82 .u = { .munmap = { 83 .u = { .munmap = {
83 .addr = addr, 84 .addr = addr,
84 .len = len } } }); 85 .len = len } } });
85 return index; 86 return ret;
86} 87}
87 88
88static int add_mprotect(unsigned long addr, unsigned long len, int r, int w, 89static int add_mprotect(unsigned long addr, unsigned long len, int r, int w,
89 int x, struct host_vm_op *ops, int index, 90 int x, struct host_vm_op *ops, int *index,
90 int last_filled, union mm_context *mmu, void **flush, 91 int last_filled, union mm_context *mmu, void **flush,
91 void *(*do_ops)(union mm_context *, 92 int (*do_ops)(union mm_context *, struct host_vm_op *,
92 struct host_vm_op *, int, int, void *)) 93 int, int, void **))
93{ 94{
94 struct host_vm_op *last; 95 struct host_vm_op *last;
96 int ret = 0;
95 97
96 if(index != -1){ 98 if(*index != -1){
97 last = &ops[index]; 99 last = &ops[*index];
98 if((last->type == MPROTECT) && 100 if((last->type == MPROTECT) &&
99 (last->u.mprotect.addr + last->u.mprotect.len == addr) && 101 (last->u.mprotect.addr + last->u.mprotect.len == addr) &&
100 (last->u.mprotect.r == r) && (last->u.mprotect.w == w) && 102 (last->u.mprotect.r == r) && (last->u.mprotect.w == w) &&
101 (last->u.mprotect.x == x)){ 103 (last->u.mprotect.x == x)){
102 last->u.mprotect.len += len; 104 last->u.mprotect.len += len;
103 return index; 105 return 0;
104 } 106 }
105 } 107 }
106 108
107 if(index == last_filled){ 109 if(*index == last_filled){
108 *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); 110 ret = (*do_ops)(mmu, ops, last_filled, 0, flush);
109 index = -1; 111 *index = -1;
110 } 112 }
111 113
112 ops[++index] = ((struct host_vm_op) { .type = MPROTECT, 114 ops[++*index] = ((struct host_vm_op) { .type = MPROTECT,
113 .u = { .mprotect = { 115 .u = { .mprotect = {
114 .addr = addr, 116 .addr = addr,
115 .len = len, 117 .len = len,
116 .r = r, 118 .r = r,
117 .w = w, 119 .w = w,
118 .x = x } } }); 120 .x = x } } });
119 return index; 121 return ret;
120} 122}
121 123
122#define ADD_ROUND(n, inc) (((n) + (inc)) & ~((inc) - 1)) 124#define ADD_ROUND(n, inc) (((n) + (inc)) & ~((inc) - 1))
123 125
124void fix_range_common(struct mm_struct *mm, unsigned long start_addr, 126void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
125 unsigned long end_addr, int force, 127 unsigned long end_addr, int force,
126 void *(*do_ops)(union mm_context *, struct host_vm_op *, 128 int (*do_ops)(union mm_context *, struct host_vm_op *,
127 int, int, void *)) 129 int, int, void **))
128{ 130{
129 pgd_t *npgd; 131 pgd_t *npgd;
130 pud_t *npud; 132 pud_t *npud;
@@ -136,20 +138,21 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
136 struct host_vm_op ops[1]; 138 struct host_vm_op ops[1];
137 void *flush = NULL; 139 void *flush = NULL;
138 int op_index = -1, last_op = sizeof(ops) / sizeof(ops[0]) - 1; 140 int op_index = -1, last_op = sizeof(ops) / sizeof(ops[0]) - 1;
141 int ret = 0;
139 142
140 if(mm == NULL) return; 143 if(mm == NULL) return;
141 144
142 ops[0].type = NONE; 145 ops[0].type = NONE;
143 for(addr = start_addr; addr < end_addr;){ 146 for(addr = start_addr; addr < end_addr && !ret;){
144 npgd = pgd_offset(mm, addr); 147 npgd = pgd_offset(mm, addr);
145 if(!pgd_present(*npgd)){ 148 if(!pgd_present(*npgd)){
146 end = ADD_ROUND(addr, PGDIR_SIZE); 149 end = ADD_ROUND(addr, PGDIR_SIZE);
147 if(end > end_addr) 150 if(end > end_addr)
148 end = end_addr; 151 end = end_addr;
149 if(force || pgd_newpage(*npgd)){ 152 if(force || pgd_newpage(*npgd)){
150 op_index = add_munmap(addr, end - addr, ops, 153 ret = add_munmap(addr, end - addr, ops,
151 op_index, last_op, mmu, 154 &op_index, last_op, mmu,
152 &flush, do_ops); 155 &flush, do_ops);
153 pgd_mkuptodate(*npgd); 156 pgd_mkuptodate(*npgd);
154 } 157 }
155 addr = end; 158 addr = end;
@@ -162,9 +165,9 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
162 if(end > end_addr) 165 if(end > end_addr)
163 end = end_addr; 166 end = end_addr;
164 if(force || pud_newpage(*npud)){ 167 if(force || pud_newpage(*npud)){
165 op_index = add_munmap(addr, end - addr, ops, 168 ret = add_munmap(addr, end - addr, ops,
166 op_index, last_op, mmu, 169 &op_index, last_op, mmu,
167 &flush, do_ops); 170 &flush, do_ops);
168 pud_mkuptodate(*npud); 171 pud_mkuptodate(*npud);
169 } 172 }
170 addr = end; 173 addr = end;
@@ -177,9 +180,9 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
177 if(end > end_addr) 180 if(end > end_addr)
178 end = end_addr; 181 end = end_addr;
179 if(force || pmd_newpage(*npmd)){ 182 if(force || pmd_newpage(*npmd)){
180 op_index = add_munmap(addr, end - addr, ops, 183 ret = add_munmap(addr, end - addr, ops,
181 op_index, last_op, mmu, 184 &op_index, last_op, mmu,
182 &flush, do_ops); 185 &flush, do_ops);
183 pmd_mkuptodate(*npmd); 186 pmd_mkuptodate(*npmd);
184 } 187 }
185 addr = end; 188 addr = end;
@@ -198,24 +201,32 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
198 } 201 }
199 if(force || pte_newpage(*npte)){ 202 if(force || pte_newpage(*npte)){
200 if(pte_present(*npte)) 203 if(pte_present(*npte))
201 op_index = add_mmap(addr, 204 ret = add_mmap(addr,
202 pte_val(*npte) & PAGE_MASK, 205 pte_val(*npte) & PAGE_MASK,
203 PAGE_SIZE, r, w, x, ops, 206 PAGE_SIZE, r, w, x, ops,
204 op_index, last_op, mmu, 207 &op_index, last_op, mmu,
205 &flush, do_ops); 208 &flush, do_ops);
206 else op_index = add_munmap(addr, PAGE_SIZE, ops, 209 else ret = add_munmap(addr, PAGE_SIZE, ops,
207 op_index, last_op, mmu, 210 &op_index, last_op, mmu,
208 &flush, do_ops); 211 &flush, do_ops);
209 } 212 }
210 else if(pte_newprot(*npte)) 213 else if(pte_newprot(*npte))
211 op_index = add_mprotect(addr, PAGE_SIZE, r, w, x, ops, 214 ret = add_mprotect(addr, PAGE_SIZE, r, w, x, ops,
212 op_index, last_op, mmu, 215 &op_index, last_op, mmu,
213 &flush, do_ops); 216 &flush, do_ops);
214 217
215 *npte = pte_mkuptodate(*npte); 218 *npte = pte_mkuptodate(*npte);
216 addr += PAGE_SIZE; 219 addr += PAGE_SIZE;
217 } 220 }
218 flush = (*do_ops)(mmu, ops, op_index, 1, flush); 221
222 if(!ret)
223 ret = (*do_ops)(mmu, ops, op_index, 1, &flush);
224
225 /* This is not an else because ret is modified above */
226 if(ret) {
227 printk("fix_range_common: failed, killing current process\n");
228 force_sig(SIGKILL, current);
229 }
219} 230}
220 231
221int flush_tlb_kernel_range_common(unsigned long start, unsigned long end) 232int flush_tlb_kernel_range_common(unsigned long start, unsigned long end)
diff --git a/arch/um/kernel/tt/tlb.c b/arch/um/kernel/tt/tlb.c
index 16fc6a28882..f1d85dbb45b 100644
--- a/arch/um/kernel/tt/tlb.c
+++ b/arch/um/kernel/tt/tlb.c
@@ -17,26 +17,31 @@
17#include "os.h" 17#include "os.h"
18#include "tlb.h" 18#include "tlb.h"
19 19
20static void *do_ops(union mm_context *mmu, struct host_vm_op *ops, int last, 20static int do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
21 int finished, void *flush) 21 int finished, void **flush)
22{ 22{
23 struct host_vm_op *op; 23 struct host_vm_op *op;
24 int i; 24 int i, ret=0;
25 25
26 for(i = 0; i <= last; i++){ 26 for(i = 0; i <= last && !ret; i++){
27 op = &ops[i]; 27 op = &ops[i];
28 switch(op->type){ 28 switch(op->type){
29 case MMAP: 29 case MMAP:
30 os_map_memory((void *) op->u.mmap.addr, op->u.mmap.fd, 30 ret = os_map_memory((void *) op->u.mmap.addr,
31 op->u.mmap.offset, op->u.mmap.len, 31 op->u.mmap.fd, op->u.mmap.offset,
32 op->u.mmap.r, op->u.mmap.w, 32 op->u.mmap.len, op->u.mmap.r,
33 op->u.mmap.x); 33 op->u.mmap.w, op->u.mmap.x);
34 break; 34 break;
35 case MUNMAP: 35 case MUNMAP:
36 os_unmap_memory((void *) op->u.munmap.addr, 36 ret = os_unmap_memory((void *) op->u.munmap.addr,
37 op->u.munmap.len); 37 op->u.munmap.len);
38 break; 38 break;
39 case MPROTECT: 39 case MPROTECT:
40 ret = protect_memory(op->u.mprotect.addr,
41 op->u.munmap.len,
42 op->u.mprotect.r,
43 op->u.mprotect.w,
44 op->u.mprotect.x, 1);
40 protect_memory(op->u.mprotect.addr, op->u.munmap.len, 45 protect_memory(op->u.mprotect.addr, op->u.munmap.len,
41 op->u.mprotect.r, op->u.mprotect.w, 46 op->u.mprotect.r, op->u.mprotect.w,
42 op->u.mprotect.x, 1); 47 op->u.mprotect.x, 1);
@@ -47,7 +52,7 @@ static void *do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
47 } 52 }
48 } 53 }
49 54
50 return NULL; 55 return ret;
51} 56}
52 57
53static void fix_range(struct mm_struct *mm, unsigned long start_addr, 58static void fix_range(struct mm_struct *mm, unsigned long start_addr,
diff --git a/arch/um/sys-i386/stub.S b/arch/um/sys-i386/stub.S
index a0f9506312d..6a70d9ab5c2 100644
--- a/arch/um/sys-i386/stub.S
+++ b/arch/um/sys-i386/stub.S
@@ -2,24 +2,50 @@
2 2
3 .globl syscall_stub 3 .globl syscall_stub
4.section .__syscall_stub, "x" 4.section .__syscall_stub, "x"
5syscall_stub:
6 int $0x80
7 mov %eax, UML_CONFIG_STUB_DATA
8 int3
9 5
10 .globl batch_syscall_stub 6 .globl batch_syscall_stub
11batch_syscall_stub: 7batch_syscall_stub:
12 mov $UML_CONFIG_STUB_DATA, %esp 8 /* load pointer to first operation */
13again: pop %eax 9 mov $(UML_CONFIG_STUB_DATA+8), %esp
10
11again:
12 /* load length of additional data */
13 mov 0x0(%esp), %eax
14
15 /* if(length == 0) : end of list */
16 /* write possible 0 to header */
17 mov %eax, UML_CONFIG_STUB_DATA+4
14 cmpl $0, %eax 18 cmpl $0, %eax
15 jz done 19 jz done
20
21 /* save current pointer */
22 mov %esp, UML_CONFIG_STUB_DATA+4
23
24 /* skip additional data */
25 add %eax, %esp
26
27 /* load syscall-# */
28 pop %eax
29
30 /* load syscall params */
16 pop %ebx 31 pop %ebx
17 pop %ecx 32 pop %ecx
18 pop %edx 33 pop %edx
19 pop %esi 34 pop %esi
20 pop %edi 35 pop %edi
21 pop %ebp 36 pop %ebp
37
38 /* execute syscall */
22 int $0x80 39 int $0x80
40
41 /* check return value */
42 pop %ebx
43 cmp %ebx, %eax
44 je again
45
46done:
47 /* save return value */
23 mov %eax, UML_CONFIG_STUB_DATA 48 mov %eax, UML_CONFIG_STUB_DATA
24 jmp again 49
25done: int3 50 /* stop */
51 int3
diff --git a/arch/um/sys-x86_64/stub.S b/arch/um/sys-x86_64/stub.S
index 957f2eff32c..03c27973578 100644
--- a/arch/um/sys-x86_64/stub.S
+++ b/arch/um/sys-x86_64/stub.S
@@ -16,21 +16,51 @@ syscall_stub:
16 16
17 .globl batch_syscall_stub 17 .globl batch_syscall_stub
18batch_syscall_stub: 18batch_syscall_stub:
19 movq $(UML_CONFIG_STUB_DATA >> 32), %rbx 19 mov $(UML_CONFIG_STUB_DATA >> 32), %rbx
20 salq $32, %rbx 20 sal $32, %rbx
21 movq $(UML_CONFIG_STUB_DATA & 0xffffffff), %rcx 21 mov $(UML_CONFIG_STUB_DATA & 0xffffffff), %rax
22 or %rcx, %rbx 22 or %rax, %rbx
23 movq %rbx, %rsp 23 /* load pointer to first operation */
24again: pop %rax 24 mov %rbx, %rsp
25 cmpq $0, %rax 25 add $0x10, %rsp
26jz done 26again:
27 /* load length of additional data */
28 mov 0x0(%rsp), %rax
29
30 /* if(length == 0) : end of list */
31 /* write possible 0 to header */
32 mov %rax, 8(%rbx)
33 cmp $0, %rax
34 jz done
35
36 /* save current pointer */
37 mov %rsp, 8(%rbx)
38
39 /* skip additional data */
40 add %rax, %rsp
41
42 /* load syscall-# */
43 pop %rax
44
45 /* load syscall params */
27 pop %rdi 46 pop %rdi
28 pop %rsi 47 pop %rsi
29 pop %rdx 48 pop %rdx
30 pop %r10 49 pop %r10
31 pop %r8 50 pop %r8
32 pop %r9 51 pop %r9
52
53 /* execute syscall */
33 syscall 54 syscall
55
56 /* check return value */
57 pop %rcx
58 cmp %rcx, %rax
59 je again
60
61done:
62 /* save return value */
34 mov %rax, (%rbx) 63 mov %rax, (%rbx)
35 jmp again 64
36done: int3 65 /* stop */
66 int3