Module Name: src
Committed By: christos
Date: Mon Nov 13 20:38:32 UTC 2017
Modified Files:
src/sys/kern: kern_exec.c
Log Message:
Use the pathbuf which we pass to namei() (which is always absolute) as the
resolved pathname. We need this in the case of scripts where p_path needs
to point to the interpreter and not the script itself. Otherwise things
like perl script that depend on /proc/$$/exe to re-exec themselves end up
being fork bombs.
In reality we should be using the fully resolved/canonicalized path here, but
namei is not giving it back to us.
To generate a diff of this commit:
cvs rdiff -u -r1.451 -r1.452 src/sys/kern/kern_exec.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.451 src/sys/kern/kern_exec.c:1.452
--- src/sys/kern/kern_exec.c:1.451 Tue Nov 7 15:58:23 2017
+++ src/sys/kern/kern_exec.c Mon Nov 13 15:38:31 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.451 2017/11/07 20:58:23 christos Exp $ */
+/* $NetBSD: kern_exec.c,v 1.452 2017/11/13 20:38:31 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.451 2017/11/07 20:58:23 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.452 2017/11/13 20:38:31 christos Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -344,9 +344,17 @@ check_exec(struct lwp *l, struct exec_pa
if ((error = namei(&nd)) != 0)
return error;
epp->ep_vp = vp = nd.ni_vp;
+#if 1
+ pathbuf_copystring(pb, epp->ep_resolvedname, PATH_MAX);
+#else
+ /*
+ * XXX: can't use nd.ni_pnbuf, because although pb contains an
+ * absolute path, nd.ni_pnbuf does not if the path contains symlinks.
+ */
/* normally this can't fail */
error = copystr(nd.ni_pnbuf, epp->ep_resolvedname, PATH_MAX, NULL);
KASSERT(error == 0);
+#endif
#ifdef DIAGNOSTIC
/* paranoia (take this out once namei stuff stabilizes) */
@@ -1154,9 +1162,7 @@ execve_runproc(struct lwp *l, struct exe
if (error != 0)
goto exec_abort;
- // XXX: Can't use epp->ep_resolvedname since namei can return
- // a relative path in pnbuf when being passed an absolute path!
- pathexec(p, data->ed_pathstring);
+ pathexec(p, epp->ep_resolvedname);
char * const newstack = STACK_GROW(vm->vm_minsaddr, epp->ep_ssize);