From 8917b8d28ccb2f718e6f8929e1ec0567ef1b0428 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 6 Feb 2006 22:06:54 +0000 Subject: [PATCH] - Always call exec_free_args() in kern_execve() instead of doing it in all the callers if the exec either succeeds or fails early. - Move the code to call exit1() if the exec fails after the vmspace is gone to the bottom of kern_execve() to cut down on some code duplication. --- sys/alpha/linux/linux_machdep.c | 1 - sys/alpha/osf1/osf1_misc.c | 1 - sys/amd64/linux32/linux32_machdep.c | 1 - sys/compat/freebsd32/freebsd32_misc.c | 1 - sys/compat/svr4/svr4_misc.c | 2 -- sys/i386/ibcs2/ibcs2_misc.c | 2 -- sys/i386/linux/linux_machdep.c | 1 - sys/kern/kern_exec.c | 31 ++++++++------------------- sys/kern/kern_kse.c | 1 - sys/sys/imgact.h | 1 - 10 files changed, 9 insertions(+), 33 deletions(-) diff --git a/sys/alpha/linux/linux_machdep.c b/sys/alpha/linux/linux_machdep.c index b4cebb09fbd7..7f468f601fa3 100644 --- a/sys/alpha/linux/linux_machdep.c +++ b/sys/alpha/linux/linux_machdep.c @@ -81,7 +81,6 @@ linux_execve(struct thread *td, struct linux_execve_args *args) free(path, M_TEMP); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } diff --git a/sys/alpha/osf1/osf1_misc.c b/sys/alpha/osf1/osf1_misc.c index 63ce5eed5cc4..13a5ca7a397f 100644 --- a/sys/alpha/osf1/osf1_misc.c +++ b/sys/alpha/osf1/osf1_misc.c @@ -1246,7 +1246,6 @@ osf1_execve(td, uap) free(path, M_TEMP); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } diff --git a/sys/amd64/linux32/linux32_machdep.c b/sys/amd64/linux32/linux32_machdep.c index 7f738bb5b2b8..2163bc217cb0 100644 --- a/sys/amd64/linux32/linux32_machdep.c +++ b/sys/amd64/linux32/linux32_machdep.c @@ -205,7 +205,6 @@ linux_execve(struct thread *td, struct linux_execve_args *args) free(path, M_TEMP); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index f2acf1a01944..4c00a205f69e 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -324,7 +324,6 @@ freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap) uap->argv, uap->envv); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c index 7fae2605102e..5a585cfad0f7 100644 --- a/sys/compat/svr4/svr4_misc.c +++ b/sys/compat/svr4/svr4_misc.c @@ -175,7 +175,6 @@ svr4_sys_execv(td, uap) free(path, M_TEMP); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } @@ -195,7 +194,6 @@ svr4_sys_execve(td, uap) free(path, M_TEMP); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c index e5ecace35bb6..c4efc02f2332 100644 --- a/sys/i386/ibcs2/ibcs2_misc.c +++ b/sys/i386/ibcs2/ibcs2_misc.c @@ -207,7 +207,6 @@ ibcs2_execv(td, uap) free(path, M_TEMP); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } @@ -227,7 +226,6 @@ ibcs2_execve(td, uap) free(path, M_TEMP); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c index 5aea62a7d809..68e7039f3529 100644 --- a/sys/i386/linux/linux_machdep.c +++ b/sys/i386/linux/linux_machdep.c @@ -122,7 +122,6 @@ linux_execve(struct thread *td, struct linux_execve_args *args) free(newpath, M_TEMP); if (error == 0) error = kern_execve(td, &eargs, NULL); - exec_free_args(&eargs); return (error); } diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index f55e196439f7..c2392ffd68e7 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -86,6 +86,7 @@ static int sysctl_kern_usrstack(SYSCTL_HANDLER_ARGS); static int sysctl_kern_stackprot(SYSCTL_HANDLER_ARGS); static int do_execve(struct thread *td, struct image_args *args, struct mac *mac_p); +static void exec_free_args(struct image_args *); /* XXX This should be vm_size_t. */ SYSCTL_PROC(_kern, KERN_PS_STRINGS, ps_strings, CTLTYPE_ULONG|CTLFLAG_RD, @@ -181,12 +182,8 @@ execve(td, uap) error = exec_copyin_args(&args, uap->fname, UIO_USERSPACE, uap->argv, uap->envv); - if (error == 0) error = kern_execve(td, &args, NULL); - - exec_free_args(&args); - return (error); } @@ -218,12 +215,8 @@ __mac_execve(td, uap) error = exec_copyin_args(&args, uap->fname, UIO_USERSPACE, uap->argv, uap->envv); - if (error == 0) error = kern_execve(td, &args, uap->mac_p); - - exec_free_args(&args); - return (error); #else return (ENOSYS); @@ -776,19 +769,6 @@ do_execve(td, args, mac_p) p->p_flag &= ~P_INEXEC; PROC_UNLOCK(p); - if (imgp->vmspace_destroyed) { - /* sorry, no more process anymore. exit gracefully */ -#ifdef MAC - mac_execve_exit(imgp); - if (interplabel != NULL) - mac_vnode_label_free(interplabel); -#endif - VFS_UNLOCK_GIANT(vfslocked); - exec_free_args(args); - exit1(td, W_EXITCODE(0, SIGABRT)); - /* NOT REACHED */ - error = 0; - } done2: #ifdef MAC mac_execve_exit(imgp); @@ -796,6 +776,13 @@ do_execve(td, args, mac_p) mac_vnode_label_free(interplabel); #endif VFS_UNLOCK_GIANT(vfslocked); + exec_free_args(args); + + if (error && imgp->vmspace_destroyed) { + /* sorry, no more process anymore. exit gracefully */ + exit1(td, W_EXITCODE(0, SIGABRT)); + /* NOT REACHED */ + } return (error); } @@ -1036,7 +1023,7 @@ exec_copyin_args(struct image_args *args, char *fname, return (0); } -void +static void exec_free_args(struct image_args *args) { diff --git a/sys/kern/kern_kse.c b/sys/kern/kern_kse.c index 15c0f180fcde..761804372eff 100644 --- a/sys/kern/kern_kse.c +++ b/sys/kern/kern_kse.c @@ -266,7 +266,6 @@ kse_thr_interrupt(struct thread *td, struct kse_thr_interrupt_args *uap) args.argv, args.envp); if (error == 0) error = kern_execve(td, &iargs, NULL); - exec_free_args(&iargs); if (error == 0) { PROC_LOCK(p); SIGSETOR(td->td_siglist, args.sigpend); diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h index b1d0f0d09973..20c65e9ecab5 100644 --- a/sys/sys/imgact.h +++ b/sys/sys/imgact.h @@ -76,7 +76,6 @@ void exec_setregs(struct thread *, u_long, u_long, u_long); int exec_shell_imgact(struct image_params *); int exec_copyin_args(struct image_args *, char *, enum uio_seg, char **, char **); -void exec_free_args(struct image_args *); #endif #endif /* !_SYS_IMGACT_H_ */