blob: 895823d0149d9cfbd75bb34b670662dafb7f9ef6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/exec.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/*
8 * #!-checking implemented by tytso.
9 */
10/*
11 * Demand-loading implemented 01.12.91 - no need to read anything but
12 * the header into memory. The inode of the executable is put into
13 * "current->executable", and page faults do the actual loading. Clean.
14 *
15 * Once more I can proudly say that linux stood up to being changed: it
16 * was less than 2 hours work to get demand-loading completely implemented.
17 *
18 * Demand loading changed July 1993 by Eric Youngdale. Use mmap instead,
19 * current->executable is only used by the procfs. This allows a dispatch
20 * table to check for several different types of binary formats. We keep
21 * trying until we recognize the file or we run out of supported binary
22 * formats.
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/slab.h>
26#include <linux/file.h>
Al Viro9f3acc32008-04-24 07:44:08 -040027#include <linux/fdtable.h>
Hugh Dickinsba92a432008-07-25 01:45:43 -070028#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/stat.h>
30#include <linux/fcntl.h>
31#include <linux/smp_lock.h>
Hugh Dickinsba92a432008-07-25 01:45:43 -070032#include <linux/swap.h>
Neil Horman74aadce2007-10-16 23:26:35 -070033#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/init.h>
Hugh Dickinsca5b1722008-07-28 15:46:18 -070035#include <linux/pagemap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/highmem.h>
37#include <linux/spinlock.h>
38#include <linux/key.h>
39#include <linux/personality.h>
40#include <linux/binfmts.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/utsname.h>
Sukadev Bhattiprolu84d73782006-12-08 02:38:01 -080042#include <linux/pid_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/module.h>
44#include <linux/namei.h>
45#include <linux/proc_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/mount.h>
47#include <linux/security.h>
Mimi Zohar6146f0d2009-02-04 09:06:57 -050048#include <linux/ima.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/syscalls.h>
Jay Lan8f0ab512006-09-30 23:28:59 -070050#include <linux/tsacct_kern.h>
Matt Helsley9f460802005-11-07 00:59:16 -080051#include <linux/cn_proc.h>
Al Viro473ae302006-04-26 14:04:08 -040052#include <linux/audit.h>
Roland McGrath6341c392008-07-25 19:45:44 -070053#include <linux/tracehook.h>
Johannes Berg5f4123b2008-07-09 10:28:40 +020054#include <linux/kmod.h>
Eric Paris6110e3a2008-12-17 13:53:20 -050055#include <linux/fsnotify.h>
Al Viro5ad4e532009-03-29 19:50:06 -040056#include <linux/fs_struct.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#include <asm/uaccess.h>
59#include <asm/mmu_context.h>
Ollie Wildb6a2fea2007-07-19 01:48:16 -070060#include <asm/tlb.h>
David Howellsa6f76f22008-11-14 10:39:24 +110061#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063int core_uses_pid;
Dan Aloni71ce92f2007-05-16 22:11:16 -070064char core_pattern[CORENAME_MAX_SIZE] = "core";
Alan Coxd6e71142005-06-23 00:09:43 -070065int suid_dumpable = 0;
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067/* The maximal length of core_pattern is also specified in sysctl.c */
68
Alexey Dobriyane4dc1b12007-10-16 23:26:03 -070069static LIST_HEAD(formats);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static DEFINE_RWLOCK(binfmt_lock);
71
Ivan Kokshaysky74641f52009-04-30 15:08:49 -070072int __register_binfmt(struct linux_binfmt * fmt, int insert)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 if (!fmt)
75 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 write_lock(&binfmt_lock);
Ivan Kokshaysky74641f52009-04-30 15:08:49 -070077 insert ? list_add(&fmt->lh, &formats) :
78 list_add_tail(&fmt->lh, &formats);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 write_unlock(&binfmt_lock);
80 return 0;
81}
82
Ivan Kokshaysky74641f52009-04-30 15:08:49 -070083EXPORT_SYMBOL(__register_binfmt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Alexey Dobriyanf6b450d2007-10-16 23:26:04 -070085void unregister_binfmt(struct linux_binfmt * fmt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 write_lock(&binfmt_lock);
Alexey Dobriyane4dc1b12007-10-16 23:26:03 -070088 list_del(&fmt->lh);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 write_unlock(&binfmt_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92EXPORT_SYMBOL(unregister_binfmt);
93
94static inline void put_binfmt(struct linux_binfmt * fmt)
95{
96 module_put(fmt->module);
97}
98
99/*
100 * Note that a shared library must be both readable and executable due to
101 * security reasons.
102 *
103 * Also note that we take the address to load from from the file itself.
104 */
Heiko Carstens1e7bfb22009-01-14 14:14:29 +0100105SYSCALL_DEFINE1(uselib, const char __user *, library)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Al Viro964bd182008-07-26 03:33:14 -0400107 struct file *file;
Al Viro964bd182008-07-26 03:33:14 -0400108 char *tmp = getname(library);
109 int error = PTR_ERR(tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Al Viro6e8341a2009-04-06 11:16:22 -0400111 if (IS_ERR(tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 goto out;
113
Al Viro6e8341a2009-04-06 11:16:22 -0400114 file = do_filp_open(AT_FDCWD, tmp,
115 O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
116 MAY_READ | MAY_EXEC | MAY_OPEN);
117 putname(tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 error = PTR_ERR(file);
119 if (IS_ERR(file))
120 goto out;
121
Al Viro6e8341a2009-04-06 11:16:22 -0400122 error = -EINVAL;
123 if (!S_ISREG(file->f_path.dentry->d_inode->i_mode))
124 goto exit;
125
126 error = -EACCES;
127 if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)
128 goto exit;
129
Eric Paris6110e3a2008-12-17 13:53:20 -0500130 fsnotify_open(file->f_path.dentry);
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 error = -ENOEXEC;
133 if(file->f_op) {
134 struct linux_binfmt * fmt;
135
136 read_lock(&binfmt_lock);
Alexey Dobriyane4dc1b12007-10-16 23:26:03 -0700137 list_for_each_entry(fmt, &formats, lh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (!fmt->load_shlib)
139 continue;
140 if (!try_module_get(fmt->module))
141 continue;
142 read_unlock(&binfmt_lock);
143 error = fmt->load_shlib(file);
144 read_lock(&binfmt_lock);
145 put_binfmt(fmt);
146 if (error != -ENOEXEC)
147 break;
148 }
149 read_unlock(&binfmt_lock);
150 }
Al Viro6e8341a2009-04-06 11:16:22 -0400151exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 fput(file);
153out:
154 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700157#ifdef CONFIG_MMU
158
159static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
160 int write)
161{
162 struct page *page;
163 int ret;
164
165#ifdef CONFIG_STACK_GROWSUP
166 if (write) {
167 ret = expand_stack_downwards(bprm->vma, pos);
168 if (ret < 0)
169 return NULL;
170 }
171#endif
172 ret = get_user_pages(current, bprm->mm, pos,
173 1, write, 1, &page, NULL);
174 if (ret <= 0)
175 return NULL;
176
177 if (write) {
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700178 unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start;
Linus Torvaldsa64e7152008-03-03 10:12:14 -0800179 struct rlimit *rlim;
180
181 /*
182 * We've historically supported up to 32 pages (ARG_MAX)
183 * of argument strings even with small stacks
184 */
185 if (size <= ARG_MAX)
186 return page;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700187
188 /*
189 * Limit to 1/4-th the stack size for the argv+env strings.
190 * This ensures that:
191 * - the remaining binfmt code will not run out of stack space,
192 * - the program will have a reasonable amount of stack left
193 * to work from.
194 */
Linus Torvaldsa64e7152008-03-03 10:12:14 -0800195 rlim = current->signal->rlim;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700196 if (size > rlim[RLIMIT_STACK].rlim_cur / 4) {
197 put_page(page);
198 return NULL;
199 }
200 }
201
202 return page;
203}
204
205static void put_arg_page(struct page *page)
206{
207 put_page(page);
208}
209
210static void free_arg_page(struct linux_binprm *bprm, int i)
211{
212}
213
214static void free_arg_pages(struct linux_binprm *bprm)
215{
216}
217
218static void flush_arg_page(struct linux_binprm *bprm, unsigned long pos,
219 struct page *page)
220{
221 flush_cache_page(bprm->vma, pos, page_to_pfn(page));
222}
223
224static int __bprm_mm_init(struct linux_binprm *bprm)
225{
Luiz Fernando N. Capitulinoeaccbfa2009-01-06 14:40:44 -0800226 int err;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700227 struct vm_area_struct *vma = NULL;
228 struct mm_struct *mm = bprm->mm;
229
230 bprm->vma = vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
231 if (!vma)
Luiz Fernando N. Capitulinoeaccbfa2009-01-06 14:40:44 -0800232 return -ENOMEM;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700233
234 down_write(&mm->mmap_sem);
235 vma->vm_mm = mm;
236
237 /*
238 * Place the stack at the largest stack address the architecture
239 * supports. Later, we'll move this to an appropriate place. We don't
240 * use STACK_TOP because that can depend on attributes which aren't
241 * configured yet.
242 */
243 vma->vm_end = STACK_TOP_MAX;
244 vma->vm_start = vma->vm_end - PAGE_SIZE;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700245 vma->vm_flags = VM_STACK_FLAGS;
Coly Li3ed75eb2007-10-18 23:39:15 -0700246 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700247 err = insert_vm_struct(mm, vma);
Luiz Fernando N. Capitulinoeaccbfa2009-01-06 14:40:44 -0800248 if (err)
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700249 goto err;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700250
251 mm->stack_vm = mm->total_vm = 1;
252 up_write(&mm->mmap_sem);
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700253 bprm->p = vma->vm_end - sizeof(void *);
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700254 return 0;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700255err:
Luiz Fernando N. Capitulinoeaccbfa2009-01-06 14:40:44 -0800256 up_write(&mm->mmap_sem);
257 bprm->vma = NULL;
258 kmem_cache_free(vm_area_cachep, vma);
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700259 return err;
260}
261
262static bool valid_arg_len(struct linux_binprm *bprm, long len)
263{
264 return len <= MAX_ARG_STRLEN;
265}
266
267#else
268
269static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
270 int write)
271{
272 struct page *page;
273
274 page = bprm->page[pos / PAGE_SIZE];
275 if (!page && write) {
276 page = alloc_page(GFP_HIGHUSER|__GFP_ZERO);
277 if (!page)
278 return NULL;
279 bprm->page[pos / PAGE_SIZE] = page;
280 }
281
282 return page;
283}
284
285static void put_arg_page(struct page *page)
286{
287}
288
289static void free_arg_page(struct linux_binprm *bprm, int i)
290{
291 if (bprm->page[i]) {
292 __free_page(bprm->page[i]);
293 bprm->page[i] = NULL;
294 }
295}
296
297static void free_arg_pages(struct linux_binprm *bprm)
298{
299 int i;
300
301 for (i = 0; i < MAX_ARG_PAGES; i++)
302 free_arg_page(bprm, i);
303}
304
305static void flush_arg_page(struct linux_binprm *bprm, unsigned long pos,
306 struct page *page)
307{
308}
309
310static int __bprm_mm_init(struct linux_binprm *bprm)
311{
312 bprm->p = PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *);
313 return 0;
314}
315
316static bool valid_arg_len(struct linux_binprm *bprm, long len)
317{
318 return len <= bprm->p;
319}
320
321#endif /* CONFIG_MMU */
322
323/*
324 * Create a new mm_struct and populate it with a temporary stack
325 * vm_area_struct. We don't have enough context at this point to set the stack
326 * flags, permissions, and offset, so we use temporary values. We'll update
327 * them later in setup_arg_pages().
328 */
329int bprm_mm_init(struct linux_binprm *bprm)
330{
331 int err;
332 struct mm_struct *mm = NULL;
333
334 bprm->mm = mm = mm_alloc();
335 err = -ENOMEM;
336 if (!mm)
337 goto err;
338
339 err = init_new_context(current, mm);
340 if (err)
341 goto err;
342
343 err = __bprm_mm_init(bprm);
344 if (err)
345 goto err;
346
347 return 0;
348
349err:
350 if (mm) {
351 bprm->mm = NULL;
352 mmdrop(mm);
353 }
354
355 return err;
356}
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358/*
359 * count() counts the number of strings in array ARGV.
360 */
361static int count(char __user * __user * argv, int max)
362{
363 int i = 0;
364
365 if (argv != NULL) {
366 for (;;) {
367 char __user * p;
368
369 if (get_user(p, argv))
370 return -EFAULT;
371 if (!p)
372 break;
373 argv++;
Jason Baron362e6662008-10-15 22:01:52 -0700374 if (i++ >= max)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 return -E2BIG;
376 cond_resched();
377 }
378 }
379 return i;
380}
381
382/*
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700383 * 'copy_strings()' copies argument/environment strings from the old
384 * processes's memory to the new process's stack. The call to get_user_pages()
385 * ensures the destination page is created and not swapped out.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 */
Adrian Bunk75c96f82005-05-05 16:16:09 -0700387static int copy_strings(int argc, char __user * __user * argv,
388 struct linux_binprm *bprm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
390 struct page *kmapped_page = NULL;
391 char *kaddr = NULL;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700392 unsigned long kpos = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 int ret;
394
395 while (argc-- > 0) {
396 char __user *str;
397 int len;
398 unsigned long pos;
399
400 if (get_user(str, argv+argc) ||
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700401 !(len = strnlen_user(str, MAX_ARG_STRLEN))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 ret = -EFAULT;
403 goto out;
404 }
405
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700406 if (!valid_arg_len(bprm, len)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 ret = -E2BIG;
408 goto out;
409 }
410
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700411 /* We're going to work our way backwords. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 pos = bprm->p;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700413 str += len;
414 bprm->p -= len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 while (len > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 int offset, bytes_to_copy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 offset = pos % PAGE_SIZE;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700420 if (offset == 0)
421 offset = PAGE_SIZE;
422
423 bytes_to_copy = offset;
424 if (bytes_to_copy > len)
425 bytes_to_copy = len;
426
427 offset -= bytes_to_copy;
428 pos -= bytes_to_copy;
429 str -= bytes_to_copy;
430 len -= bytes_to_copy;
431
432 if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
433 struct page *page;
434
435 page = get_arg_page(bprm, pos, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 if (!page) {
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700437 ret = -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 goto out;
439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700441 if (kmapped_page) {
442 flush_kernel_dcache_page(kmapped_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 kunmap(kmapped_page);
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700444 put_arg_page(kmapped_page);
445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 kmapped_page = page;
447 kaddr = kmap(kmapped_page);
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700448 kpos = pos & PAGE_MASK;
449 flush_arg_page(bprm, kpos, kmapped_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700451 if (copy_from_user(kaddr+offset, str, bytes_to_copy)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 ret = -EFAULT;
453 goto out;
454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456 }
457 ret = 0;
458out:
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700459 if (kmapped_page) {
460 flush_kernel_dcache_page(kmapped_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 kunmap(kmapped_page);
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700462 put_arg_page(kmapped_page);
463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 return ret;
465}
466
467/*
468 * Like copy_strings, but get argv and its values from kernel memory.
469 */
470int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm)
471{
472 int r;
473 mm_segment_t oldfs = get_fs();
474 set_fs(KERNEL_DS);
475 r = copy_strings(argc, (char __user * __user *)argv, bprm);
476 set_fs(oldfs);
477 return r;
478}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479EXPORT_SYMBOL(copy_strings_kernel);
480
481#ifdef CONFIG_MMU
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483/*
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700484 * During bprm_mm_init(), we create a temporary stack at STACK_TOP_MAX. Once
485 * the binfmt code determines where the new stack should reside, we shift it to
486 * its final location. The process proceeds as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 *
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700488 * 1) Use shift to calculate the new vma endpoints.
489 * 2) Extend vma to cover both the old and new ranges. This ensures the
490 * arguments passed to subsequent functions are consistent.
491 * 3) Move vma's page tables to the new range.
492 * 4) Free up any cleared pgd range.
493 * 5) Shrink the vma to cover only the new range.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 */
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700495static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
497 struct mm_struct *mm = vma->vm_mm;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700498 unsigned long old_start = vma->vm_start;
499 unsigned long old_end = vma->vm_end;
500 unsigned long length = old_end - old_start;
501 unsigned long new_start = old_start - shift;
502 unsigned long new_end = old_end - shift;
503 struct mmu_gather *tlb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700505 BUG_ON(new_start > new_end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700507 /*
508 * ensure there are no vmas between where we want to go
509 * and where we are
510 */
511 if (vma != find_vma(mm, new_start))
512 return -EFAULT;
513
514 /*
515 * cover the whole range: [new_start, old_end)
516 */
517 vma_adjust(vma, new_start, old_end, vma->vm_pgoff, NULL);
518
519 /*
520 * move the page tables downwards, on failure we rely on
521 * process cleanup to remove whatever mess we made.
522 */
523 if (length != move_page_tables(vma, old_start,
524 vma, new_start, length))
525 return -ENOMEM;
526
527 lru_add_drain();
528 tlb = tlb_gather_mmu(mm, 0);
529 if (new_end > old_start) {
530 /*
531 * when the old and new regions overlap clear from new_end.
532 */
Jan Beulich42b77722008-07-23 21:27:10 -0700533 free_pgd_range(tlb, new_end, old_end, new_end,
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700534 vma->vm_next ? vma->vm_next->vm_start : 0);
535 } else {
536 /*
537 * otherwise, clean from old_start; this is done to not touch
538 * the address space in [new_end, old_start) some architectures
539 * have constraints on va-space that make this illegal (IA64) -
540 * for the others its just a little faster.
541 */
Jan Beulich42b77722008-07-23 21:27:10 -0700542 free_pgd_range(tlb, old_start, old_end, new_end,
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700543 vma->vm_next ? vma->vm_next->vm_start : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 }
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700545 tlb_finish_mmu(tlb, new_end, old_end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700547 /*
548 * shrink the vma to just the new range.
549 */
550 vma_adjust(vma, new_start, new_end, vma->vm_pgoff, NULL);
551
552 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553}
554
555#define EXTRA_STACK_VM_PAGES 20 /* random */
556
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700557/*
558 * Finalizes the stack vm_area_struct. The flags and permissions are updated,
559 * the stack is optionally relocated, and some extra space is added.
560 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561int setup_arg_pages(struct linux_binprm *bprm,
562 unsigned long stack_top,
563 int executable_stack)
564{
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700565 unsigned long ret;
566 unsigned long stack_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 struct mm_struct *mm = current->mm;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700568 struct vm_area_struct *vma = bprm->vma;
569 struct vm_area_struct *prev = NULL;
570 unsigned long vm_flags;
571 unsigned long stack_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573#ifdef CONFIG_STACK_GROWSUP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /* Limit stack size to 1GB */
575 stack_base = current->signal->rlim[RLIMIT_STACK].rlim_max;
576 if (stack_base > (1 << 30))
577 stack_base = 1 << 30;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700579 /* Make sure we didn't let the argument array grow too large. */
580 if (vma->vm_end - vma->vm_start > stack_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 return -ENOMEM;
582
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700583 stack_base = PAGE_ALIGN(stack_top - stack_base);
584
585 stack_shift = vma->vm_start - stack_base;
586 mm->arg_start = bprm->p - stack_shift;
587 bprm->p = vma->vm_end - stack_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#else
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700589 stack_top = arch_align_stack(stack_top);
590 stack_top = PAGE_ALIGN(stack_top);
591 stack_shift = vma->vm_end - stack_top;
592
593 bprm->p -= stack_shift;
594 mm->arg_start = bprm->p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#endif
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700596
597 if (bprm->loader)
598 bprm->loader -= stack_shift;
599 bprm->exec -= stack_shift;
600
601 down_write(&mm->mmap_sem);
Hugh Dickins96a8e132008-07-10 21:19:20 +0100602 vm_flags = VM_STACK_FLAGS;
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700603
604 /*
605 * Adjust stack execute permissions; explicitly enable for
606 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
607 * (arch default) otherwise.
608 */
609 if (unlikely(executable_stack == EXSTACK_ENABLE_X))
610 vm_flags |= VM_EXEC;
611 else if (executable_stack == EXSTACK_DISABLE_X)
612 vm_flags &= ~VM_EXEC;
613 vm_flags |= mm->def_flags;
614
615 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
616 vm_flags);
617 if (ret)
618 goto out_unlock;
619 BUG_ON(prev != vma);
620
621 /* Move stack pages down in memory. */
622 if (stack_shift) {
623 ret = shift_arg_pages(vma, stack_shift);
624 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 up_write(&mm->mmap_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 return ret;
627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629
Ollie Wildb6a2fea2007-07-19 01:48:16 -0700630#ifdef CONFIG_STACK_GROWSUP
631 stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE;
632#else
633 stack_base = vma->vm_start - EXTRA_STACK_VM_PAGES * PAGE_SIZE;
634#endif
635 ret = expand_stack(vma, stack_base);
636 if (ret)
637 ret = -EFAULT;
638
639out_unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 up_write(&mm->mmap_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 return 0;
642}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643EXPORT_SYMBOL(setup_arg_pages);
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#endif /* CONFIG_MMU */
646
647struct file *open_exec(const char *name)
648{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 struct file *file;
Christoph Hellwige56b6a52008-05-19 07:53:34 +0200650 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Al Viro6e8341a2009-04-06 11:16:22 -0400652 file = do_filp_open(AT_FDCWD, name,
653 O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
654 MAY_EXEC | MAY_OPEN);
655 if (IS_ERR(file))
Christoph Hellwige56b6a52008-05-19 07:53:34 +0200656 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Christoph Hellwige56b6a52008-05-19 07:53:34 +0200658 err = -EACCES;
Al Viro6e8341a2009-04-06 11:16:22 -0400659 if (!S_ISREG(file->f_path.dentry->d_inode->i_mode))
660 goto exit;
Christoph Hellwige56b6a52008-05-19 07:53:34 +0200661
Al Viro6e8341a2009-04-06 11:16:22 -0400662 if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)
663 goto exit;
Christoph Hellwige56b6a52008-05-19 07:53:34 +0200664
Eric Paris6110e3a2008-12-17 13:53:20 -0500665 fsnotify_open(file->f_path.dentry);
666
Christoph Hellwige56b6a52008-05-19 07:53:34 +0200667 err = deny_write_access(file);
Al Viro6e8341a2009-04-06 11:16:22 -0400668 if (err)
669 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Al Viro6e8341a2009-04-06 11:16:22 -0400671out:
Christoph Hellwige56b6a52008-05-19 07:53:34 +0200672 return file;
673
Al Viro6e8341a2009-04-06 11:16:22 -0400674exit:
675 fput(file);
Christoph Hellwige56b6a52008-05-19 07:53:34 +0200676 return ERR_PTR(err);
677}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678EXPORT_SYMBOL(open_exec);
679
680int kernel_read(struct file *file, unsigned long offset,
681 char *addr, unsigned long count)
682{
683 mm_segment_t old_fs;
684 loff_t pos = offset;
685 int result;
686
687 old_fs = get_fs();
688 set_fs(get_ds());
689 /* The cast to a user pointer is valid due to the set_fs() */
690 result = vfs_read(file, (void __user *)addr, count, &pos);
691 set_fs(old_fs);
692 return result;
693}
694
695EXPORT_SYMBOL(kernel_read);
696
697static int exec_mmap(struct mm_struct *mm)
698{
699 struct task_struct *tsk;
700 struct mm_struct * old_mm, *active_mm;
701
702 /* Notify parent that we're no longer interested in the old VM */
703 tsk = current;
704 old_mm = current->mm;
705 mm_release(tsk, old_mm);
706
707 if (old_mm) {
708 /*
709 * Make sure that if there is a core dump in progress
710 * for the old mm, we get out and die instead of going
711 * through with the exec. We must hold mmap_sem around
Oleg Nesterov999d9fc2008-07-25 01:47:41 -0700712 * checking core_state and changing tsk->mm.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 */
714 down_read(&old_mm->mmap_sem);
Oleg Nesterov999d9fc2008-07-25 01:47:41 -0700715 if (unlikely(old_mm->core_state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 up_read(&old_mm->mmap_sem);
717 return -EINTR;
718 }
719 }
720 task_lock(tsk);
721 active_mm = tsk->active_mm;
722 tsk->mm = mm;
723 tsk->active_mm = mm;
724 activate_mm(active_mm, mm);
725 task_unlock(tsk);
726 arch_pick_mmap_layout(mm);
727 if (old_mm) {
728 up_read(&old_mm->mmap_sem);
Eric Sesterhenn7dddb122006-04-01 01:13:38 +0200729 BUG_ON(active_mm != old_mm);
Balbir Singh31a78f22008-09-28 23:09:31 +0100730 mm_update_next_owner(old_mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 mmput(old_mm);
732 return 0;
733 }
734 mmdrop(active_mm);
735 return 0;
736}
737
738/*
739 * This function makes sure the current process has its own signal table,
740 * so that flush_signal_handlers can later reset the handlers without
741 * disturbing other processes. (Other processes might share the signal
742 * table via the CLONE_SIGHAND option to clone().)
743 */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800744static int de_thread(struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745{
746 struct signal_struct *sig = tsk->signal;
Oleg Nesterovb2c903b2007-10-16 23:27:22 -0700747 struct sighand_struct *oldsighand = tsk->sighand;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 spinlock_t *lock = &oldsighand->siglock;
749 int count;
750
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700751 if (thread_group_empty(tsk))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 goto no_thread_group;
753
754 /*
755 * Kill all other threads in the thread group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 spin_lock_irq(lock);
Oleg Nesteroved5d2ca2008-02-04 22:27:24 -0800758 if (signal_group_exit(sig)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 /*
760 * Another group action in progress, just
761 * return so that the signal is processed.
762 */
763 spin_unlock_irq(lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 return -EAGAIN;
765 }
Oleg Nesteroved5d2ca2008-02-04 22:27:24 -0800766 sig->group_exit_task = tsk;
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700767 zap_other_threads(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Oleg Nesterovfea9d172008-02-08 04:19:19 -0800769 /* Account for the thread group leader hanging around: */
770 count = thread_group_leader(tsk) ? 1 : 2;
Oleg Nesterov6db840f2007-10-16 23:27:23 -0700771 sig->notify_count = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 while (atomic_read(&sig->count) > count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 __set_current_state(TASK_UNINTERRUPTIBLE);
774 spin_unlock_irq(lock);
775 schedule();
776 spin_lock_irq(lock);
777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 spin_unlock_irq(lock);
779
780 /*
781 * At this point all other threads have exited, all we have to
782 * do is to wait for the thread group leader to become inactive,
783 * and to assume its PID:
784 */
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700785 if (!thread_group_leader(tsk)) {
Oleg Nesterov81879262008-12-01 14:18:16 -0800786 struct task_struct *leader = tsk->group_leader;
Oleg Nesterov6db840f2007-10-16 23:27:23 -0700787
Oleg Nesterov2800d8d2008-04-30 00:53:12 -0700788 sig->notify_count = -1; /* for exit_notify() */
Oleg Nesterov6db840f2007-10-16 23:27:23 -0700789 for (;;) {
790 write_lock_irq(&tasklist_lock);
791 if (likely(leader->exit_state))
792 break;
793 __set_current_state(TASK_UNINTERRUPTIBLE);
794 write_unlock_irq(&tasklist_lock);
795 schedule();
796 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Roland McGrathf5e90282006-04-10 22:54:16 -0700798 /*
799 * The only record we have of the real-time age of a
800 * process, regardless of execs it's done, is start_time.
801 * All the past CPU time is accumulated in signal_struct
802 * from sister threads now dead. But in this non-leader
803 * exec, nothing survives from the original leader thread,
804 * whose birth marks the true age of this process now.
805 * When we take on its identity by switching to its PID, we
806 * also take its birthdate (always earlier than our own).
807 */
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700808 tsk->start_time = leader->start_time;
Roland McGrathf5e90282006-04-10 22:54:16 -0700809
Pavel Emelyanovbac0abd2007-10-18 23:40:18 -0700810 BUG_ON(!same_thread_group(leader, tsk));
811 BUG_ON(has_group_leader_pid(tsk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 /*
813 * An exec() starts a new thread group with the
814 * TGID of the previous thread group. Rehash the
815 * two threads with a switched PID, and release
816 * the former thread group leader:
817 */
Eric W. Biedermand73d6522006-03-28 16:11:03 -0800818
819 /* Become a process group leader with the old leader's pid.
Eric W. Biedermanc18258c2006-09-27 01:51:06 -0700820 * The old leader becomes a thread of the this thread group.
821 * Note: The old leader also uses this pid until release_task
Eric W. Biedermand73d6522006-03-28 16:11:03 -0800822 * is called. Odd but simple and correct.
823 */
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700824 detach_pid(tsk, PIDTYPE_PID);
825 tsk->pid = leader->pid;
Sukadev Bhattiprolu3743ca02007-10-18 23:39:51 -0700826 attach_pid(tsk, PIDTYPE_PID, task_pid(leader));
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700827 transfer_pid(leader, tsk, PIDTYPE_PGID);
828 transfer_pid(leader, tsk, PIDTYPE_SID);
829 list_replace_rcu(&leader->tasks, &tsk->tasks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700831 tsk->group_leader = tsk;
832 leader->group_leader = tsk;
Eric W. Biedermande12a782006-04-10 17:16:49 -0600833
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700834 tsk->exit_signal = SIGCHLD;
Oleg Nesterov962b5642005-11-23 13:37:43 -0800835
836 BUG_ON(leader->exit_state != EXIT_ZOMBIE);
837 leader->exit_state = EXIT_DEAD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 write_unlock_irq(&tasklist_lock);
Oleg Nesterov81879262008-12-01 14:18:16 -0800839
840 release_task(leader);
Oleg Nesteroved5d2ca2008-02-04 22:27:24 -0800841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Oleg Nesterov6db840f2007-10-16 23:27:23 -0700843 sig->group_exit_task = NULL;
844 sig->notify_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846no_thread_group:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 exit_itimers(sig);
Oleg Nesterovcbaffba2008-05-26 20:55:42 +0400848 flush_itimer_signals();
Oleg Nesterov329f7db2005-11-07 21:12:43 +0300849
Oleg Nesterovb2c903b2007-10-16 23:27:22 -0700850 if (atomic_read(&oldsighand->count) != 1) {
851 struct sighand_struct *newsighand;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 /*
Oleg Nesterovb2c903b2007-10-16 23:27:22 -0700853 * This ->sighand is shared with the CLONE_SIGHAND
854 * but not CLONE_THREAD task, switch to the new one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 */
Oleg Nesterovb2c903b2007-10-16 23:27:22 -0700856 newsighand = kmem_cache_alloc(sighand_cachep, GFP_KERNEL);
857 if (!newsighand)
858 return -ENOMEM;
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 atomic_set(&newsighand->count, 1);
861 memcpy(newsighand->action, oldsighand->action,
862 sizeof(newsighand->action));
863
864 write_lock_irq(&tasklist_lock);
865 spin_lock(&oldsighand->siglock);
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700866 rcu_assign_pointer(tsk->sighand, newsighand);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 spin_unlock(&oldsighand->siglock);
868 write_unlock_irq(&tasklist_lock);
869
Davide Libenzifba2afa2007-05-10 22:23:13 -0700870 __cleanup_sighand(oldsighand);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 }
872
Eric W. Biedermanaafe6c22006-09-27 01:51:13 -0700873 BUG_ON(!thread_group_leader(tsk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 return 0;
875}
Oleg Nesterov0840a902007-10-16 23:27:22 -0700876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877/*
878 * These functions flushes out all traces of the currently running executable
879 * so that a new one can be started
880 */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800881static void flush_old_files(struct files_struct * files)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
883 long j = -1;
Dipankar Sarmabadf1662005-09-09 13:04:10 -0700884 struct fdtable *fdt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 spin_lock(&files->file_lock);
887 for (;;) {
888 unsigned long set, i;
889
890 j++;
891 i = j * __NFDBITS;
Dipankar Sarmabadf1662005-09-09 13:04:10 -0700892 fdt = files_fdtable(files);
Vadim Lobanovbbea9f62006-12-10 02:21:12 -0800893 if (i >= fdt->max_fds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 break;
Dipankar Sarmabadf1662005-09-09 13:04:10 -0700895 set = fdt->close_on_exec->fds_bits[j];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 if (!set)
897 continue;
Dipankar Sarmabadf1662005-09-09 13:04:10 -0700898 fdt->close_on_exec->fds_bits[j] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 spin_unlock(&files->file_lock);
900 for ( ; set ; i++,set >>= 1) {
901 if (set & 1) {
902 sys_close(i);
903 }
904 }
905 spin_lock(&files->file_lock);
906
907 }
908 spin_unlock(&files->file_lock);
909}
910
Andrew Morton59714d62008-02-04 22:27:21 -0800911char *get_task_comm(char *buf, struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
913 /* buf must be at least sizeof(tsk->comm) in size */
914 task_lock(tsk);
915 strncpy(buf, tsk->comm, sizeof(tsk->comm));
916 task_unlock(tsk);
Andrew Morton59714d62008-02-04 22:27:21 -0800917 return buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
920void set_task_comm(struct task_struct *tsk, char *buf)
921{
922 task_lock(tsk);
923 strlcpy(tsk->comm, buf, sizeof(tsk->comm));
924 task_unlock(tsk);
925}
926
927int flush_old_exec(struct linux_binprm * bprm)
928{
929 char * name;
930 int i, ch, retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 char tcomm[sizeof(current->comm)];
932
933 /*
934 * Make sure we have a private signal table and that
935 * we are unassociated from the previous thread group.
936 */
937 retval = de_thread(current);
938 if (retval)
939 goto out;
940
Matt Helsley925d1c42008-04-29 01:01:36 -0700941 set_mm_exe_file(bprm->mm, bprm->file);
942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 * Release all of the old mmap stuff
945 */
946 retval = exec_mmap(bprm->mm);
947 if (retval)
Al Virofd8328b2008-04-22 05:11:59 -0400948 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 bprm->mm = NULL; /* We're using it now */
951
952 /* This is the point of no return */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 current->sas_ss_sp = current->sas_ss_size = 0;
954
David Howellsda9592e2008-11-14 10:39:05 +1100955 if (current_euid() == current_uid() && current_egid() == current_gid())
Kawai, Hidehiro6c5d5232007-07-19 01:48:27 -0700956 set_dumpable(current->mm, 1);
Alan Coxd6e71142005-06-23 00:09:43 -0700957 else
Kawai, Hidehiro6c5d5232007-07-19 01:48:27 -0700958 set_dumpable(current->mm, suid_dumpable);
Alan Coxd6e71142005-06-23 00:09:43 -0700959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 name = bprm->filename;
Paolo 'Blaisorblade' Giarrusso36772092005-05-05 16:16:12 -0700961
962 /* Copies the binary name from after last slash */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 for (i=0; (ch = *(name++)) != '\0';) {
964 if (ch == '/')
Paolo 'Blaisorblade' Giarrusso36772092005-05-05 16:16:12 -0700965 i = 0; /* overwrite what we wrote */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 else
967 if (i < (sizeof(tcomm) - 1))
968 tcomm[i++] = ch;
969 }
970 tcomm[i] = '\0';
971 set_task_comm(current, tcomm);
972
973 current->flags &= ~PF_RANDOMIZE;
974 flush_thread();
975
Benjamin Herrenschmidt0551fbd2006-02-28 16:59:19 -0800976 /* Set the new mm task size. We have to do that late because it may
977 * depend on TIF_32BIT which is only updated in flush_thread() on
978 * some architectures like powerpc
979 */
980 current->mm->task_size = TASK_SIZE;
981
David Howellsa6f76f22008-11-14 10:39:24 +1100982 /* install the new credentials */
983 if (bprm->cred->uid != current_euid() ||
984 bprm->cred->gid != current_egid()) {
Marcel Holtmannd2d56c52007-08-17 21:47:58 +0200985 current->pdeath_signal = 0;
986 } else if (file_permission(bprm->file, MAY_READ) ||
David Howellsa6f76f22008-11-14 10:39:24 +1100987 bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP) {
Kawai, Hidehiro6c5d5232007-07-19 01:48:27 -0700988 set_dumpable(current->mm, suid_dumpable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 }
990
David Howellsa6f76f22008-11-14 10:39:24 +1100991 current->personality &= ~bprm->per_clear;
992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 /* An exec changes our domain. We are no longer part of the thread
994 group */
995
996 current->self_exec_id++;
997
998 flush_signal_handlers(current, 0);
999 flush_old_files(current->files);
1000
1001 return 0;
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003out:
1004 return retval;
1005}
1006
1007EXPORT_SYMBOL(flush_old_exec);
1008
David Howellsa6f76f22008-11-14 10:39:24 +11001009/*
1010 * install the new credentials for this executable
1011 */
1012void install_exec_creds(struct linux_binprm *bprm)
1013{
1014 security_bprm_committing_creds(bprm);
1015
1016 commit_creds(bprm->cred);
1017 bprm->cred = NULL;
1018
1019 /* cred_exec_mutex must be held at least to this point to prevent
1020 * ptrace_attach() from altering our determination of the task's
1021 * credentials; any time after this it may be unlocked */
1022
1023 security_bprm_committed_creds(bprm);
1024}
1025EXPORT_SYMBOL(install_exec_creds);
1026
1027/*
1028 * determine how safe it is to execute the proposed program
1029 * - the caller must hold current->cred_exec_mutex to protect against
1030 * PTRACE_ATTACH
1031 */
Al Viro498052b2009-03-30 07:20:30 -04001032int check_unsafe_exec(struct linux_binprm *bprm)
David Howellsa6f76f22008-11-14 10:39:24 +11001033{
David Howells0bf2f3a2009-02-06 11:45:46 +00001034 struct task_struct *p = current, *t;
Al Virof1191b52009-03-30 07:35:18 -04001035 unsigned n_fs;
Al Viro498052b2009-03-30 07:20:30 -04001036 int res = 0;
David Howellsa6f76f22008-11-14 10:39:24 +11001037
1038 bprm->unsafe = tracehook_unsafe_exec(p);
1039
David Howells0bf2f3a2009-02-06 11:45:46 +00001040 n_fs = 1;
Al Viro498052b2009-03-30 07:20:30 -04001041 write_lock(&p->fs->lock);
Oleg Nesterov437f7fd2009-04-24 01:02:45 +02001042 rcu_read_lock();
David Howells0bf2f3a2009-02-06 11:45:46 +00001043 for (t = next_thread(p); t != p; t = next_thread(t)) {
1044 if (t->fs == p->fs)
1045 n_fs++;
David Howells0bf2f3a2009-02-06 11:45:46 +00001046 }
Oleg Nesterov437f7fd2009-04-24 01:02:45 +02001047 rcu_read_unlock();
David Howells0bf2f3a2009-02-06 11:45:46 +00001048
Al Virof1191b52009-03-30 07:35:18 -04001049 if (p->fs->users > n_fs) {
David Howellsa6f76f22008-11-14 10:39:24 +11001050 bprm->unsafe |= LSM_UNSAFE_SHARE;
Al Viro498052b2009-03-30 07:20:30 -04001051 } else {
Oleg Nesterov8c652f92009-04-24 01:01:56 +02001052 res = -EAGAIN;
1053 if (!p->fs->in_exec) {
1054 p->fs->in_exec = 1;
1055 res = 1;
1056 }
Al Viro498052b2009-03-30 07:20:30 -04001057 }
Al Viro498052b2009-03-30 07:20:30 -04001058 write_unlock(&p->fs->lock);
1059
1060 return res;
David Howellsa6f76f22008-11-14 10:39:24 +11001061}
1062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063/*
1064 * Fill the binprm structure from the inode.
1065 * Check permissions, then read the first 128 (BINPRM_BUF_SIZE) bytes
David Howellsa6f76f22008-11-14 10:39:24 +11001066 *
1067 * This may be called multiple times for binary chains (scripts for example).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 */
1069int prepare_binprm(struct linux_binprm *bprm)
1070{
David Howellsa6f76f22008-11-14 10:39:24 +11001071 umode_t mode;
Josef "Jeff" Sipek0f7fc9e2006-12-08 02:36:35 -08001072 struct inode * inode = bprm->file->f_path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 int retval;
1074
1075 mode = inode->i_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 if (bprm->file->f_op == NULL)
1077 return -EACCES;
1078
David Howellsa6f76f22008-11-14 10:39:24 +11001079 /* clear any previous set[ug]id data from a previous binary */
1080 bprm->cred->euid = current_euid();
1081 bprm->cred->egid = current_egid();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
David Howellsa6f76f22008-11-14 10:39:24 +11001083 if (!(bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 /* Set-uid? */
1085 if (mode & S_ISUID) {
David Howellsa6f76f22008-11-14 10:39:24 +11001086 bprm->per_clear |= PER_CLEAR_ON_SETID;
1087 bprm->cred->euid = inode->i_uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
1089
1090 /* Set-gid? */
1091 /*
1092 * If setgid is set but no group execute bit then this
1093 * is a candidate for mandatory locking, not a setgid
1094 * executable.
1095 */
1096 if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
David Howellsa6f76f22008-11-14 10:39:24 +11001097 bprm->per_clear |= PER_CLEAR_ON_SETID;
1098 bprm->cred->egid = inode->i_gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 }
1100 }
1101
1102 /* fill in binprm security blob */
David Howellsa6f76f22008-11-14 10:39:24 +11001103 retval = security_bprm_set_creds(bprm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 if (retval)
1105 return retval;
David Howellsa6f76f22008-11-14 10:39:24 +11001106 bprm->cred_prepared = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
David Howellsa6f76f22008-11-14 10:39:24 +11001108 memset(bprm->buf, 0, BINPRM_BUF_SIZE);
1109 return kernel_read(bprm->file, 0, bprm->buf, BINPRM_BUF_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
1112EXPORT_SYMBOL(prepare_binprm);
1113
Nick Piggin4fc75ff2007-05-08 00:25:16 -07001114/*
1115 * Arguments are '\0' separated strings found at the location bprm->p
1116 * points to; chop off the first by relocating brpm->p to right after
1117 * the first '\0' encountered.
1118 */
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001119int remove_arg_zero(struct linux_binprm *bprm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001121 int ret = 0;
1122 unsigned long offset;
1123 char *kaddr;
1124 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001126 if (!bprm->argc)
1127 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001129 do {
1130 offset = bprm->p & ~PAGE_MASK;
1131 page = get_arg_page(bprm, bprm->p, 0);
1132 if (!page) {
1133 ret = -EFAULT;
1134 goto out;
1135 }
1136 kaddr = kmap_atomic(page, KM_USER0);
Nick Piggin4fc75ff2007-05-08 00:25:16 -07001137
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001138 for (; offset < PAGE_SIZE && kaddr[offset];
1139 offset++, bprm->p++)
1140 ;
Nick Piggin4fc75ff2007-05-08 00:25:16 -07001141
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001142 kunmap_atomic(kaddr, KM_USER0);
1143 put_arg_page(page);
Nick Piggin4fc75ff2007-05-08 00:25:16 -07001144
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001145 if (offset == PAGE_SIZE)
1146 free_arg_page(bprm, (bprm->p >> PAGE_SHIFT) - 1);
1147 } while (offset == PAGE_SIZE);
Nick Piggin4fc75ff2007-05-08 00:25:16 -07001148
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001149 bprm->p++;
1150 bprm->argc--;
1151 ret = 0;
Nick Piggin4fc75ff2007-05-08 00:25:16 -07001152
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001153out:
1154 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156EXPORT_SYMBOL(remove_arg_zero);
1157
1158/*
1159 * cycle the list of binary formats handler, until one recognizes the image
1160 */
1161int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1162{
Roland McGrath85f33462008-12-09 19:36:38 -08001163 unsigned int depth = bprm->recursion_depth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 int try,retval;
1165 struct linux_binfmt *fmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 retval = security_bprm_check(bprm);
1168 if (retval)
1169 return retval;
Mimi Zohar6146f0d2009-02-04 09:06:57 -05001170 retval = ima_bprm_check(bprm);
1171 if (retval)
1172 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174 /* kernel module loader fixup */
1175 /* so we don't try to load run modprobe in kernel space. */
1176 set_fs(USER_DS);
Al Viro473ae302006-04-26 14:04:08 -04001177
1178 retval = audit_bprm(bprm);
1179 if (retval)
1180 return retval;
1181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 retval = -ENOENT;
1183 for (try=0; try<2; try++) {
1184 read_lock(&binfmt_lock);
Alexey Dobriyane4dc1b12007-10-16 23:26:03 -07001185 list_for_each_entry(fmt, &formats, lh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 int (*fn)(struct linux_binprm *, struct pt_regs *) = fmt->load_binary;
1187 if (!fn)
1188 continue;
1189 if (!try_module_get(fmt->module))
1190 continue;
1191 read_unlock(&binfmt_lock);
1192 retval = fn(bprm, regs);
Roland McGrath85f33462008-12-09 19:36:38 -08001193 /*
1194 * Restore the depth counter to its starting value
1195 * in this call, so we don't have to rely on every
1196 * load_binary function to restore it on return.
1197 */
1198 bprm->recursion_depth = depth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 if (retval >= 0) {
Roland McGrath85f33462008-12-09 19:36:38 -08001200 if (depth == 0)
1201 tracehook_report_exec(fmt, bprm, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 put_binfmt(fmt);
1203 allow_write_access(bprm->file);
1204 if (bprm->file)
1205 fput(bprm->file);
1206 bprm->file = NULL;
1207 current->did_exec = 1;
Matt Helsley9f460802005-11-07 00:59:16 -08001208 proc_exec_connector(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 return retval;
1210 }
1211 read_lock(&binfmt_lock);
1212 put_binfmt(fmt);
1213 if (retval != -ENOEXEC || bprm->mm == NULL)
1214 break;
1215 if (!bprm->file) {
1216 read_unlock(&binfmt_lock);
1217 return retval;
1218 }
1219 }
1220 read_unlock(&binfmt_lock);
1221 if (retval != -ENOEXEC || bprm->mm == NULL) {
1222 break;
Johannes Berg5f4123b2008-07-09 10:28:40 +02001223#ifdef CONFIG_MODULES
1224 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225#define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
1226 if (printable(bprm->buf[0]) &&
1227 printable(bprm->buf[1]) &&
1228 printable(bprm->buf[2]) &&
1229 printable(bprm->buf[3]))
1230 break; /* -ENOEXEC */
1231 request_module("binfmt-%04x", *(unsigned short *)(&bprm->buf[2]));
1232#endif
1233 }
1234 }
1235 return retval;
1236}
1237
1238EXPORT_SYMBOL(search_binary_handler);
1239
Al Viro08a6fac2008-05-10 16:38:25 -04001240void free_bprm(struct linux_binprm *bprm)
1241{
1242 free_arg_pages(bprm);
David Howellsa6f76f22008-11-14 10:39:24 +11001243 if (bprm->cred)
1244 abort_creds(bprm->cred);
Al Viro08a6fac2008-05-10 16:38:25 -04001245 kfree(bprm);
1246}
1247
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248/*
1249 * sys_execve() executes a new program.
1250 */
1251int do_execve(char * filename,
1252 char __user *__user *argv,
1253 char __user *__user *envp,
1254 struct pt_regs * regs)
1255{
1256 struct linux_binprm *bprm;
1257 struct file *file;
Al Viro3b125382008-04-22 05:31:30 -04001258 struct files_struct *displaced;
Oleg Nesterov8c652f92009-04-24 01:01:56 +02001259 bool clear_in_exec;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Al Viro3b125382008-04-22 05:31:30 -04001262 retval = unshare_files(&displaced);
Al Virofd8328b2008-04-22 05:11:59 -04001263 if (retval)
1264 goto out_ret;
1265
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 retval = -ENOMEM;
Oliver Neukum11b0b5a2006-03-25 03:08:13 -08001267 bprm = kzalloc(sizeof(*bprm), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 if (!bprm)
Al Virofd8328b2008-04-22 05:11:59 -04001269 goto out_files;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
David Howellsa6f76f22008-11-14 10:39:24 +11001271 retval = mutex_lock_interruptible(&current->cred_exec_mutex);
1272 if (retval < 0)
1273 goto out_free;
Kentaro Takedaf9ce1f12009-02-05 17:18:11 +09001274 current->in_execve = 1;
David Howellsa6f76f22008-11-14 10:39:24 +11001275
1276 retval = -ENOMEM;
1277 bprm->cred = prepare_exec_creds();
1278 if (!bprm->cred)
1279 goto out_unlock;
Al Viro498052b2009-03-30 07:20:30 -04001280
1281 retval = check_unsafe_exec(bprm);
Oleg Nesterov8c652f92009-04-24 01:01:56 +02001282 if (retval < 0)
Al Viro498052b2009-03-30 07:20:30 -04001283 goto out_unlock;
Oleg Nesterov8c652f92009-04-24 01:01:56 +02001284 clear_in_exec = retval;
David Howellsa6f76f22008-11-14 10:39:24 +11001285
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 file = open_exec(filename);
1287 retval = PTR_ERR(file);
1288 if (IS_ERR(file))
Al Viro498052b2009-03-30 07:20:30 -04001289 goto out_unmark;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 sched_exec();
1292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 bprm->file = file;
1294 bprm->filename = filename;
1295 bprm->interp = filename;
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001296
1297 retval = bprm_mm_init(bprm);
1298 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 goto out_file;
1300
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001301 bprm->argc = count(argv, MAX_ARG_STRINGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 if ((retval = bprm->argc) < 0)
David Howellsa6f76f22008-11-14 10:39:24 +11001303 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001305 bprm->envc = count(envp, MAX_ARG_STRINGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 if ((retval = bprm->envc) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 goto out;
1308
1309 retval = prepare_binprm(bprm);
1310 if (retval < 0)
1311 goto out;
1312
1313 retval = copy_strings_kernel(1, &bprm->filename, bprm);
1314 if (retval < 0)
1315 goto out;
1316
1317 bprm->exec = bprm->p;
1318 retval = copy_strings(bprm->envc, envp, bprm);
1319 if (retval < 0)
1320 goto out;
1321
1322 retval = copy_strings(bprm->argc, argv, bprm);
1323 if (retval < 0)
1324 goto out;
1325
Oleg Nesterov7b34e422008-07-25 01:47:37 -07001326 current->flags &= ~PF_KTHREAD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 retval = search_binary_handler(bprm,regs);
David Howellsa6f76f22008-11-14 10:39:24 +11001328 if (retval < 0)
1329 goto out;
1330
1331 /* execve succeeded */
Al Viro498052b2009-03-30 07:20:30 -04001332 current->fs->in_exec = 0;
Kentaro Takedaf9ce1f12009-02-05 17:18:11 +09001333 current->in_execve = 0;
David Howellsa6f76f22008-11-14 10:39:24 +11001334 mutex_unlock(&current->cred_exec_mutex);
1335 acct_update_integrals(current);
1336 free_bprm(bprm);
1337 if (displaced)
1338 put_files_struct(displaced);
1339 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
1341out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 if (bprm->mm)
Ollie Wildb6a2fea2007-07-19 01:48:16 -07001343 mmput (bprm->mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345out_file:
1346 if (bprm->file) {
1347 allow_write_access(bprm->file);
1348 fput(bprm->file);
1349 }
David Howellsa6f76f22008-11-14 10:39:24 +11001350
Al Viro498052b2009-03-30 07:20:30 -04001351out_unmark:
Oleg Nesterov8c652f92009-04-24 01:01:56 +02001352 if (clear_in_exec)
1353 current->fs->in_exec = 0;
Al Viro498052b2009-03-30 07:20:30 -04001354
David Howellsa6f76f22008-11-14 10:39:24 +11001355out_unlock:
Kentaro Takedaf9ce1f12009-02-05 17:18:11 +09001356 current->in_execve = 0;
David Howellsa6f76f22008-11-14 10:39:24 +11001357 mutex_unlock(&current->cred_exec_mutex);
1358
1359out_free:
Al Viro08a6fac2008-05-10 16:38:25 -04001360 free_bprm(bprm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Al Virofd8328b2008-04-22 05:11:59 -04001362out_files:
Al Viro3b125382008-04-22 05:31:30 -04001363 if (displaced)
1364 reset_files_struct(displaced);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365out_ret:
1366 return retval;
1367}
1368
1369int set_binfmt(struct linux_binfmt *new)
1370{
1371 struct linux_binfmt *old = current->binfmt;
1372
1373 if (new) {
1374 if (!try_module_get(new->module))
1375 return -1;
1376 }
1377 current->binfmt = new;
1378 if (old)
1379 module_put(old->module);
1380 return 0;
1381}
1382
1383EXPORT_SYMBOL(set_binfmt);
1384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385/* format_corename will inspect the pattern parameter, and output a
1386 * name into corename, which must have space for at least
1387 * CORENAME_MAX_SIZE bytes plus one byte for the zero terminator.
1388 */
Oleg Nesterov64093242008-10-18 20:28:22 -07001389static int format_corename(char *corename, long signr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
David Howells86a264a2008-11-14 10:39:18 +11001391 const struct cred *cred = current_cred();
Oleg Nesterov565b9b12008-07-25 01:47:47 -07001392 const char *pat_ptr = core_pattern;
1393 int ispipe = (*pat_ptr == '|');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 char *out_ptr = corename;
1395 char *const out_end = corename + CORENAME_MAX_SIZE;
1396 int rc;
1397 int pid_in_pattern = 0;
1398
1399 /* Repeat as long as we have more pattern to process and more output
1400 space */
1401 while (*pat_ptr) {
1402 if (*pat_ptr != '%') {
1403 if (out_ptr == out_end)
1404 goto out;
1405 *out_ptr++ = *pat_ptr++;
1406 } else {
1407 switch (*++pat_ptr) {
1408 case 0:
1409 goto out;
1410 /* Double percent, output one percent */
1411 case '%':
1412 if (out_ptr == out_end)
1413 goto out;
1414 *out_ptr++ = '%';
1415 break;
1416 /* pid */
1417 case 'p':
1418 pid_in_pattern = 1;
1419 rc = snprintf(out_ptr, out_end - out_ptr,
Pavel Emelyanovb4888932007-10-18 23:40:14 -07001420 "%d", task_tgid_vnr(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 if (rc > out_end - out_ptr)
1422 goto out;
1423 out_ptr += rc;
1424 break;
1425 /* uid */
1426 case 'u':
1427 rc = snprintf(out_ptr, out_end - out_ptr,
David Howells86a264a2008-11-14 10:39:18 +11001428 "%d", cred->uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 if (rc > out_end - out_ptr)
1430 goto out;
1431 out_ptr += rc;
1432 break;
1433 /* gid */
1434 case 'g':
1435 rc = snprintf(out_ptr, out_end - out_ptr,
David Howells86a264a2008-11-14 10:39:18 +11001436 "%d", cred->gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 if (rc > out_end - out_ptr)
1438 goto out;
1439 out_ptr += rc;
1440 break;
1441 /* signal that caused the coredump */
1442 case 's':
1443 rc = snprintf(out_ptr, out_end - out_ptr,
1444 "%ld", signr);
1445 if (rc > out_end - out_ptr)
1446 goto out;
1447 out_ptr += rc;
1448 break;
1449 /* UNIX time of coredump */
1450 case 't': {
1451 struct timeval tv;
1452 do_gettimeofday(&tv);
1453 rc = snprintf(out_ptr, out_end - out_ptr,
1454 "%lu", tv.tv_sec);
1455 if (rc > out_end - out_ptr)
1456 goto out;
1457 out_ptr += rc;
1458 break;
1459 }
1460 /* hostname */
1461 case 'h':
1462 down_read(&uts_sem);
1463 rc = snprintf(out_ptr, out_end - out_ptr,
Serge E. Hallyne9ff3992006-10-02 02:18:11 -07001464 "%s", utsname()->nodename);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 up_read(&uts_sem);
1466 if (rc > out_end - out_ptr)
1467 goto out;
1468 out_ptr += rc;
1469 break;
1470 /* executable */
1471 case 'e':
1472 rc = snprintf(out_ptr, out_end - out_ptr,
1473 "%s", current->comm);
1474 if (rc > out_end - out_ptr)
1475 goto out;
1476 out_ptr += rc;
1477 break;
Neil Horman74aadce2007-10-16 23:26:35 -07001478 /* core limit size */
1479 case 'c':
1480 rc = snprintf(out_ptr, out_end - out_ptr,
1481 "%lu", current->signal->rlim[RLIMIT_CORE].rlim_cur);
1482 if (rc > out_end - out_ptr)
1483 goto out;
1484 out_ptr += rc;
1485 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 default:
1487 break;
1488 }
1489 ++pat_ptr;
1490 }
1491 }
1492 /* Backward compatibility with core_uses_pid:
1493 *
1494 * If core_pattern does not include a %p (as is the default)
1495 * and core_uses_pid is set, then .%pid will be appended to
Alan Coxc4bbafd2007-04-16 22:53:13 -07001496 * the filename. Do not do this for piped commands. */
Oleg Nesterov64093242008-10-18 20:28:22 -07001497 if (!ispipe && !pid_in_pattern && core_uses_pid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 rc = snprintf(out_ptr, out_end - out_ptr,
Pavel Emelyanovb4888932007-10-18 23:40:14 -07001499 ".%d", task_tgid_vnr(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 if (rc > out_end - out_ptr)
1501 goto out;
1502 out_ptr += rc;
1503 }
Alan Coxc4bbafd2007-04-16 22:53:13 -07001504out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 *out_ptr = 0;
Alan Coxc4bbafd2007-04-16 22:53:13 -07001506 return ispipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001509static int zap_process(struct task_struct *start)
Oleg Nesterovaceecc02006-06-26 00:26:05 -07001510{
1511 struct task_struct *t;
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001512 int nr = 0;
Oleg Nesterov281de332006-06-26 00:26:06 -07001513
Oleg Nesterovd5f70c02006-06-26 00:26:07 -07001514 start->signal->flags = SIGNAL_GROUP_EXIT;
1515 start->signal->group_stop_count = 0;
Oleg Nesterovaceecc02006-06-26 00:26:05 -07001516
1517 t = start;
1518 do {
1519 if (t != current && t->mm) {
Oleg Nesterov281de332006-06-26 00:26:06 -07001520 sigaddset(&t->pending.signal, SIGKILL);
1521 signal_wake_up(t, 1);
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001522 nr++;
Oleg Nesterovaceecc02006-06-26 00:26:05 -07001523 }
Oleg Nesterove4901f92008-07-25 01:47:31 -07001524 } while_each_thread(start, t);
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001525
1526 return nr;
Oleg Nesterovaceecc02006-06-26 00:26:05 -07001527}
1528
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001529static inline int zap_threads(struct task_struct *tsk, struct mm_struct *mm,
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001530 struct core_state *core_state, int exit_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
1532 struct task_struct *g, *p;
Oleg Nesterov5debfa62006-06-26 00:26:09 -07001533 unsigned long flags;
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001534 int nr = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001536 spin_lock_irq(&tsk->sighand->siglock);
Oleg Nesteroved5d2ca2008-02-04 22:27:24 -08001537 if (!signal_group_exit(tsk->signal)) {
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001538 mm->core_state = core_state;
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001539 tsk->signal->group_exit_code = exit_code;
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001540 nr = zap_process(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 }
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001542 spin_unlock_irq(&tsk->sighand->siglock);
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001543 if (unlikely(nr < 0))
1544 return nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001546 if (atomic_read(&mm->mm_users) == nr + 1)
Oleg Nesterov5debfa62006-06-26 00:26:09 -07001547 goto done;
Oleg Nesterove4901f92008-07-25 01:47:31 -07001548 /*
1549 * We should find and kill all tasks which use this mm, and we should
Oleg Nesterov999d9fc2008-07-25 01:47:41 -07001550 * count them correctly into ->nr_threads. We don't take tasklist
Oleg Nesterove4901f92008-07-25 01:47:31 -07001551 * lock, but this is safe wrt:
1552 *
1553 * fork:
1554 * None of sub-threads can fork after zap_process(leader). All
1555 * processes which were created before this point should be
1556 * visible to zap_threads() because copy_process() adds the new
1557 * process to the tail of init_task.tasks list, and lock/unlock
1558 * of ->siglock provides a memory barrier.
1559 *
1560 * do_exit:
1561 * The caller holds mm->mmap_sem. This means that the task which
1562 * uses this mm can't pass exit_mm(), so it can't exit or clear
1563 * its ->mm.
1564 *
1565 * de_thread:
1566 * It does list_replace_rcu(&leader->tasks, &current->tasks),
1567 * we must see either old or new leader, this does not matter.
1568 * However, it can change p->sighand, so lock_task_sighand(p)
1569 * must be used. Since p->mm != NULL and we hold ->mmap_sem
1570 * it can't fail.
1571 *
1572 * Note also that "g" can be the old leader with ->mm == NULL
1573 * and already unhashed and thus removed from ->thread_group.
1574 * This is OK, __unhash_process()->list_del_rcu() does not
1575 * clear the ->next pointer, we will find the new leader via
1576 * next_thread().
1577 */
Oleg Nesterov7b1c6152006-06-26 00:26:08 -07001578 rcu_read_lock();
Oleg Nesterovaceecc02006-06-26 00:26:05 -07001579 for_each_process(g) {
Oleg Nesterov5debfa62006-06-26 00:26:09 -07001580 if (g == tsk->group_leader)
1581 continue;
Oleg Nesterov15b9f362008-07-25 01:47:39 -07001582 if (g->flags & PF_KTHREAD)
1583 continue;
Oleg Nesterovaceecc02006-06-26 00:26:05 -07001584 p = g;
1585 do {
1586 if (p->mm) {
Oleg Nesterov15b9f362008-07-25 01:47:39 -07001587 if (unlikely(p->mm == mm)) {
Oleg Nesterov5debfa62006-06-26 00:26:09 -07001588 lock_task_sighand(p, &flags);
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001589 nr += zap_process(p);
Oleg Nesterov5debfa62006-06-26 00:26:09 -07001590 unlock_task_sighand(p, &flags);
1591 }
Oleg Nesterovaceecc02006-06-26 00:26:05 -07001592 break;
1593 }
Oleg Nesterove4901f92008-07-25 01:47:31 -07001594 } while_each_thread(g, p);
Oleg Nesterovaceecc02006-06-26 00:26:05 -07001595 }
Oleg Nesterov7b1c6152006-06-26 00:26:08 -07001596 rcu_read_unlock();
Oleg Nesterov5debfa62006-06-26 00:26:09 -07001597done:
Oleg Nesterovc5f1cc82008-07-25 01:47:42 -07001598 atomic_set(&core_state->nr_threads, nr);
Oleg Nesterov8cd9c242008-07-25 01:47:42 -07001599 return nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
Oleg Nesterov9d5b3272008-07-25 01:47:43 -07001602static int coredump_wait(int exit_code, struct core_state *core_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603{
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001604 struct task_struct *tsk = current;
1605 struct mm_struct *mm = tsk->mm;
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001606 struct completion *vfork_done;
Oleg Nesterov2384f552005-10-30 15:02:47 -08001607 int core_waiters;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Oleg Nesterov9d5b3272008-07-25 01:47:43 -07001609 init_completion(&core_state->startup);
Oleg Nesterovb564daf2008-07-25 01:47:44 -07001610 core_state->dumper.task = tsk;
1611 core_state->dumper.next = NULL;
Oleg Nesterov9d5b3272008-07-25 01:47:43 -07001612 core_waiters = zap_threads(tsk, mm, core_state, exit_code);
Oleg Nesterov2384f552005-10-30 15:02:47 -08001613 up_write(&mm->mmap_sem);
1614
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001615 if (unlikely(core_waiters < 0))
1616 goto fail;
1617
1618 /*
1619 * Make sure nobody is waiting for us to release the VM,
1620 * otherwise we can deadlock when we wait on each other
1621 */
1622 vfork_done = tsk->vfork_done;
1623 if (vfork_done) {
1624 tsk->vfork_done = NULL;
1625 complete(vfork_done);
1626 }
1627
Oleg Nesterov2384f552005-10-30 15:02:47 -08001628 if (core_waiters)
Oleg Nesterov9d5b3272008-07-25 01:47:43 -07001629 wait_for_completion(&core_state->startup);
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001630fail:
Oleg Nesterovdcf560c2006-06-26 00:26:08 -07001631 return core_waiters;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Oleg Nesterova94e2d42008-07-25 01:47:46 -07001634static void coredump_finish(struct mm_struct *mm)
1635{
1636 struct core_thread *curr, *next;
1637 struct task_struct *task;
1638
1639 next = mm->core_state->dumper.next;
1640 while ((curr = next) != NULL) {
1641 next = curr->next;
1642 task = curr->task;
1643 /*
1644 * see exit_mm(), curr->task must not see
1645 * ->task == NULL before we read ->next.
1646 */
1647 smp_mb();
1648 curr->task = NULL;
1649 wake_up_process(task);
1650 }
1651
1652 mm->core_state = NULL;
1653}
1654
Kawai, Hidehiro6c5d5232007-07-19 01:48:27 -07001655/*
1656 * set_dumpable converts traditional three-value dumpable to two flags and
1657 * stores them into mm->flags. It modifies lower two bits of mm->flags, but
1658 * these bits are not changed atomically. So get_dumpable can observe the
1659 * intermediate state. To avoid doing unexpected behavior, get get_dumpable
1660 * return either old dumpable or new one by paying attention to the order of
1661 * modifying the bits.
1662 *
1663 * dumpable | mm->flags (binary)
1664 * old new | initial interim final
1665 * ---------+-----------------------
1666 * 0 1 | 00 01 01
1667 * 0 2 | 00 10(*) 11
1668 * 1 0 | 01 00 00
1669 * 1 2 | 01 11 11
1670 * 2 0 | 11 10(*) 00
1671 * 2 1 | 11 11 01
1672 *
1673 * (*) get_dumpable regards interim value of 10 as 11.
1674 */
1675void set_dumpable(struct mm_struct *mm, int value)
1676{
1677 switch (value) {
1678 case 0:
1679 clear_bit(MMF_DUMPABLE, &mm->flags);
1680 smp_wmb();
1681 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
1682 break;
1683 case 1:
1684 set_bit(MMF_DUMPABLE, &mm->flags);
1685 smp_wmb();
1686 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
1687 break;
1688 case 2:
1689 set_bit(MMF_DUMP_SECURELY, &mm->flags);
1690 smp_wmb();
1691 set_bit(MMF_DUMPABLE, &mm->flags);
1692 break;
1693 }
1694}
Kawai, Hidehiro6c5d5232007-07-19 01:48:27 -07001695
1696int get_dumpable(struct mm_struct *mm)
1697{
1698 int ret;
1699
1700 ret = mm->flags & 0x3;
1701 return (ret >= 2) ? 2 : ret;
1702}
1703
WANG Cong8cd3ac32009-01-06 14:42:48 -08001704void do_coredump(long signr, int exit_code, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Oleg Nesterov9d5b3272008-07-25 01:47:43 -07001706 struct core_state core_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 char corename[CORENAME_MAX_SIZE + 1];
1708 struct mm_struct *mm = current->mm;
1709 struct linux_binfmt * binfmt;
1710 struct inode * inode;
1711 struct file * file;
David Howellsd84f4f92008-11-14 10:39:23 +11001712 const struct cred *old_cred;
1713 struct cred *cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 int retval = 0;
Alan Coxd6e71142005-06-23 00:09:43 -07001715 int flag = 0;
Andi Kleend025c9d2006-09-30 23:29:28 -07001716 int ispipe = 0;
Neil Horman7dc0b222007-10-16 23:26:34 -07001717 unsigned long core_limit = current->signal->rlim[RLIMIT_CORE].rlim_cur;
Neil Horman74aadce2007-10-16 23:26:35 -07001718 char **helper_argv = NULL;
1719 int helper_argc = 0;
1720 char *delimit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Steve Grubb0a4ff8c2007-04-19 10:28:21 -04001722 audit_core_dumps(signr);
1723
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 binfmt = current->binfmt;
1725 if (!binfmt || !binfmt->core_dump)
1726 goto fail;
David Howellsd84f4f92008-11-14 10:39:23 +11001727
1728 cred = prepare_creds();
1729 if (!cred) {
1730 retval = -ENOMEM;
1731 goto fail;
1732 }
1733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 down_write(&mm->mmap_sem);
Roland McGrath00ec99d2007-11-11 19:13:43 -08001735 /*
1736 * If another thread got here first, or we are not dumpable, bail out.
1737 */
Oleg Nesterov999d9fc2008-07-25 01:47:41 -07001738 if (mm->core_state || !get_dumpable(mm)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 up_write(&mm->mmap_sem);
David Howellsd84f4f92008-11-14 10:39:23 +11001740 put_cred(cred);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 goto fail;
1742 }
Alan Coxd6e71142005-06-23 00:09:43 -07001743
1744 /*
1745 * We cannot trust fsuid as being the "true" uid of the
1746 * process nor do we know its entire history. We only know it
1747 * was tainted so we dump it as root in mode 2.
1748 */
Kawai, Hidehiro6c5d5232007-07-19 01:48:27 -07001749 if (get_dumpable(mm) == 2) { /* Setuid core dump mode */
Alan Coxd6e71142005-06-23 00:09:43 -07001750 flag = O_EXCL; /* Stop rewrite attacks */
David Howellsd84f4f92008-11-14 10:39:23 +11001751 cred->fsuid = 0; /* Dump root private */
Alan Coxd6e71142005-06-23 00:09:43 -07001752 }
Oleg Nesterov1291cf42005-10-30 15:02:54 -08001753
Oleg Nesterov9d5b3272008-07-25 01:47:43 -07001754 retval = coredump_wait(exit_code, &core_state);
David Howellsd84f4f92008-11-14 10:39:23 +11001755 if (retval < 0) {
1756 put_cred(cred);
Oleg Nesterov1291cf42005-10-30 15:02:54 -08001757 goto fail;
David Howellsd84f4f92008-11-14 10:39:23 +11001758 }
1759
1760 old_cred = override_creds(cred);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
1762 /*
1763 * Clear any false indication of pending signals that might
1764 * be seen by the filesystem code called to write the core file.
1765 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 clear_thread_flag(TIF_SIGPENDING);
1767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 /*
1769 * lock_kernel() because format_corename() is controlled by sysctl, which
1770 * uses lock_kernel()
1771 */
1772 lock_kernel();
Oleg Nesterov64093242008-10-18 20:28:22 -07001773 ispipe = format_corename(corename, signr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 unlock_kernel();
Neil Horman7dc0b222007-10-16 23:26:34 -07001775 /*
1776 * Don't bother to check the RLIMIT_CORE value if core_pattern points
1777 * to a pipe. Since we're not writing directly to the filesystem
1778 * RLIMIT_CORE doesn't really apply, as no actual core file will be
1779 * created unless the pipe reader choses to write out the core file
1780 * at which point file size limits and permissions will be imposed
1781 * as it does with any other process
1782 */
Neil Horman74aadce2007-10-16 23:26:35 -07001783 if ((!ispipe) && (core_limit < binfmt->min_coredump))
Neil Horman7dc0b222007-10-16 23:26:34 -07001784 goto fail_unlock;
1785
Alan Coxc4bbafd2007-04-16 22:53:13 -07001786 if (ispipe) {
Neil Horman74aadce2007-10-16 23:26:35 -07001787 helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc);
Tetsuo Handa350eaf72009-01-06 14:41:11 -08001788 if (!helper_argv) {
1789 printk(KERN_WARNING "%s failed to allocate memory\n",
1790 __func__);
1791 goto fail_unlock;
1792 }
Neil Horman74aadce2007-10-16 23:26:35 -07001793 /* Terminate the string before the first option */
1794 delimit = strchr(corename, ' ');
1795 if (delimit)
1796 *delimit = '\0';
Neil Horman32321132007-10-16 23:26:36 -07001797 delimit = strrchr(helper_argv[0], '/');
1798 if (delimit)
1799 delimit++;
1800 else
1801 delimit = helper_argv[0];
1802 if (!strcmp(delimit, current->comm)) {
1803 printk(KERN_NOTICE "Recursive core dump detected, "
1804 "aborting\n");
1805 goto fail_unlock;
1806 }
1807
1808 core_limit = RLIM_INFINITY;
1809
Andi Kleend025c9d2006-09-30 23:29:28 -07001810 /* SIGPIPE can happen, but it's just never processed */
Neil Horman32321132007-10-16 23:26:36 -07001811 if (call_usermodehelper_pipe(corename+1, helper_argv, NULL,
1812 &file)) {
Andi Kleend025c9d2006-09-30 23:29:28 -07001813 printk(KERN_INFO "Core dump to %s pipe failed\n",
1814 corename);
1815 goto fail_unlock;
1816 }
Andi Kleend025c9d2006-09-30 23:29:28 -07001817 } else
1818 file = filp_open(corename,
Alexey Dobriyan6d4df672006-12-06 20:40:39 -08001819 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
1820 0600);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 if (IS_ERR(file))
1822 goto fail_unlock;
Josef "Jeff" Sipek0f7fc9e2006-12-08 02:36:35 -08001823 inode = file->f_path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 if (inode->i_nlink > 1)
1825 goto close_fail; /* multiple links - don't dump */
Josef "Jeff" Sipek0f7fc9e2006-12-08 02:36:35 -08001826 if (!ispipe && d_unhashed(file->f_path.dentry))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 goto close_fail;
1828
Andi Kleend025c9d2006-09-30 23:29:28 -07001829 /* AK: actually i see no reason to not allow this for named pipes etc.,
1830 but keep the previous behaviour for now. */
1831 if (!ispipe && !S_ISREG(inode->i_mode))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 goto close_fail;
Ingo Molnarc46f7392007-11-28 13:59:18 +01001833 /*
1834 * Dont allow local users get cute and trick others to coredump
1835 * into their pre-created files:
1836 */
David Howellsda9592e2008-11-14 10:39:05 +11001837 if (inode->i_uid != current_fsuid())
Ingo Molnarc46f7392007-11-28 13:59:18 +01001838 goto close_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 if (!file->f_op)
1840 goto close_fail;
1841 if (!file->f_op->write)
1842 goto close_fail;
Josef "Jeff" Sipek0f7fc9e2006-12-08 02:36:35 -08001843 if (!ispipe && do_truncate(file->f_path.dentry, 0, 0, file) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 goto close_fail;
1845
Neil Horman7dc0b222007-10-16 23:26:34 -07001846 retval = binfmt->core_dump(signr, regs, file, core_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 if (retval)
1849 current->signal->group_exit_code |= 0x80;
1850close_fail:
1851 filp_close(file, NULL);
1852fail_unlock:
Neil Horman74aadce2007-10-16 23:26:35 -07001853 if (helper_argv)
1854 argv_free(helper_argv);
1855
David Howellsd84f4f92008-11-14 10:39:23 +11001856 revert_creds(old_cred);
1857 put_cred(cred);
Oleg Nesterova94e2d42008-07-25 01:47:46 -07001858 coredump_finish(mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859fail:
WANG Cong8cd3ac32009-01-06 14:42:48 -08001860 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861}