Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161928893
D58094.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D58094.diff
View Options
diff --git a/lib/libsys/ptrace.2 b/lib/libsys/ptrace.2
--- a/lib/libsys/ptrace.2
+++ b/lib/libsys/ptrace.2
@@ -468,6 +468,17 @@
apply.)
The tracing process will see the newly-traced process stop and may
then control it as if it had been traced all along.
+.It Dv PT_ATTACH_PD
+The request attaches to the process specified by the process
+descriptor passed in the
+.Fa data
+argument.
+Otherwise, it is identical to
+.Dv PT_ATTACH .
+.Pp
+The
+.Fa pid
+argument must be set to zero.
.It Dv PT_DETACH
This request is like PT_CONTINUE, except that it does not allow
specifying an alternate place to continue execution, and after it
diff --git a/sys/kern/subr_capability.c b/sys/kern/subr_capability.c
--- a/sys/kern/subr_capability.c
+++ b/sys/kern/subr_capability.c
@@ -93,6 +93,8 @@
const cap_rights_t cap_pdkill_rights = CAP_RIGHTS_INITIALIZER(CAP_PDKILL);
const cap_rights_t cap_pdwait_rights = CAP_RIGHTS_INITIALIZER(CAP_PDWAIT);
const cap_rights_t cap_pread_rights = CAP_RIGHTS_INITIALIZER(CAP_PREAD);
+const cap_rights_t cap_ptrace_attach_rights =
+ CAP_RIGHTS_INITIALIZER(CAP_PTRACE_ATTACH);
const cap_rights_t cap_pwrite_rights = CAP_RIGHTS_INITIALIZER(CAP_PWRITE);
const cap_rights_t cap_read_rights = CAP_RIGHTS_INITIALIZER(CAP_READ);
const cap_rights_t cap_recv_rights = CAP_RIGHTS_INITIALIZER(CAP_RECV);
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -43,6 +43,7 @@
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
+#include <sys/procdesc.h>
#include <sys/ptrace.h>
#include <sys/reg.h>
#include <sys/rwlock.h>
@@ -978,6 +979,8 @@
struct ptrace_coredump *pc;
struct thr_coredump_req *tcq;
struct thr_syscall_req *tsr;
+ struct file *pfp;
+ struct procdesc *pd;
int error, num, tmp;
lwpid_t tid = 0, *buf;
#ifdef COMPAT_FREEBSD32
@@ -988,11 +991,13 @@
curp = td->td_proc;
proctree_locked = false;
p2_req_set = false;
+ fp = NULL;
/* Lock proctree before locking the process. */
switch (req) {
case PT_TRACE_ME:
case PT_ATTACH:
+ case PT_ATTACH_PD:
case PT_STEP:
case PT_CONTINUE:
case PT_TO_SCE:
@@ -1015,7 +1020,27 @@
p = td->td_proc;
PROC_LOCK(p);
} else {
- if (pid <= PID_MAX) {
+ if (req == PT_ATTACH_PD) {
+ if (pid != 0) {
+ sx_xunlock(&proctree_lock);
+ return (EINVAL);
+ }
+ error = fget(td, data, &cap_ptrace_attach_rights,
+ &pfp);
+ if (error != 0) {
+ sx_xunlock(&proctree_lock);
+ return (error);
+ }
+ if (pfp->f_type != DTYPE_PROCDESC) {
+ error = EBADF;
+ goto fail_fp;
+ }
+ pd = pfp->f_data;
+ p = pd->pd_proc;
+ PROC_LOCK(p);
+ tid = pid;
+ pid = p->p_pid;
+ } else if (pid <= PID_MAX) {
if ((p = pfind(pid)) == NULL) {
if (proctree_locked)
sx_xunlock(&proctree_lock);
@@ -1183,6 +1208,7 @@
break;
case PT_ATTACH:
+ case PT_ATTACH_PD:
/* security check done above */
/*
* It would be nice if the tracing relationship was separate
@@ -1857,8 +1883,11 @@
p->p_flag2 &= ~P2_PTRACEREQ;
}
PROC_UNLOCK(p);
+fail_fp:
if (proctree_locked)
sx_xunlock(&proctree_lock);
+ if (fp != NULL)
+ fdrop(pfp, td);
return (error);
}
#undef PROC_READ
diff --git a/sys/sys/caprights.h b/sys/sys/caprights.h
--- a/sys/sys/caprights.h
+++ b/sys/sys/caprights.h
@@ -95,6 +95,7 @@
extern const cap_rights_t cap_pdkill_rights;
extern const cap_rights_t cap_pdwait_rights;
extern const cap_rights_t cap_pread_rights;
+extern const cap_rights_t cap_ptrace_attach_rights;
extern const cap_rights_t cap_pwrite_rights;
extern const cap_rights_t cap_read_rights;
extern const cap_rights_t cap_recv_rights;
diff --git a/sys/sys/capsicum.h b/sys/sys/capsicum.h
--- a/sys/sys/capsicum.h
+++ b/sys/sys/capsicum.h
@@ -299,7 +299,9 @@
/* Allows pddupfd(2). */
#define CAP_PDDUPFD CAPRIGHT(1, 0x0000000000800000ULL)
-#define CAP_UNUSED1_25 CAPRIGHT(1, 0x0000000001000000ULL)
+/* Allows ptrace(PT_ATTACH_PD) */
+#define CAP_PTRACE_ATTACH CAPRIGHT(1, 0x0000000001000000ULL)
+
#define CAP_UNUSED1_26 CAPRIGHT(1, 0x0000000002000000ULL)
#define CAP_UNUSED1_27 CAPRIGHT(1, 0x0000000004000000ULL)
#define CAP_UNUSED1_28 CAPRIGHT(1, 0x0000000008000000ULL)
@@ -334,7 +336,7 @@
#define CAP_UNUSED1_57 CAPRIGHT(1, 0x0100000000000000ULL)
/* All used bits for index 1. */
-#define CAP_ALL1 CAPRIGHT(1, 0x0000000000FFFFFFULL)
+#define CAP_ALL1 CAPRIGHT(1, 0x0000000001FFFFFFULL)
/* Backward compatibility. */
#define CAP_POLL_EVENT CAP_EVENT
diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h
--- a/sys/sys/ptrace.h
+++ b/sys/sys/ptrace.h
@@ -85,6 +85,7 @@
#define PT_GETREGSET 42 /* Get a target register set */
#define PT_SETREGSET 43 /* Set a target register set */
#define PT_SC_REMOTE 44 /* Execute a syscall */
+#define PT_ATTACH_PD 45 /* Attach by process descriptor */
#define PT_FIRSTMACH 64 /* for machine-specific requests */
#define PT_LASTMACH 127
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 9, 2:46 AM (11 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34871054
Default Alt Text
D58094.diff (4 KB)
Attached To
Mode
D58094: ptrace(PT_ATTACH_PD)
Attached
Detach File
Event Timeline
Log In to Comment