4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * #!-checking implemented by tytso.
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.
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.
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
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/swap.h>
39 #include <linux/utsname.h>
40 #define __NO_VERSION__
41 #include <linux/module.h>
43 #include <asm/uaccess.h>
44 #include <asm/pgalloc.h>
45 #include <asm/mmu_context.h>
48 #include <linux/kmod.h>
52 char core_pattern[65] = "core";
53 int core_setuid_ok = 0;
54 /* The maximal length of core_pattern is also specified in sysctl.c */
56 static struct linux_binfmt *formats;
57 static rwlock_t binfmt_lock = RW_LOCK_UNLOCKED;
59 int register_binfmt(struct linux_binfmt * fmt)
61 struct linux_binfmt ** tmp = &formats;
67 write_lock(&binfmt_lock);
70 write_unlock(&binfmt_lock);
77 write_unlock(&binfmt_lock);
81 int unregister_binfmt(struct linux_binfmt * fmt)
83 struct linux_binfmt ** tmp = &formats;
85 write_lock(&binfmt_lock);
89 write_unlock(&binfmt_lock);
94 write_unlock(&binfmt_lock);
98 static inline void put_binfmt(struct linux_binfmt * fmt)
101 __MOD_DEC_USE_COUNT(fmt->module);
105 * Note that a shared library must be both readable and executable due to
108 * Also note that we take the address to load from from the file itself.
110 asmlinkage long sys_uselib(const char * library)
116 error = user_path_walk(library, &nd);
121 if (!S_ISREG(nd.dentry->d_inode->i_mode))
124 error = permission(nd.dentry->d_inode, MAY_READ | MAY_EXEC);
128 file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
129 error = PTR_ERR(file);
134 if(file->f_op && file->f_op->read) {
135 struct linux_binfmt * fmt;
137 read_lock(&binfmt_lock);
138 for (fmt = formats ; fmt ; fmt = fmt->next) {
139 if (!fmt->load_shlib)
141 if (!try_inc_mod_count(fmt->module))
143 read_unlock(&binfmt_lock);
144 error = fmt->load_shlib(file);
145 read_lock(&binfmt_lock);
147 if (error != -ENOEXEC)
150 read_unlock(&binfmt_lock);
161 * count() counts the number of arguments/envelopes
163 static int count(char ** argv, int max)
171 if (get_user(p, argv))
184 * 'copy_strings()' copies argument/envelope strings from user
185 * memory to free pages in kernel mem. These are in a format ready
186 * to be put directly into the top of new user memory.
188 int copy_strings(int argc,char ** argv, struct linux_binprm *bprm)
190 struct page *kmapped_page = NULL;
199 if (get_user(str, argv+argc) ||
200 !(len = strnlen_user(str, bprm->p))) {
211 /* XXX: add architecture specific overflow check here. */
216 int offset, bytes_to_copy;
219 offset = pos % PAGE_SIZE;
221 page = bprm->page[i];
224 page = alloc_page(GFP_HIGHUSER);
225 bprm->page[i] = page;
233 if (page != kmapped_page) {
235 kunmap(kmapped_page);
237 kaddr = kmap(kmapped_page);
240 memset(kaddr, 0, offset);
241 bytes_to_copy = PAGE_SIZE - offset;
242 if (bytes_to_copy > len) {
245 memset(kaddr+offset+len, 0,
246 PAGE_SIZE-offset-len);
248 err = copy_from_user(kaddr+offset, str, bytes_to_copy);
254 pos += bytes_to_copy;
255 str += bytes_to_copy;
256 len -= bytes_to_copy;
262 kunmap(kmapped_page);
267 * Like copy_strings, but get argv and its values from kernel memory.
269 int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm)
272 mm_segment_t oldfs = get_fs();
274 r = copy_strings(argc, argv, bprm);
280 * This routine is used to map in a page into an address space: needed by
281 * execve() for the initial stack and environment pages.
283 * tsk->mmap_sem is held for writing.
285 void put_dirty_page(struct task_struct * tsk, struct page *page, unsigned long address)
290 struct vm_area_struct *vma;
291 pgprot_t prot = PAGE_COPY;
293 if (page_count(page) != 1)
294 printk(KERN_ERR "mem_map disagrees with %p at %08lx\n", page, address);
295 pgd = pgd_offset(tsk->mm, address);
297 spin_lock(&tsk->mm->page_table_lock);
298 pmd = pmd_alloc(tsk->mm, pgd, address);
301 pte = pte_alloc(tsk->mm, pmd, address);
307 flush_dcache_page(page);
308 flush_page_to_ram(page);
309 /* lookup is cheap because there is only a single entry in the list */
310 vma = find_vma(tsk->mm, address);
312 prot = vma->vm_page_prot;
313 set_pte(pte, pte_mkdirty(pte_mkwrite(mk_pte(page, prot))));
315 spin_unlock(&tsk->mm->page_table_lock);
317 /* no need for flush_tlb */
320 spin_unlock(&tsk->mm->page_table_lock);
322 force_sig(SIGKILL, tsk);
326 int setup_arg_pages(struct linux_binprm *bprm)
328 unsigned long stack_base;
329 struct vm_area_struct *mpnt;
332 stack_base = STACK_TOP - MAX_ARG_PAGES*PAGE_SIZE;
334 bprm->p += stack_base;
336 bprm->loader += stack_base;
337 bprm->exec += stack_base;
339 mpnt = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
343 down_write(¤t->mm->mmap_sem);
345 mpnt->vm_mm = current->mm;
346 mpnt->vm_start = PAGE_MASK & (unsigned long) bprm->p;
347 mpnt->vm_end = STACK_TOP;
348 mpnt->vm_flags = VM_STACK_FLAGS;
349 mpnt->vm_page_prot = protection_map[VM_STACK_FLAGS & 0x7];
352 mpnt->vm_file = NULL;
353 mpnt->vm_private_data = (void *) 0;
354 if ((ret = insert_vm_struct(current->mm, mpnt))) {
355 up_write(¤t->mm->mmap_sem);
356 kmem_cache_free(vm_area_cachep, mpnt);
359 current->mm->total_vm = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
362 for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
363 struct page *page = bprm->page[i];
365 bprm->page[i] = NULL;
366 put_dirty_page(current,page,stack_base);
368 stack_base += PAGE_SIZE;
370 up_write(¤t->mm->mmap_sem);
375 struct file *open_exec(const char *name)
382 err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd);
385 inode = nd.dentry->d_inode;
386 file = ERR_PTR(-EACCES);
387 if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
388 S_ISREG(inode->i_mode)) {
389 int err = permission(inode, MAY_EXEC);
390 if (!err && !(inode->i_mode & 0111))
394 file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
396 err = deny_write_access(file);
411 int kernel_read(struct file *file, unsigned long offset,
412 char * addr, unsigned long count)
416 int result = -ENOSYS;
418 if (!file->f_op->read)
422 result = file->f_op->read(file, addr, count, &pos);
428 static int exec_mmap(void)
430 struct mm_struct * mm, * old_mm;
432 old_mm = current->mm;
434 if (old_mm && atomic_read(&old_mm->mm_users) == 1) {
436 down_write(&old_mm->mmap_sem);
438 up_write(&old_mm->mmap_sem);
445 struct mm_struct *active_mm;
447 if (init_new_context(current, mm)) {
452 /* Add it to the list of mm's */
453 spin_lock(&mmlist_lock);
454 list_add(&mm->mmlist, &init_mm.mmlist);
456 spin_unlock(&mmlist_lock);
459 active_mm = current->active_mm;
461 current->active_mm = mm;
462 task_unlock(current);
463 activate_mm(active_mm, mm);
466 if (active_mm != old_mm) BUG();
477 * This function makes sure the current process has its own signal table,
478 * so that flush_signal_handlers can later reset the handlers without
479 * disturbing other processes. (Other processes might share the signal
480 * table via the CLONE_SIGNAL option to clone().)
483 static inline int make_private_signals(void)
485 struct signal_struct * newsig;
487 if (atomic_read(¤t->sig->count) <= 1)
489 newsig = kmem_cache_alloc(sigact_cachep, GFP_KERNEL);
492 spin_lock_init(&newsig->siglock);
493 atomic_set(&newsig->count, 1);
494 memcpy(newsig->action, current->sig->action, sizeof(newsig->action));
495 spin_lock_irq(¤t->sigmask_lock);
496 current->sig = newsig;
497 spin_unlock_irq(¤t->sigmask_lock);
502 * If make_private_signals() made a copy of the signal table, decrement the
503 * refcount of the original table, and free it if necessary.
504 * We don't do that in make_private_signals() so that we can back off
505 * in flush_old_exec() if an error occurs after calling make_private_signals().
508 static inline void release_old_signals(struct signal_struct * oldsig)
510 if (current->sig == oldsig)
512 if (atomic_dec_and_test(&oldsig->count))
513 kmem_cache_free(sigact_cachep, oldsig);
517 * These functions flushes out all traces of the currently running executable
518 * so that a new one can be started
521 static inline void flush_old_files(struct files_struct * files)
525 write_lock(&files->file_lock);
527 unsigned long set, i;
531 if (i >= files->max_fds || i >= files->max_fdset)
533 set = files->close_on_exec->fds_bits[j];
536 files->close_on_exec->fds_bits[j] = 0;
537 write_unlock(&files->file_lock);
538 for ( ; set ; i++,set >>= 1) {
543 write_lock(&files->file_lock);
546 write_unlock(&files->file_lock);
550 * An execve() will automatically "de-thread" the process.
551 * Note: we don't have to hold the tasklist_lock to test
552 * whether we migth need to do this. If we're not part of
553 * a thread group, there is no way we can become one
554 * dynamically. And if we are, we only need to protect the
555 * unlink - even if we race with the last other thread exit,
556 * at worst the list_del_init() might end up being a no-op.
558 static inline void de_thread(struct task_struct *tsk)
560 if (!list_empty(&tsk->thread_group)) {
561 write_lock_irq(&tasklist_lock);
562 list_del_init(&tsk->thread_group);
563 write_unlock_irq(&tasklist_lock);
566 /* Minor oddity: this might stay the same. */
567 tsk->tgid = tsk->pid;
570 void get_task_comm(char *buf, struct task_struct *tsk)
572 /* buf must be at least sizeof(tsk->comm) in size */
574 memcpy(buf, tsk->comm, sizeof(tsk->comm));
578 void set_task_comm(struct task_struct *tsk, char *buf)
581 strncpy(tsk->comm, buf, sizeof(tsk->comm));
582 tsk->comm[sizeof(tsk->comm)-1]='\0';
586 int flush_old_exec(struct linux_binprm * bprm)
590 unsigned new_mm_dumpable;
591 struct signal_struct * oldsig;
592 struct files_struct * files;
593 char tcomm[sizeof(current->comm)];
596 * Make sure we have a private signal table
598 oldsig = current->sig;
599 retval = make_private_signals();
600 if (retval) goto flush_failed;
603 * Make sure we have private file handles. Ask the
604 * fork helper to do the work for us and the exit
605 * helper to do the cleanup of the old one.
608 files = current->files; /* refcounted so safe to hold */
609 retval = unshare_files();
614 * Release all of the old mmap stuff
616 retval = exec_mmap();
617 if (retval) goto mmap_failed;
619 /* This is the point of no return */
621 put_files_struct(files);
622 release_old_signals(oldsig);
624 current->sas_ss_sp = current->sas_ss_size = 0;
626 new_mm_dumpable = 0; /* no change */
627 if (current->euid == current->uid && current->egid == current->gid) {
629 current->task_dumpable = 1;
632 name = bprm->filename;
633 for (i=0; (ch = *(name++)) != '\0';) {
637 if (i < (sizeof(tcomm) - 1))
641 set_task_comm(current, tcomm);
647 if (bprm->e_uid != current->euid || bprm->e_gid != current->egid) {
648 current->mm->dumpable = 0;
649 current->pdeath_signal = 0;
650 } else if (permission(bprm->file->f_dentry->d_inode, MAY_READ)) {
651 current->mm->dumpable = 0;
652 } else if (new_mm_dumpable)
653 current->mm->dumpable = 1;
655 /* An exec changes our domain. We are no longer part of the thread
658 current->self_exec_id++;
660 flush_signal_handlers(current);
661 flush_old_files(current->files);
666 put_files_struct(current->files);
667 current->files = files;
669 spin_lock_irq(¤t->sigmask_lock);
670 if (current->sig != oldsig) {
671 kmem_cache_free(sigact_cachep, current->sig);
672 current->sig = oldsig;
674 spin_unlock_irq(¤t->sigmask_lock);
679 * We mustn't allow tracing of suid binaries, unless
680 * the tracer has the capability to trace anything..
682 static inline int must_not_trace_exec(struct task_struct * p)
684 return (p->ptrace & PT_PTRACED) && !(p->ptrace & PT_PTRACE_CAP);
688 * Fill the binprm structure from the inode.
689 * Check permissions, then read the first 128 (BINPRM_BUF_SIZE) bytes
691 int prepare_binprm(struct linux_binprm *bprm)
694 struct inode * inode = bprm->file->f_dentry->d_inode;
696 mode = inode->i_mode;
698 * Check execute perms again - if the caller has CAP_DAC_OVERRIDE,
699 * vfs_permission lets a non-executable through
701 if (!(mode & 0111)) /* with at least _one_ execute bit set */
703 if (bprm->file->f_op == NULL)
706 bprm->e_uid = current->euid;
707 bprm->e_gid = current->egid;
709 if(!(bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)) {
712 bprm->e_uid = inode->i_uid;
716 * If setgid is set but no group execute bit then this
717 * is a candidate for mandatory locking, not a setgid
720 if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
721 bprm->e_gid = inode->i_gid;
724 /* We don't have VFS support for capabilities yet */
725 cap_clear(bprm->cap_inheritable);
726 cap_clear(bprm->cap_permitted);
727 cap_clear(bprm->cap_effective);
729 /* To support inheritance of root-permissions and suid-root
730 * executables under compatibility mode, we raise all three
731 * capability sets for the file.
733 * If only the real uid is 0, we only raise the inheritable
734 * and permitted sets of the executable file.
737 if (!issecure(SECURE_NOROOT)) {
738 if (bprm->e_uid == 0 || current->uid == 0) {
739 cap_set_full(bprm->cap_inheritable);
740 cap_set_full(bprm->cap_permitted);
742 if (bprm->e_uid == 0)
743 cap_set_full(bprm->cap_effective);
746 memset(bprm->buf,0,BINPRM_BUF_SIZE);
747 return kernel_read(bprm->file,0,bprm->buf,BINPRM_BUF_SIZE);
751 * This function is used to produce the new IDs and capabilities
752 * from the old ones and the file's capabilities.
754 * The formula used for evolving capabilities is:
757 * (***) pP' = (fP & X) | (fI & pI)
758 * pE' = pP' & fE [NB. fE is 0 or ~0]
760 * I=Inheritable, P=Permitted, E=Effective // p=process, f=file
761 * ' indicates post-exec(), and X is the global 'cap_bset'.
765 void compute_creds(struct linux_binprm *bprm)
767 kernel_cap_t new_permitted, working;
770 new_permitted = cap_intersect(bprm->cap_permitted, cap_bset);
771 working = cap_intersect(bprm->cap_inheritable,
772 current->cap_inheritable);
773 new_permitted = cap_combine(new_permitted, working);
775 if (bprm->e_uid != current->uid || bprm->e_gid != current->gid ||
776 !cap_issubset(new_permitted, current->cap_permitted)) {
777 current->mm->dumpable = 0;
778 current->pdeath_signal = 0;
781 if (must_not_trace_exec(current)
782 || atomic_read(¤t->fs->count) > 1
783 || atomic_read(¤t->files->count) > 1
784 || atomic_read(¤t->sig->count) > 1) {
785 if(!capable(CAP_SETUID)) {
786 bprm->e_uid = current->uid;
787 bprm->e_gid = current->gid;
789 if(!capable(CAP_SETPCAP)) {
790 new_permitted = cap_intersect(new_permitted,
791 current->cap_permitted);
798 /* For init, we want to retain the capabilities set
799 * in the init_task struct. Thus we skip the usual
800 * capability rules */
801 if (current->pid != 1) {
802 current->cap_permitted = new_permitted;
803 current->cap_effective =
804 cap_intersect(new_permitted, bprm->cap_effective);
807 /* AUD: Audit candidate if current->cap_effective is set */
809 current->suid = current->euid = current->fsuid = bprm->e_uid;
810 current->sgid = current->egid = current->fsgid = bprm->e_gid;
814 current->keep_capabilities = 0;
818 void remove_arg_zero(struct linux_binprm *bprm)
821 unsigned long offset;
825 offset = bprm->p % PAGE_SIZE;
828 while (bprm->p++, *(kaddr+offset++)) {
829 if (offset != PAGE_SIZE)
834 page = bprm->page[bprm->p/PAGE_SIZE];
843 * cycle the list of binary formats handler, until one recognizes the image
845 int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
848 struct linux_binfmt *fmt;
850 /* handle /sbin/loader.. */
852 struct exec * eh = (struct exec *) bprm->buf;
854 if (!bprm->loader && eh->fh.f_magic == 0x183 &&
855 (eh->fh.f_flags & 0x3000) == 0x3000)
858 unsigned long loader;
860 allow_write_access(bprm->file);
864 loader = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
866 file = open_exec("/sbin/loader");
867 retval = PTR_ERR(file);
871 /* Remember if the application is TASO. */
872 bprm->sh_bang = eh->ah.entry < 0x100000000;
875 bprm->loader = loader;
876 retval = prepare_binprm(bprm);
879 /* should call search_binary_handler recursively here,
880 but it does not matter */
884 /* kernel module loader fixup */
885 /* so we don't try to load run modprobe in kernel space. */
887 for (try=0; try<2; try++) {
888 read_lock(&binfmt_lock);
889 for (fmt = formats ; fmt ; fmt = fmt->next) {
890 int (*fn)(struct linux_binprm *, struct pt_regs *) = fmt->load_binary;
893 if (!try_inc_mod_count(fmt->module))
895 read_unlock(&binfmt_lock);
896 retval = fn(bprm, regs);
899 allow_write_access(bprm->file);
903 current->did_exec = 1;
906 read_lock(&binfmt_lock);
908 if (retval != -ENOEXEC)
911 read_unlock(&binfmt_lock);
915 read_unlock(&binfmt_lock);
916 if (retval != -ENOEXEC) {
920 #define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
922 if (printable(bprm->buf[0]) &&
923 printable(bprm->buf[1]) &&
924 printable(bprm->buf[2]) &&
925 printable(bprm->buf[3]))
926 break; /* -ENOEXEC */
927 sprintf(modname, "binfmt-%04x", *(unsigned short *)(&bprm->buf[2]));
928 request_module(modname);
937 * sys_execve() executes a new program.
939 int do_execve(char * filename, char ** argv, char ** envp, struct pt_regs * regs)
941 struct linux_binprm bprm;
946 file = open_exec(filename);
948 retval = PTR_ERR(file);
952 bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
953 memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0]));
956 bprm.filename = filename;
960 if ((bprm.argc = count(argv, bprm.p / sizeof(void *))) < 0) {
961 allow_write_access(file);
966 if ((bprm.envc = count(envp, bprm.p / sizeof(void *))) < 0) {
967 allow_write_access(file);
972 retval = prepare_binprm(&bprm);
976 retval = copy_strings_kernel(1, &bprm.filename, &bprm);
981 retval = copy_strings(bprm.envc, envp, &bprm);
985 retval = copy_strings(bprm.argc, argv, &bprm);
989 retval = search_binary_handler(&bprm,regs);
995 /* Something went wrong, return the inode and free the argument pages*/
996 allow_write_access(bprm.file);
1000 for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
1001 struct page * page = bprm.page[i];
1009 void set_binfmt(struct linux_binfmt *new)
1011 struct linux_binfmt *old = current->binfmt;
1012 if (new && new->module)
1013 __MOD_INC_USE_COUNT(new->module);
1014 current->binfmt = new;
1015 if (old && old->module)
1016 __MOD_DEC_USE_COUNT(old->module);
1019 #define CORENAME_MAX_SIZE 64
1021 /* format_corename will inspect the pattern parameter, and output a
1022 * name into corename, which must have space for at least
1023 * CORENAME_MAX_SIZE bytes plus one byte for the zero terminator.
1025 void format_corename(char *corename, const char *pattern, long signr)
1027 const char *pat_ptr = pattern;
1028 char *out_ptr = corename;
1029 char *const out_end = corename + CORENAME_MAX_SIZE;
1031 int pid_in_pattern = 0;
1033 /* Repeat as long as we have more pattern to process and more output
1036 if (*pat_ptr != '%') {
1037 if (out_ptr == out_end)
1039 *out_ptr++ = *pat_ptr++;
1041 switch (*++pat_ptr) {
1044 /* Double percent, output one percent */
1046 if (out_ptr == out_end)
1053 rc = snprintf(out_ptr, out_end - out_ptr,
1054 "%d", current->pid);
1055 if (rc > out_end - out_ptr)
1061 rc = snprintf(out_ptr, out_end - out_ptr,
1062 "%d", current->uid);
1063 if (rc > out_end - out_ptr)
1069 rc = snprintf(out_ptr, out_end - out_ptr,
1070 "%d", current->gid);
1071 if (rc > out_end - out_ptr)
1075 /* signal that caused the coredump */
1077 rc = snprintf(out_ptr, out_end - out_ptr,
1079 if (rc > out_end - out_ptr)
1083 /* UNIX time of coredump */
1086 do_gettimeofday(&tv);
1087 rc = snprintf(out_ptr, out_end - out_ptr,
1089 if (rc > out_end - out_ptr)
1096 down_read(&uts_sem);
1097 rc = snprintf(out_ptr, out_end - out_ptr,
1098 "%s", system_utsname.nodename);
1100 if (rc > out_end - out_ptr)
1106 rc = snprintf(out_ptr, out_end - out_ptr,
1107 "%s", current->comm);
1108 if (rc > out_end - out_ptr)
1118 /* Backward compatibility with core_uses_pid:
1120 * If core_pattern does not include a %p (as is the default)
1121 * and core_uses_pid is set, then .%pid will be appended to
1124 && (core_uses_pid || atomic_read(¤t->mm->mm_users) != 1)) {
1125 rc = snprintf(out_ptr, out_end - out_ptr,
1126 ".%d", current->pid);
1127 if (rc > out_end - out_ptr)
1135 int do_coredump(long signr, struct pt_regs * regs)
1137 struct linux_binfmt * binfmt;
1138 char corename[CORENAME_MAX_SIZE + 1];
1140 struct inode * inode;
1142 int fsuid = current->fsuid;
1145 binfmt = current->binfmt;
1146 if (!binfmt || !binfmt->core_dump)
1148 if (!is_dumpable(current))
1150 if(!core_setuid_ok || !current->task_dumpable)
1154 current->mm->dumpable = 0;
1155 if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump)
1158 format_corename(corename, core_pattern, signr);
1159 file = filp_open(corename, O_CREAT | 2 | O_NOFOLLOW, 0600);
1162 inode = file->f_dentry->d_inode;
1163 if (inode->i_nlink > 1)
1164 goto close_fail; /* multiple links - don't dump */
1165 if (d_unhashed(file->f_dentry))
1168 if (!S_ISREG(inode->i_mode))
1171 * Dont allow local users get cute and trick others to coredump
1172 * into their pre-created files:
1174 if (inode->i_uid != current->fsuid)
1178 if (!file->f_op->write)
1180 if (do_truncate(file->f_dentry, 0) != 0)
1183 retval = binfmt->core_dump(signr, regs, file);
1186 filp_close(file, NULL);
1188 if (fsuid != current->fsuid)
1189 current->fsuid = fsuid;