Source-Changes-HG archive

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

[src/trunk]: src/sys Disallow tracing of processes unless tracer's root direc...



details:   https://anonhg.NetBSD.org/src/rev/c90bf11e4a9b
branches:  trunk
changeset: 467488:c90bf11e4a9b
user:      sommerfe <sommerfe%NetBSD.org@localhost>
date:      Thu Mar 25 04:45:56 1999 +0000

description:
Disallow tracing of processes unless tracer's root directory is at or
above tracee's root directory.

diffstat:

 sys/kern/sys_process.c         |  10 +++++++++-
 sys/kern/vfs_getcwd.c          |  25 ++++++++++++++++++++++++-
 sys/miscfs/procfs/procfs_mem.c |  10 +++++++++-
 sys/sys/proc.h                 |   3 ++-
 4 files changed, 44 insertions(+), 4 deletions(-)

diffs (103 lines):

diff -r b8d99e209b56 -r c90bf11e4a9b sys/kern/sys_process.c
--- a/sys/kern/sys_process.c    Thu Mar 25 04:45:37 1999 +0000
+++ b/sys/kern/sys_process.c    Thu Mar 25 04:45:56 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_process.c,v 1.60 1999/03/24 05:51:25 mrg Exp $     */
+/*     $NetBSD: sys_process.c,v 1.61 1999/03/25 04:45:57 sommerfe Exp $        */
 
 /*-
  * Copyright (c) 1994 Christopher G. Demetriou.  All rights reserved.
@@ -142,6 +142,14 @@
                 */
                if (t == initproc && securelevel > -1)
                        return (EPERM);
+
+               /*
+                * (4) the tracer is chrooted, and its root directory is
+                * not at or above the root directory of the tracee
+                */
+
+               if (!proc_isunder(t, p))
+                       return EPERM;
                break;
 
        case  PT_READ_I:
diff -r b8d99e209b56 -r c90bf11e4a9b sys/kern/vfs_getcwd.c
--- a/sys/kern/vfs_getcwd.c     Thu Mar 25 04:45:37 1999 +0000
+++ b/sys/kern/vfs_getcwd.c     Thu Mar 25 04:45:56 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_getcwd.c,v 1.2 1999/03/25 02:32:18 nathanw Exp $ */
+/* $NetBSD: vfs_getcwd.c,v 1.3 1999/03/25 04:45:57 sommerfe Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -453,6 +453,29 @@
                return 0;
 }
 
+/*
+ * Returns true if proc p1's root directory equal to or under p2's
+ * root directory.
+ *
+ * Intended to be used from ptrace/procfs sorts of things.
+ */
+
+int proc_isunder (p1, p2)
+       struct proc *p1;
+       struct proc *p2;
+{
+       struct vnode *r1 = p1->p_fd->fd_rdir;
+       struct vnode *r2 = p2->p_fd->fd_rdir;
+       
+       if (r1 == NULL)
+               return (r2 == NULL);
+       else if (r2 == NULL)
+               return 1;
+       else
+               return vn_isunder(r1, r2, p2);
+}
+
+
 int sys___getcwd(p, v, retval) 
        struct proc *p;
        void   *v;
diff -r b8d99e209b56 -r c90bf11e4a9b sys/miscfs/procfs/procfs_mem.c
--- a/sys/miscfs/procfs/procfs_mem.c    Thu Mar 25 04:45:37 1999 +0000
+++ b/sys/miscfs/procfs/procfs_mem.c    Thu Mar 25 04:45:56 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_mem.c,v 1.22 1999/03/24 05:51:27 mrg Exp $      */
+/*     $NetBSD: procfs_mem.c,v 1.23 1999/03/25 04:45:57 sommerfe Exp $ */
 
 /*
  * Copyright (c) 1993 Jan-Simon Pendry
@@ -156,6 +156,14 @@
        if (t == initproc && securelevel > -1)
                return (EPERM);
 
+       /*
+        * (3) the tracer is chrooted, and its root directory is
+        * not at or above the root directory of the tracee
+        */
+
+       if (!proc_isunder(t, p))
+               return EPERM;
+       
        return (0);
 }
 
diff -r b8d99e209b56 -r c90bf11e4a9b sys/sys/proc.h
--- a/sys/sys/proc.h    Thu Mar 25 04:45:37 1999 +0000
+++ b/sys/sys/proc.h    Thu Mar 25 04:45:56 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proc.h,v 1.73 1999/03/24 05:51:29 mrg Exp $    */
+/*     $NetBSD: proc.h,v 1.74 1999/03/25 04:45:56 sommerfe Exp $       */
 
 /*-
  * Copyright (c) 1986, 1989, 1991, 1993
@@ -352,5 +352,6 @@
 void   cpu_switch __P((struct proc *));
 void   cpu_wait __P((struct proc *));
 void   cpu_exit __P((struct proc *));
+int    proc_isunder __P((struct proc *, struct proc*));
 #endif /* _KERNEL */
 #endif /* !_SYS_PROC_H_ */



Home | Main Index | Thread Index | Old Index