Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Canonicalize the interpreter path in #! scr...
details: https://anonhg.NetBSD.org/src/rev/6b10bb680477
branches: trunk
changeset: 318514:6b10bb680477
user: christos <christos%NetBSD.org@localhost>
date: Fri Apr 27 18:33:24 2018 +0000
description:
Canonicalize the interpreter path in #! scripts since check_exec() expects
an absolute path, and we KASSERT if that's not the case later.
diffstat:
sys/kern/exec_script.c | 10 ++++------
sys/kern/kern_exec.c | 25 ++++++++++++++++---------
sys/sys/exec.h | 6 ++++--
3 files changed, 24 insertions(+), 17 deletions(-)
diffs (125 lines):
diff -r 3e3d4698bb4e -r 6b10bb680477 sys/kern/exec_script.c
--- a/sys/kern/exec_script.c Fri Apr 27 16:50:56 2018 +0000
+++ b/sys/kern/exec_script.c Fri Apr 27 18:33:24 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_script.c,v 1.74 2014/09/05 09:20:59 matt Exp $ */
+/* $NetBSD: exec_script.c,v 1.75 2018/04/27 18:33:24 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.74 2014/09/05 09:20:59 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.75 2018/04/27 18:33:24 christos Exp $");
#if defined(SETUIDSCRIPTS) && !defined(FDSCRIPTS)
#define FDSCRIPTS /* Need this for safe set-id scripts. */
@@ -280,10 +280,8 @@
epp->ep_hdrvalid = 0;
/* try loading the interpreter */
- shell_pathbuf = pathbuf_create(shellname);
- if (shell_pathbuf == NULL) {
- error = ENOMEM;
- } else {
+ if ((error = exec_makepathbuf(l, shellname, UIO_SYSSPACE,
+ &shell_pathbuf, NULL)) == 0) {
error = check_exec(l, epp, shell_pathbuf);
pathbuf_destroy(shell_pathbuf);
}
diff -r 3e3d4698bb4e -r 6b10bb680477 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Fri Apr 27 16:50:56 2018 +0000
+++ b/sys/kern/kern_exec.c Fri Apr 27 18:33:24 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.456 2018/02/23 19:43:08 maxv Exp $ */
+/* $NetBSD: kern_exec.c,v 1.457 2018/04/27 18:33:24 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.456 2018/02/23 19:43:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.457 2018/04/27 18:33:24 christos Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -607,9 +607,9 @@
#endif
}
-static int
-makepathbuf(struct lwp *l, const char *upath, struct pathbuf **pbp,
- size_t *offs)
+int
+exec_makepathbuf(struct lwp *l, const char *upath, enum uio_seg seg,
+ struct pathbuf **pbp, size_t *offs)
{
char *path, *bp;
size_t len, tlen;
@@ -617,7 +617,11 @@
struct cwdinfo *cwdi;
path = PNBUF_GET();
- error = copyinstr(upath, path, MAXPATHLEN, &len);
+ if (seg == UIO_SYSSPACE) {
+ error = copystr(upath, path, MAXPATHLEN, &len);
+ } else {
+ error = copyinstr(upath, path, MAXPATHLEN, &len);
+ }
if (error) {
PNBUF_PUT(path);
DPRINTF(("%s: copyin path @%p %d\n", __func__, upath, error));
@@ -625,7 +629,8 @@
}
if (path[0] == '/') {
- *offs = 0;
+ if (offs)
+ *offs = 0;
goto out;
}
@@ -651,7 +656,8 @@
memmove(path, bp, tlen);
path[tlen] = '\0';
- *offs = tlen - len;
+ if (offs)
+ *offs = tlen - len;
out:
*pbp = pathbuf_assimilate(path);
return 0;
@@ -730,7 +736,8 @@
* functions call check_exec() recursively - for example,
* see exec_script_makecmds().
*/
- if ((error = makepathbuf(l, path, &data->ed_pathbuf, &offs)) != 0)
+ if ((error = exec_makepathbuf(l, path, UIO_USERSPACE,
+ &data->ed_pathbuf, &offs)) != 0)
goto clrflg;
data->ed_pathstring = pathbuf_stringcopy_get(data->ed_pathbuf);
data->ed_resolvedpathbuf = PNBUF_GET();
diff -r 3e3d4698bb4e -r 6b10bb680477 sys/sys/exec.h
--- a/sys/sys/exec.h Fri Apr 27 16:50:56 2018 +0000
+++ b/sys/sys/exec.h Fri Apr 27 18:33:24 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.h,v 1.152 2017/11/07 19:44:05 christos Exp $ */
+/* $NetBSD: exec.h,v 1.153 2018/04/27 18:33:24 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -310,7 +310,9 @@
void posix_spawn_fa_free(struct posix_spawn_file_actions *, size_t);
int do_posix_spawn(struct lwp *, pid_t *, bool*, const char *,
struct posix_spawn_file_actions *, struct posix_spawnattr *,
- char *const *argv, char *const *, execve_fetch_element_t);
+ char *const *, char *const *, execve_fetch_element_t);
+int exec_makepathbuf(struct lwp *, const char *, enum uio_seg,
+ struct pathbuf **, size_t *);
extern int maxexec;
Home |
Main Index |
Thread Index |
Old Index