2016-10-14 11:38:31 +03:00
|
|
|
/* $NetBSD: sys_process.c,v 1.172 2016/10/14 08:38:31 skrll Exp $ */
|
2008-04-24 22:39:20 +04:00
|
|
|
|
|
|
|
/*-
|
2009-02-05 00:17:39 +03:00
|
|
|
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
|
2008-04-24 22:39:20 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2009-02-05 00:17:39 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew Doran.
|
|
|
|
*
|
2008-04-24 22:39:20 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1994-08-15 20:32:41 +04:00
|
|
|
|
1994-08-15 20:29:22 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1982, 1986, 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* (c) UNIX System Laboratories, Inc.
|
|
|
|
* All or some portions of this file are derived from material licensed
|
|
|
|
* to the University of California by American Telephone and Telegraph
|
|
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
|
|
*
|
2002-05-09 19:44:44 +04:00
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
1994-08-15 20:29:22 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from: @(#)sys_process.c 8.1 (Berkeley) 6/10/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1993 Jan-Simon Pendry.
|
|
|
|
* Copyright (c) 1994 Christopher G. Demetriou. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1994-08-15 20:29:22 +04:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from: @(#)sys_process.c 8.1 (Berkeley) 6/10/93
|
|
|
|
*/
|
|
|
|
|
1994-08-15 20:32:41 +04:00
|
|
|
/*
|
|
|
|
* References:
|
|
|
|
* (1) Bach's "The Design of the UNIX Operating System",
|
|
|
|
* (2) sys/miscfs/procfs from UCB's 4.4BSD-Lite distribution,
|
|
|
|
* (3) the "4.4BSD Programmer's Reference Manual" published
|
|
|
|
* by USENIX and O'Reilly & Associates.
|
|
|
|
* The 4.4BSD PRM does a reasonably good job of documenting what the various
|
|
|
|
* ptrace() requests should actually do, and its text is quoted several times
|
|
|
|
* in this file.
|
|
|
|
*/
|
|
|
|
|
2007-09-21 23:14:12 +04:00
|
|
|
#include <sys/cdefs.h>
|
2016-10-14 11:38:31 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.172 2016/10/14 08:38:31 skrll Exp $");
|
2007-09-21 23:14:12 +04:00
|
|
|
|
2006-08-30 14:17:49 +04:00
|
|
|
#include "opt_ptrace.h"
|
2006-08-30 15:08:15 +04:00
|
|
|
#include "opt_ktrace.h"
|
2016-05-25 20:43:58 +03:00
|
|
|
#include "opt_pax.h"
|
2006-08-30 03:34:48 +04:00
|
|
|
|
1994-08-15 20:29:22 +04:00
|
|
|
#include <sys/param.h>
|
1994-10-20 07:22:35 +03:00
|
|
|
#include <sys/systm.h>
|
1994-08-15 20:29:22 +04:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/errno.h>
|
2015-07-02 06:47:54 +03:00
|
|
|
#include <sys/exec.h>
|
2016-05-25 20:43:58 +03:00
|
|
|
#include <sys/pax.h>
|
1994-08-15 20:32:41 +04:00
|
|
|
#include <sys/ptrace.h>
|
|
|
|
#include <sys/uio.h>
|
2002-08-28 11:27:14 +04:00
|
|
|
#include <sys/ras.h>
|
2009-01-22 17:38:34 +03:00
|
|
|
#include <sys/kmem.h>
|
2006-05-15 01:15:11 +04:00
|
|
|
#include <sys/kauth.h>
|
1994-10-20 07:22:35 +03:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
1998-02-05 10:59:28 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1994-08-15 20:32:41 +04:00
|
|
|
#include <machine/reg.h>
|
|
|
|
|
2006-08-30 15:08:15 +04:00
|
|
|
#ifdef PTRACE
|
2014-11-24 05:34:04 +03:00
|
|
|
|
|
|
|
# ifdef DEBUG
|
|
|
|
# define DPRINTF(a) uprintf a
|
|
|
|
# else
|
|
|
|
# define DPRINTF(a)
|
|
|
|
# endif
|
|
|
|
|
2009-10-03 02:18:56 +04:00
|
|
|
static kauth_listener_t ptrace_listener;
|
2015-07-02 06:47:54 +03:00
|
|
|
#ifdef PTRACE
|
|
|
|
static int process_auxv_offset(struct proc *, struct uio *);
|
|
|
|
#endif
|
2009-10-03 02:18:56 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
ptrace_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
|
|
|
|
void *arg0, void *arg1, void *arg2, void *arg3)
|
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = KAUTH_RESULT_DEFER;
|
|
|
|
p = arg0;
|
|
|
|
|
|
|
|
if (action != KAUTH_PROCESS_PTRACE)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
switch ((u_long)arg1) {
|
|
|
|
case PT_TRACE_ME:
|
|
|
|
case PT_ATTACH:
|
|
|
|
case PT_WRITE_I:
|
|
|
|
case PT_WRITE_D:
|
|
|
|
case PT_READ_I:
|
|
|
|
case PT_READ_D:
|
|
|
|
case PT_IO:
|
|
|
|
#ifdef PT_GETREGS
|
|
|
|
case PT_GETREGS:
|
|
|
|
#endif
|
|
|
|
#ifdef PT_SETREGS
|
|
|
|
case PT_SETREGS:
|
|
|
|
#endif
|
|
|
|
#ifdef PT_GETFPREGS
|
|
|
|
case PT_GETFPREGS:
|
|
|
|
#endif
|
|
|
|
#ifdef PT_SETFPREGS
|
|
|
|
case PT_SETFPREGS:
|
|
|
|
#endif
|
2011-09-03 00:07:41 +04:00
|
|
|
case PT_SET_EVENT_MASK:
|
|
|
|
case PT_GET_EVENT_MASK:
|
|
|
|
case PT_GET_PROCESS_STATE:
|
2009-10-03 02:18:56 +04:00
|
|
|
#ifdef __HAVE_PTRACE_MACHDEP
|
|
|
|
PTRACE_MACHDEP_REQUEST_CASES
|
|
|
|
#endif
|
|
|
|
if (kauth_cred_getuid(cred) != kauth_cred_getuid(p->p_cred) ||
|
|
|
|
ISSET(p->p_flag, PK_SUGID)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = KAUTH_RESULT_ALLOW;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef PT_STEP
|
|
|
|
case PT_STEP:
|
|
|
|
#endif
|
|
|
|
case PT_CONTINUE:
|
|
|
|
case PT_KILL:
|
|
|
|
case PT_DETACH:
|
|
|
|
case PT_LWPINFO:
|
|
|
|
case PT_SYSCALL:
|
2011-09-01 02:58:39 +04:00
|
|
|
case PT_SYSCALLEMU:
|
2009-10-03 02:18:56 +04:00
|
|
|
case PT_DUMPCORE:
|
|
|
|
result = KAUTH_RESULT_ALLOW;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ptrace_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
ptrace_listener = kauth_listen_scope(KAUTH_SCOPE_PROCESS,
|
|
|
|
ptrace_listener_cb, NULL);
|
|
|
|
}
|
|
|
|
|
1994-08-15 20:29:22 +04:00
|
|
|
/*
|
|
|
|
* Process debugging system call.
|
|
|
|
*/
|
1994-10-20 07:22:35 +03:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
sys_ptrace(struct lwp *l, const struct sys_ptrace_args *uap, register_t *retval)
|
1995-09-20 01:40:36 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1994-10-20 07:22:35 +03:00
|
|
|
syscallarg(int) req;
|
|
|
|
syscallarg(pid_t) pid;
|
2007-03-04 08:59:00 +03:00
|
|
|
syscallarg(void *) addr;
|
1994-10-20 07:22:35 +03:00
|
|
|
syscallarg(int) data;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2003-01-18 13:06:22 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2010-04-07 17:10:46 +04:00
|
|
|
struct lwp *lt;
|
|
|
|
#ifdef PT_STEP
|
|
|
|
struct lwp *lt2;
|
|
|
|
#endif
|
1994-08-15 20:32:41 +04:00
|
|
|
struct proc *t; /* target process */
|
|
|
|
struct uio uio;
|
|
|
|
struct iovec iov;
|
2002-03-17 20:02:45 +03:00
|
|
|
struct ptrace_io_desc piod;
|
2011-09-03 00:07:41 +04:00
|
|
|
struct ptrace_event pe;
|
|
|
|
struct ptrace_state ps;
|
2003-05-20 22:16:08 +04:00
|
|
|
struct ptrace_lwpinfo pl;
|
2006-03-01 15:38:10 +03:00
|
|
|
struct vmspace *vm;
|
2007-02-10 00:55:00 +03:00
|
|
|
int error, write, tmp, req, pheld;
|
2010-04-06 17:50:22 +04:00
|
|
|
int signo = 0;
|
|
|
|
int resume_all;
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_t ksi;
|
2005-01-09 22:22:55 +03:00
|
|
|
char *path;
|
2011-07-03 12:57:43 +04:00
|
|
|
int len = 0;
|
1994-08-15 20:32:41 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
error = 0;
|
|
|
|
req = SCARG(uap, req);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If attaching or detaching, we need to get a write hold on the
|
|
|
|
* proclist lock so that we can re-parent the target process.
|
|
|
|
*/
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
1994-08-15 20:32:41 +04:00
|
|
|
/* "A foolish consistency..." XXX */
|
2007-11-07 03:23:13 +03:00
|
|
|
if (req == PT_TRACE_ME) {
|
1994-08-15 20:32:41 +04:00
|
|
|
t = p;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(t->p_lock);
|
2007-11-07 03:23:13 +03:00
|
|
|
} else {
|
1994-08-15 20:32:41 +04:00
|
|
|
/* Find the process we're supposed to be operating on. */
|
2010-07-01 06:38:26 +04:00
|
|
|
t = proc_find(SCARG(uap, pid));
|
|
|
|
if (t == NULL) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
1994-08-15 20:32:41 +04:00
|
|
|
return (ESRCH);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2006-12-27 13:02:46 +03:00
|
|
|
|
Tons of process scope changes.
- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.
- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.
- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.
- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).
- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.
- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.
- Make bsd44 secmodel code handle the newly added rqeuests appropriately.
All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.
- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.
Discussed with christos@ and yamt@.
2008-01-23 18:04:38 +03:00
|
|
|
/* XXX-elad */
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(t->p_lock);
|
2006-12-27 13:02:46 +03:00
|
|
|
error = kauth_authorize_process(l->l_cred, KAUTH_PROCESS_CANSEE,
|
Tons of process scope changes.
- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.
- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.
- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.
- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).
- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.
- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.
- Make bsd44 secmodel code handle the newly added rqeuests appropriately.
All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.
- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.
Discussed with christos@ and yamt@.
2008-01-23 18:04:38 +03:00
|
|
|
t, KAUTH_ARG(KAUTH_REQ_PROCESS_CANSEE_ENTRY), NULL, NULL);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (error) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2006-12-27 13:02:46 +03:00
|
|
|
return (ESRCH);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
1994-08-15 20:32:41 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Grab a reference on the process to prevent it from execing or
|
|
|
|
* exiting.
|
|
|
|
*/
|
2007-11-07 03:23:13 +03:00
|
|
|
if (!rw_tryenter(&t->p_reflock, RW_READER)) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2007-11-07 03:23:13 +03:00
|
|
|
return EBUSY;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2002-01-12 00:16:27 +03:00
|
|
|
|
1994-08-15 20:32:41 +04:00
|
|
|
/* Make sure we can operate on it. */
|
2007-02-10 00:55:00 +03:00
|
|
|
switch (req) {
|
1994-08-15 20:32:41 +04:00
|
|
|
case PT_TRACE_ME:
|
|
|
|
/* Saying that you're being traced is always legal. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PT_ATTACH:
|
|
|
|
/*
|
|
|
|
* You can't attach to a process if:
|
|
|
|
* (1) it's the process that's doing the attaching,
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (t->p_pid == p->p_pid) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1994-08-15 20:32:41 +04:00
|
|
|
|
|
|
|
/*
|
2000-09-24 11:31:28 +04:00
|
|
|
* (2) it's a system process
|
|
|
|
*/
|
2007-02-18 01:31:36 +03:00
|
|
|
if (t->p_flag & PK_SYSTEM) {
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EPERM;
|
|
|
|
break;
|
|
|
|
}
|
2000-09-24 11:31:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* (3) it's already being traced, or
|
1994-08-15 20:32:41 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (ISSET(t->p_slflag, PSL_TRACED)) {
|
|
|
|
error = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
1994-08-15 20:32:41 +04:00
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* (4) the tracer is chrooted, and its root directory is
|
|
|
|
* not at or above the root directory of the tracee
|
1999-03-25 07:45:56 +03:00
|
|
|
*/
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock); /* XXXSMP */
|
2007-02-10 00:55:00 +03:00
|
|
|
tmp = proc_isunder(t, l);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(t->p_lock); /* XXXSMP */
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!tmp) {
|
|
|
|
error = EPERM;
|
|
|
|
break;
|
|
|
|
}
|
1994-08-15 20:32:41 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PT_READ_I:
|
|
|
|
case PT_READ_D:
|
|
|
|
case PT_WRITE_I:
|
|
|
|
case PT_WRITE_D:
|
2002-03-17 20:02:45 +03:00
|
|
|
case PT_IO:
|
1994-08-15 20:32:41 +04:00
|
|
|
#ifdef PT_GETREGS
|
|
|
|
case PT_GETREGS:
|
|
|
|
#endif
|
|
|
|
#ifdef PT_SETREGS
|
|
|
|
case PT_SETREGS:
|
|
|
|
#endif
|
|
|
|
#ifdef PT_GETFPREGS
|
|
|
|
case PT_GETFPREGS:
|
|
|
|
#endif
|
|
|
|
#ifdef PT_SETFPREGS
|
|
|
|
case PT_SETFPREGS:
|
|
|
|
#endif
|
2001-12-05 03:58:05 +03:00
|
|
|
#ifdef __HAVE_PTRACE_MACHDEP
|
|
|
|
PTRACE_MACHDEP_REQUEST_CASES
|
|
|
|
#endif
|
2006-12-27 13:02:46 +03:00
|
|
|
/*
|
|
|
|
* You can't read/write the memory or registers of a process
|
|
|
|
* if the tracer is chrooted, and its root directory is not at
|
|
|
|
* or above the root directory of the tracee.
|
|
|
|
*/
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock); /* XXXSMP */
|
2007-02-10 00:55:00 +03:00
|
|
|
tmp = proc_isunder(t, l);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(t->p_lock); /* XXXSMP */
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!tmp) {
|
|
|
|
error = EPERM;
|
|
|
|
break;
|
|
|
|
}
|
2006-12-27 13:02:46 +03:00
|
|
|
/*FALLTHROUGH*/
|
2001-12-05 03:58:05 +03:00
|
|
|
|
2006-12-27 13:02:46 +03:00
|
|
|
case PT_CONTINUE:
|
|
|
|
case PT_KILL:
|
|
|
|
case PT_DETACH:
|
|
|
|
case PT_LWPINFO:
|
|
|
|
case PT_SYSCALL:
|
2011-09-01 02:58:39 +04:00
|
|
|
case PT_SYSCALLEMU:
|
2006-12-27 13:02:46 +03:00
|
|
|
case PT_DUMPCORE:
|
|
|
|
#ifdef PT_STEP
|
|
|
|
case PT_STEP:
|
|
|
|
#endif
|
2011-09-03 00:07:41 +04:00
|
|
|
case PT_SET_EVENT_MASK:
|
|
|
|
case PT_GET_EVENT_MASK:
|
|
|
|
case PT_GET_PROCESS_STATE:
|
1994-08-15 20:32:41 +04:00
|
|
|
/*
|
|
|
|
* You can't do what you want to the process if:
|
|
|
|
* (1) It's not being traced at all,
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!ISSET(t->p_slflag, PSL_TRACED)) {
|
|
|
|
error = EPERM;
|
|
|
|
break;
|
|
|
|
}
|
1994-08-15 20:32:41 +04:00
|
|
|
|
|
|
|
/*
|
1997-04-28 08:49:27 +04:00
|
|
|
* (2) it's being traced by procfs (which has
|
|
|
|
* different signal delivery semantics),
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (ISSET(t->p_slflag, PSL_FSTRACE)) {
|
2014-11-24 05:34:04 +03:00
|
|
|
DPRINTF(("file system traced\n"));
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EBUSY;
|
|
|
|
break;
|
2006-04-02 02:34:00 +04:00
|
|
|
}
|
1997-04-28 08:49:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* (3) it's not being traced by _you_, or
|
1994-08-15 20:32:41 +04:00
|
|
|
*/
|
2006-04-02 02:34:00 +04:00
|
|
|
if (t->p_pptr != p) {
|
2014-11-24 05:34:04 +03:00
|
|
|
DPRINTF(("parent %d != %d\n", t->p_pptr->p_pid,
|
|
|
|
p->p_pid));
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EBUSY;
|
|
|
|
break;
|
2006-04-02 02:34:00 +04:00
|
|
|
}
|
1994-08-15 20:32:41 +04:00
|
|
|
|
|
|
|
/*
|
1997-04-28 08:49:27 +04:00
|
|
|
* (4) it's not currently stopped.
|
1994-08-15 20:32:41 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (t->p_stat != SSTOP || !t->p_waited /* XXXSMP */) {
|
2014-11-24 05:34:04 +03:00
|
|
|
DPRINTF(("stat %d flag %d\n", t->p_stat,
|
|
|
|
!t->p_waited));
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EBUSY;
|
|
|
|
break;
|
2006-04-02 02:34:00 +04:00
|
|
|
}
|
1994-08-15 20:32:41 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* It was not a legal request. */
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-05 00:17:39 +03:00
|
|
|
if (error == 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
error = kauth_authorize_process(l->l_cred,
|
Tons of process scope changes.
- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.
- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.
- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.
- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).
- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.
- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.
- Make bsd44 secmodel code handle the newly added rqeuests appropriately.
All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.
- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.
Discussed with christos@ and yamt@.
2008-01-23 18:04:38 +03:00
|
|
|
KAUTH_PROCESS_PTRACE, t, KAUTH_ARG(req),
|
2007-02-10 00:55:00 +03:00
|
|
|
NULL, NULL);
|
2009-02-05 00:17:39 +03:00
|
|
|
}
|
|
|
|
if (error == 0) {
|
|
|
|
lt = lwp_find_first(t);
|
|
|
|
if (lt == NULL)
|
|
|
|
error = ESRCH;
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (error != 0) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2007-11-07 03:23:13 +03:00
|
|
|
rw_exit(&t->p_reflock);
|
2007-02-10 00:55:00 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
/* Do single-step fixup if needed. */
|
|
|
|
FIX_SSTEP(t);
|
2008-07-02 23:49:58 +04:00
|
|
|
KASSERT(lt != NULL);
|
2008-04-24 22:39:20 +04:00
|
|
|
lwp_addref(lt);
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Which locks do we need held? XXX Ugly.
|
|
|
|
*/
|
|
|
|
switch (req) {
|
|
|
|
#ifdef PT_STEP
|
|
|
|
case PT_STEP:
|
|
|
|
#endif
|
|
|
|
case PT_CONTINUE:
|
|
|
|
case PT_DETACH:
|
|
|
|
case PT_KILL:
|
|
|
|
case PT_SYSCALL:
|
2011-09-01 02:58:39 +04:00
|
|
|
case PT_SYSCALLEMU:
|
2007-02-10 00:55:00 +03:00
|
|
|
case PT_ATTACH:
|
2008-04-24 22:39:20 +04:00
|
|
|
case PT_TRACE_ME:
|
2007-02-10 00:55:00 +03:00
|
|
|
pheld = 1;
|
|
|
|
break;
|
|
|
|
default:
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
pheld = 0;
|
|
|
|
break;
|
1994-08-15 20:32:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now do the operation. */
|
1995-02-09 08:19:18 +03:00
|
|
|
write = 0;
|
1994-08-15 20:32:41 +04:00
|
|
|
*retval = 0;
|
2000-07-28 08:21:26 +04:00
|
|
|
tmp = 0;
|
2010-04-06 17:50:22 +04:00
|
|
|
resume_all = 1;
|
1994-08-15 20:32:41 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
switch (req) {
|
1994-08-15 20:32:41 +04:00
|
|
|
case PT_TRACE_ME:
|
|
|
|
/* Just set the trace flag. */
|
2007-02-10 00:55:00 +03:00
|
|
|
SET(t->p_slflag, PSL_TRACED);
|
2002-07-26 00:04:02 +04:00
|
|
|
t->p_opptr = t->p_pptr;
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
1994-08-15 20:32:41 +04:00
|
|
|
|
2001-07-22 17:33:58 +04:00
|
|
|
case PT_WRITE_I: /* XXX no separate I and D spaces */
|
1994-08-15 20:32:41 +04:00
|
|
|
case PT_WRITE_D:
|
2002-08-28 11:27:14 +04:00
|
|
|
#if defined(__HAVE_RAS)
|
|
|
|
/*
|
|
|
|
* Can't write to a RAS
|
|
|
|
*/
|
2007-03-04 08:59:00 +03:00
|
|
|
if (ras_lookup(t, SCARG(uap, addr)) != (void *)-1) {
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EACCES;
|
|
|
|
break;
|
2002-08-28 11:27:14 +04:00
|
|
|
}
|
|
|
|
#endif
|
1994-08-15 20:32:41 +04:00
|
|
|
write = 1;
|
2000-07-28 08:21:26 +04:00
|
|
|
tmp = SCARG(uap, data);
|
2007-02-10 00:55:00 +03:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
2001-07-22 17:33:58 +04:00
|
|
|
case PT_READ_I: /* XXX no separate I and D spaces */
|
1994-08-15 20:32:41 +04:00
|
|
|
case PT_READ_D:
|
|
|
|
/* write = 0 done above. */
|
2007-03-04 08:59:00 +03:00
|
|
|
iov.iov_base = (void *)&tmp;
|
2000-07-28 08:21:26 +04:00
|
|
|
iov.iov_len = sizeof(tmp);
|
1994-08-15 20:32:41 +04:00
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
2004-05-26 20:28:05 +04:00
|
|
|
uio.uio_offset = (off_t)(unsigned long)SCARG(uap, addr);
|
2000-07-28 08:21:26 +04:00
|
|
|
uio.uio_resid = sizeof(tmp);
|
1994-08-15 20:32:41 +04:00
|
|
|
uio.uio_rw = write ? UIO_WRITE : UIO_READ;
|
2006-03-01 15:38:10 +03:00
|
|
|
UIO_SETUP_SYSSPACE(&uio);
|
2006-11-28 20:27:09 +03:00
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
error = process_domem(l, lt, &uio);
|
2000-07-28 08:21:26 +04:00
|
|
|
if (!write)
|
|
|
|
*retval = tmp;
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
2005-02-27 00:34:55 +03:00
|
|
|
|
2002-03-17 20:02:45 +03:00
|
|
|
case PT_IO:
|
|
|
|
error = copyin(SCARG(uap, addr), &piod, sizeof(piod));
|
|
|
|
if (error)
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
2015-07-02 06:47:54 +03:00
|
|
|
|
|
|
|
iov.iov_base = piod.piod_addr;
|
|
|
|
iov.iov_len = piod.piod_len;
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = (off_t)(unsigned long)piod.piod_offs;
|
|
|
|
uio.uio_resid = piod.piod_len;
|
|
|
|
|
2002-03-17 20:02:45 +03:00
|
|
|
switch (piod.piod_op) {
|
|
|
|
case PIOD_READ_D:
|
|
|
|
case PIOD_READ_I:
|
|
|
|
uio.uio_rw = UIO_READ;
|
|
|
|
break;
|
|
|
|
case PIOD_WRITE_D:
|
|
|
|
case PIOD_WRITE_I:
|
2006-12-04 21:50:19 +03:00
|
|
|
/*
|
|
|
|
* Can't write to a RAS
|
|
|
|
*/
|
2007-10-24 18:50:38 +04:00
|
|
|
if (ras_lookup(t, SCARG(uap, addr)) != (void *)-1) {
|
2006-12-04 21:50:19 +03:00
|
|
|
return (EACCES);
|
|
|
|
}
|
2002-03-17 20:02:45 +03:00
|
|
|
uio.uio_rw = UIO_WRITE;
|
|
|
|
break;
|
2015-07-02 06:47:54 +03:00
|
|
|
case PIOD_READ_AUXV:
|
|
|
|
req = PT_READ_D;
|
|
|
|
uio.uio_rw = UIO_READ;
|
2016-09-29 23:40:53 +03:00
|
|
|
tmp = t->p_execsw->es_arglen * PROC_PTRSZ(t);
|
2015-07-02 06:47:54 +03:00
|
|
|
if (uio.uio_offset > tmp)
|
|
|
|
return EIO;
|
|
|
|
if (uio.uio_resid > tmp - uio.uio_offset)
|
|
|
|
uio.uio_resid = tmp - uio.uio_offset;
|
|
|
|
piod.piod_len = iov.iov_len = uio.uio_resid;
|
|
|
|
error = process_auxv_offset(t, &uio);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
break;
|
2002-03-17 20:02:45 +03:00
|
|
|
default:
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
2002-03-17 20:02:45 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
if (error)
|
|
|
|
break;
|
2006-12-06 21:54:02 +03:00
|
|
|
error = proc_vmspace_getref(l->l_proc, &vm);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (error)
|
|
|
|
break;
|
2006-12-06 21:54:02 +03:00
|
|
|
uio.uio_vmspace = vm;
|
2006-11-28 20:27:09 +03:00
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
error = process_domem(l, lt, &uio);
|
2002-03-17 20:02:45 +03:00
|
|
|
piod.piod_len -= uio.uio_resid;
|
|
|
|
(void) copyout(&piod, SCARG(uap, addr), sizeof(piod));
|
2006-03-01 15:38:10 +03:00
|
|
|
uvmspace_free(vm);
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
1994-08-15 20:32:41 +04:00
|
|
|
|
2003-01-23 20:35:18 +03:00
|
|
|
case PT_DUMPCORE:
|
2005-01-09 22:22:55 +03:00
|
|
|
if ((path = SCARG(uap, addr)) != NULL) {
|
|
|
|
char *dst;
|
2009-01-22 17:38:34 +03:00
|
|
|
len = SCARG(uap, data);
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (len < 0 || len >= MAXPATHLEN) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-01-22 17:38:34 +03:00
|
|
|
dst = kmem_alloc(len + 1, KM_SLEEP);
|
2005-01-09 22:22:55 +03:00
|
|
|
if ((error = copyin(path, dst, len)) != 0) {
|
2009-01-22 17:38:34 +03:00
|
|
|
kmem_free(dst, len + 1);
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
2005-01-09 22:22:55 +03:00
|
|
|
}
|
|
|
|
path = dst;
|
2005-01-09 23:25:26 +03:00
|
|
|
path[len] = '\0';
|
2005-01-09 22:22:55 +03:00
|
|
|
}
|
2008-11-19 21:35:57 +03:00
|
|
|
error = (*coredump_vec)(lt, path);
|
2005-01-09 22:22:55 +03:00
|
|
|
if (path)
|
2009-01-22 17:38:34 +03:00
|
|
|
kmem_free(path, len + 1);
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
2003-01-23 20:35:18 +03:00
|
|
|
|
1994-08-15 20:32:41 +04:00
|
|
|
#ifdef PT_STEP
|
|
|
|
case PT_STEP:
|
|
|
|
/*
|
|
|
|
* From the 4.4BSD PRM:
|
|
|
|
* "Execution continues as in request PT_CONTINUE; however
|
|
|
|
* as soon as possible after execution of at least one
|
|
|
|
* instruction, execution stops again. [ ... ]"
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
case PT_CONTINUE:
|
2006-03-05 10:21:37 +03:00
|
|
|
case PT_SYSCALL:
|
1995-02-03 14:35:57 +03:00
|
|
|
case PT_DETACH:
|
2007-02-10 00:55:00 +03:00
|
|
|
if (req == PT_SYSCALL) {
|
|
|
|
if (!ISSET(t->p_slflag, PSL_SYSCALL)) {
|
|
|
|
SET(t->p_slflag, PSL_SYSCALL);
|
2006-03-07 10:19:44 +03:00
|
|
|
#ifdef __HAVE_SYSCALL_INTERN
|
2006-03-05 10:21:37 +03:00
|
|
|
(*t->p_emul->e_syscall_intern)(t);
|
2006-03-07 10:19:44 +03:00
|
|
|
#endif
|
2006-03-05 10:21:37 +03:00
|
|
|
}
|
|
|
|
} else {
|
2007-02-10 00:55:00 +03:00
|
|
|
if (ISSET(t->p_slflag, PSL_SYSCALL)) {
|
|
|
|
CLR(t->p_slflag, PSL_SYSCALL);
|
2006-03-07 10:19:44 +03:00
|
|
|
#ifdef __HAVE_SYSCALL_INTERN
|
2006-03-05 10:21:37 +03:00
|
|
|
(*t->p_emul->e_syscall_intern)(t);
|
2006-03-07 10:19:44 +03:00
|
|
|
#endif
|
2006-03-05 10:21:37 +03:00
|
|
|
}
|
|
|
|
}
|
2011-08-29 21:31:50 +04:00
|
|
|
t->p_trace_enabled = trace_is_enabled(t);
|
2006-03-05 10:21:37 +03:00
|
|
|
|
2010-04-06 17:50:22 +04:00
|
|
|
/*
|
|
|
|
* Pick up the LWPID, if supplied. There are two cases:
|
|
|
|
* data < 0 : step or continue single thread, lwp = -data
|
|
|
|
* data > 0 in PT_STEP : step this thread, continue others
|
|
|
|
* For operations other than PT_STEP, data > 0 means
|
|
|
|
* data is the signo to deliver to the process.
|
|
|
|
*/
|
|
|
|
tmp = SCARG(uap, data);
|
|
|
|
if (tmp >= 0) {
|
|
|
|
#ifdef PT_STEP
|
|
|
|
if (req == PT_STEP)
|
|
|
|
signo = 0;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
signo = tmp;
|
|
|
|
tmp = 0; /* don't search for LWP */
|
|
|
|
}
|
2016-10-14 11:37:05 +03:00
|
|
|
} else
|
2010-04-06 17:50:22 +04:00
|
|
|
tmp = -tmp;
|
2016-10-14 11:38:31 +03:00
|
|
|
|
2010-04-06 17:50:22 +04:00
|
|
|
if (tmp > 0) {
|
|
|
|
if (req == PT_DETACH) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lwp_delref2 (lt);
|
|
|
|
lt = lwp_find(t, tmp);
|
|
|
|
if (lt == NULL) {
|
|
|
|
error = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lwp_addref(lt);
|
|
|
|
resume_all = 0;
|
|
|
|
signo = 0;
|
|
|
|
}
|
2016-10-14 11:38:31 +03:00
|
|
|
|
1994-08-15 20:32:41 +04:00
|
|
|
/*
|
|
|
|
* From the 4.4BSD PRM:
|
|
|
|
* "The data argument is taken as a signal number and the
|
|
|
|
* child's execution continues at location addr as if it
|
1995-02-09 02:38:29 +03:00
|
|
|
* incurred that signal. Normally the signal number will
|
1994-08-15 20:32:41 +04:00
|
|
|
* be either 0 to indicate that the signal that caused the
|
|
|
|
* stop should be ignored, or that value fetched out of
|
|
|
|
* the process's image indicating which signal caused
|
|
|
|
* the stop. If addr is (int *)1 then execution continues
|
|
|
|
* from where it stopped."
|
|
|
|
*/
|
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
/* Check that the data is a valid signal number or zero. */
|
2010-04-06 17:50:22 +04:00
|
|
|
if (signo < 0 || signo >= NSIG) {
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1994-08-15 20:32:41 +04:00
|
|
|
|
2002-08-28 11:27:14 +04:00
|
|
|
/* If the address parameter is not (int *)1, set the pc. */
|
2009-10-22 01:11:57 +04:00
|
|
|
if ((int *)SCARG(uap, addr) != (int *)1) {
|
|
|
|
error = process_set_pc(lt, SCARG(uap, addr));
|
|
|
|
if (error != 0)
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
2009-10-22 01:11:57 +04:00
|
|
|
}
|
1995-02-09 08:19:18 +03:00
|
|
|
#ifdef PT_STEP
|
1994-08-15 20:32:41 +04:00
|
|
|
/*
|
|
|
|
* Arrange for a single-step, if that's requested and possible.
|
2010-04-06 17:50:22 +04:00
|
|
|
* More precisely, set the single step status as requested for
|
|
|
|
* the requested thread, and clear it for other threads.
|
1994-08-15 20:32:41 +04:00
|
|
|
*/
|
2010-04-06 17:50:22 +04:00
|
|
|
LIST_FOREACH(lt2, &t->p_lwps, l_sibling) {
|
2016-10-14 11:37:05 +03:00
|
|
|
if (lt != lt2) {
|
2010-04-06 17:50:22 +04:00
|
|
|
lwp_lock(lt2);
|
|
|
|
process_sstep(lt2, 0);
|
|
|
|
lwp_unlock(lt2);
|
|
|
|
}
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
error = process_sstep(lt, req == PT_STEP);
|
2009-10-22 01:11:57 +04:00
|
|
|
if (error)
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
1995-02-09 08:19:18 +03:00
|
|
|
#endif
|
2007-02-10 00:55:00 +03:00
|
|
|
if (req == PT_DETACH) {
|
|
|
|
CLR(t->p_slflag, PSL_TRACED|PSL_FSTRACE|PSL_SYSCALL);
|
|
|
|
|
1995-02-03 14:35:57 +03:00
|
|
|
/* give process back to original parent or init */
|
2002-07-26 00:04:02 +04:00
|
|
|
if (t->p_opptr != t->p_pptr) {
|
|
|
|
struct proc *pp = t->p_opptr;
|
1995-02-03 14:35:57 +03:00
|
|
|
proc_reparent(t, pp ? pp : initproc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not being traced any more */
|
2002-07-26 00:04:02 +04:00
|
|
|
t->p_opptr = NULL;
|
1995-02-03 14:35:57 +03:00
|
|
|
}
|
1995-06-09 03:51:01 +04:00
|
|
|
sendsig:
|
2011-09-03 00:07:41 +04:00
|
|
|
t->p_fpid = 0;
|
1994-08-15 20:32:41 +04:00
|
|
|
/* Finally, deliver the requested signal (or none). */
|
1995-02-03 14:35:57 +03:00
|
|
|
if (t->p_stat == SSTOP) {
|
2003-02-08 00:44:45 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Unstop the process. If it needs to take a
|
|
|
|
* signal, make all efforts to ensure that at
|
|
|
|
* an LWP runs to see it.
|
2003-02-08 00:44:45 +03:00
|
|
|
*/
|
2016-04-04 23:47:57 +03:00
|
|
|
t->p_xsig = signo;
|
2010-04-06 17:50:22 +04:00
|
|
|
if (resume_all)
|
|
|
|
proc_unstop(t);
|
|
|
|
else
|
|
|
|
lwp_unstop(lt);
|
2007-12-21 02:02:38 +03:00
|
|
|
} else if (signo != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
KSI_INIT_EMPTY(&ksi);
|
2007-12-21 02:02:38 +03:00
|
|
|
ksi.ksi_signo = signo;
|
2007-02-10 00:55:00 +03:00
|
|
|
kpsignal2(t, &ksi);
|
1995-02-03 14:35:57 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
1995-08-13 13:05:51 +04:00
|
|
|
|
2011-09-01 02:58:39 +04:00
|
|
|
case PT_SYSCALLEMU:
|
|
|
|
if (!ISSET(t->p_slflag, PSL_SYSCALL) || t->p_stat != SSTOP) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SET(t->p_slflag, PSL_SYSCALLEMU);
|
|
|
|
break;
|
|
|
|
|
1994-08-15 20:32:41 +04:00
|
|
|
case PT_KILL:
|
|
|
|
/* just send the process a KILL signal. */
|
2007-12-21 02:02:38 +03:00
|
|
|
signo = SIGKILL;
|
1994-08-15 20:32:41 +04:00
|
|
|
goto sendsig; /* in PT_CONTINUE, above. */
|
|
|
|
|
|
|
|
case PT_ATTACH:
|
|
|
|
/*
|
|
|
|
* Go ahead and set the trace flag.
|
|
|
|
* Save the old parent (it's reset in
|
|
|
|
* _DETACH, and also in kern_exit.c:wait4()
|
|
|
|
* Reparent the process so that the tracing
|
|
|
|
* proc gets to see all the action.
|
|
|
|
* Stop the target.
|
|
|
|
*/
|
2002-07-26 00:04:02 +04:00
|
|
|
t->p_opptr = t->p_pptr;
|
|
|
|
if (t->p_pptr != p) {
|
2008-05-13 13:16:11 +04:00
|
|
|
struct proc *parent = t->p_pptr;
|
|
|
|
|
|
|
|
if (parent->p_lock < t->p_lock) {
|
|
|
|
if (!mutex_tryenter(parent->p_lock)) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2008-05-13 13:16:11 +04:00
|
|
|
mutex_enter(parent->p_lock);
|
2016-01-09 10:52:38 +03:00
|
|
|
mutex_enter(t->p_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
}
|
2008-05-13 13:16:11 +04:00
|
|
|
} else if (parent->p_lock > t->p_lock) {
|
|
|
|
mutex_enter(parent->p_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
}
|
2008-05-13 13:16:11 +04:00
|
|
|
parent->p_slflag |= PSL_CHTRACED;
|
1994-08-15 20:32:41 +04:00
|
|
|
proc_reparent(t, p);
|
2008-05-13 13:16:11 +04:00
|
|
|
if (parent->p_lock != t->p_lock)
|
|
|
|
mutex_exit(parent->p_lock);
|
2002-07-26 00:04:02 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
SET(t->p_slflag, PSL_TRACED);
|
2007-12-21 02:02:38 +03:00
|
|
|
signo = SIGSTOP;
|
1995-06-06 00:57:54 +04:00
|
|
|
goto sendsig;
|
1994-08-15 20:32:41 +04:00
|
|
|
|
2011-09-03 00:07:41 +04:00
|
|
|
case PT_GET_EVENT_MASK:
|
2014-11-24 05:34:04 +03:00
|
|
|
if (SCARG(uap, data) != sizeof(pe)) {
|
|
|
|
DPRINTF(("ptrace(%d): %d != %zu\n", req,
|
|
|
|
SCARG(uap, data), sizeof(pe)));
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-03 00:07:41 +04:00
|
|
|
memset(&pe, 0, sizeof(pe));
|
2016-10-14 11:38:31 +03:00
|
|
|
pe.pe_set_event = ISSET(t->p_slflag, PSL_TRACEFORK) ?
|
2014-11-24 05:34:04 +03:00
|
|
|
PTRACE_FORK : 0;
|
2011-09-03 00:07:41 +04:00
|
|
|
error = copyout(&pe, SCARG(uap, addr), sizeof(pe));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PT_SET_EVENT_MASK:
|
2014-11-24 05:34:04 +03:00
|
|
|
if (SCARG(uap, data) != sizeof(pe)) {
|
|
|
|
DPRINTF(("ptrace(%d): %d != %zu\n", req,
|
|
|
|
SCARG(uap, data), sizeof(pe)));
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-03 00:07:41 +04:00
|
|
|
if ((error = copyin(SCARG(uap, addr), &pe, sizeof(pe))) != 0)
|
|
|
|
return error;
|
|
|
|
if (pe.pe_set_event & PTRACE_FORK)
|
|
|
|
SET(t->p_slflag, PSL_TRACEFORK);
|
|
|
|
else
|
|
|
|
CLR(t->p_slflag, PSL_TRACEFORK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PT_GET_PROCESS_STATE:
|
2014-11-24 05:34:04 +03:00
|
|
|
if (SCARG(uap, data) != sizeof(ps)) {
|
|
|
|
DPRINTF(("ptrace(%d): %d != %zu\n", req,
|
|
|
|
SCARG(uap, data), sizeof(ps)));
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-03 00:07:41 +04:00
|
|
|
memset(&ps, 0, sizeof(ps));
|
|
|
|
if (t->p_fpid) {
|
|
|
|
ps.pe_report_event = PTRACE_FORK;
|
|
|
|
ps.pe_other_pid = t->p_fpid;
|
|
|
|
}
|
|
|
|
error = copyout(&ps, SCARG(uap, addr), sizeof(ps));
|
|
|
|
break;
|
|
|
|
|
2003-05-20 22:16:08 +04:00
|
|
|
case PT_LWPINFO:
|
2007-02-10 00:55:00 +03:00
|
|
|
if (SCARG(uap, data) != sizeof(pl)) {
|
2014-11-24 05:34:04 +03:00
|
|
|
DPRINTF(("ptrace(%d): %d != %zu\n", req,
|
|
|
|
SCARG(uap, data), sizeof(pl)));
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-15 19:20:09 +04:00
|
|
|
error = copyin(SCARG(uap, addr), &pl, sizeof(pl));
|
2003-05-20 22:16:08 +04:00
|
|
|
if (error)
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
2003-05-20 22:16:08 +04:00
|
|
|
tmp = pl.pl_lwpid;
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_delref(lt);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(t->p_lock);
|
2003-05-20 22:16:08 +04:00
|
|
|
if (tmp == 0)
|
2009-02-05 00:17:39 +03:00
|
|
|
lt = lwp_find_first(t);
|
2003-05-20 22:16:08 +04:00
|
|
|
else {
|
2008-09-27 07:52:24 +04:00
|
|
|
lt = lwp_find(t, tmp);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (lt == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-15 23:55:15 +03:00
|
|
|
lt = LIST_NEXT(lt, l_sibling);
|
2003-05-20 22:16:08 +04:00
|
|
|
}
|
2009-02-05 00:17:39 +03:00
|
|
|
while (lt != NULL && !lwp_alive(lt))
|
2007-10-08 18:08:26 +04:00
|
|
|
lt = LIST_NEXT(lt, l_sibling);
|
2003-05-20 22:16:08 +04:00
|
|
|
pl.pl_lwpid = 0;
|
|
|
|
pl.pl_event = 0;
|
|
|
|
if (lt) {
|
2007-03-15 23:55:15 +03:00
|
|
|
lwp_addref(lt);
|
2003-05-20 22:16:08 +04:00
|
|
|
pl.pl_lwpid = lt->l_lid;
|
|
|
|
if (lt->l_lid == t->p_sigctx.ps_lwp)
|
|
|
|
pl.pl_event = PL_EVENT_SIGNAL;
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2003-05-20 22:16:08 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
error = copyout(&pl, SCARG(uap, addr), sizeof(pl));
|
|
|
|
break;
|
2003-05-20 22:16:08 +04:00
|
|
|
|
1994-08-15 20:32:41 +04:00
|
|
|
#ifdef PT_SETREGS
|
|
|
|
case PT_SETREGS:
|
|
|
|
write = 1;
|
|
|
|
#endif
|
|
|
|
#ifdef PT_GETREGS
|
|
|
|
case PT_GETREGS:
|
|
|
|
/* write = 0 done above. */
|
|
|
|
#endif
|
|
|
|
#if defined(PT_SETREGS) || defined(PT_GETREGS)
|
2003-01-18 13:06:22 +03:00
|
|
|
tmp = SCARG(uap, data);
|
|
|
|
if (tmp != 0 && t->p_nlwps > 1) {
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_delref(lt);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(t->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
lt = lwp_find(t, tmp);
|
|
|
|
if (lt == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lwp_addref(lt);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!process_validregs(lt))
|
|
|
|
error = EINVAL;
|
1994-08-15 20:32:41 +04:00
|
|
|
else {
|
2006-03-01 15:38:10 +03:00
|
|
|
error = proc_vmspace_getref(l->l_proc, &vm);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (error)
|
|
|
|
break;
|
1994-10-20 07:22:35 +03:00
|
|
|
iov.iov_base = SCARG(uap, addr);
|
1994-08-15 20:32:41 +04:00
|
|
|
iov.iov_len = sizeof(struct reg);
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = 0;
|
|
|
|
uio.uio_resid = sizeof(struct reg);
|
|
|
|
uio.uio_rw = write ? UIO_WRITE : UIO_READ;
|
2006-03-01 15:38:10 +03:00
|
|
|
uio.uio_vmspace = vm;
|
2006-11-28 20:27:09 +03:00
|
|
|
|
2006-03-01 15:38:10 +03:00
|
|
|
error = process_doregs(l, lt, &uio);
|
|
|
|
uvmspace_free(vm);
|
1994-08-15 20:32:41 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
1994-08-15 20:32:41 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PT_SETFPREGS
|
|
|
|
case PT_SETFPREGS:
|
|
|
|
write = 1;
|
|
|
|
#endif
|
|
|
|
#ifdef PT_GETFPREGS
|
|
|
|
case PT_GETFPREGS:
|
|
|
|
/* write = 0 done above. */
|
|
|
|
#endif
|
|
|
|
#if defined(PT_SETFPREGS) || defined(PT_GETFPREGS)
|
2003-01-18 13:06:22 +03:00
|
|
|
tmp = SCARG(uap, data);
|
|
|
|
if (tmp != 0 && t->p_nlwps > 1) {
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_delref(lt);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(t->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
lt = lwp_find(t, tmp);
|
|
|
|
if (lt == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lwp_addref(lt);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!process_validfpregs(lt))
|
|
|
|
error = EINVAL;
|
1994-08-15 20:32:41 +04:00
|
|
|
else {
|
2006-03-01 15:38:10 +03:00
|
|
|
error = proc_vmspace_getref(l->l_proc, &vm);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (error)
|
|
|
|
break;
|
1994-10-20 07:22:35 +03:00
|
|
|
iov.iov_base = SCARG(uap, addr);
|
1994-08-15 20:32:41 +04:00
|
|
|
iov.iov_len = sizeof(struct fpreg);
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = 0;
|
|
|
|
uio.uio_resid = sizeof(struct fpreg);
|
|
|
|
uio.uio_rw = write ? UIO_WRITE : UIO_READ;
|
2006-03-01 15:38:10 +03:00
|
|
|
uio.uio_vmspace = vm;
|
2006-11-28 20:27:09 +03:00
|
|
|
|
2006-03-01 15:38:10 +03:00
|
|
|
error = process_dofpregs(l, lt, &uio);
|
|
|
|
uvmspace_free(vm);
|
1994-08-15 20:32:41 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
1994-08-15 20:32:41 +04:00
|
|
|
#endif
|
2001-12-05 03:58:05 +03:00
|
|
|
|
|
|
|
#ifdef __HAVE_PTRACE_MACHDEP
|
|
|
|
PTRACE_MACHDEP_REQUEST_CASES
|
2007-02-10 00:55:00 +03:00
|
|
|
error = ptrace_machdep_dorequest(l, lt,
|
|
|
|
req, SCARG(uap, addr), SCARG(uap, data));
|
|
|
|
break;
|
2001-12-05 03:58:05 +03:00
|
|
|
#endif
|
1994-08-15 20:32:41 +04:00
|
|
|
}
|
1994-08-15 20:29:22 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (pheld) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->p_lock);
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
if (lt != NULL)
|
|
|
|
lwp_delref(lt);
|
2007-11-07 03:23:13 +03:00
|
|
|
rw_exit(&t->p_reflock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
return error;
|
1994-08-15 20:29:22 +04:00
|
|
|
}
|
2002-05-09 19:44:44 +04:00
|
|
|
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
process_doregs(struct lwp *curl /*tracer*/,
|
2005-12-07 08:53:24 +03:00
|
|
|
struct lwp *l /*traced*/,
|
|
|
|
struct uio *uio)
|
2002-05-09 19:44:44 +04:00
|
|
|
{
|
|
|
|
#if defined(PT_GETREGS) || defined(PT_SETREGS)
|
|
|
|
int error;
|
|
|
|
struct reg r;
|
|
|
|
char *kv;
|
|
|
|
int kl;
|
|
|
|
|
2004-05-14 20:36:33 +04:00
|
|
|
if (uio->uio_offset < 0 || uio->uio_offset > (off_t)sizeof(r))
|
|
|
|
return EINVAL;
|
|
|
|
|
2002-05-09 19:44:44 +04:00
|
|
|
kl = sizeof(r);
|
2004-05-14 20:36:33 +04:00
|
|
|
kv = (char *)&r;
|
2002-05-09 19:44:44 +04:00
|
|
|
|
|
|
|
kv += uio->uio_offset;
|
|
|
|
kl -= uio->uio_offset;
|
2004-05-14 20:36:33 +04:00
|
|
|
if ((size_t)kl > uio->uio_resid)
|
2002-05-09 19:44:44 +04:00
|
|
|
kl = uio->uio_resid;
|
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
error = process_read_regs(l, &r);
|
2002-05-09 19:44:44 +04:00
|
|
|
if (error == 0)
|
|
|
|
error = uiomove(kv, kl, uio);
|
|
|
|
if (error == 0 && uio->uio_rw == UIO_WRITE) {
|
2003-01-18 13:06:22 +03:00
|
|
|
if (l->l_stat != LSSTOP)
|
2002-05-09 19:44:44 +04:00
|
|
|
error = EBUSY;
|
|
|
|
else
|
2003-01-18 13:06:22 +03:00
|
|
|
error = process_write_regs(l, &r);
|
2002-05-09 19:44:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uio->uio_offset = 0;
|
|
|
|
return (error);
|
|
|
|
#else
|
|
|
|
return (EINVAL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
process_validregs(struct lwp *l)
|
2002-05-09 19:44:44 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(PT_SETREGS) || defined(PT_GETREGS)
|
2007-02-18 01:31:36 +03:00
|
|
|
return ((l->l_flag & LW_SYSTEM) == 0);
|
2002-05-09 19:44:44 +04:00
|
|
|
#else
|
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
process_dofpregs(struct lwp *curl /*tracer*/,
|
2005-12-07 08:53:24 +03:00
|
|
|
struct lwp *l /*traced*/,
|
|
|
|
struct uio *uio)
|
2002-05-09 19:44:44 +04:00
|
|
|
{
|
|
|
|
#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS)
|
|
|
|
int error;
|
|
|
|
struct fpreg r;
|
|
|
|
char *kv;
|
2009-12-14 03:47:10 +03:00
|
|
|
size_t kl;
|
2002-05-09 19:44:44 +04:00
|
|
|
|
2004-05-14 20:36:33 +04:00
|
|
|
if (uio->uio_offset < 0 || uio->uio_offset > (off_t)sizeof(r))
|
|
|
|
return EINVAL;
|
|
|
|
|
2002-05-09 19:44:44 +04:00
|
|
|
kl = sizeof(r);
|
2004-05-14 20:36:33 +04:00
|
|
|
kv = (char *)&r;
|
2002-05-09 19:44:44 +04:00
|
|
|
|
|
|
|
kv += uio->uio_offset;
|
|
|
|
kl -= uio->uio_offset;
|
2014-09-21 21:17:15 +04:00
|
|
|
if (kl > uio->uio_resid)
|
2002-05-09 19:44:44 +04:00
|
|
|
kl = uio->uio_resid;
|
|
|
|
|
2014-01-04 04:10:02 +04:00
|
|
|
error = process_read_fpregs(l, &r, &kl);
|
2002-05-09 19:44:44 +04:00
|
|
|
if (error == 0)
|
|
|
|
error = uiomove(kv, kl, uio);
|
|
|
|
if (error == 0 && uio->uio_rw == UIO_WRITE) {
|
2003-01-18 13:06:22 +03:00
|
|
|
if (l->l_stat != LSSTOP)
|
2002-05-09 19:44:44 +04:00
|
|
|
error = EBUSY;
|
|
|
|
else
|
2014-01-04 04:10:02 +04:00
|
|
|
error = process_write_fpregs(l, &r, kl);
|
2002-05-09 19:44:44 +04:00
|
|
|
}
|
|
|
|
uio->uio_offset = 0;
|
|
|
|
return (error);
|
|
|
|
#else
|
|
|
|
return (EINVAL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
process_validfpregs(struct lwp *l)
|
2002-05-09 19:44:44 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(PT_SETFPREGS) || defined(PT_GETFPREGS)
|
2007-02-18 01:31:36 +03:00
|
|
|
return ((l->l_flag & LW_SYSTEM) == 0);
|
2002-05-09 19:44:44 +04:00
|
|
|
#else
|
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
}
|
2006-09-02 01:05:33 +04:00
|
|
|
#endif /* PTRACE */
|
2002-05-09 19:44:44 +04:00
|
|
|
|
2007-12-31 18:31:24 +03:00
|
|
|
#if defined(KTRACE) || defined(PTRACE)
|
2002-05-09 19:44:44 +04:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
process_domem(struct lwp *curl /*tracer*/,
|
|
|
|
struct lwp *l /*traced*/,
|
2005-12-07 08:53:24 +03:00
|
|
|
struct uio *uio)
|
2002-05-09 19:44:44 +04:00
|
|
|
{
|
2005-12-11 15:16:03 +03:00
|
|
|
struct proc *p = l->l_proc; /* traced */
|
2004-05-05 01:33:40 +04:00
|
|
|
struct vmspace *vm;
|
2002-05-09 19:44:44 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
size_t len;
|
|
|
|
#ifdef PMAP_NEED_PROCWR
|
|
|
|
vaddr_t addr;
|
|
|
|
#endif
|
|
|
|
|
2006-11-28 20:27:09 +03:00
|
|
|
error = 0;
|
2002-05-09 19:44:44 +04:00
|
|
|
len = uio->uio_resid;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
#ifdef PMAP_NEED_PROCWR
|
|
|
|
addr = uio->uio_offset;
|
|
|
|
#endif
|
|
|
|
|
2004-05-05 01:33:40 +04:00
|
|
|
vm = p->p_vmspace;
|
|
|
|
|
2007-07-21 23:21:53 +04:00
|
|
|
mutex_enter(&vm->vm_map.misc_lock);
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((l->l_flag & LW_WEXIT) || vm->vm_refcnt < 1)
|
2004-05-05 01:33:40 +04:00
|
|
|
error = EFAULT;
|
|
|
|
if (error == 0)
|
|
|
|
p->p_vmspace->vm_refcnt++; /* XXX */
|
2007-07-21 23:21:53 +04:00
|
|
|
mutex_exit(&vm->vm_map.misc_lock);
|
2004-05-05 01:33:40 +04:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2016-05-25 20:43:58 +03:00
|
|
|
error = uvm_io(&vm->vm_map, uio, pax_mprotect_prot(l));
|
2004-05-05 01:33:40 +04:00
|
|
|
uvmspace_free(vm);
|
2002-05-09 19:44:44 +04:00
|
|
|
|
|
|
|
#ifdef PMAP_NEED_PROCWR
|
2004-03-13 21:43:18 +03:00
|
|
|
if (error == 0 && uio->uio_rw == UIO_WRITE)
|
2002-05-09 19:44:44 +04:00
|
|
|
pmap_procwr(p, addr, len);
|
|
|
|
#endif
|
|
|
|
return (error);
|
|
|
|
}
|
2007-12-31 18:31:24 +03:00
|
|
|
#endif /* KTRACE || PTRACE */
|
2002-05-09 19:44:44 +04:00
|
|
|
|
2006-08-30 15:08:15 +04:00
|
|
|
#if defined(KTRACE) || defined(PTRACE)
|
2006-03-05 10:21:37 +03:00
|
|
|
void
|
2008-01-05 15:41:43 +03:00
|
|
|
process_stoptrace(void)
|
2006-03-05 10:21:37 +03:00
|
|
|
{
|
2008-01-05 15:41:43 +03:00
|
|
|
struct lwp *l = curlwp;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc, *pp;
|
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
pp = p->p_pptr;
|
|
|
|
if (pp->p_pid == 1) {
|
|
|
|
CLR(p->p_slflag, PSL_SYSCALL); /* XXXSMP */
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2006-03-05 10:21:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-04 23:47:57 +03:00
|
|
|
p->p_xsig = SIGTRAP;
|
2007-02-10 00:55:00 +03:00
|
|
|
proc_stop(p, 1, SIGSTOP);
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2007-04-20 02:42:10 +04:00
|
|
|
|
2011-09-06 15:22:42 +04:00
|
|
|
if (sigispending(l, 0)) {
|
|
|
|
lwp_lock(l);
|
|
|
|
l->l_flag |= LW_PENDSIG;
|
|
|
|
lwp_unlock(l);
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2006-03-05 10:21:37 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
#endif /* KTRACE || PTRACE */
|
2015-07-02 06:47:54 +03:00
|
|
|
|
|
|
|
#ifdef PTRACE
|
|
|
|
static int
|
|
|
|
process_auxv_offset(struct proc *p, struct uio *uio)
|
|
|
|
{
|
|
|
|
struct ps_strings pss;
|
|
|
|
int error;
|
|
|
|
off_t off = (off_t)p->p_psstrp;
|
|
|
|
|
|
|
|
if ((error = copyin_psstrings(p, &pss)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if (pss.ps_envstr == NULL)
|
|
|
|
return EIO;
|
|
|
|
|
|
|
|
uio->uio_offset += (off_t)(vaddr_t)(pss.ps_envstr + pss.ps_nenvstr + 1);
|
|
|
|
#ifdef __MACHINE_STACK_GROWS_UP
|
|
|
|
if (uio->uio_offset < off)
|
|
|
|
return EIO;
|
|
|
|
#else
|
|
|
|
if (uio->uio_offset > off)
|
|
|
|
return EIO;
|
|
|
|
if ((uio->uio_offset + uio->uio_resid) > off)
|
|
|
|
uio->uio_resid = off - uio->uio_offset;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|