diff options
Diffstat (limited to 'fs/binfmt_aout.c')
-rw-r--r-- | fs/binfmt_aout.c | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index 346b69405363..f96eff04e11a 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c | |||
@@ -20,10 +20,11 @@ | |||
20 | #include <linux/fcntl.h> | 20 | #include <linux/fcntl.h> |
21 | #include <linux/ptrace.h> | 21 | #include <linux/ptrace.h> |
22 | #include <linux/user.h> | 22 | #include <linux/user.h> |
23 | #include <linux/slab.h> | ||
24 | #include <linux/binfmts.h> | 23 | #include <linux/binfmts.h> |
25 | #include <linux/personality.h> | 24 | #include <linux/personality.h> |
26 | #include <linux/init.h> | 25 | #include <linux/init.h> |
26 | #include <linux/coredump.h> | ||
27 | #include <linux/slab.h> | ||
27 | 28 | ||
28 | #include <asm/system.h> | 29 | #include <asm/system.h> |
29 | #include <asm/uaccess.h> | 30 | #include <asm/uaccess.h> |
@@ -60,26 +61,6 @@ static int set_brk(unsigned long start, unsigned long end) | |||
60 | } | 61 | } |
61 | 62 | ||
62 | /* | 63 | /* |
63 | * These are the only things you should do on a core-file: use only these | ||
64 | * macros to write out all the necessary info. | ||
65 | */ | ||
66 | |||
67 | static int dump_write(struct file *file, const void *addr, int nr) | ||
68 | { | ||
69 | return file->f_op->write(file, addr, nr, &file->f_pos) == nr; | ||
70 | } | ||
71 | |||
72 | #define DUMP_WRITE(addr, nr) \ | ||
73 | if (!dump_write(file, (void *)(addr), (nr))) \ | ||
74 | goto end_coredump; | ||
75 | |||
76 | #define DUMP_SEEK(offset) \ | ||
77 | if (file->f_op->llseek) { \ | ||
78 | if (file->f_op->llseek(file,(offset),0) != (offset)) \ | ||
79 | goto end_coredump; \ | ||
80 | } else file->f_pos = (offset) | ||
81 | |||
82 | /* | ||
83 | * Routine writes a core dump image in the current directory. | 64 | * Routine writes a core dump image in the current directory. |
84 | * Currently only a stub-function. | 65 | * Currently only a stub-function. |
85 | * | 66 | * |
@@ -94,14 +75,16 @@ static int aout_core_dump(struct coredump_params *cprm) | |||
94 | struct file *file = cprm->file; | 75 | struct file *file = cprm->file; |
95 | mm_segment_t fs; | 76 | mm_segment_t fs; |
96 | int has_dumped = 0; | 77 | int has_dumped = 0; |
97 | unsigned long dump_start, dump_size; | 78 | void __user *dump_start; |
79 | int dump_size; | ||
98 | struct user dump; | 80 | struct user dump; |
99 | #ifdef __alpha__ | 81 | #ifdef __alpha__ |
100 | # define START_DATA(u) (u.start_data) | 82 | # define START_DATA(u) ((void __user *)u.start_data) |
101 | #else | 83 | #else |
102 | # define START_DATA(u) ((u.u_tsize << PAGE_SHIFT) + u.start_code) | 84 | # define START_DATA(u) ((void __user *)((u.u_tsize << PAGE_SHIFT) + \ |
85 | u.start_code)) | ||
103 | #endif | 86 | #endif |
104 | # define START_STACK(u) (u.start_stack) | 87 | # define START_STACK(u) ((void __user *)u.start_stack) |
105 | 88 | ||
106 | fs = get_fs(); | 89 | fs = get_fs(); |
107 | set_fs(KERNEL_DS); | 90 | set_fs(KERNEL_DS); |
@@ -123,33 +106,38 @@ static int aout_core_dump(struct coredump_params *cprm) | |||
123 | 106 | ||
124 | /* make sure we actually have a data and stack area to dump */ | 107 | /* make sure we actually have a data and stack area to dump */ |
125 | set_fs(USER_DS); | 108 | set_fs(USER_DS); |
126 | if (!access_ok(VERIFY_READ, (void __user *)START_DATA(dump), dump.u_dsize << PAGE_SHIFT)) | 109 | if (!access_ok(VERIFY_READ, START_DATA(dump), dump.u_dsize << PAGE_SHIFT)) |
127 | dump.u_dsize = 0; | 110 | dump.u_dsize = 0; |
128 | if (!access_ok(VERIFY_READ, (void __user *)START_STACK(dump), dump.u_ssize << PAGE_SHIFT)) | 111 | if (!access_ok(VERIFY_READ, START_STACK(dump), dump.u_ssize << PAGE_SHIFT)) |
129 | dump.u_ssize = 0; | 112 | dump.u_ssize = 0; |
130 | 113 | ||
131 | set_fs(KERNEL_DS); | 114 | set_fs(KERNEL_DS); |
132 | /* struct user */ | 115 | /* struct user */ |
133 | DUMP_WRITE(&dump,sizeof(dump)); | 116 | if (!dump_write(file, &dump, sizeof(dump))) |
117 | goto end_coredump; | ||
134 | /* Now dump all of the user data. Include malloced stuff as well */ | 118 | /* Now dump all of the user data. Include malloced stuff as well */ |
135 | DUMP_SEEK(PAGE_SIZE); | 119 | if (!dump_seek(cprm->file, PAGE_SIZE - sizeof(dump))) |
120 | goto end_coredump; | ||
136 | /* now we start writing out the user space info */ | 121 | /* now we start writing out the user space info */ |
137 | set_fs(USER_DS); | 122 | set_fs(USER_DS); |
138 | /* Dump the data area */ | 123 | /* Dump the data area */ |
139 | if (dump.u_dsize != 0) { | 124 | if (dump.u_dsize != 0) { |
140 | dump_start = START_DATA(dump); | 125 | dump_start = START_DATA(dump); |
141 | dump_size = dump.u_dsize << PAGE_SHIFT; | 126 | dump_size = dump.u_dsize << PAGE_SHIFT; |
142 | DUMP_WRITE(dump_start,dump_size); | 127 | if (!dump_write(file, dump_start, dump_size)) |
128 | goto end_coredump; | ||
143 | } | 129 | } |
144 | /* Now prepare to dump the stack area */ | 130 | /* Now prepare to dump the stack area */ |
145 | if (dump.u_ssize != 0) { | 131 | if (dump.u_ssize != 0) { |
146 | dump_start = START_STACK(dump); | 132 | dump_start = START_STACK(dump); |
147 | dump_size = dump.u_ssize << PAGE_SHIFT; | 133 | dump_size = dump.u_ssize << PAGE_SHIFT; |
148 | DUMP_WRITE(dump_start,dump_size); | 134 | if (!dump_write(file, dump_start, dump_size)) |
135 | goto end_coredump; | ||
149 | } | 136 | } |
150 | /* Finally dump the task struct. Not be used by gdb, but could be useful */ | 137 | /* Finally dump the task struct. Not be used by gdb, but could be useful */ |
151 | set_fs(KERNEL_DS); | 138 | set_fs(KERNEL_DS); |
152 | DUMP_WRITE(current,sizeof(*current)); | 139 | if (!dump_write(file, current, sizeof(*current))) |
140 | goto end_coredump; | ||
153 | end_coredump: | 141 | end_coredump: |
154 | set_fs(fs); | 142 | set_fs(fs); |
155 | return has_dumped; | 143 | return has_dumped; |
@@ -247,7 +235,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs) | |||
247 | * size limits imposed on them by creating programs with large | 235 | * size limits imposed on them by creating programs with large |
248 | * arrays in the data or bss. | 236 | * arrays in the data or bss. |
249 | */ | 237 | */ |
250 | rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur; | 238 | rlim = rlimit(RLIMIT_DATA); |
251 | if (rlim >= RLIM_INFINITY) | 239 | if (rlim >= RLIM_INFINITY) |
252 | rlim = ~0; | 240 | rlim = ~0; |
253 | if (ex.a_data + ex.a_bss > rlim) | 241 | if (ex.a_data + ex.a_bss > rlim) |
@@ -264,6 +252,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs) | |||
264 | #else | 252 | #else |
265 | set_personality(PER_LINUX); | 253 | set_personality(PER_LINUX); |
266 | #endif | 254 | #endif |
255 | setup_new_exec(bprm); | ||
267 | 256 | ||
268 | current->mm->end_code = ex.a_text + | 257 | current->mm->end_code = ex.a_text + |
269 | (current->mm->start_code = N_TXTADDR(ex)); | 258 | (current->mm->start_code = N_TXTADDR(ex)); |