diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2005-12-11 21:30:32 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2005-12-11 21:30:32 +0000 |
commit | a342f962baf22ac9db5f3bd2a04ed48f1e2a2b74 (patch) | |
tree | d3643230668304deebb48d98ba0541e2eb192241 /sys | |
parent | bdbdd1c8cc21dca99b15a748a74b14759192348c (diff) |
Replace procfs_domem() with a similar interface, process_domem(), which lives
out of procfs and gets a ptrace request PT_{READ,WRITE}_{I,D} as argument;
also procfs_checkioperm() becomes process_checkioperm().
From art@ some time ago; ok kettenis@ pedro@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/alpha/process_machdep.c | 6 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/trap.c | 6 | ||||
-rw-r--r-- | sys/arch/m88k/m88k/trap.c | 9 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/trap.c | 11 | ||||
-rw-r--r-- | sys/conf/files | 3 | ||||
-rw-r--r-- | sys/dev/systrace.c | 7 | ||||
-rw-r--r-- | sys/kern/sys_process.c | 100 | ||||
-rw-r--r-- | sys/miscfs/procfs/procfs.h | 4 | ||||
-rw-r--r-- | sys/miscfs/procfs/procfs_cmdline.c | 4 | ||||
-rw-r--r-- | sys/miscfs/procfs/procfs_ctl.c | 4 | ||||
-rw-r--r-- | sys/miscfs/procfs/procfs_mem.c | 132 | ||||
-rw-r--r-- | sys/miscfs/procfs/procfs_subr.c | 5 | ||||
-rw-r--r-- | sys/miscfs/procfs/procfs_vnops.c | 4 | ||||
-rw-r--r-- | sys/sys/ptrace.h | 4 |
14 files changed, 119 insertions, 180 deletions
diff --git a/sys/arch/alpha/alpha/process_machdep.c b/sys/arch/alpha/alpha/process_machdep.c index a99c685acfb..4d2d5d920ee 100644 --- a/sys/arch/alpha/alpha/process_machdep.c +++ b/sys/arch/alpha/alpha/process_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: process_machdep.c,v 1.9 2002/04/28 20:55:14 pvalchev Exp $ */ +/* $OpenBSD: process_machdep.c,v 1.10 2005/12/11 21:30:27 miod Exp $ */ /* $NetBSD: process_machdep.c,v 1.7 1996/07/11 20:14:21 cgd Exp $ */ /*- @@ -185,7 +185,7 @@ ptrace_read_int(struct proc *p, vaddr_t addr, u_int32_t *v) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = p; - return procfs_domem(curproc, p, NULL, &uio); + return process_domem(curproc, p, &uio, PT_READ_I); } int @@ -203,7 +203,7 @@ ptrace_write_int(struct proc *p, vaddr_t addr, u_int32_t v) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_WRITE; uio.uio_procp = p; - return procfs_domem(curproc, p, NULL, &uio); + return process_domem(curproc, p, &uio, PT_WRITE_I); } u_int64_t diff --git a/sys/arch/hppa/hppa/trap.c b/sys/arch/hppa/hppa/trap.c index f06d01ccce0..ab0e6b8a4c1 100644 --- a/sys/arch/hppa/hppa/trap.c +++ b/sys/arch/hppa/hppa/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.91 2005/10/26 18:35:44 martin Exp $ */ +/* $OpenBSD: trap.c,v 1.92 2005/12/11 21:30:30 miod Exp $ */ /* * Copyright (c) 1998-2004 Michael Shalayeff @@ -615,7 +615,7 @@ ss_get_value(struct proc *p, vaddr_t addr, u_int *value) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = curproc; - return (procfs_domem(curproc, p, NULL, &uio)); + return (process_domem(curproc, p, &uio, PT_READ_I)); } int @@ -633,7 +633,7 @@ ss_put_value(struct proc *p, vaddr_t addr, u_int value) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_WRITE; uio.uio_procp = curproc; - return (procfs_domem(curproc, p, NULL, &uio)); + return (process_domem(curproc, p, &uio, PT_WRITE_I)); } void diff --git a/sys/arch/m88k/m88k/trap.c b/sys/arch/m88k/m88k/trap.c index 9e7e12cd031..206ef090931 100644 --- a/sys/arch/m88k/m88k/trap.c +++ b/sys/arch/m88k/m88k/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.27 2005/12/07 07:38:58 miod Exp $ */ +/* $OpenBSD: trap.c,v 1.28 2005/12/11 21:30:30 miod Exp $ */ /* * Copyright (c) 2004, Miodrag Vallat. * Copyright (c) 1998 Steve Murphree, Jr. @@ -81,9 +81,6 @@ #define USERMODE(PSR) (((PSR) & PSR_MODE) == 0) #define SYSTEMMODE(PSR) (((PSR) & PSR_MODE) != 0) -/* sigh */ -extern int procfs_domem(struct proc *, struct proc *, void *, struct uio *); - __dead void panictrap(int, struct trapframe *); __dead void error_fatal(struct trapframe *); int double_reg_fixup(struct trapframe *); @@ -1506,7 +1503,7 @@ ss_get_value(struct proc *p, vaddr_t addr, u_int *value) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = curproc; - return (procfs_domem(curproc, p, NULL, &uio)); + return (process_domem(curproc, p, &uio, PT_READ_I)); } int @@ -1524,7 +1521,7 @@ ss_put_value(struct proc *p, vaddr_t addr, u_int value) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_WRITE; uio.uio_procp = curproc; - return (procfs_domem(curproc, p, NULL, &uio)); + return (process_domem(curproc, p, &uio, PT_WRITE_I)); } /* diff --git a/sys/arch/mips64/mips64/trap.c b/sys/arch/mips64/mips64/trap.c index d3de97d148e..0047dc01377 100644 --- a/sys/arch/mips64/mips64/trap.c +++ b/sys/arch/mips64/mips64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.26 2005/11/06 10:26:56 martin Exp $ */ +/* $OpenBSD: trap.c,v 1.27 2005/12/11 21:30:30 miod Exp $ */ /* tracked to 1.23 */ /* @@ -630,7 +630,8 @@ printf("SIG-BUSB @%p pc %p, ra %p\n", trapframe->badvaddr, trapframe->pc, trapfr uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_WRITE; uio.uio_procp = curproc; - error = procfs_domem(p, p, NULL, &uio); + error = process_domem(curproc, p, &uio, + PT_WRITE_I); Mips_SyncCache(); if (error) @@ -1067,7 +1068,7 @@ cpu_singlestep(p) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = curproc; - procfs_domem(curproc, p, NULL, &uio); + process_domem(curproc, p, &uio, PT_READ_I); /* compute next address after current location */ if (curinstr != 0) { @@ -1094,7 +1095,7 @@ cpu_singlestep(p) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = curproc; - procfs_domem(curproc, p, NULL, &uio); + process_domem(curproc, p, &uio, PT_READ_I); /* * Store breakpoint instruction at the "next" location now. @@ -1108,7 +1109,7 @@ cpu_singlestep(p) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_WRITE; uio.uio_procp = curproc; - error = procfs_domem(curproc, p, NULL, &uio); + error = process_domem(curproc, p, &uio, PT_WRITE_I); Mips_SyncCache(); if (error) return (EFAULT); diff --git a/sys/conf/files b/sys/conf/files index ee51fc26e5b..c34ad120a81 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.356 2005/12/06 20:18:57 pedro Exp $ +# $OpenBSD: files,v 1.357 2005/12/11 21:30:30 miod Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -666,7 +666,6 @@ file miscfs/portal/portal_vnops.c portal file miscfs/procfs/procfs_cmdline.c procfs file miscfs/procfs/procfs_ctl.c procfs file miscfs/procfs/procfs_linux.c procfs -file miscfs/procfs/procfs_mem.c file miscfs/procfs/procfs_note.c procfs file miscfs/procfs/procfs_status.c procfs file miscfs/procfs/procfs_subr.c procfs diff --git a/sys/dev/systrace.c b/sys/dev/systrace.c index 9fa8f3292cd..8670f716d0f 100644 --- a/sys/dev/systrace.c +++ b/sys/dev/systrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: systrace.c,v 1.39 2005/11/19 02:18:00 pedro Exp $ */ +/* $OpenBSD: systrace.c,v 1.40 2005/12/11 21:30:30 miod Exp $ */ /* * Copyright 2002 Niels Provos <provos@citi.umich.edu> * All rights reserved. @@ -47,11 +47,10 @@ #include <sys/mount.h> #include <sys/namei.h> #include <sys/poll.h> +#include <sys/ptrace.h> #include <compat/common/compat_util.h> -#include <miscfs/procfs/procfs.h> - #include <dev/systrace.h> void systraceattach(int); @@ -1211,7 +1210,7 @@ systrace_io(struct str_process *strp, struct systrace_io *io) uio.uio_segflg = UIO_USERSPACE; uio.uio_procp = p; - error = procfs_domem(p, t, NULL, &uio); + error = process_domem(p, t, &uio, PT_WRITE_I); io->strio_len -= uio.uio_resid; out: diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index f6bd38083f7..84a1145524e 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_process.c,v 1.32 2005/09/14 20:55:59 kettenis Exp $ */ +/* $OpenBSD: sys_process.c,v 1.33 2005/12/11 21:30:31 miod Exp $ */ /* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */ /*- @@ -67,8 +67,6 @@ #include <machine/reg.h> -#include <miscfs/procfs/procfs.h> - /* * Process debugging system call. */ @@ -101,6 +99,7 @@ sys_ptrace(p, v, retval) #endif int error, write; int temp; + int req; int s; /* "A foolish consistency..." XXX */ @@ -258,7 +257,8 @@ sys_ptrace(p, v, retval) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = write ? UIO_WRITE : UIO_READ; uio.uio_procp = p; - error = procfs_domem(p, t, NULL, &uio); + error = process_domem(p, t, &uio, write ? PT_WRITE_I : + PT_READ_I); if (write == 0) *retval = temp; return (error); @@ -275,18 +275,26 @@ sys_ptrace(p, v, retval) uio.uio_segflg = UIO_USERSPACE; uio.uio_procp = p; switch (piod.piod_op) { - case PIOD_READ_D: case PIOD_READ_I: + req = PT_READ_I; + uio.uio_rw = UIO_READ; + break; + case PIOD_READ_D: + req = PT_READ_D; uio.uio_rw = UIO_READ; break; - case PIOD_WRITE_D: case PIOD_WRITE_I: + req = PT_WRITE_I; + uio.uio_rw = UIO_WRITE; + break; + case PIOD_WRITE_D: + req = PT_WRITE_D; uio.uio_rw = UIO_WRITE; break; default: return (EINVAL); } - error = procfs_domem(p, t, NULL, &uio); + error = process_domem(p, t, &uio, req); piod.piod_len -= uio.uio_resid; (void) copyout(&piod, SCARG(uap, addr), sizeof(piod)); return (error); @@ -439,7 +447,7 @@ sys_ptrace(p, v, retval) case PT_SETREGS: KASSERT((p->p_flag & P_SYSTEM) == 0); - if ((error = procfs_checkioperm(p, t)) != 0) + if ((error = process_checkioperm(p, t)) != 0) return (error); regs = malloc(sizeof(*regs), M_TEMP, M_WAITOK); @@ -453,7 +461,7 @@ sys_ptrace(p, v, retval) return (error); case PT_GETREGS: KASSERT((p->p_flag & P_SYSTEM) == 0); - if ((error = procfs_checkioperm(p, t)) != 0) + if ((error = process_checkioperm(p, t)) != 0) return (error); regs = malloc(sizeof(*regs), M_TEMP, M_WAITOK); @@ -468,7 +476,7 @@ sys_ptrace(p, v, retval) #ifdef PT_SETFPREGS case PT_SETFPREGS: KASSERT((p->p_flag & P_SYSTEM) == 0); - if ((error = procfs_checkioperm(p, t)) != 0) + if ((error = process_checkioperm(p, t)) != 0) return (error); fpregs = malloc(sizeof(*fpregs), M_TEMP, M_WAITOK); @@ -484,7 +492,7 @@ sys_ptrace(p, v, retval) #ifdef PT_GETFPREGS case PT_GETFPREGS: KASSERT((p->p_flag & P_SYSTEM) == 0); - if ((error = procfs_checkioperm(p, t)) != 0) + if ((error = process_checkioperm(p, t)) != 0) return (error); fpregs = malloc(sizeof(*fpregs), M_TEMP, M_WAITOK); @@ -500,7 +508,7 @@ sys_ptrace(p, v, retval) #ifdef PT_SETXMMREGS case PT_SETXMMREGS: KASSERT((p->p_flag & P_SYSTEM) == 0); - if ((error = procfs_checkioperm(p, t)) != 0) + if ((error = process_checkioperm(p, t)) != 0) return (error); xmmregs = malloc(sizeof(*xmmregs), M_TEMP, M_WAITOK); @@ -516,7 +524,7 @@ sys_ptrace(p, v, retval) #ifdef PT_GETXMMREGS case PT_GETXMMREGS: KASSERT((p->p_flag & P_SYSTEM) == 0); - if ((error = procfs_checkioperm(p, t)) != 0) + if ((error = process_checkioperm(p, t)) != 0) return (error); xmmregs = malloc(sizeof(*xmmregs), M_TEMP, M_WAITOK); @@ -542,3 +550,69 @@ sys_ptrace(p, v, retval) #endif return 0; } + +/* + * Check if a process is allowed to fiddle with the memory of another. + * + * p = tracer + * t = tracee + * + * 1. You can't attach to a process not owned by you or one that has raised + * its privileges. + * 1a. ...unless you are root. + * + * 2. init is always off-limits because it can control the securelevel. + * 2a. ...unless securelevel is permanently set to insecure. + * + * 3. Processes that are in the process of doing an exec() are always + * off-limits because of the can of worms they are. Just wait a + * second. + */ +int +process_checkioperm(struct proc *p, struct proc *t) +{ + int error; + + if ((t->p_cred->p_ruid != p->p_cred->p_ruid || + ISSET(t->p_flag, P_SUGIDEXEC) || + ISSET(t->p_flag, P_SUGID)) && + (error = suser(p, 0)) != 0) + return (error); + + if ((t->p_pid == 1) && (securelevel > -1)) + return (EPERM); + + if (t->p_flag & P_INEXEC) + return (EAGAIN); + + return (0); +} + +int +process_domem(struct proc *curp, struct proc *p, struct uio *uio, int req) +{ + int error; + vaddr_t addr; + vsize_t len; + + len = uio->uio_resid; + if (len == 0) + return (0); + + if ((error = process_checkioperm(curp, p)) != 0) + return (error); + + /* XXXCDC: how should locking work here? */ + if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1)) + return(EFAULT); + addr = uio->uio_offset; + p->p_vmspace->vm_refcnt++; /* XXX */ + error = uvm_io(&p->p_vmspace->vm_map, uio, + (req == PT_WRITE_I) ? UVM_IO_FIXPROT : 0); + uvmspace_free(p->p_vmspace); + + if (error == 0 && req == PT_WRITE_I) + pmap_proc_iflush(p, addr, len); + + return (error); +} diff --git a/sys/miscfs/procfs/procfs.h b/sys/miscfs/procfs/procfs.h index ced28816398..20debdd1e41 100644 --- a/sys/miscfs/procfs/procfs.h +++ b/sys/miscfs/procfs/procfs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: procfs.h,v 1.22 2003/09/23 16:51:13 millert Exp $ */ +/* $OpenBSD: procfs.h,v 1.23 2005/12/11 21:30:31 miod Exp $ */ /* $NetBSD: procfs.h,v 1.17 1996/02/12 15:01:41 christos Exp $ */ /* @@ -111,10 +111,8 @@ int vfs_getuserstr(struct uio *, char *, int *); const vfs_namemap_t *vfs_findname(const vfs_namemap_t *, char *, int); int procfs_allocvp(struct mount *, struct vnode **, long, pfstype); -int procfs_checkioperm(struct proc *p, struct proc *t); int procfs_doctl(struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio); int procfs_dofpregs(struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio); -int procfs_domem(struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio); int procfs_donote(struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio); int procfs_doregs(struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio); int procfs_dostatus(struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio); diff --git a/sys/miscfs/procfs/procfs_cmdline.c b/sys/miscfs/procfs/procfs_cmdline.c index 191130d5e1f..bd9d9c68e52 100644 --- a/sys/miscfs/procfs/procfs_cmdline.c +++ b/sys/miscfs/procfs/procfs_cmdline.c @@ -1,4 +1,4 @@ -/* $OpenBSD: procfs_cmdline.c,v 1.5 2005/11/04 21:48:07 miod Exp $ */ +/* $OpenBSD: procfs_cmdline.c,v 1.6 2005/12/11 21:30:31 miod Exp $ */ /* $NetBSD: procfs_cmdline.c,v 1.3 1999/03/13 22:26:48 thorpej Exp $ */ /* @@ -93,7 +93,7 @@ procfs_docmdline(curp, p, pfs, uio) } /* - * NOTE: Don't bother doing a procfs_checkioperm() here + * NOTE: Don't bother doing a process_checkioperm() here * because the psstrings info is available by using ps(1), * so it's not like there's anything to protect here. */ diff --git a/sys/miscfs/procfs/procfs_ctl.c b/sys/miscfs/procfs/procfs_ctl.c index 9f4cf99ef36..7fac58d0d48 100644 --- a/sys/miscfs/procfs/procfs_ctl.c +++ b/sys/miscfs/procfs/procfs_ctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: procfs_ctl.c,v 1.16 2005/05/31 11:35:33 art Exp $ */ +/* $OpenBSD: procfs_ctl.c,v 1.17 2005/12/11 21:30:31 miod Exp $ */ /* $NetBSD: procfs_ctl.c,v 1.14 1996/02/09 22:40:48 christos Exp $ */ /* @@ -126,7 +126,7 @@ procfs_control(curp, p, op) if (ISSET(p->p_flag, P_TRACED)) return (EBUSY); - if ((error = procfs_checkioperm(curp, p)) != 0) + if ((error = process_checkioperm(curp, p)) != 0) return (error); /* diff --git a/sys/miscfs/procfs/procfs_mem.c b/sys/miscfs/procfs/procfs_mem.c deleted file mode 100644 index 56b73a22c04..00000000000 --- a/sys/miscfs/procfs/procfs_mem.c +++ /dev/null @@ -1,132 +0,0 @@ -/* $OpenBSD: procfs_mem.c,v 1.23 2005/11/04 21:48:07 miod Exp $ */ -/* $NetBSD: procfs_mem.c,v 1.8 1996/02/09 22:40:50 christos Exp $ */ - -/* - * Copyright (c) 1993 Jan-Simon Pendry - * Copyright (c) 1993 Sean Eric Fagan - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Jan-Simon Pendry and Sean Eric Fagan. - * - * 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. - * 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. - * - * @(#)procfs_mem.c 8.5 (Berkeley) 6/15/94 - */ - -/* - * This is a lightly hacked and merged version - * of sef's pread/pwrite functions - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/time.h> -#include <sys/kernel.h> -#include <sys/proc.h> -#include <sys/vnode.h> -#include <miscfs/procfs/procfs.h> - -#include <uvm/uvm_extern.h> - -/* - * Copy data in and out of the target process. - * We do this by mapping the process's page into - * the kernel and then doing a uiomove direct - * from the kernel address space. - */ -int -procfs_domem(curp, p, pfs, uio) - struct proc *curp; /* tracer */ - struct proc *p; /* traced */ - struct pfsnode *pfs; - struct uio *uio; -{ - int error; - vaddr_t addr; - vsize_t len; - - len = uio->uio_resid; - if (len == 0) - return (0); - - if ((error = procfs_checkioperm(curp, p)) != 0) - return (error); - - /* XXXCDC: how should locking work here? */ - if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1)) - return(EFAULT); - addr = uio->uio_offset; - p->p_vmspace->vm_refcnt++; /* XXX */ - error = uvm_io(&p->p_vmspace->vm_map, uio, - uio->uio_rw == UIO_WRITE ? UVM_IO_FIXPROT : 0); - uvmspace_free(p->p_vmspace); - - if (error == 0 && uio->uio_rw == UIO_WRITE) - pmap_proc_iflush(p, addr, len); - - return error; -} - -/* - * Ensure that a process has permission to perform I/O on another. - * Arguments: - * p The process wishing to do the I/O (the tracer). - * t The process who's memory/registers will be read/written. - * - * You cannot attach to a process's mem/regs if: - * - * (1) It's not owned by you, or the last exec - * gave us setuid/setgid privs (unless - * you're root), or... - * - * (2) It's init, which controls the security level - * of the entire system, and the system was not - * compiled with permanently insecure mode turned - * on. - * - * (3) It's currently execing. - */ -int -procfs_checkioperm(p, t) - struct proc *p, *t; -{ - int error; - - if ((t->p_cred->p_ruid != p->p_cred->p_ruid || - ISSET(t->p_flag, P_SUGIDEXEC) || - ISSET(t->p_flag, P_SUGID)) && - (error = suser(p, 0)) != 0) - return (error); - - if ((t->p_pid == 1) && (securelevel > -1)) - return (EPERM); - - if (t->p_flag & P_INEXEC) - return (EAGAIN); - - return (0); -} diff --git a/sys/miscfs/procfs/procfs_subr.c b/sys/miscfs/procfs/procfs_subr.c index 5826d25f5c5..ac8a5769c01 100644 --- a/sys/miscfs/procfs/procfs_subr.c +++ b/sys/miscfs/procfs/procfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: procfs_subr.c,v 1.23 2005/11/19 02:18:01 pedro Exp $ */ +/* $OpenBSD: procfs_subr.c,v 1.24 2005/12/11 21:30:31 miod Exp $ */ /* $NetBSD: procfs_subr.c,v 1.15 1996/02/12 15:01:42 christos Exp $ */ /* @@ -44,6 +44,7 @@ #include <sys/vnode.h> #include <sys/malloc.h> #include <sys/stat.h> +#include <sys/ptrace.h> #include <miscfs/procfs/procfs.h> @@ -229,7 +230,7 @@ procfs_rw(v) return (procfs_dostatus(curp, p, pfs, uio)); case Pmem: - return (procfs_domem(curp, p, pfs, uio)); + return (process_domem(curp, p, uio, PT_WRITE_I)); case Pcmdline: return (procfs_docmdline(curp, p, pfs, uio)); diff --git a/sys/miscfs/procfs/procfs_vnops.c b/sys/miscfs/procfs/procfs_vnops.c index 244a0012feb..c235332da09 100644 --- a/sys/miscfs/procfs/procfs_vnops.c +++ b/sys/miscfs/procfs/procfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: procfs_vnops.c,v 1.36 2005/04/21 23:28:55 deraadt Exp $ */ +/* $OpenBSD: procfs_vnops.c,v 1.37 2005/12/11 21:30:31 miod Exp $ */ /* $NetBSD: procfs_vnops.c,v 1.40 1996/03/16 23:52:55 christos Exp $ */ /* @@ -227,7 +227,7 @@ procfs_open(v) ((pfs->pfs_flags & O_EXCL) && (ap->a_mode & FWRITE))) return (EBUSY); - if ((error = procfs_checkioperm(p1, p2)) != 0) + if ((error = process_checkioperm(p1, p2)) != 0) return (error); if (ap->a_mode & FWRITE) diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index e20a7490fee..be8fa766385 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ptrace.h,v 1.9 2005/09/14 20:55:59 kettenis Exp $ */ +/* $OpenBSD: ptrace.h,v 1.10 2005/12/11 21:30:31 miod Exp $ */ /* $NetBSD: ptrace.h,v 1.21 1996/02/09 18:25:26 christos Exp $ */ /*- @@ -106,6 +106,8 @@ int process_sstep(struct proc *p, int sstep); int process_write_fpregs(struct proc *p, struct fpreg *regs); #endif int process_write_regs(struct proc *p, struct reg *regs); +int process_checkioperm(struct proc *, struct proc *); +int process_domem(struct proc *, struct proc *, struct uio *, int); #ifndef FIX_SSTEP #define FIX_SSTEP(p) |