vserver 1.9.3
[linux-2.6.git] / fs / exec.c
index 284207a..121b5a4 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -436,9 +436,9 @@ int setup_arg_pages(struct linux_binprm *bprm, int executable_stack)
                mpnt->vm_flags |= mm->def_flags;
                mpnt->vm_page_prot = protection_map[mpnt->vm_flags & 0x7];
                insert_vm_struct(mm, mpnt);
-               // mm->total_vm = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
-               vx_vmpages_sub(mm, mm->total_vm -
-                       ((mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT));
+               // mm->stack_vm = mm->total_vm = vma_pages(mpnt);
+               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
+               mm->stack_vm = mm->total_vm;
        }
 
        for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
@@ -551,6 +551,7 @@ static int exec_mmap(struct mm_struct *mm)
        tsk->active_mm = mm;
        activate_mm(active_mm, mm);
        task_unlock(tsk);
+       arch_pick_mmap_layout(mm);
        if (old_mm) {
                if (active_mm != old_mm) BUG();
                mmput(old_mm);
@@ -745,8 +746,10 @@ no_thread_group:
        spin_unlock(&oldsighand->siglock);
        write_unlock_irq(&tasklist_lock);
 
-       if (newsig && atomic_dec_and_test(&oldsig->count))
+       if (newsig && atomic_dec_and_test(&oldsig->count)) {
+               exit_itimers(oldsig);
                kmem_cache_free(signal_cachep, oldsig);
+       }
 
        if (atomic_dec_and_test(&oldsighand->count))
                kmem_cache_free(sighand_cachep, oldsighand);
@@ -791,11 +794,27 @@ static inline void flush_old_files(struct files_struct * files)
        spin_unlock(&files->file_lock);
 }
 
+void get_task_comm(char *buf, struct task_struct *tsk)
+{
+       /* buf must be at least sizeof(tsk->comm) in size */
+       task_lock(tsk);
+       memcpy(buf, tsk->comm, sizeof(tsk->comm));
+       task_unlock(tsk);
+}
+
+void set_task_comm(struct task_struct *tsk, char *buf)
+{
+       task_lock(tsk);
+       strlcpy(tsk->comm, buf, sizeof(tsk->comm));
+       task_unlock(tsk);
+}
+
 int flush_old_exec(struct linux_binprm * bprm)
 {
        char * name;
        int i, ch, retval;
        struct files_struct *files;
+       char tcomm[sizeof(current->comm)];
 
        /*
         * Make sure we have a private signal table and that
@@ -836,10 +855,11 @@ int flush_old_exec(struct linux_binprm * bprm)
                if (ch == '/')
                        i = 0;
                else
-                       if (i < 15)
-                               current->comm[i++] = ch;
+                       if (i < (sizeof(tcomm) - 1))
+                               tcomm[i++] = ch;
        }
-       current->comm[i] = '\0';
+       tcomm[i] = '\0';
+       set_task_comm(current, tcomm);
 
        flush_thread();
 
@@ -1079,7 +1099,7 @@ int do_execve(char * filename,
        char __user *__user *envp,
        struct pt_regs * regs)
 {
-       struct linux_binprm bprm;
+       struct linux_binprm *bprm;
        struct file *file;
        int retval;
        int i;
@@ -1090,87 +1110,89 @@ int do_execve(char * filename,
        if (IS_ERR(file))
                return retval;
 
-       sched_balance_exec();
-
-       bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
-       memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0]));
-
-       bprm.file = file;
-       bprm.filename = filename;
-       bprm.interp = filename;
-       bprm.interp_flags = 0;
-       bprm.interp_data = 0;
-       bprm.sh_bang = 0;
-       bprm.loader = 0;
-       bprm.exec = 0;
-       bprm.security = NULL;
-       bprm.mm = mm_alloc();
+       sched_exec();
+
        retval = -ENOMEM;
-       if (!bprm.mm)
+       bprm = kmalloc(sizeof(*bprm), GFP_KERNEL);
+       if (!bprm)
+               goto out_ret;
+       memset(bprm, 0, sizeof(*bprm));
+
+       bprm->p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
+
+       bprm->file = file;
+       bprm->filename = filename;
+       bprm->interp = filename;
+       bprm->mm = mm_alloc();
+       if (!bprm->mm)
                goto out_file;
 
-       retval = init_new_context(current, bprm.mm);
+       retval = init_new_context(current, bprm->mm);
        if (retval < 0)
                goto out_mm;
 
-       bprm.argc = count(argv, bprm.p / sizeof(void *));
-       if ((retval = bprm.argc) < 0)
+       bprm->argc = count(argv, bprm->p / sizeof(void *));
+       if ((retval = bprm->argc) < 0)
                goto out_mm;
 
-       bprm.envc = count(envp, bprm.p / sizeof(void *));
-       if ((retval = bprm.envc) < 0)
+       bprm->envc = count(envp, bprm->p / sizeof(void *));
+       if ((retval = bprm->envc) < 0)
                goto out_mm;
 
-       retval = security_bprm_alloc(&bprm);
+       retval = security_bprm_alloc(bprm);
        if (retval)
                goto out;
 
-       retval = prepare_binprm(&bprm);
+       retval = prepare_binprm(bprm);
        if (retval < 0)
                goto out;
 
-       retval = copy_strings_kernel(1, &bprm.filename, &bprm);
+       retval = copy_strings_kernel(1, &bprm->filename, bprm);
        if (retval < 0)
                goto out;
 
-       bprm.exec = bprm.p;
-       retval = copy_strings(bprm.envc, envp, &bprm);
+       bprm->exec = bprm->p;
+       retval = copy_strings(bprm->envc, envp, bprm);
        if (retval < 0)
                goto out;
 
-       retval = copy_strings(bprm.argc, argv, &bprm);
+       retval = copy_strings(bprm->argc, argv, bprm);
        if (retval < 0)
                goto out;
 
-       retval = search_binary_handler(&bprm,regs);
+       retval = search_binary_handler(bprm,regs);
        if (retval >= 0) {
-               free_arg_pages(&bprm);
+               free_arg_pages(bprm);
 
                /* execve success */
-               security_bprm_free(&bprm);
+               security_bprm_free(bprm);
+               kfree(bprm);
                return retval;
        }
 
 out:
        /* Something went wrong, return the inode and free the argument pages*/
        for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
