Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys Systrace support.



details:   https://anonhg.NetBSD.org/src/rev/22fc7f642834
branches:  trunk
changeset: 532889:22fc7f642834
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jun 17 16:23:58 2002 +0000

description:
Systrace support.

diffstat:

 sys/sys/conf.h     |    10 +-
 sys/sys/ktrace.h   |     4 +-
 sys/sys/proc.h     |     4 +-
 sys/sys/systm.h    |     8 +-
 sys/sys/systrace.h |   176 ++++++
 sys/sys/tree.h     |  1338 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 1535 insertions(+), 5 deletions(-)

diffs (truncated from 1618 to 300 lines):

diff -r 7249e983fbab -r 22fc7f642834 sys/sys/conf.h
--- a/sys/sys/conf.h    Mon Jun 17 16:22:50 2002 +0000
+++ b/sys/sys/conf.h    Mon Jun 17 16:23:58 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: conf.h,v 1.101 2002/04/23 06:48:46 manu Exp $  */
+/*     $NetBSD: conf.h,v 1.102 2002/06/17 16:23:58 christos Exp $      */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -333,6 +333,12 @@
        dev_init(c,n,write), dev_init(c,n,ioctl), \
        dev_noimpl(stop,enodev), 0, seltrue, dev_init(c,n,mmap) }
 
+/* open, close, read, write, ioctl */
+#define        cdev_systrace_init(c,n) { \
+       dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+       dev_init(c,n,write), dev_init(c,n,ioctl), dev_noimpl(stop,enodev), \
+       0,  dev_noimpl(poll,enodev), dev_noimpl(mmap,enodev) }
+
 /* (open), (close), read, write */
 #define cdev_swap_init(c,n) { \
        dev_noimpl(open,nullop), dev_noimpl(close,nullop), \
@@ -621,6 +627,8 @@
 #endif
 cdev_decl(svr4_net);
 
+cdev_decl(systrace);
+
 cdev_decl(tun);
 
 /*
diff -r 7249e983fbab -r 22fc7f642834 sys/sys/ktrace.h
--- a/sys/sys/ktrace.h  Mon Jun 17 16:22:50 2002 +0000
+++ b/sys/sys/ktrace.h  Mon Jun 17 16:23:58 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ktrace.h,v 1.22 2001/01/05 22:25:27 jdolecek Exp $     */
+/*     $NetBSD: ktrace.h,v 1.23 2002/06/17 16:23:58 christos Exp $     */
 
 /*
  * Copyright (c) 1988, 1993
@@ -189,7 +189,7 @@
 void ktrgenio __P((struct proc *, int, enum uio_rw, struct iovec *, int, int));
 void ktrnamei __P((struct proc *, char *));
 void ktrpsig __P((struct proc *, int, sig_t, sigset_t *, int));
-void ktrsyscall __P((struct proc *, register_t, size_t, register_t []));
+void ktrsyscall __P((struct proc *, register_t, register_t []));
 void ktrsysret __P((struct proc *, register_t, int, register_t));
 void ktruser __P((struct proc *, const char *, void *, size_t, int));
 void ktrderef __P((struct proc *));
diff -r 7249e983fbab -r 22fc7f642834 sys/sys/proc.h
--- a/sys/sys/proc.h    Mon Jun 17 16:22:50 2002 +0000
+++ b/sys/sys/proc.h    Mon Jun 17 16:23:58 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proc.h,v 1.137 2002/04/02 20:20:00 jdolecek Exp $      */
+/*     $NetBSD: proc.h,v 1.138 2002/06/17 16:23:58 christos Exp $      */
 
 /*-
  * Copyright (c) 1986, 1989, 1991, 1993
@@ -200,6 +200,7 @@
 
        int             p_traceflag;    /* Kernel trace points */
        struct file     *p_tracep;      /* Trace to file */
+       void            *p_systrace;    /* Back pointer to systrace */
 
        struct vnode    *p_textvp;      /* Vnode of executable */
 
@@ -296,6 +297,7 @@
 #define        P_32            0x040000 /* 32-bit process (used on 64-bit kernels) */
 #define        P_BIGLOCK       0x080000 /* Process needs kernel "big lock" to run */
 #define        P_INEXEC        0x100000 /* Process is exec'ing and cannot be traced */
+#define        P_SYSTRACE      0x200000 /* Process system call tracing active */
 
 
 /*
diff -r 7249e983fbab -r 22fc7f642834 sys/sys/systm.h
--- a/sys/sys/systm.h   Mon Jun 17 16:22:50 2002 +0000
+++ b/sys/sys/systm.h   Mon Jun 17 16:23:58 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: systm.h,v 1.144 2002/05/21 01:38:26 thorpej Exp $      */
+/*     $NetBSD: systm.h,v 1.145 2002/06/17 16:23:58 christos Exp $     */
 
 /*-
  * Copyright (c) 1982, 1988, 1991, 1993
@@ -312,6 +312,12 @@
 void   exithook_disestablish __P((void *));
 void   doexithooks __P((struct proc *));
 
+/*
+ * kernel syscall tracing/debugging hooks.
+ */
+int    trace_enter __P((struct proc *, register_t, void *, register_t []));
+void   trace_exit __P((struct proc *, register_t, void *, register_t [], int));
+
 int    uiomove __P((void *, int, struct uio *));
 
 #ifdef _KERNEL
