From 1c843354aaeddb57f4be11a2cd5eeb3278265a03 Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Fri, 15 Aug 2003 05:25:06 +0000 Subject: [PATCH] Add or finish support for machine dependent ptrace requests. When we check for permissions, do it for all requests, not the known requests. Later when we actually service the request we deal with the invalid requests we previously caught earlier. This commit changes the behaviour of the ptrace(2) interface for boundary cases such as an unknown request without proper permissions. Previously we would return EINVAL. Now we return EBUSY or EPERM. Platforms need to define __HAVE_PTRACE_MACHDEP when they have MD requests. This makes the prototype of cpu_ptrace() visible and introduces a call to this function for all requests greater or equal to PT_FIRSTMACH. Silence on: audit --- sys/kern/sys_process.c | 35 +++++++++++++---------------------- sys/sys/ptrace.h | 4 ++++ 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index bdecbf3a52c..51bbdcd7e01 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -336,6 +336,7 @@ ptrace(struct thread *td, struct ptrace_args *uap) break; default: addr = uap->addr; + break; } if (error) return (error); @@ -449,21 +450,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) /* OK */ break; - case PT_READ_I: - case PT_READ_D: - case PT_WRITE_I: - case PT_WRITE_D: - case PT_IO: - case PT_CONTINUE: - case PT_KILL: - case PT_STEP: - case PT_DETACH: - case PT_GETREGS: - case PT_SETREGS: - case PT_GETFPREGS: - case PT_SETFPREGS: - case PT_GETDBREGS: - case PT_SETDBREGS: + default: /* not being traced... */ if ((p->p_flag & P_TRACED) == 0) { error = EPERM; @@ -484,10 +471,6 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) /* OK */ break; - - default: - error = EINVAL; - goto fail; } td2 = FIRST_THREAD_IN_PROC(p); @@ -702,12 +685,20 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) return (error); default: - KASSERT(0, ("unreachable code\n")); +#ifdef __HAVE_PTRACE_MACHDEP + if (req >= PT_FIRSTMACH) { + _PHOLD(p); + error = cpu_ptrace(td2, req, addr, data); + _PRELE(p); + PROC_UNLOCK(p); + return (error); + } +#endif break; } - KASSERT(0, ("unreachable code\n")); - return (0); + /* Unknown request. */ + error = EINVAL; fail: PROC_UNLOCK(p); diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index 09d87428492..ef7262a6766 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -81,6 +81,10 @@ struct ptrace_io_desc { int ptrace_set_pc(struct thread *_td, unsigned long _addr); int ptrace_single_step(struct thread *_td); +#ifdef __HAVE_PTRACE_MACHDEP +int cpu_ptrace(struct thread *_td, int _req, void *_addr, int _data); +#endif + /* * These are prototypes for functions that implement some of the * debugging functionality exported by procfs / linprocfs and by the