summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2002-03-14 00:42:26 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2002-03-14 00:42:26 +0000
commit4e75a2f3d47fcb4101ad6c63743e4262538a944a (patch)
tree8b4782ea02392ac0303642f999b3a00a9de95490 /sys/arch
parent31d9f37c33069ba39395849737d1ef3662a4c687 (diff)
Turn the ptrace(2) syscall into a kernel compile option, option PTRACE in
your kernel configuration file. By default, GENERIC will enable this. When PTRACE is not enabled, several ptrace-like features of the procfs filesystem will be disabled as well (namely, the ability to read and write any process' registers, as well as attching, single stepping and detaching to/from processes). This should help paranoid people build better sandboxens, and us to build smaller ramdisks.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/alpha/alpha/process_machdep.c44
-rw-r--r--sys/arch/hppa/hppa/process_machdep.c17
-rw-r--r--sys/arch/i386/i386/process_machdep.c6
-rw-r--r--sys/arch/m68k/m68k/process_machdep.c29
-rw-r--r--sys/arch/mvme88k/mvme88k/process_machdep.c41
-rw-r--r--sys/arch/powerpc/powerpc/process_machdep.c50
-rw-r--r--sys/arch/sparc/sparc/process_machdep.c47
-rw-r--r--sys/arch/sparc64/sparc64/process_machdep.c64
-rw-r--r--sys/arch/vax/vax/machdep.c6
9 files changed, 162 insertions, 142 deletions
diff --git a/sys/arch/alpha/alpha/process_machdep.c b/sys/arch/alpha/alpha/process_machdep.c
index 4e15522218f..5de30a17b88 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.6 2002/03/12 11:58:14 art Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.7 2002/03/14 00:42:20 miod Exp $ */
/* $NetBSD: process_machdep.c,v 1.7 1996/07/11 20:14:21 cgd Exp $ */
/*-
@@ -108,6 +108,24 @@ process_read_regs(p, regs)
}
int
+process_read_fpregs(p, regs)
+ struct proc *p;
+ struct fpreg *regs;
+{
+
+ if (p == fpcurproc) {
+ alpha_pal_wrfen(1);
+ savefpstate(process_fpframe(p));
+ alpha_pal_wrfen(0);
+ }
+
+ bcopy(process_fpframe(p), regs, sizeof(struct fpreg));
+ return (0);
+}
+
+#ifdef PTRACE
+
+int
process_write_regs(p, regs)
struct proc *p;
struct reg *regs;
@@ -120,29 +138,25 @@ process_write_regs(p, regs)
}
int
-process_set_pc(p, addr)
+process_sstep(p, sstep)
struct proc *p;
- caddr_t addr;
+ int sstep;
{
- struct trapframe *frame = process_frame(p);
- frame->tf_regs[FRAME_PC] = (u_int64_t)addr;
+ if (sstep)
+ return (EINVAL);
+
return (0);
}
int
-process_read_fpregs(p, regs)
+process_set_pc(p, addr)
struct proc *p;
- struct fpreg *regs;
+ caddr_t addr;
{
+ struct trapframe *frame = process_frame(p);
- if (p == fpcurproc) {
- alpha_pal_wrfen(1);
- savefpstate(process_fpframe(p));
- alpha_pal_wrfen(0);
- }
-
- bcopy(process_fpframe(p), regs, sizeof(struct fpreg));
+ frame->tf_regs[FRAME_PC] = (u_int64_t)addr;
return (0);
}
@@ -348,3 +362,5 @@ process_sstep(struct proc *p, int sstep)
return (0);
}
+
+#endif /* PTRACE */
diff --git a/sys/arch/hppa/hppa/process_machdep.c b/sys/arch/hppa/hppa/process_machdep.c
index afe2e97dcc4..324f5fec427 100644
--- a/sys/arch/hppa/hppa/process_machdep.c
+++ b/sys/arch/hppa/hppa/process_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process_machdep.c,v 1.3 1999/06/18 05:19:52 mickey Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.4 2002/03/14 00:42:24 miod Exp $ */
/*
* Copyright (c) 1999 Michael Shalayeff
@@ -48,20 +48,22 @@ process_read_regs(p, regs)
}
int
-process_write_regs(p, regs)
+process_read_fpregs(p, fpregs)
struct proc *p;
- struct reg *regs;
+ struct fpreg *fpregs;
{
- bcopy (&regs[1], &p->p_md.md_regs->tf_r1, sizeof(*regs) - sizeof(*regs));
+ bcopy (p->p_addr->u_pcb.pcb_fpregs, fpregs, sizeof(*fpregs));
return 0;
}
+#ifdef PTRACE
+
int
-process_read_fpregs(p, fpregs)
+process_write_regs(p, regs)
struct proc *p;
- struct fpreg *fpregs;
+ struct reg *regs;
{
- bcopy (p->p_addr->u_pcb.pcb_fpregs, fpregs, sizeof(*fpregs));
+ bcopy (&regs[1], &p->p_md.md_regs->tf_r1, sizeof(*regs) - sizeof(*regs));
return 0;
}
@@ -94,3 +96,4 @@ process_set_pc(p, addr)
return 0;
}
+#endif /* PTRACE */
diff --git a/sys/arch/i386/i386/process_machdep.c b/sys/arch/i386/i386/process_machdep.c
index 26c441dc8d3..7897ee4bf8c 100644
--- a/sys/arch/i386/i386/process_machdep.c
+++ b/sys/arch/i386/i386/process_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process_machdep.c,v 1.8 2002/02/18 23:26:18 mickey Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.9 2002/03/14 00:42:24 miod Exp $ */
/* $NetBSD: process_machdep.c,v 1.22 1996/05/03 19:42:25 christos Exp $ */
/*
@@ -160,6 +160,8 @@ process_read_fpregs(p, regs)
return (0);
}
+#ifdef PTRACE
+
int
process_write_regs(p, regs)
struct proc *p;
@@ -271,3 +273,5 @@ process_set_pc(p, addr)
return (0);
}
+
+#endif /* PTRACE */
diff --git a/sys/arch/m68k/m68k/process_machdep.c b/sys/arch/m68k/m68k/process_machdep.c
index e5ab757693b..172df418e0b 100644
--- a/sys/arch/m68k/m68k/process_machdep.c
+++ b/sys/arch/m68k/m68k/process_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process_machdep.c,v 1.4 2001/06/23 05:40:57 art Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.5 2002/03/14 00:42:24 miod Exp $ */
/* $NetBSD: process_machdep.c,v 1.17 1996/05/06 20:05:24 gwr Exp $ */
/*
@@ -63,27 +63,8 @@
#include <machine/psl.h>
#include <machine/reg.h>
-static __inline struct frame *process_frame __P((struct proc *p));
-static __inline struct fpframe *process_fpframe __P((struct proc *p));
-
-static __inline struct frame *
-process_frame(p)
- struct proc *p;
-{
- void *ptr;
-
- ptr = p->p_md.md_regs;
-
- return (ptr);
-}
-
-static __inline struct fpframe *
-process_fpframe(p)
- struct proc *p;
-{
-
- return (&p->p_addr->u_pcb.pcb_fpregs);
-}
+#define process_frame(p) (struct frame *)&((p)->p_md.md_regs)
+#define process_fpframe(p) &((p)->p_addr->u_pcb.pcb_fpregs)
int
process_read_regs(p, regs)
@@ -114,6 +95,8 @@ process_read_fpregs(p, regs)
return (0);
}
+#ifdef PTRACE
+
int
process_write_regs(p, regs)
struct proc *p;
@@ -197,3 +180,5 @@ process_set_pc(p, addr)
return (0);
}
+
+#endif /* PTRACE */
diff --git a/sys/arch/mvme88k/mvme88k/process_machdep.c b/sys/arch/mvme88k/mvme88k/process_machdep.c
index 0afc9abedc2..9866e9e55b2 100644
--- a/sys/arch/mvme88k/mvme88k/process_machdep.c
+++ b/sys/arch/mvme88k/mvme88k/process_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process_machdep.c,v 1.9 2001/03/09 05:44:42 smurph Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.10 2002/03/14 00:42:24 miod Exp $ */
/*
* Copyright (c) 1993 The Regents of the University of California.
@@ -82,12 +82,30 @@ process_read_regs(p, regs)
struct proc *p;
struct reg *regs;
{
-
bcopy((caddr_t)USER_REGS(p), (caddr_t)regs, sizeof(struct reg));
return (0);
}
int
+process_read_fpregs(p, regs)
+ struct proc *p;
+ struct fpreg *regs;
+{
+#if 0
+ extern struct fpstate initfpstate;
+ struct fpstate *statep = &initfpstate;
+
+ /* NOTE: struct fpreg == struct fpstate */
+ if (p->p_md.md_fpstate)
+ statep = p->p_md.md_fpstate;
+ bcopy(statep, regs, sizeof(struct fpreg));
+#endif
+ return 0;
+}
+
+#ifdef PTRACE
+
+int
process_write_regs(p, regs)
struct proc *p;
struct reg *regs;
@@ -124,23 +142,6 @@ process_set_pc(p, addr)
}
int
-process_read_fpregs(p, regs)
- struct proc *p;
- struct fpreg *regs;
-{
-#if 0
- extern struct fpstate initfpstate;
- struct fpstate *statep = &initfpstate;
-
- /* NOTE: struct fpreg == struct fpstate */
- if (p->p_md.md_fpstate)
- statep = p->p_md.md_fpstate;
- bcopy(statep, regs, sizeof(struct fpreg));
-#endif
- return 0;
-}
-
-int
process_write_fpregs(p, regs)
struct proc *p;
struct fpreg *regs;
@@ -153,3 +154,5 @@ process_write_fpregs(p, regs)
#endif
return 0;
}
+
+#endif /* PTRACE */
diff --git a/sys/arch/powerpc/powerpc/process_machdep.c b/sys/arch/powerpc/powerpc/process_machdep.c
index 994cd40ff3d..2bda245f97c 100644
--- a/sys/arch/powerpc/powerpc/process_machdep.c
+++ b/sys/arch/powerpc/powerpc/process_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process_machdep.c,v 1.4 2001/07/09 01:11:09 mickey Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.5 2002/03/14 00:42:24 miod Exp $ */
/* $NetBSD: process_machdep.c,v 1.1 1996/09/30 16:34:53 ws Exp $ */
/*
@@ -37,6 +37,31 @@
#include <sys/ptrace.h>
#include <machine/reg.h>
+int
+process_read_regs(p, regs)
+ struct proc *p;
+ struct reg *regs;
+{
+ struct trapframe *tf = trapframe(p);
+
+ bcopy(&(tf->fixreg[0]), &(regs->gpr[0]), sizeof(regs->gpr));
+ bzero(&(regs->fpr[0]), sizeof(regs->fpr));
+ /*
+ * need to do floating point here
+ */
+ regs->pc = tf->srr0;
+ regs->ps = tf->srr1; /* is this the correct value for this ? */
+ regs->cnd = tf->cr;
+ regs->lr = tf->lr;
+ regs->cnt = tf->ctr;
+ regs->xer = tf->xer;
+ regs->mq = 0; /* what should this really be? */
+
+ return (0);
+}
+
+#ifdef PTRACE
+
/*
* Set the process's program counter.
*/
@@ -64,28 +89,7 @@ process_sstep(p, sstep)
tf->srr1 &= ~PSL_SE;
return 0;
}
-int
-process_read_regs(p, regs)
- struct proc *p;
- struct reg *regs;
-{
- struct trapframe *tf = trapframe(p);
- bcopy(&(tf->fixreg[0]), &(regs->gpr[0]), sizeof(regs->gpr));
- bzero(&(regs->fpr[0]), sizeof(regs->fpr));
- /*
- * need to do floating point here
- */
- regs->pc = tf->srr0;
- regs->ps = tf->srr1; /* is this the correct value for this ? */
- regs->cnd = tf->cr;
- regs->lr = tf->lr;
- regs->cnt = tf->ctr;
- regs->xer = tf->xer;
- regs->mq = 0; /* what should this really be? */
-
- return (0);
-}
int
process_write_regs(p, regs)
struct proc *p;
@@ -107,3 +111,5 @@ process_write_regs(p, regs)
return (0);
}
+
+#endif /* PTRACE */
diff --git a/sys/arch/sparc/sparc/process_machdep.c b/sys/arch/sparc/sparc/process_machdep.c
index f5354856add..9fde6799301 100644
--- a/sys/arch/sparc/sparc/process_machdep.c
+++ b/sys/arch/sparc/sparc/process_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process_machdep.c,v 1.4 2002/02/20 22:28:23 deraadt Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.5 2002/03/14 00:42:24 miod Exp $ */
/* $NetBSD: process_machdep.c,v 1.6 1996/03/14 21:09:26 christos Exp $ */
/*
@@ -74,8 +74,6 @@
#include <machine/frame.h>
#include <sys/ptrace.h>
-u_int32_t process_get_wcookie(struct proc *p);
-
int
process_read_regs(p, regs)
struct proc *p;
@@ -87,6 +85,23 @@ process_read_regs(p, regs)
}
int
+process_read_fpregs(p, regs)
+ struct proc *p;
+ struct fpreg *regs;
+{
+ extern struct fpstate initfpstate;
+ struct fpstate *statep = &initfpstate;
+
+ /* NOTE: struct fpreg == struct fpstate */
+ if (p->p_md.md_fpstate)
+ statep = p->p_md.md_fpstate;
+ bcopy(statep, regs, sizeof(struct fpreg));
+ return 0;
+}
+
+#ifdef PTRACE
+
+int
process_write_regs(p, regs)
struct proc *p;
struct reg *regs;
@@ -118,24 +133,9 @@ process_set_pc(p, addr)
}
int
-process_read_fpregs(p, regs)
-struct proc *p;
-struct fpreg *regs;
-{
- extern struct fpstate initfpstate;
- struct fpstate *statep = &initfpstate;
-
- /* NOTE: struct fpreg == struct fpstate */
- if (p->p_md.md_fpstate)
- statep = p->p_md.md_fpstate;
- bcopy(statep, regs, sizeof(struct fpreg));
- return 0;
-}
-
-int
process_write_fpregs(p, regs)
-struct proc *p;
-struct fpreg *regs;
+ struct proc *p;
+ struct fpreg *regs;
{
if (p->p_md.md_fpstate == NULL)
return EINVAL;
@@ -144,9 +144,4 @@ struct fpreg *regs;
return 0;
}
-u_int32_t
-process_get_wcookie(p)
- struct proc *p;
-{
- return p->p_addr->u_pcb.pcb_wcookie;
-}
+#endif /* PTRACE */
diff --git a/sys/arch/sparc64/sparc64/process_machdep.c b/sys/arch/sparc64/sparc64/process_machdep.c
index adb7b98a089..0efd1c967a9 100644
--- a/sys/arch/sparc64/sparc64/process_machdep.c
+++ b/sys/arch/sparc64/sparc64/process_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process_machdep.c,v 1.2 2001/08/20 20:23:53 jason Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.3 2002/03/14 00:42:24 miod Exp $ */
/* $NetBSD: process_machdep.c,v 1.10 2000/09/26 22:05:50 eeh Exp $ */
/*
@@ -115,6 +115,35 @@ process_read_regs(p, regs)
}
int
+process_read_fpregs(p, regs)
+ struct proc *p;
+ struct fpreg *regs;
+{
+ extern struct fpstate64 initfpstate;
+ struct fpstate64 *statep = &initfpstate;
+ struct fpreg32 *regp = (struct fpreg32 *)regs;
+ int i;
+
+ if (!(curproc->p_flag & P_32)) {
+ /* 64-bit mode -- copy in fregs */
+ /* NOTE: struct fpreg == struct fpstate */
+ if (p->p_md.md_fpstate)
+ statep = p->p_md.md_fpstate;
+ bcopy(statep, regs, sizeof(struct fpreg64));
+ return 0;
+ }
+ /* 32-bit mode -- copy out & convert 32-bit fregs */
+ if (p->p_md.md_fpstate)
+ statep = p->p_md.md_fpstate;
+ for (i=0; i<32; i++)
+ regp->fr_regs[i] = statep->fs_regs[i];
+
+ return 0;
+}
+
+#ifdef PTRACE
+
+int
process_write_regs(p, regs)
struct proc *p;
struct reg *regs;
@@ -174,36 +203,9 @@ process_set_pc(p, addr)
}
int
-process_read_fpregs(p, regs)
-struct proc *p;
-struct fpreg *regs;
-{
- extern struct fpstate64 initfpstate;
- struct fpstate64 *statep = &initfpstate;
- struct fpreg32 *regp = (struct fpreg32 *)regs;
- int i;
-
- if (!(curproc->p_flag & P_32)) {
- /* 64-bit mode -- copy in fregs */
- /* NOTE: struct fpreg == struct fpstate */
- if (p->p_md.md_fpstate)
- statep = p->p_md.md_fpstate;
- bcopy(statep, regs, sizeof(struct fpreg64));
- return 0;
- }
- /* 32-bit mode -- copy out & convert 32-bit fregs */
- if (p->p_md.md_fpstate)
- statep = p->p_md.md_fpstate;
- for (i=0; i<32; i++)
- regp->fr_regs[i] = statep->fs_regs[i];
-
- return 0;
-}
-
-int
process_write_fpregs(p, regs)
-struct proc *p;
-struct fpreg *regs;
+ struct proc *p;
+ struct fpreg *regs;
{
extern struct fpstate64 initfpstate;
@@ -232,3 +234,5 @@ struct fpreg *regs;
return 0;
}
+
+#endif /* PTRACE */
diff --git a/sys/arch/vax/vax/machdep.c b/sys/arch/vax/vax/machdep.c
index 3c5ef44b619..5ba63f36e73 100644
--- a/sys/arch/vax/vax/machdep.c
+++ b/sys/arch/vax/vax/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.53 2002/02/17 22:59:53 maja Exp $ */
+/* $OpenBSD: machdep.c,v 1.54 2002/03/14 00:42:24 miod Exp $ */
/* $NetBSD: machdep.c,v 1.108 2000/09/13 15:00:23 thorpej Exp $ */
/*
@@ -643,6 +643,8 @@ process_read_regs(p, regs)
return 0;
}
+#ifdef PTRACE
+
int
process_write_regs(p, regs)
struct proc *p;
@@ -700,6 +702,8 @@ process_sstep(p, sstep)
return (0);
}
+#endif /* PTRACE */
+
#undef PHYSMEMDEBUG
/*
* Allocates a virtual range suitable for mapping in physical memory.