This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / fs / exec.c
1 /*
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
25 #include <linux/config.h>
26 #include <linux/slab.h>
27 #include <linux/file.h>
28 #include <linux/mman.h>
29 #include <linux/a.out.h>
30 #include <linux/stat.h>
31 #include <linux/fcntl.h>
32 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/pagemap.h>
35 #include <linux/highmem.h>
36 #include <linux/spinlock.h>
37 #include <linux/personality.h>
38 #include <linux/binfmts.h>
39 #include <linux/swap.h>
40 #include <linux/utsname.h>
41 #include <linux/module.h>
42 #include <linux/namei.h>
43 #include <linux/proc_fs.h>
44 #include <linux/ptrace.h>
45 #include <linux/mount.h>
46 #include <linux/security.h>
47 #include <linux/syscalls.h>
48 #include <linux/rmap.h>
49 #include <linux/ckrm.h>
50 #include <linux/vs_memory.h>
51 #include <linux/ckrm_mem.h>
52
53 #include <asm/uaccess.h>
54 #include <asm/mmu_context.h>
55
56 #ifdef CONFIG_KMOD
57 #include <linux/kmod.h>
58 #endif
59
60 int core_uses_pid;
61 char core_pattern[65] = "core";
62 int suid_dumpable = 0;
63
64 EXPORT_SYMBOL(suid_dumpable);
65
66 /* The maximal length of core_pattern is also specified in sysctl.c */
67
68 static struct linux_binfmt *formats;
69 static rwlock_t binfmt_lock = RW_LOCK_UNLOCKED;
70
71 int register_binfmt(struct linux_binfmt * fmt)
72 {
73         struct linux_binfmt ** tmp = &formats;
74
75         if (!fmt)
76                 return -EINVAL;
77         if (fmt->next)
78                 return -EBUSY;
79         write_lock(&binfmt_lock);
80         while (*tmp) {
81                 if (fmt == *tmp) {
82                         write_unlock(&binfmt_lock);
83                         return -EBUSY;
84                 }
85                 tmp = &(*tmp)->next;
86         }
87         fmt->next = formats;
88         formats = fmt;
89         write_unlock(&binfmt_lock);
90         return 0;       
91 }
92
93 EXPORT_SYMBOL(register_binfmt);
94
95 int unregister_binfmt(struct linux_binfmt * fmt)
96 {
97         struct linux_binfmt ** tmp = &formats;
98
99         write_lock(&binfmt_lock);
100         while (*tmp) {
101                 if (fmt == *tmp) {
102                         *tmp = fmt->next;
103                         write_unlock(&binfmt_lock);
104                         return 0;
105                 }
106                 tmp = &(*tmp)->next;
107         }
108         write_unlock(&binfmt_lock);
109         return -EINVAL;
110 }
111
112 EXPORT_SYMBOL(unregister_binfmt);
113
114 static inline void put_binfmt(struct linux_binfmt * fmt)
115 {
116         module_put(fmt->module);
117 }
118
119 /*
120  * Note that a shared library must be both readable and executable due to
121  * security reasons.
122  *
123  * Also note that we take the address to load from from the file itself.
124  */
125 asmlinkage long sys_uselib(const char __user * library)
126 {
127         struct file * file;
128         struct nameidata nd;
129         int error;
130
131         nd.intent.open.flags = FMODE_READ;
132         error = __user_walk(library, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
133         if (error)
134                 goto out;
135
136         error = -EINVAL;
137         if (!S_ISREG(nd.dentry->d_inode->i_mode))
138                 goto exit;
139
140         error = permission(nd.dentry->d_inode, MAY_READ | MAY_EXEC, &nd);
141         if (error)
142                 goto exit;
143
144         file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
145         error = PTR_ERR(file);
146         if (IS_ERR(file))
147                 goto out;
148
149         error = -ENOEXEC;
150         if(file->f_op) {
151                 struct linux_binfmt * fmt;
152
153                 read_lock(&binfmt_lock);
154                 for (fmt = formats ; fmt ; fmt = fmt->next) {
155                         if (!fmt->load_shlib)
156                                 continue;
157                         if (!try_module_get(fmt->module))
158                                 continue;
159                         read_unlock(&binfmt_lock);
160                         error = fmt->load_shlib(file);
161                         read_lock(&binfmt_lock);
162                         put_binfmt(fmt);
163                         if (error != -ENOEXEC)
164                                 break;
165                 }
166                 read_unlock(&binfmt_lock);
167         }
168         fput(file);
169 out:
170         return error;
171 exit:
172         path_release(&nd);
173         goto out;
174 }
175
176 /*
177  * count() counts the number of strings in array ARGV.
178  */
179 static int count(char __user * __user * argv, int max)
180 {
181         int i = 0;
182
183         if (argv != NULL) {
184                 for (;;) {
185                         char __user * p;
186
187                         if (get_user(p, argv))
188                                 return -EFAULT;
189                         if (!p)
190                                 break;
191                         argv++;
192                         if(++i > max)
193                                 return -E2BIG;
194                 }
195         }
196         return i;
197 }
198
199 /*
200  * 'copy_strings()' copies argument/environment strings from user
201  * memory to free pages in kernel mem. These are in a format ready
202  * to be put directly into the top of new user memory.
203  */
204 int copy_strings(int argc,char __user * __user * argv, struct linux_binprm *bprm)
205 {
206         struct page *kmapped_page = NULL;
207         char *kaddr = NULL;
208         int ret;
209
210         while (argc-- > 0) {
211                 char __user *str;
212                 int len;
213                 unsigned long pos;
214
215                 if (get_user(str, argv+argc) ||
216                                 !(len = strnlen_user(str, bprm->p))) {
217                         ret = -EFAULT;
218                         goto out;
219                 }
220
221                 if (bprm->p < len)  {
222                         ret = -E2BIG;
223                         goto out;
224                 }
225
226                 bprm->p -= len;
227                 /* XXX: add architecture specific overflow check here. */
228                 pos = bprm->p;
229
230                 while (len > 0) {
231                         int i, new, err;
232                         int offset, bytes_to_copy;
233                         struct page *page;
234
235                         offset = pos % PAGE_SIZE;
236                         i = pos/PAGE_SIZE;
237                         page = bprm->page[i];
238                         new = 0;
239                         if (!page) {
240                                 page = alloc_page(GFP_HIGHUSER);
241                                 bprm->page[i] = page;
242                                 if (!page) {
243                                         ret = -ENOMEM;
244                                         goto out;
245                                 }
246                                 new = 1;
247                         }
248
249                         if (page != kmapped_page) {
250                                 if (kmapped_page)
251                                         kunmap(kmapped_page);
252                                 kmapped_page = page;
253                                 kaddr = kmap(kmapped_page);
254                         }
255                         if (new && offset)
256                                 memset(kaddr, 0, offset);
257                         bytes_to_copy = PAGE_SIZE - offset;
258                         if (bytes_to_copy > len) {
259                                 bytes_to_copy = len;
260                                 if (new)
261                                         memset(kaddr+offset+len, 0,
262                                                 PAGE_SIZE-offset-len);
263                         }
264                         err = copy_from_user(kaddr+offset, str, bytes_to_copy);
265                         if (err) {
266                                 ret = -EFAULT;
267                                 goto out;
268                         }
269
270                         pos += bytes_to_copy;
271                         str += bytes_to_copy;
272                         len -= bytes_to_copy;
273                 }
274         }
275         ret = 0;
276 out:
277         if (kmapped_page)
278                 kunmap(kmapped_page);
279         return ret;
280 }
281
282 /*
283  * Like copy_strings, but get argv and its values from kernel memory.
284  */
285 int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm)
286 {
287         int r;
288         mm_segment_t oldfs = get_fs();
289         set_fs(KERNEL_DS);
290         r = copy_strings(argc, (char __user * __user *)argv, bprm);
291         set_fs(oldfs);
292         return r;
293 }
294
295 EXPORT_SYMBOL(copy_strings_kernel);
296
297 #ifdef CONFIG_MMU
298 /*
299  * This routine is used to map in a page into an address space: needed by
300  * execve() for the initial stack and environment pages.
301  *
302  * vma->vm_mm->mmap_sem is held for writing.
303  */
304 void install_arg_page(struct vm_area_struct *vma,
305                         struct page *page, unsigned long address)
306 {
307         struct mm_struct *mm = vma->vm_mm;
308         pgd_t * pgd;
309         pmd_t * pmd;
310         pte_t * pte;
311
312         if (unlikely(anon_vma_prepare(vma)))
313                 goto out_sig;
314
315         flush_dcache_page(page);
316         pgd = pgd_offset(mm, address);
317
318         spin_lock(&mm->page_table_lock);
319         pmd = pmd_alloc(mm, pgd, address);
320         if (!pmd)
321                 goto out;
322         pte = pte_alloc_map(mm, pmd, address);
323         if (!pte)
324                 goto out;
325         if (!pte_none(*pte)) {
326                 pte_unmap(pte);
327                 goto out;
328         }
329         // mm->rss++;
330         vx_rsspages_inc(mm);
331         lru_cache_add_active(page);
332         set_pte(pte, pte_mkdirty(pte_mkwrite(mk_pte(
333                                         page, vma->vm_page_prot))));
334         page_add_anon_rmap(page, vma, address);
335         pte_unmap(pte);
336         spin_unlock(&mm->page_table_lock);
337
338         /* no need for flush_tlb */
339         return;
340 out:
341         spin_unlock(&mm->page_table_lock);
342 out_sig:
343         __free_page(page);
344         force_sig(SIGKILL, current);
345 }
346
347 int setup_arg_pages(struct linux_binprm *bprm, int executable_stack)
348 {
349         unsigned long stack_base;
350         struct vm_area_struct *mpnt;
351         struct mm_struct *mm = current->mm;
352         int i, ret;
353         long arg_size;
354
355 #ifdef CONFIG_STACK_GROWSUP
356         /* Move the argument and environment strings to the bottom of the
357          * stack space.
358          */
359         int offset, j;
360         char *to, *from;
361
362         /* Start by shifting all the pages down */
363         i = 0;
364         for (j = 0; j < MAX_ARG_PAGES; j++) {
365                 struct page *page = bprm->page[j];
366                 if (!page)
367                         continue;
368                 bprm->page[i++] = page;
369         }
370
371         /* Now move them within their pages */
372         offset = bprm->p % PAGE_SIZE;
373         to = kmap(bprm->page[0]);
374         for (j = 1; j < i; j++) {
375                 memmove(to, to + offset, PAGE_SIZE - offset);
376                 from = kmap(bprm->page[j]);
377                 memcpy(to + PAGE_SIZE - offset, from, offset);
378                 kunmap(bprm->page[j - 1]);
379                 to = from;
380         }
381         memmove(to, to + offset, PAGE_SIZE - offset);
382         kunmap(bprm->page[j - 1]);
383
384         /* Adjust bprm->p to point to the end of the strings. */
385         bprm->p = PAGE_SIZE * i - offset;
386
387         /* Limit stack size to 1GB */
388         stack_base = current->rlim[RLIMIT_STACK].rlim_max;
389         if (stack_base > (1 << 30))
390                 stack_base = 1 << 30;
391         stack_base = PAGE_ALIGN(STACK_TOP - stack_base);
392
393         mm->arg_start = stack_base;
394         arg_size = i << PAGE_SHIFT;
395
396         /* zero pages that were copied above */
397         while (i < MAX_ARG_PAGES)
398                 bprm->page[i++] = NULL;
399 #else
400 #ifdef __HAVE_ARCH_ALIGN_STACK
401         stack_base = arch_align_stack(STACK_TOP - MAX_ARG_PAGES*PAGE_SIZE);
402         stack_base = PAGE_ALIGN(stack_base);
403 #else
404         stack_base = STACK_TOP - MAX_ARG_PAGES * PAGE_SIZE;
405 #endif
406         mm->arg_start = bprm->p + stack_base;
407         arg_size = STACK_TOP - (PAGE_MASK & (unsigned long) mm->arg_start);
408 #endif
409
410         bprm->p += stack_base;
411         if (bprm->loader)
412                 bprm->loader += stack_base;
413         bprm->exec += stack_base;
414
415         mpnt = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
416         if (!mpnt)
417                 return -ENOMEM;
418
419         if (security_vm_enough_memory(arg_size >> PAGE_SHIFT) ||
420                 !vx_vmpages_avail(mm, arg_size >> PAGE_SHIFT)) {
421                 kmem_cache_free(vm_area_cachep, mpnt);
422                 return -ENOMEM;
423         }
424
425         memset(mpnt, 0, sizeof(*mpnt));
426
427         down_write(&mm->mmap_sem);
428         {
429                 mpnt->vm_mm = mm;
430 #ifdef CONFIG_STACK_GROWSUP
431                 mpnt->vm_start = stack_base;
432                 mpnt->vm_end = PAGE_MASK &
433                         (PAGE_SIZE - 1 + (unsigned long) bprm->p);
434 #else
435                 mpnt->vm_start = PAGE_MASK & (unsigned long) bprm->p;
436                 mpnt->vm_end = STACK_TOP;
437 #endif
438                 /* Adjust stack execute permissions; explicitly enable
439                  * for EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X
440                  * and leave alone (arch default) otherwise. */
441                 if (unlikely(executable_stack == EXSTACK_ENABLE_X))
442                         mpnt->vm_flags = VM_STACK_FLAGS |  VM_EXEC;
443                 else if (executable_stack == EXSTACK_DISABLE_X)
444                         mpnt->vm_flags = VM_STACK_FLAGS & ~VM_EXEC;
445                 else
446                         mpnt->vm_flags = VM_STACK_FLAGS;
447                 mpnt->vm_flags |= mm->def_flags;
448                 mpnt->vm_page_prot = protection_map[mpnt->vm_flags & 0x7];
449                 if ((ret = insert_vm_struct(mm, mpnt))) {
450                         up_write(&mm->mmap_sem);
451                         kmem_cache_free(vm_area_cachep, mpnt);
452                         return ret;
453                 }
454                 // mm->stack_vm = mm->total_vm = vma_pages(mpnt);
455                 vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
456                 mm->stack_vm = mm->total_vm;
457         }
458
459         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
460                 struct page *page = bprm->page[i];
461                 if (page) {
462                         bprm->page[i] = NULL;
463                         install_arg_page(mpnt, page, stack_base);
464                 }
465                 stack_base += PAGE_SIZE;
466         }
467         up_write(&mm->mmap_sem);
468         
469         return 0;
470 }
471
472 EXPORT_SYMBOL(setup_arg_pages);
473
474 #define free_arg_pages(bprm) do { } while (0)
475
476 #else
477
478 static inline void free_arg_pages(struct linux_binprm *bprm)
479 {
480         int i;
481
482         for (i = 0; i < MAX_ARG_PAGES; i++) {
483                 if (bprm->page[i])
484                         __free_page(bprm->page[i]);
485                 bprm->page[i] = NULL;
486         }
487 }
488
489 #endif /* CONFIG_MMU */
490
491 struct file *open_exec(const char *name)
492 {
493         struct nameidata nd;
494         int err;
495         struct file *file;
496
497         nd.intent.open.flags = FMODE_READ;
498         err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
499         file = ERR_PTR(err);
500
501         if (!err) {
502                 struct inode *inode = nd.dentry->d_inode;
503                 file = ERR_PTR(-EACCES);
504                 if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
505                     S_ISREG(inode->i_mode)) {
506                         int err = permission(inode, MAY_EXEC, &nd);
507                         if (!err && !(inode->i_mode & 0111))
508                                 err = -EACCES;
509                         file = ERR_PTR(err);
510                         if (!err) {
511                                 file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
512                                 if (!IS_ERR(file)) {
513                                         err = deny_write_access(file);
514                                         if (err) {
515                                                 fput(file);
516                                                 file = ERR_PTR(err);
517                                         }
518                                 }
519 out:
520                                 return file;
521                         }
522                 }
523                 path_release(&nd);
524         }
525         goto out;
526 }
527
528 EXPORT_SYMBOL(open_exec);
529
530 int kernel_read(struct file *file, unsigned long offset,
531         char *addr, unsigned long count)
532 {
533         mm_segment_t old_fs;
534         loff_t pos = offset;
535         int result;
536
537         old_fs = get_fs();
538         set_fs(get_ds());
539         /* The cast to a user pointer is valid due to the set_fs() */
540         result = vfs_read(file, (void __user *)addr, count, &pos);
541         set_fs(old_fs);
542         return result;
543 }
544
545 EXPORT_SYMBOL(kernel_read);
546
547 static int exec_mmap(struct mm_struct *mm)
548 {
549         struct task_struct *tsk;
550         struct mm_struct * old_mm, *active_mm;
551
552         /* Add it to the list of mm's */
553         spin_lock(&mmlist_lock);
554         list_add(&mm->mmlist, &init_mm.mmlist);
555         mmlist_nr++;
556         spin_unlock(&mmlist_lock);
557
558         /* Notify parent that we're no longer interested in the old VM */
559         tsk = current;
560         old_mm = current->mm;
561         mm_release(tsk, old_mm);
562
563         task_lock(tsk);
564         active_mm = tsk->active_mm;
565         tsk->mm = mm;
566         tsk->active_mm = mm;
567         activate_mm(active_mm, mm);
568         task_unlock(tsk);
569         arch_pick_mmap_layout(mm);
570 #ifdef CONFIG_CKRM_RES_MEM
571         if (old_mm) {
572                 spin_lock(&old_mm->peertask_lock);
573                 list_del(&tsk->mm_peers);
574                 ckrm_mem_evaluate_mm(old_mm);
575                 spin_unlock(&old_mm->peertask_lock);
576         }
577         spin_lock(&mm->peertask_lock);
578         list_add_tail(&tsk->mm_peers, &mm->tasklist);
579         ckrm_mem_evaluate_mm(mm);
580         spin_unlock(&mm->peertask_lock);
581 #endif
582         if (old_mm) {
583                 if (active_mm != old_mm) BUG();
584                 mmput(old_mm);
585                 return 0;
586         }
587         mmdrop(active_mm);
588         return 0;
589 }
590
591 /*
592  * This function makes sure the current process has its own signal table,
593  * so that flush_signal_handlers can later reset the handlers without
594  * disturbing other processes.  (Other processes might share the signal
595  * table via the CLONE_SIGHAND option to clone().)
596  */
597 static inline int de_thread(struct task_struct *tsk)
598 {
599         struct signal_struct *newsig, *oldsig = tsk->signal;
600         struct sighand_struct *newsighand, *oldsighand = tsk->sighand;
601         spinlock_t *lock = &oldsighand->siglock;
602         int count;
603
604         /*
605          * If we don't share sighandlers, then we aren't sharing anything
606          * and we can just re-use it all.
607          */
608         if (atomic_read(&oldsighand->count) <= 1)
609                 return 0;
610
611         newsighand = kmem_cache_alloc(sighand_cachep, GFP_KERNEL);
612         if (!newsighand)
613                 return -ENOMEM;
614
615         spin_lock_init(&newsighand->siglock);
616         atomic_set(&newsighand->count, 1);
617         memcpy(newsighand->action, oldsighand->action, sizeof(newsighand->action));
618
619         /*
620          * See if we need to allocate a new signal structure
621          */
622         newsig = NULL;
623         if (atomic_read(&oldsig->count) > 1) {
624                 newsig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
625                 if (!newsig) {
626                         kmem_cache_free(sighand_cachep, newsighand);
627                         return -ENOMEM;
628                 }
629                 atomic_set(&newsig->count, 1);
630                 newsig->group_exit = 0;
631                 newsig->group_exit_code = 0;
632                 newsig->group_exit_task = NULL;
633                 newsig->group_stop_count = 0;
634                 newsig->curr_target = NULL;
635                 init_sigpending(&newsig->shared_pending);
636                 INIT_LIST_HEAD(&newsig->posix_timers);
637
638                 newsig->tty = oldsig->tty;
639                 newsig->pgrp = oldsig->pgrp;
640                 newsig->session = oldsig->session;
641                 newsig->leader = oldsig->leader;
642                 newsig->tty_old_pgrp = oldsig->tty_old_pgrp;
643         }
644
645         if (thread_group_empty(current))
646                 goto no_thread_group;
647
648         /*
649          * Kill all other threads in the thread group.
650          * We must hold tasklist_lock to call zap_other_threads.
651          */
652         read_lock(&tasklist_lock);
653         spin_lock_irq(lock);
654         if (oldsig->group_exit) {
655                 /*
656                  * Another group action in progress, just
657                  * return so that the signal is processed.
658                  */
659                 spin_unlock_irq(lock);
660                 read_unlock(&tasklist_lock);
661                 kmem_cache_free(sighand_cachep, newsighand);
662                 if (newsig)
663                         kmem_cache_free(signal_cachep, newsig);
664                 return -EAGAIN;
665         }
666         oldsig->group_exit = 1;
667         zap_other_threads(current);
668         read_unlock(&tasklist_lock);
669
670         /*
671          * Account for the thread group leader hanging around:
672          */
673         count = 2;
674         if (current->pid == current->tgid)
675                 count = 1;
676         while (atomic_read(&oldsig->count) > count) {
677                 oldsig->group_exit_task = current;
678                 oldsig->notify_count = count;
679                 __set_current_state(TASK_UNINTERRUPTIBLE);
680                 spin_unlock_irq(lock);
681                 schedule();
682                 spin_lock_irq(lock);
683         }
684         spin_unlock_irq(lock);
685
686         /*
687          * At this point all other threads have exited, all we have to
688          * do is to wait for the thread group leader to become inactive,
689          * and to assume its PID:
690          */
691         if (current->pid != current->tgid) {
692                 struct task_struct *leader = current->group_leader, *parent;
693                 struct dentry *proc_dentry1, *proc_dentry2;
694                 unsigned long exit_state, ptrace;
695
696                 /*
697                  * Wait for the thread group leader to be a zombie.
698                  * It should already be zombie at this point, most
699                  * of the time.
700                  */
701                 while (leader->exit_state != EXIT_ZOMBIE)
702                         yield();
703
704                 spin_lock(&leader->proc_lock);
705                 spin_lock(&current->proc_lock);
706                 proc_dentry1 = proc_pid_unhash(current);
707                 proc_dentry2 = proc_pid_unhash(leader);
708                 write_lock_irq(&tasklist_lock);
709
710                 if (leader->tgid != current->tgid)
711                         BUG();
712                 if (current->pid == current->tgid)
713                         BUG();
714                 /*
715                  * An exec() starts a new thread group with the
716                  * TGID of the previous thread group. Rehash the
717                  * two threads with a switched PID, and release
718                  * the former thread group leader:
719                  */
720                 ptrace = leader->ptrace;
721                 parent = leader->parent;
722
723                 ptrace_unlink(current);
724                 ptrace_unlink(leader);
725                 remove_parent(current);
726                 remove_parent(leader);
727
728                 switch_exec_pids(leader, current);
729
730                 current->parent = current->real_parent = leader->real_parent;
731                 leader->parent = leader->real_parent = child_reaper;
732                 current->group_leader = current;
733                 leader->group_leader = leader;
734
735                 add_parent(current, current->parent);
736                 add_parent(leader, leader->parent);
737                 if (ptrace) {
738                         current->ptrace = ptrace;
739                         __ptrace_link(current, parent);
740                 }
741
742                 list_del(&current->tasks);
743                 list_add_tail(&current->tasks, &init_task.tasks);
744                 current->exit_signal = SIGCHLD;
745                 exit_state = leader->exit_state;
746
747                 write_unlock_irq(&tasklist_lock);
748                 spin_unlock(&leader->proc_lock);
749                 spin_unlock(&current->proc_lock);
750                 proc_pid_flush(proc_dentry1);
751                 proc_pid_flush(proc_dentry2);
752
753                 if (exit_state != EXIT_ZOMBIE)
754                         BUG();
755                 release_task(leader);
756         }
757
758 no_thread_group:
759
760         write_lock_irq(&tasklist_lock);
761         spin_lock(&oldsighand->siglock);
762         spin_lock(&newsighand->siglock);
763
764         if (current == oldsig->curr_target)
765                 oldsig->curr_target = next_thread(current);
766         if (newsig)
767                 current->signal = newsig;
768         current->sighand = newsighand;
769         init_sigpending(&current->pending);
770         recalc_sigpending();
771
772         spin_unlock(&newsighand->siglock);
773         spin_unlock(&oldsighand->siglock);
774         write_unlock_irq(&tasklist_lock);
775
776         if (newsig && atomic_dec_and_test(&oldsig->count)) {
777                 exit_itimers(oldsig);
778                 kmem_cache_free(signal_cachep, oldsig);
779         }
780
781         if (atomic_dec_and_test(&oldsighand->count))
782                 kmem_cache_free(sighand_cachep, oldsighand);
783
784         if (!thread_group_empty(current))
785                 BUG();
786         if (current->tgid != current->pid)
787                 BUG();
788         return 0;
789 }
790         
791 /*
792  * These functions flushes out all traces of the currently running executable
793  * so that a new one can be started
794  */
795
796 static inline void flush_old_files(struct files_struct * files)
797 {
798         long j = -1;
799
800         spin_lock(&files->file_lock);
801         for (;;) {
802                 unsigned long set, i;
803
804                 j++;
805                 i = j * __NFDBITS;
806                 if (i >= files->max_fds || i >= files->max_fdset)
807                         break;
808                 set = files->close_on_exec->fds_bits[j];
809                 if (!set)
810                         continue;
811                 files->close_on_exec->fds_bits[j] = 0;
812                 spin_unlock(&files->file_lock);
813                 for ( ; set ; i++,set >>= 1) {
814                         if (set & 1) {
815                                 sys_close(i);
816                         }
817                 }
818                 spin_lock(&files->file_lock);
819
820         }
821         spin_unlock(&files->file_lock);
822 }
823
824 void get_task_comm(char *buf, struct task_struct *tsk)
825 {
826         /* buf must be at least sizeof(tsk->comm) in size */
827         task_lock(tsk);
828         memcpy(buf, tsk->comm, sizeof(tsk->comm));
829         task_unlock(tsk);
830 }
831
832 void set_task_comm(struct task_struct *tsk, char *buf)
833 {
834         task_lock(tsk);
835         strlcpy(tsk->comm, buf, sizeof(tsk->comm));
836         task_unlock(tsk);
837 }
838
839 int flush_old_exec(struct linux_binprm * bprm)
840 {
841         char * name;
842         int i, ch, retval;
843         struct files_struct *files;
844         char tcomm[sizeof(current->comm)];
845
846         /*
847          * Make sure we have a private signal table and that
848          * we are unassociated from the previous thread group.
849          */
850         retval = de_thread(current);
851         if (retval)
852                 goto out;
853
854         /*
855          * Make sure we have private file handles. Ask the
856          * fork helper to do the work for us and the exit
857          * helper to do the cleanup of the old one.
858          */
859         files = current->files;         /* refcounted so safe to hold */
860         retval = unshare_files();
861         if (retval)
862                 goto out;
863         /*
864          * Release all of the old mmap stuff
865          */
866         retval = exec_mmap(bprm->mm);
867         if (retval)
868                 goto mmap_failed;
869
870         bprm->mm = NULL;                /* We're using it now */
871
872         /* This is the point of no return */
873         steal_locks(files);
874         put_files_struct(files);
875
876         current->sas_ss_sp = current->sas_ss_size = 0;
877
878         if (current->euid == current->uid && current->egid == current->gid)
879                 current->mm->dumpable = 1;
880         else
881                 current->mm->dumpable = suid_dumpable;
882                 
883         name = bprm->filename;
884         for (i=0; (ch = *(name++)) != '\0';) {
885                 if (ch == '/')
886                         i = 0;
887                 else
888                         if (i < (sizeof(tcomm) - 1))
889                                 tcomm[i++] = ch;
890         }
891         tcomm[i] = '\0';
892         set_task_comm(current, tcomm);
893
894         current->flags &= ~PF_RELOCEXEC;
895         flush_thread();
896
897         if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || 
898             permission(bprm->file->f_dentry->d_inode,MAY_READ, NULL) ||
899             (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP))
900                 current->mm->dumpable = suid_dumpable;
901
902         /* An exec changes our domain. We are no longer part of the thread
903            group */
904
905         current->self_exec_id++;
906                         
907         flush_signal_handlers(current, 0);
908         flush_old_files(current->files);
909
910         return 0;
911
912 mmap_failed:
913         put_files_struct(current->files);
914         current->files = files;
915 out:
916         return retval;
917 }
918
919 EXPORT_SYMBOL(flush_old_exec);
920
921 /* 
922  * Fill the binprm structure from the inode. 
923  * Check permissions, then read the first 128 (BINPRM_BUF_SIZE) bytes
924  */
925 int prepare_binprm(struct linux_binprm *bprm)
926 {
927         int mode;
928         struct inode * inode = bprm->file->f_dentry->d_inode;
929         int retval;
930
931         mode = inode->i_mode;
932         /*
933          * Check execute perms again - if the caller has CAP_DAC_OVERRIDE,
934          * vfs_permission lets a non-executable through
935          */
936         if (!(mode & 0111))     /* with at least _one_ execute bit set */
937                 return -EACCES;
938         if (bprm->file->f_op == NULL)
939                 return -EACCES;
940
941         bprm->e_uid = current->euid;
942         bprm->e_gid = current->egid;
943
944         if(!(bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)) {
945                 /* Set-uid? */
946                 if (mode & S_ISUID) {
947                         current->personality &= ~PER_CLEAR_ON_SETID;
948                         bprm->e_uid = inode->i_uid;
949                 }
950
951                 /* Set-gid? */
952                 /*
953                  * If setgid is set but no group execute bit then this
954                  * is a candidate for mandatory locking, not a setgid
955                  * executable.
956                  */
957                 if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
958                         current->personality &= ~PER_CLEAR_ON_SETID;
959                         bprm->e_gid = inode->i_gid;
960                 }
961         }
962
963         /* fill in binprm security blob */
964         retval = security_bprm_set(bprm);
965         if (retval)
966                 return retval;
967
968         memset(bprm->buf,0,BINPRM_BUF_SIZE);
969         return kernel_read(bprm->file,0,bprm->buf,BINPRM_BUF_SIZE);
970 }
971
972 EXPORT_SYMBOL(prepare_binprm);
973
974 static inline int unsafe_exec(struct task_struct *p)
975 {
976         int unsafe = 0;
977         if (p->ptrace & PT_PTRACED) {
978                 if (p->ptrace & PT_PTRACE_CAP)
979                         unsafe |= LSM_UNSAFE_PTRACE_CAP;
980                 else
981                         unsafe |= LSM_UNSAFE_PTRACE;
982         }
983         if (atomic_read(&p->fs->count) > 1 ||
984             atomic_read(&p->files->count) > 1 ||
985             atomic_read(&p->sighand->count) > 1)
986                 unsafe |= LSM_UNSAFE_SHARE;
987
988         return unsafe;
989 }
990
991 void compute_creds(struct linux_binprm *bprm)
992 {
993         int unsafe;
994         task_lock(current);
995         unsafe = unsafe_exec(current);
996         security_bprm_apply_creds(bprm, unsafe);
997         task_unlock(current);
998 }
999
1000 EXPORT_SYMBOL(compute_creds);
1001
1002 void remove_arg_zero(struct linux_binprm *bprm)
1003 {
1004         if (bprm->argc) {
1005                 unsigned long offset;
1006                 char * kaddr;
1007                 struct page *page;
1008
1009                 offset = bprm->p % PAGE_SIZE;
1010                 goto inside;
1011
1012                 while (bprm->p++, *(kaddr+offset++)) {
1013                         if (offset != PAGE_SIZE)
1014                                 continue;
1015                         offset = 0;
1016                         kunmap_atomic(kaddr, KM_USER0);
1017 inside:
1018                         page = bprm->page[bprm->p/PAGE_SIZE];
1019                         kaddr = kmap_atomic(page, KM_USER0);
1020                 }
1021                 kunmap_atomic(kaddr, KM_USER0);
1022                 bprm->argc--;
1023         }
1024 }
1025
1026 EXPORT_SYMBOL(remove_arg_zero);
1027
1028 /*
1029  * cycle the list of binary formats handler, until one recognizes the image
1030  */
1031 int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1032 {
1033         int try,retval;
1034         struct linux_binfmt *fmt;
1035 #ifdef __alpha__
1036         /* handle /sbin/loader.. */
1037         {
1038             struct exec * eh = (struct exec *) bprm->buf;
1039
1040             if (!bprm->loader && eh->fh.f_magic == 0x183 &&
1041                 (eh->fh.f_flags & 0x3000) == 0x3000)
1042             {
1043                 struct file * file;
1044                 unsigned long loader;
1045
1046                 allow_write_access(bprm->file);
1047                 fput(bprm->file);
1048                 bprm->file = NULL;
1049
1050                 loader = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
1051
1052                 file = open_exec("/sbin/loader");
1053                 retval = PTR_ERR(file);
1054                 if (IS_ERR(file))
1055                         return retval;
1056
1057                 /* Remember if the application is TASO.  */
1058                 bprm->sh_bang = eh->ah.entry < 0x100000000UL;
1059
1060                 bprm->file = file;
1061                 bprm->loader = loader;
1062                 retval = prepare_binprm(bprm);
1063                 if (retval<0)
1064                         return retval;
1065                 /* should call search_binary_handler recursively here,
1066                    but it does not matter */
1067             }
1068         }
1069 #endif
1070         retval = security_bprm_check(bprm);
1071         if (retval)
1072                 return retval;
1073
1074         /* kernel module loader fixup */
1075         /* so we don't try to load run modprobe in kernel space. */
1076         set_fs(USER_DS);
1077         retval = -ENOENT;
1078         for (try=0; try<2; try++) {
1079                 read_lock(&binfmt_lock);
1080                 for (fmt = formats ; fmt ; fmt = fmt->next) {
1081                         int (*fn)(struct linux_binprm *, struct pt_regs *) = fmt->load_binary;
1082                         if (!fn)
1083                                 continue;
1084                         if (!try_module_get(fmt->module))
1085                                 continue;
1086                         read_unlock(&binfmt_lock);
1087                         retval = fn(bprm, regs);
1088                         if (retval >= 0) {
1089                                 put_binfmt(fmt);
1090                                 allow_write_access(bprm->file);
1091                                 if (bprm->file)
1092                                         fput(bprm->file);
1093                                 bprm->file = NULL;
1094                                 current->did_exec = 1;
1095                                 ckrm_cb_exec(bprm->filename);
1096                                 return retval;
1097                         }
1098                         read_lock(&binfmt_lock);
1099                         put_binfmt(fmt);
1100                         if (retval != -ENOEXEC || bprm->mm == NULL)
1101                                 break;
1102                         if (!bprm->file) {
1103                                 read_unlock(&binfmt_lock);
1104                                 return retval;
1105                         }
1106                 }
1107                 read_unlock(&binfmt_lock);
1108                 if (retval != -ENOEXEC || bprm->mm == NULL) {
1109                         break;
1110 #ifdef CONFIG_KMOD
1111                 }else{
1112 #define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
1113                         if (printable(bprm->buf[0]) &&
1114                             printable(bprm->buf[1]) &&
1115                             printable(bprm->buf[2]) &&
1116                             printable(bprm->buf[3]))
1117                                 break; /* -ENOEXEC */
1118                         request_module("binfmt-%04x", *(unsigned short *)(&bprm->buf[2]));
1119 #endif
1120                 }
1121         }
1122         return retval;
1123 }
1124
1125 EXPORT_SYMBOL(search_binary_handler);
1126
1127 /*
1128  * sys_execve() executes a new program.
1129  */
1130 int do_execve(char * filename,
1131         char __user *__user *argv,
1132         char __user *__user *envp,
1133         struct pt_regs * regs)
1134 {
1135         struct linux_binprm *bprm;
1136         struct file *file;
1137         int retval;
1138         int i;
1139
1140         file = open_exec(filename);
1141
1142         retval = PTR_ERR(file);
1143         if (IS_ERR(file))
1144                 return retval;
1145
1146         sched_exec();
1147
1148         retval = -ENOMEM;
1149         bprm = kmalloc(sizeof(*bprm), GFP_KERNEL);
1150         if (!bprm)
1151                 goto out_ret;
1152         memset(bprm, 0, sizeof(*bprm));
1153
1154         bprm->p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
1155
1156         bprm->file = file;
1157         bprm->filename = filename;
1158         bprm->interp = filename;
1159         bprm->mm = mm_alloc();
1160         if (!bprm->mm)
1161                 goto out_file;
1162
1163         retval = init_new_context(current, bprm->mm);
1164         if (retval < 0)
1165                 goto out_mm;
1166
1167         bprm->argc = count(argv, bprm->p / sizeof(void *));
1168         if ((retval = bprm->argc) < 0)
1169                 goto out_mm;
1170
1171         bprm->envc = count(envp, bprm->p / sizeof(void *));
1172         if ((retval = bprm->envc) < 0)
1173                 goto out_mm;
1174
1175         retval = security_bprm_alloc(bprm);
1176         if (retval)
1177                 goto out;
1178
1179         retval = prepare_binprm(bprm);
1180         if (retval < 0)
1181                 goto out;
1182
1183         retval = copy_strings_kernel(1, &bprm->filename, bprm);
1184         if (retval < 0)
1185                 goto out;
1186
1187         bprm->exec = bprm->p;
1188         retval = copy_strings(bprm->envc, envp, bprm);
1189         if (retval < 0)
1190                 goto out;
1191
1192         retval = copy_strings(bprm->argc, argv, bprm);
1193         if (retval < 0)
1194                 goto out;
1195
1196         retval = search_binary_handler(bprm,regs);
1197         if (retval >= 0) {
1198                 free_arg_pages(bprm);
1199
1200                 /* execve success */
1201                 security_bprm_free(bprm);
1202                 kfree(bprm);
1203                 return retval;
1204         }
1205
1206 out:
1207         /* Something went wrong, return the inode and free the argument pages*/
1208         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
1209                 struct page * page = bprm->page[i];
1210                 if (page)
1211                         __free_page(page);
1212         }
1213
1214         if (bprm->security)
1215                 security_bprm_free(bprm);
1216
1217 out_mm:
1218         if (bprm->mm)
1219                 mmdrop(bprm->mm);
1220
1221 out_file:
1222         if (bprm->file) {
1223                 allow_write_access(bprm->file);
1224                 fput(bprm->file);
1225         }
1226         kfree(bprm);
1227
1228 out_ret:
1229         return retval;
1230 }
1231
1232 int set_binfmt(struct linux_binfmt *new)
1233 {
1234         struct linux_binfmt *old = current->binfmt;
1235
1236         if (new) {
1237                 if (!try_module_get(new->module))
1238                         return -1;
1239         }
1240         current->binfmt = new;
1241         if (old)
1242                 module_put(old->module);
1243         return 0;
1244 }
1245
1246 EXPORT_SYMBOL(set_binfmt);
1247
1248 #define CORENAME_MAX_SIZE 64
1249
1250 /* format_corename will inspect the pattern parameter, and output a
1251  * name into corename, which must have space for at least
1252  * CORENAME_MAX_SIZE bytes plus one byte for the zero terminator.
1253  */
1254 static void format_corename(char *corename, const char *pattern, long signr)
1255 {
1256         const char *pat_ptr = pattern;
1257         char *out_ptr = corename;
1258         char *const out_end = corename + CORENAME_MAX_SIZE;
1259         int rc;
1260         int pid_in_pattern = 0;
1261
1262         /* Repeat as long as we have more pattern to process and more output
1263            space */
1264         while (*pat_ptr) {
1265                 if (*pat_ptr != '%') {
1266                         if (out_ptr == out_end)
1267                                 goto out;
1268                         *out_ptr++ = *pat_ptr++;
1269                 } else {
1270                         switch (*++pat_ptr) {
1271                         case 0:
1272                                 goto out;
1273                         /* Double percent, output one percent */
1274                         case '%':
1275                                 if (out_ptr == out_end)
1276                                         goto out;
1277                                 *out_ptr++ = '%';
1278                                 break;
1279                         /* pid */
1280                         case 'p':
1281                                 pid_in_pattern = 1;
1282                                 rc = snprintf(out_ptr, out_end - out_ptr,
1283                                               "%d", current->tgid);
1284                                 if (rc > out_end - out_ptr)
1285                                         goto out;
1286                                 out_ptr += rc;
1287                                 break;
1288                         /* uid */
1289                         case 'u':
1290                                 rc = snprintf(out_ptr, out_end - out_ptr,
1291                                               "%d", current->uid);
1292                                 if (rc > out_end - out_ptr)
1293                                         goto out;
1294                                 out_ptr += rc;
1295                                 break;
1296                         /* gid */
1297                         case 'g':
1298                                 rc = snprintf(out_ptr, out_end - out_ptr,
1299                                               "%d", current->gid);
1300                                 if (rc > out_end - out_ptr)
1301                                         goto out;
1302                                 out_ptr += rc;
1303                                 break;
1304                         /* signal that caused the coredump */
1305                         case 's':
1306                                 rc = snprintf(out_ptr, out_end - out_ptr,
1307                                               "%ld", signr);
1308                                 if (rc > out_end - out_ptr)
1309                                         goto out;
1310                                 out_ptr += rc;
1311                                 break;
1312                         /* UNIX time of coredump */
1313                         case 't': {
1314                                 struct timeval tv;
1315                                 do_gettimeofday(&tv);
1316                                 rc = snprintf(out_ptr, out_end - out_ptr,
1317                                               "%lu", tv.tv_sec);
1318                                 if (rc > out_end - out_ptr)
1319                                         goto out;
1320                                 out_ptr += rc;
1321                                 break;
1322                         }
1323                         /* hostname */
1324                         case 'h':
1325                                 down_read(&uts_sem);
1326                                 rc = snprintf(out_ptr, out_end - out_ptr,
1327                                               "%s", system_utsname.nodename);
1328                                 up_read(&uts_sem);
1329                                 if (rc > out_end - out_ptr)
1330                                         goto out;
1331                                 out_ptr += rc;
1332                                 break;
1333                         /* executable */
1334                         case 'e':
1335                                 rc = snprintf(out_ptr, out_end - out_ptr,
1336                                               "%s", current->comm);
1337                                 if (rc > out_end - out_ptr)
1338                                         goto out;
1339                                 out_ptr += rc;
1340                                 break;
1341                         default:
1342                                 break;
1343                         }
1344                         ++pat_ptr;
1345                 }
1346         }
1347         /* Backward compatibility with core_uses_pid:
1348          *
1349          * If core_pattern does not include a %p (as is the default)
1350          * and core_uses_pid is set, then .%pid will be appended to
1351          * the filename */
1352         if (!pid_in_pattern
1353             && (core_uses_pid || atomic_read(&current->mm->mm_users) != 1)) {
1354                 rc = snprintf(out_ptr, out_end - out_ptr,
1355                               ".%d", current->tgid);
1356                 if (rc > out_end - out_ptr)
1357                         goto out;
1358                 out_ptr += rc;
1359         }
1360       out:
1361         *out_ptr = 0;
1362 }
1363
1364 static void zap_threads (struct mm_struct *mm)
1365 {
1366         struct task_struct *g, *p;
1367         struct task_struct *tsk = current;
1368         struct completion *vfork_done = tsk->vfork_done;
1369
1370         /*
1371          * Make sure nobody is waiting for us to release the VM,
1372          * otherwise we can deadlock when we wait on each other
1373          */
1374         if (vfork_done) {
1375                 tsk->vfork_done = NULL;
1376                 complete(vfork_done);
1377         }
1378
1379         read_lock(&tasklist_lock);
1380         do_each_thread(g,p)
1381                 if (mm == p->mm && p != tsk) {
1382                         force_sig_specific(SIGKILL, p);
1383                         mm->core_waiters++;
1384                 }
1385         while_each_thread(g,p);
1386
1387         read_unlock(&tasklist_lock);
1388 }
1389
1390 static void coredump_wait(struct mm_struct *mm)
1391 {
1392         DECLARE_COMPLETION(startup_done);
1393
1394         mm->core_waiters++; /* let other threads block */
1395         mm->core_startup_done = &startup_done;
1396
1397         /* give other threads a chance to run: */
1398         yield();
1399
1400         zap_threads(mm);
1401         if (--mm->core_waiters) {
1402                 up_write(&mm->mmap_sem);
1403                 wait_for_completion(&startup_done);
1404         } else
1405                 up_write(&mm->mmap_sem);
1406         BUG_ON(mm->core_waiters);
1407 }
1408
1409 int do_coredump(long signr, int exit_code, struct pt_regs * regs)
1410 {
1411         char corename[CORENAME_MAX_SIZE + 1];
1412         struct mm_struct *mm = current->mm;
1413         struct linux_binfmt * binfmt;
1414         struct inode * inode;
1415         struct file * file;
1416         int retval = 0;
1417         int fsuid = current->fsuid;
1418         int flag = 0;
1419         
1420         binfmt = current->binfmt;
1421         if (!binfmt || !binfmt->core_dump)
1422                 goto fail;
1423         if (current->tux_exit)
1424                 current->tux_exit();
1425         down_write(&mm->mmap_sem);
1426         if (!mm->dumpable) {
1427                 up_write(&mm->mmap_sem);
1428                 goto fail;
1429         }
1430         
1431         /*
1432          *      We cannot trust fsuid as being the "true" uid of the
1433          *      process nor do we know its entire history. We only know it
1434          *      was tainted so we dump it as root in mode 2.
1435          */
1436         if (mm->dumpable == 2)          /* Setuid core dump mode */
1437         {
1438                 flag = O_EXCL;          /* Stop rewrite attacks */
1439                 current->fsuid = 0;     /* Dump root private */
1440         }
1441         mm->dumpable = 0;
1442         init_completion(&mm->core_done);
1443         current->signal->group_exit = 1;
1444         current->signal->group_exit_code = exit_code;
1445         coredump_wait(mm);
1446
1447         if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump)
1448                 goto fail_unlock;
1449
1450         /*
1451          * lock_kernel() because format_corename() is controlled by sysctl, which
1452          * uses lock_kernel()
1453          */
1454         lock_kernel();
1455         format_corename(corename, core_pattern, signr);
1456         unlock_kernel();
1457         file = filp_open(corename, O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag, 0600);
1458         if (IS_ERR(file))
1459                 goto fail_unlock;
1460         inode = file->f_dentry->d_inode;
1461         if (inode->i_nlink > 1)
1462                 goto close_fail;        /* multiple links - don't dump */
1463         if (d_unhashed(file->f_dentry))
1464                 goto close_fail;
1465
1466         if (!S_ISREG(inode->i_mode))
1467                 goto close_fail;
1468         if (!file->f_op)
1469                 goto close_fail;
1470         if (!file->f_op->write)
1471                 goto close_fail;
1472         if (do_truncate(file->f_dentry, 0) != 0)
1473                 goto close_fail;
1474
1475         retval = binfmt->core_dump(signr, regs, file);
1476
1477         current->signal->group_exit_code |= 0x80;
1478 close_fail:
1479         filp_close(file, NULL);
1480 fail_unlock:
1481         current->fsuid = fsuid;
1482         complete_all(&mm->core_done);
1483 fail:
1484         return retval;
1485 }