Source-Changes-HG archive

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

[src/netbsd-1-4]: src/sys/kern Pull up revision 1.69 (via patch, requested by...



details:   https://anonhg.NetBSD.org/src/rev/5041384825a3
branches:  netbsd-1-4
changeset: 470528:5041384825a3
user:      he <he%NetBSD.org@localhost>
date:      Sun Apr 30 12:08:06 2000 +0000

description:
Pull up revision 1.69 (via patch, requested by sommerfeld):
  Fix two bugs:
   o A malicious or erroneous program can hog the CPU in uiomove()
   o A ktrace of such a program can hog large amounts of kernel memory
  This increses the size of struct proc, so kernel-grovellers need
  rebuild after this.

diffstat:

 sys/kern/kern_synch.c |  104 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 103 insertions(+), 1 deletions(-)

diffs (133 lines):

diff -r 12ce8f12b5de -r 5041384825a3 sys/kern/kern_synch.c
--- a/sys/kern/kern_synch.c     Sun Apr 30 12:07:35 2000 +0000
+++ b/sys/kern/kern_synch.c     Sun Apr 30 12:08:06 2000 +0000
@@ -1,4 +1,41 @@
-/*     $NetBSD: kern_synch.c,v 1.57.2.1 1999/10/17 22:29:40 cgd Exp $  */
+/*     $NetBSD: kern_synch.c,v 1.57.2.2 2000/04/30 12:08:06 he Exp $   */
+
+/*-
+ * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * 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 the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
 
 /*-
  * Copyright (c) 1982, 1986, 1990, 1991, 1993
@@ -82,7 +119,21 @@
 roundrobin(arg)
        void *arg;
 {
+       int s;
 
+       if (curproc != NULL) {
+               s = splstatclock();
+               if (curproc->p_schedflags & PSCHED_SEENRR) {
+                       /*
+                        * The process has already been through a roundrobin
+                        * without switching and may be hogging the CPU.
+                        * Indicate that the process should yield.
+                        */
+                       curproc->p_schedflags |= PSCHED_SHOULDYIELD;
+               } else
+                       curproc->p_schedflags |= PSCHED_SEENRR;
+               splx(s);
+       }
        need_resched();
        timeout(roundrobin, NULL, hz / 10);
 }
@@ -569,6 +620,51 @@
 }
 
 /*
+ * General yield call.  Puts the current process back on its run queue and
+ * performs a voluntary context switch.
+ */
+void
+yield()
+{
+       struct proc *p = curproc;
+       int s;
+
+       p->p_priority = p->p_usrpri;
+       s = splstatclock();
+       setrunqueue(p);
+       p->p_stats->p_ru.ru_nvcsw++;
+       mi_switch();
+       splx(s);
+}
+
+/*
+ * General preemption call.  Puts the current process back on its run queue
+ * and performs an involuntary context switch.  If a process is supplied,
+ * we switch to that process.  Otherwise, we use the normal process selection
+ * criteria.
+ */
+void
+preempt(newp)
+       struct proc *newp;
+{
+       struct proc *p = curproc;
+       int s;
+
+       /*
+        * XXX Switching to a specific process is not supported yet.
+        */
+       if (newp != NULL)
+               panic("preempt: cpu_preempt not yet implemented");
+
+       p->p_priority = p->p_usrpri;
+       s = splstatclock(); 
+       setrunqueue(p);
+       p->p_stats->p_ru.ru_nivcsw++;
+       mi_switch();
+       splx(s);
+}
+
+/*
  * The machine independent parts of mi_switch().
  * Must be called at splstatclock() or higher.
  */
@@ -627,6 +723,12 @@
        }
 
        /*
+        * Process is about to yield the CPU; clear the appropriate
+        * scheduling flags.
+        */
+       p->p_schedflags &= ~PSCHED_SWITCHCLEAR;
+
+       /*
         * Pick a new current process and record its start time.
         */
        uvmexp.swtch++;



Home | Main Index | Thread Index | Old Index