Add a boolean argument to indicate if we have a path/true (execve) or an

fd/false (fexecve). This is needed to differentiate between them because
NULL/-1 can be readily passed from userland.
This commit is contained in:
christos 2019-09-17 15:19:27 +00:00
parent 3663af43d9
commit eb654c054f
4 changed files with 34 additions and 32 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_execve.c,v 1.40 2019/09/15 20:26:51 christos Exp $ */
/* $NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.40 2019/09/15 20:26:51 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -72,7 +72,7 @@ netbsd32_execve(struct lwp *l, const struct netbsd32_execve_args *uap, register_
syscallarg(netbsd32_charpp) envp;
} */
return execve1(l, SCARG_P32(uap, path), -1, SCARG_P32(uap, argp),
return execve1(l, true, SCARG_P32(uap, path), -1, SCARG_P32(uap, argp),
SCARG_P32(uap, envp), netbsd32_execve_fetch_element);
}
@ -86,7 +86,7 @@ netbsd32_fexecve(struct lwp *l, const struct netbsd32_fexecve_args *uap,
syscallarg(netbsd32_charpp) envp;
} */
return execve1(l, NULL, SCARG(uap, fd), SCARG_P32(uap, argp),
return execve1(l, false, NULL, SCARG(uap, fd), SCARG_P32(uap, argp),
SCARG_P32(uap, envp), netbsd32_execve_fetch_element);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sunos32_misc.c,v 1.80 2019/09/17 07:58:54 mrg Exp $ */
/* $NetBSD: sunos32_misc.c,v 1.81 2019/09/17 15:19:27 christos Exp $ */
/* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp */
/*
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.80 2019/09/17 07:58:54 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.81 2019/09/17 15:19:27 christos Exp $");
#define COMPAT_SUNOS 1
@ -388,7 +388,7 @@ sunos32_sys_execv(struct lwp *l, const struct sunos32_sys_execv_args *uap, regis
} */
const char *path = SCARG_P32(uap, path);
return execve1(l, path, -1, SCARG_P32(uap, argp), NULL,
return execve1(l, true, path, -1, SCARG_P32(uap, argp), NULL,
sunos32_execve_fetch_element);
}
@ -402,9 +402,8 @@ sunos32_sys_execve(struct lwp *l, const struct sunos32_sys_execve_args *uap, reg
} */
const char *path = SCARG_P32(uap, path);
return execve1(l, path, -1, SCARG_P32(uap, argp),
SCARG_P32(uap, envp),
sunos32_execve_fetch_element);
return execve1(l, true, path, -1, SCARG_P32(uap, argp),
SCARG_P32(uap, envp), sunos32_execve_fetch_element);
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exec.c,v 1.480 2019/09/15 20:23:50 christos Exp $ */
/* $NetBSD: kern_exec.c,v 1.481 2019/09/17 15:19:27 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.480 2019/09/15 20:23:50 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.481 2019/09/17 15:19:27 christos Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@ -583,7 +583,7 @@ sys_execve(struct lwp *l, const struct sys_execve_args *uap, register_t *retval)
syscallarg(char * const *) envp;
} */
return execve1(l, SCARG(uap, path), -1, SCARG(uap, argp),
return execve1(l, true, SCARG(uap, path), -1, SCARG(uap, argp),
SCARG(uap, envp), execve_fetch_element);
}
@ -597,7 +597,7 @@ sys_fexecve(struct lwp *l, const struct sys_fexecve_args *uap,
syscallarg(char * const *) envp;
} */
return execve1(l, NULL, SCARG(uap, fd), SCARG(uap, argp),
return execve1(l, false, NULL, SCARG(uap, fd), SCARG(uap, argp),
SCARG(uap, envp), execve_fetch_element);
}
@ -719,8 +719,9 @@ exec_vm_minaddr(vaddr_t va_min)
}
static int
execve_loadvm(struct lwp *l, const char *path, int fd, char * const *args,
char * const *envs, execve_fetch_element_t fetch_element,
execve_loadvm(struct lwp *l, bool has_path, const char *path, int fd,
char * const *args, char * const *envs,
execve_fetch_element_t fetch_element,
struct execve_data * restrict data)
{
struct exec_package * const epp = &data->ed_pack;
@ -770,14 +771,7 @@ execve_loadvm(struct lwp *l, const char *path, int fd, char * const *args,
*/
rw_enter(&p->p_reflock, RW_WRITER);
if (path == NULL) {
data->ed_pathbuf = pathbuf_assimilate(strcpy(PNBUF_GET(), "/"));
data->ed_pathstring = pathbuf_stringcopy_get(data->ed_pathbuf);
epp->ep_kname = "*fexecve*";
data->ed_resolvedname = NULL;
epp->ep_resolvedname = NULL;
epp->ep_xfd = fd;
} else {
if (has_path) {
size_t offs;
/*
* Init the namei data to point the file user's program name.
@ -794,6 +788,13 @@ execve_loadvm(struct lwp *l, const char *path, int fd, char * const *args,
data->ed_resolvedname = PNBUF_GET();
epp->ep_resolvedname = data->ed_resolvedname;
epp->ep_xfd = -1;
} else {
data->ed_pathbuf = pathbuf_assimilate(strcpy(PNBUF_GET(), "/"));
data->ed_pathstring = pathbuf_stringcopy_get(data->ed_pathbuf);
epp->ep_kname = "*fexecve*";
data->ed_resolvedname = NULL;
epp->ep_resolvedname = NULL;
epp->ep_xfd = fd;
}
@ -1406,13 +1407,15 @@ execve_runproc(struct lwp *l, struct execve_data * restrict data,
}
int
execve1(struct lwp *l, const char *path, int fd, char * const *args,
char * const *envs, execve_fetch_element_t fetch_element)
execve1(struct lwp *l, bool has_path, const char *path, int fd,
char * const *args, char * const *envs,
execve_fetch_element_t fetch_element)
{
struct execve_data data;
int error;
error = execve_loadvm(l, path, fd, args, envs, fetch_element, &data);
error = execve_loadvm(l, has_path, path, fd, args, envs, fetch_element,
&data);
if (error)
return error;
error = execve_runproc(l, &data, false, false);
@ -2436,7 +2439,7 @@ do_posix_spawn(struct lwp *l1, pid_t *pid_res, bool *child_ok, const char *path,
* Do the first part of the exec now, collect state
* in spawn_data.
*/
error = execve_loadvm(l1, path, -1, argv,
error = execve_loadvm(l1, true, path, -1, argv,
envp, fetch, &spawn_data->sed_exec);
if (error == EJUSTRETURN)
error = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: exec.h,v 1.155 2019/09/15 20:26:27 christos Exp $ */
/* $NetBSD: exec.h,v 1.156 2019/09/17 15:19:27 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -302,14 +302,14 @@ void new_vmcmd(struct exec_vmcmd_set *,
new_vmcmd(evsp,lwp,len,addr,vp,offset,prot,flags)
typedef int (*execve_fetch_element_t)(char * const *, size_t, char **);
int execve1(struct lwp *, const char *, int, char * const *, char * const *,
execve_fetch_element_t);
int execve1(struct lwp *, bool, const char *, int, char * const *,
char * const *, execve_fetch_element_t);
struct posix_spawn_file_actions;
struct posix_spawnattr;
int check_posix_spawn (struct lwp *);
void posix_spawn_fa_free(struct posix_spawn_file_actions *, size_t);
int do_posix_spawn(struct lwp *, pid_t *, bool*, const char *,
int do_posix_spawn(struct lwp *, pid_t *, bool *, const char *,
struct posix_spawn_file_actions *, struct posix_spawnattr *,
char *const *, char *const *, execve_fetch_element_t);
int exec_makepathbuf(struct lwp *, const char *, enum uio_seg,