Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Use the pathbuf which we pass to namei() (which is ...



details:   https://anonhg.NetBSD.org/src/rev/05baabcca8b5
branches:  trunk
changeset: 827822:05baabcca8b5
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Nov 13 20:38:31 2017 +0000

description:
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.

diffstat:

 sys/kern/kern_exec.c |  16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diffs (47 lines):

diff -r b931121f9a5c -r 05baabcca8b5 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Mon Nov 13 20:21:10 2017 +0000
+++ b/sys/kern/kern_exec.c      Mon Nov 13 20:38:31 2017 +0000
@@ -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 @@
        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 @@
        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);
 



Home | Main Index | Thread Index | Old Index