diff -r 7249e983fbab -r 22fc7f642834 sys/sys/systrace.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/sys/systrace.h        Mon Jun 17 16:23:58 2002 +0000
@@ -0,0 +1,176 @@
+/*     $NetBSD: systrace.h,v 1.1 2002/06/17 16:23:58 christos Exp $    */
+
+/*
+ * Copyright 2002 Niels Provos <provos%citi.umich.edu@localhost>
+ * All rights reserved.
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Niels Provos.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+#ifndef _SYSTRACE_H_
+#define _SYSTRACE_H_
+
+#include <sys/select.h>
+#include <sys/ioccom.h>
+
+#define        SYSTR_CLONE     _IOR('s', 1, int)
+
+#define SYSTR_EMULEN   8       /* sync with sys proc */
+
+struct str_msg_emul {
+       char emul[SYSTR_EMULEN];
+};
+
+#define SYSTR_MAX_POLICIES     64
+#define SYSTR_MAXARGS          64
+
+struct str_msg_ask {
+       int32_t code;
+       int32_t argsize;
+       register_t args[SYSTR_MAXARGS];
+       register_t rval[2];
+       int32_t result;
+};
+
+/* Queued on fork or exit of a process */
+
+struct str_msg_child {
+       pid_t new_pid;
+};
+
+#define SYSTR_MSG_ASK  1
+#define SYSTR_MSG_RES  2
+#define SYSTR_MSG_EMUL 3
+#define SYSTR_MSG_CHILD        4
+
+#define SYSTR_MSG_NOPROCESS(x) \
+       ((x)->msg.msg_type == SYSTR_MSG_CHILD)
+
+struct str_message {
+       int32_t msg_type;
+       pid_t msg_pid;
+       int16_t msg_policy;
+       int16_t reserved;
+       union {
+               struct str_msg_emul msg_emul;
+               struct str_msg_ask msg_ask;
+               struct str_msg_child msg_child;
+       } msg_data;
+};
+
+struct systrace_answer {
+       pid_t stra_pid;
+       int32_t stra_policy;
+       int32_t stra_error;
+       int32_t stra_flags;
+};
+
+#define SYSTR_READ             1
+#define SYSTR_WRITE            2
+
+struct systrace_io {
+       pid_t strio_pid;
+       int32_t strio_op;
+       void *strio_offs;
+       void *strio_addr;
+       size_t strio_len;
+};
+
+#define SYSTR_POLICY_NEW       1
+#define SYSTR_POLICY_ASSIGN    2
+#define SYSTR_POLICY_MODIFY    3
+
+struct systrace_policy {
+       int32_t strp_op;
+       int32_t strp_num;
+       union {
+               struct {
+                       int16_t code;
+                       int16_t policy;
+               } assign;
+               pid_t pid;
+               int32_t maxents;
+       } strp_data;
+};
+
+#define strp_pid       strp_data.pid
+#define strp_maxents   strp_data.maxents
+#define strp_code      strp_data.assign.code
+#define strp_policy    strp_data.assign.policy
+
+#define STRIOCATTACH   _IOW('s', 101, pid_t)
+#define STRIOCDETACH   _IOW('s', 102, pid_t)
+#define STRIOCANSWER   _IOW('s', 103, struct systrace_answer)
+#define STRIOCIO       _IOWR('s', 104, struct systrace_io)
+#define STRIOCPOLICY   _IOWR('s', 105, struct systrace_policy)
+#define STRIOCGETCWD   _IOW('s', 106, pid_t)
+#define STRIOCRESCWD   _IO('s', 107)
+#define STRIOCREPORT   _IOW('s', 108, pid_t)
+
+#define SYSTR_POLICY_ASK       0
+#define SYSTR_POLICY_PERMIT    1
+#define SYSTR_POLICY_NEVER     2
+
+#define SYSTR_FLAGS_RESULT     0x001
+
+#ifdef _KERNEL
+/* XXX: these shouldn't be here. */
+#define SET(t, f)      ((t) |= (f))
+#define        ISSET(t, f)     ((t) & (f))
+#define        CLR(t, f)       ((t) &= ~(f))
+
+struct str_process;
+struct fsystrace {
+       struct lock lock;
+       struct selinfo si;
+
+       TAILQ_HEAD(strprocessq, str_process) processes;
+       size_t nprocesses;
+
+       TAILQ_HEAD(strpolicyq, str_policy) policies;
+
+       struct strprocessq messages;
+
+       size_t npolicynr;
+       size_t npolicies;
+
+       int issuser;
+
+       /* cwd magic */
+       pid_t fd_pid;
+       struct vnode *fd_cdir;
+       struct vnode *fd_rdir;
+};
+
+/* Internal prototypes */
+
+int systrace_enter(struct proc *, register_t, void *, register_t []);
+void systrace_exit(struct proc *, register_t, void *, register_t [], int);
+void systrace_sys_exit(struct proc *);
+void systrace_sys_fork(struct proc *, struct proc *);
+void systrace_init(void);
+
+#endif /* _KERNEL */
+#endif /* !_SYSTRACE_H_ */
diff -r 7249e983fbab -r 22fc7f642834 sys/sys/tree.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/sys/tree.h    Mon Jun 17 16:23:58 2002 +0000
@@ -0,0 +1,1338 @@
+/*     $NetBSD: tree.h,v 1.1 2002/06/17 16:23:59 christos Exp $        */
+/*     $OpenBSD: tree.h,v 1.4 2002/03/26 02:47:28 hugh Exp $   */
+/*
+ * Copyright 2002 Niels Provos <provos%citi.umich.edu@localhost>
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT



Home | Main Index | Thread Index | Old Index