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
This commit is contained in:
parent
3e1b578a28
commit
1c843354aa
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user