Source-Changes-HG archive

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

[src/trunk]: src/sys Attach implicit threads to initproc instead of proc0. T...



details:   https://anonhg.NetBSD.org/src/rev/a2f81f5628cb
branches:  trunk
changeset: 758259:a2f81f5628cb
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Oct 29 15:32:23 2010 +0000

description:
Attach implicit threads to initproc instead of proc0.  This way
applications which alter, by purpose or by accident, the uid in an
implicit thread are don't affect kernel threads.

from discussion with njoly

diffstat:

 sys/kern/kern_descrip.c                  |   5 ++---
 sys/rump/librump/rumpkern/lwproc.c       |  16 ++++++++++------
 sys/rump/librump/rumpkern/rump.c         |  22 +++++++++++++++++-----
 sys/rump/librump/rumpkern/rump_private.h |   4 ++--
 sys/rump/librump/rumpkern/scheduler.c    |   6 +++---
 sys/rump/librump/rumpkern/threads.c      |   6 +++---
 6 files changed, 37 insertions(+), 22 deletions(-)

diffs (200 lines):

diff -r 41cf92fd9ac2 -r a2f81f5628cb sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c   Fri Oct 29 15:27:50 2010 +0000
+++ b/sys/kern/kern_descrip.c   Fri Oct 29 15:32:23 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_descrip.c,v 1.206 2010/09/01 15:15:18 pooka Exp $ */
+/*     $NetBSD: kern_descrip.c,v 1.207 2010/10/29 15:32:23 pooka Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.206 2010/09/01 15:15:18 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.207 2010/10/29 15:32:23 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1339,7 +1339,6 @@
 {
        filedesc_t *fdp = l->l_fd;
 
-       KASSERT(fdp == curlwp->l_fd || fdp == lwp0.l_fd);
        atomic_inc_uint(&fdp->fd_refcnt);
 }
 
diff -r 41cf92fd9ac2 -r a2f81f5628cb sys/rump/librump/rumpkern/lwproc.c
--- a/sys/rump/librump/rumpkern/lwproc.c        Fri Oct 29 15:27:50 2010 +0000
+++ b/sys/rump/librump/rumpkern/lwproc.c        Fri Oct 29 15:32:23 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: lwproc.c,v 1.2 2010/09/01 21:16:56 pooka Exp $        */
+/*      $NetBSD: lwproc.c,v 1.3 2010/10/29 15:32:24 pooka Exp $        */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.2 2010/09/01 21:16:56 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.3 2010/10/29 15:32:24 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -222,16 +222,20 @@
 }
 
 struct lwp *
-rump__lwproc_allockernlwp(void)
+rump__lwproc_alloclwp(struct proc *p)
 {
-       struct proc *p;
        struct lwp *l;
+       bool newproc = false;
+
+       if (p == NULL) {
+               p = lwproc_newproc(&proc0);
+               newproc = true;
+       }
 
        l = kmem_zalloc(sizeof(*l), KM_SLEEP);
 
-       p = &proc0;
        mutex_enter(p->p_lock);
-       lwproc_makelwp(p, l, false, false);
+       lwproc_makelwp(p, l, false, newproc);
 
        return l;
 }
diff -r 41cf92fd9ac2 -r a2f81f5628cb sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Fri Oct 29 15:27:50 2010 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Fri Oct 29 15:32:23 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump.c,v 1.192 2010/10/28 11:30:07 pooka Exp $ */
+/*     $NetBSD: rump.c,v 1.193 2010/10/29 15:32:24 pooka Exp $ */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.192 2010/10/28 11:30:07 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.193 2010/10/29 15:32:24 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -86,8 +86,7 @@
 
 char machine[] = MACHINE;
 
-/* pretend the master rump proc is init */
-struct proc *initproc = &proc0;
+struct proc *initproc;
 
 struct rumpuser_mtx *rump_giantlock;
 
@@ -322,9 +321,10 @@
        lwp_initspecific(&lwp0);
 
        rump_scheduler_init(numcpu);
