summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2015-11-03 08:31:01 +0000
committerkib <kib@FreeBSD.org>2015-11-03 08:31:01 +0000
commit4042a41aefa37363843b47eb3c9750e91c6dd37a (patch)
tree6333081fd943c7cf5717fa150dfba6e6e3158974 /sys/kern
parent5e283417b20f49343d939a29a2343b558c6c4221 (diff)
downloadFreeBSD-src-4042a41aefa37363843b47eb3c9750e91c6dd37a.zip
FreeBSD-src-4042a41aefa37363843b47eb3c9750e91c6dd37a.tar.gz
MFC r289660,r289664:
Do not allow to execute ptrace(PT_TRACE_ME) when the process is already traced or when there is no parent which can trace the process.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/sys_process.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index a3a861f..5efec4f 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -442,7 +442,7 @@ ptrace_vm_entry(struct thread *td, struct proc *p, struct ptrace_vm_entry *pve)
}
#ifdef COMPAT_FREEBSD32
-static int
+static int
ptrace_vm_entry32(struct thread *td, struct proc *p,
struct ptrace_vm_entry32 *pve32)
{
@@ -743,7 +743,18 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
*/
switch (req) {
case PT_TRACE_ME:
- /* Always legal. */
+ /*
+ * Always legal, when there is a parent process which
+ * could trace us. Otherwise, reject.
+ */
+ if ((p->p_flag & P_TRACED) != 0) {
+ error = EBUSY;
+ goto fail;
+ }
+ if (p->p_pptr == initproc) {
+ error = EPERM;
+ goto fail;
+ }
break;
case PT_ATTACH:
OpenPOWER on IntegriCloud