-               struct page * page = bprm.page[i];
+               struct page * page = bprm->page[i];
                if (page)
                        __free_page(page);
        }
 
-       if (bprm.security)
-               security_bprm_free(&bprm);
+       if (bprm->security)
+               security_bprm_free(bprm);
 
 out_mm:
-       if (bprm.mm)
-               mmdrop(bprm.mm);
+       if (bprm->mm)
+               mmdrop(bprm->mm);
 
 out_file:
-       if (bprm.file) {
-               allow_write_access(bprm.file);
-               fput(bprm.file);
+       if (bprm->file) {
+               allow_write_access(bprm->file);
+               fput(bprm->file);
        }
+       kfree(bprm);
+
+out_ret:
        return retval;
 }
 
@@ -1198,7 +1220,7 @@ EXPORT_SYMBOL(set_binfmt);
  * name into corename, which must have space for at least
  * CORENAME_MAX_SIZE bytes plus one byte for the zero terminator.
  */
-void format_corename(char *corename, const char *pattern, long signr)
+static void format_corename(char *corename, const char *pattern, long signr)
 {
        const char *pat_ptr = pattern;
        char *out_ptr = corename;
@@ -1362,7 +1384,6 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
        struct file * file;
        int retval = 0;
 
-       lock_kernel();
        binfmt = current->binfmt;
        if (!binfmt || !binfmt->core_dump)
                goto fail;
@@ -1380,7 +1401,13 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
        if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump)
                goto fail_unlock;
 
-       format_corename(corename, core_pattern, signr);
+       /*
+        * lock_kernel() because format_corename() is controlled by sysctl, which
+        * uses lock_kernel()
+        */
+       lock_kernel();
+       format_corename(corename, core_pattern, signr);
+       unlock_kernel();
        file = filp_open(corename, O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE, 0600);
        if (IS_ERR(file))
                goto fail_unlock;
@@ -1407,6 +1434,5 @@ close_fail:
 fail_unlock:
        complete_all(&mm->core_done);
 fail:
-       unlock_kernel();
        return retval;
 }