-       /* revert temporary context and schedule a real context */
+       /* revert temporary context and schedule a semireal context */
        l->l_cpu = NULL;
        rumpuser_set_curlwp(NULL);
+       initproc = &proc0; /* borrow proc0 before we get initproc started */
        rump_schedule();
 
        percpu_init();
@@ -407,6 +407,18 @@
        if (rump_threads)
                vmem_rehash_start();
 
+       /*
+        * Create init, used to attach implicit threads in rump.
+        * (note: must be done after vfsinit to get cwdi)
+        */
+       (void)rump__lwproc_alloclwp(NULL); /* dummy thread for initproc */
+       mutex_enter(proc_lock);
+       initproc = proc_find_raw(1);
+       mutex_exit(proc_lock);
+       if (initproc == NULL)
+               panic("where in the world is initproc?");
+
+       /* release cpu */
        rump_unschedule();
 
        return 0;
diff -r 41cf92fd9ac2 -r a2f81f5628cb sys/rump/librump/rumpkern/rump_private.h
--- a/sys/rump/librump/rumpkern/rump_private.h  Fri Oct 29 15:27:50 2010 +0000
+++ b/sys/rump/librump/rumpkern/rump_private.h  Fri Oct 29 15:32:23 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump_private.h,v 1.59 2010/10/27 20:44:49 pooka Exp $  */
+/*     $NetBSD: rump_private.h,v 1.60 2010/10/29 15:32:24 pooka Exp $  */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -105,7 +105,7 @@
 
 extern struct cpu_info *rump_cpu;
 
-struct lwp *   rump__lwproc_allockernlwp(void);
+struct lwp *   rump__lwproc_alloclwp(struct proc *);
 
 void   rump_cpus_bootstrap(int);
 void   rump_scheduler_init(int);
diff -r 41cf92fd9ac2 -r a2f81f5628cb sys/rump/librump/rumpkern/scheduler.c
--- a/sys/rump/librump/rumpkern/scheduler.c     Fri Oct 29 15:27:50 2010 +0000
+++ b/sys/rump/librump/rumpkern/scheduler.c     Fri Oct 29 15:32:23 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: scheduler.c,v 1.20 2010/09/07 07:59:48 pooka Exp $    */
+/*      $NetBSD: scheduler.c,v 1.21 2010/10/29 15:32:24 pooka Exp $    */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.20 2010/09/07 07:59:48 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.21 2010/10/29 15:32:24 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -236,7 +236,7 @@
                rumpuser_set_curlwp(&lwp0);
 
                /* allocate thread, switch to it, and release lwp0 */
-               l = rump__lwproc_allockernlwp();
+               l = rump__lwproc_alloclwp(initproc);
                rump_lwproc_switch(l);
                lwp0rele();
 
diff -r 41cf92fd9ac2 -r a2f81f5628cb sys/rump/librump/rumpkern/threads.c
--- a/sys/rump/librump/rumpkern/threads.c       Fri Oct 29 15:27:50 2010 +0000
+++ b/sys/rump/librump/rumpkern/threads.c       Fri Oct 29 15:32:23 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: threads.c,v 1.12 2010/09/01 19:37:59 pooka Exp $       */
+/*     $NetBSD: threads.c,v 1.13 2010/10/29 15:32:24 pooka Exp $       */
 
 /*
  * Copyright (c) 2007-2009 Antti Kantee.  All Rights Reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.12 2010/09/01 19:37:59 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.13 2010/10/29 15:32:24 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -139,7 +139,7 @@
        k = malloc(sizeof(*k), M_TEMP, M_WAITOK);
        k->f = func;
        k->arg = arg;
-       k->mylwp = l = rump__lwproc_allockernlwp();
+       k->mylwp = l = rump__lwproc_alloclwp(&proc0);
        l->l_flag |= LW_SYSTEM;
        if (flags & KTHREAD_MPSAFE)
                l->l_pflag |= LP_MPSAFE;



Home | Main Index | Thread Index | Old Index