CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sat Nov 7 20:43:23 UTC 2015 Modified Files: src/sys/kern [netbsd-5]: kern_exec.c kern_exit.c kern_synch.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #1979): sys/kern/kern_synch.c: revision 1.309 sys/kern/kern_exit.c: revisions 1.246, 1.247 sys/kern/kern_exec.c: revision 1.419 In execve_runproc(), update the p_waited entry for the process being moved to SSTOP state, not for its parent. (It is correct to update the parent's p_nstopchild count.) If the value is not already zero, it could prevent its parent from waiting for the process. Fixes PR kern/50298 -- When clearing out the scheduler queues during system shutdown, we move all processes to the SSTOP state. Make sure we update each process's p_waited and the parents' p_nstopchild counters to maintain consistent values. Should not make any real difference this late in the shutdown process, but we should still be consistent just in case. Fixes PR kern/50318 -- Currently, if a process is exiting and its parent has indicated no intent of reaping the process (nor any other children), the process wil get reparented to init. Since the state of the exiting process at this point is SDEAD, proc_reparent() will not update either the old or new parent's p_nstopchild counters. This change causes both old and new parents to be properly updated. Fixes PR kern/50300 -- For processes marked with PS_STOPEXIT, update the process's p_waited value, and update its parent's p_nstopchild value when marking the process's p_stat to SSTOP. The process needed to be SACTIVE to get here, so this transition represents an additional process for which the parent needs to wait. Fixes PR kern/50308 To generate a diff of this commit: cvs rdiff -u -r1.280.4.3 -r1.280.4.4 src/sys/kern/kern_exec.c cvs rdiff -u -r1.214.4.2 -r1.214.4.3 src/sys/kern/kern_exit.c cvs rdiff -u -r1.254.2.6 -r1.254.2.7 src/sys/kern/kern_synch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_exec.c diff -u src/sys/kern/kern_exec.c:1.280.4.3 src/sys/kern/kern_exec.c:1.280.4.4 --- src/sys/kern/kern_exec.c:1.280.4.3 Wed Apr 1 21:03:04 2009 +++ src/sys/kern/kern_exec.c Sat Nov 7 20:43:23 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exec.c,v 1.280.4.3 2009/04/01 21:03:04 snj Exp $ */ +/* $NetBSD: kern_exec.c,v 1.280.4.4 2015/11/07 20:43:23 snj Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.280.4.3 2009/04/01 21:03:04 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.280.4.4 2015/11/07 20:43:23 snj Exp $"); #include "opt_ktrace.h" #include "opt_syscall_debug.h" @@ -1104,7 +1104,7 @@ execve1(struct lwp *l, const char *path, if (p->p_sflag & PS_STOPEXEC) { KERNEL_UNLOCK_ALL(l, >l_biglocks); p->p_pptr->p_nstopchild++; - p->p_pptr->p_waited = 0; + p->p_waited = 0; mutex_enter(p->p_lock); ksiginfo_queue_init(); sigclearall(p, , ); Index: src/sys/kern/kern_exit.c diff -u src/sys/kern/kern_exit.c:1.214.4.2 src/sys/kern/kern_exit.c:1.214.4.3 --- src/sys/kern/kern_exit.c:1.214.4.2 Wed Jul 1 22:30:30 2009 +++ src/sys/kern/kern_exit.c Sat Nov 7 20:43:23 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exit.c,v 1.214.4.2 2009/07/01 22:30:30 snj Exp $ */ +/* $NetBSD: kern_exit.c,v 1.214.4.3 2015/11/07 20:43:23 snj Exp $ */ /*- * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.214.4.2 2009/07/01 22:30:30 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.214.4.3 2015/11/07 20:43:23 snj Exp $"); #include "opt_ktrace.h" #include "opt_perfctrs.h" @@ -234,8 +234,15 @@ exit1(struct lwp *l, int rv) if (__predict_false(p->p_sflag & PS_STOPEXIT)) { KERNEL_UNLOCK_ALL(l, >l_biglocks); sigclearall(p, , ); + + if (!mutex_tryenter(proc_lock)) { + mutex_exit(p->p_lock); + mutex_enter(proc_lock); + mutex_enter(p->p_lock); + } p->p_waited = 0; - membar_producer(); + p->p_pptr->p_nstopchild++; + mutex_exit(proc_lock); p->p_stat = SSTOP; lwp_lock(l); p->p_nrlwps--; @@ -1011,7 +1018,7 @@ proc_reparent(struct proc *child, struct if (child->p_pptr == parent) return; - if (child->p_stat == SZOMB || + if (child->p_stat == SZOMB || child->p_stat == SDEAD || (child->p_stat == SSTOP && !child->p_waited)) { child->p_pptr->p_nstopchild--; parent->p_nstopchild++; Index: src/sys/kern/kern_synch.c diff -u src/sys/kern/kern_synch.c:1.254.2.6 src/sys/kern/kern_synch.c:1.254.2.7 --- src/sys/kern/kern_synch.c:1.254.2.6 Thu Apr 23 17:47:13 2009 +++ src/sys/kern/kern_synch.c Sat Nov 7 20:43:23 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_synch.c,v 1.254.2.6 2009/04/23 17:47:13 snj Exp $ */ +/* $NetBSD: kern_synch.c,v 1.254.2.7 2015/11/07 20:43:23 snj Exp $
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sat Nov 7 20:45:20 UTC 2015 Modified Files: src/sys/kern [netbsd-5]: kern_sig.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #1980): sys/kern/kern_sig.c: revision 1.321 When delivering a signal, it's possible that the process's state in p_stat is SACTIVE yet p_sflag is PS_STOPPING (while waiting for other lwp's to stop). In that case, we don't want to adjust the parent's p_nstopchild count. Found by Robert Elz. To generate a diff of this commit: cvs rdiff -u -r1.289.4.8 -r1.289.4.9 src/sys/kern/kern_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_sig.c diff -u src/sys/kern/kern_sig.c:1.289.4.8 src/sys/kern/kern_sig.c:1.289.4.9 --- src/sys/kern/kern_sig.c:1.289.4.8 Sat Mar 17 19:14:08 2012 +++ src/sys/kern/kern_sig.c Sat Nov 7 20:45:19 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.289.4.8 2012/03/17 19:14:08 bouyer Exp $ */ +/* $NetBSD: kern_sig.c,v 1.289.4.9 2015/11/07 20:45:19 snj Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.289.4.8 2012/03/17 19:14:08 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.289.4.9 2015/11/07 20:45:19 snj Exp $"); #include "opt_ptrace.h" #include "opt_compat_sunos.h" @@ -1402,14 +1402,13 @@ kpsignal2(struct proc *p, ksiginfo_t *ks } if ((prop & SA_CONT) != 0 || signo == SIGKILL) { /* - * Re-adjust p_nstopchild if the process wasn't - * collected by its parent. + * Re-adjust p_nstopchild if the process was + * stopped but not yet collected by its parent. */ + if (p->p_stat == SSTOP && !p->p_waited) +p->p_pptr->p_nstopchild--; p->p_stat = SACTIVE; p->p_sflag &= ~PS_STOPPING; - if (!p->p_waited) { -p->p_pptr->p_nstopchild--; - } if (p->p_slflag & PSL_TRACED) { KASSERT(signo == SIGKILL); goto deliver;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sat Nov 7 20:50:07 UTC 2015 Modified Files: src/sys/kern [netbsd-5]: kern_exit.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #1981): sys/kern/kern_exit.c: revision 1.248 Update value of p_stat before we release the proc_lock. Thanks to Robert Elz. To generate a diff of this commit: cvs rdiff -u -r1.214.4.3 -r1.214.4.4 src/sys/kern/kern_exit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_exit.c diff -u src/sys/kern/kern_exit.c:1.214.4.3 src/sys/kern/kern_exit.c:1.214.4.4 --- src/sys/kern/kern_exit.c:1.214.4.3 Sat Nov 7 20:43:23 2015 +++ src/sys/kern/kern_exit.c Sat Nov 7 20:50:07 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exit.c,v 1.214.4.3 2015/11/07 20:43:23 snj Exp $ */ +/* $NetBSD: kern_exit.c,v 1.214.4.4 2015/11/07 20:50:07 snj Exp $ */ /*- * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.214.4.3 2015/11/07 20:43:23 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.214.4.4 2015/11/07 20:50:07 snj Exp $"); #include "opt_ktrace.h" #include "opt_perfctrs.h" @@ -242,8 +242,8 @@ exit1(struct lwp *l, int rv) } p->p_waited = 0; p->p_pptr->p_nstopchild++; - mutex_exit(proc_lock); p->p_stat = SSTOP; + mutex_exit(proc_lock); lwp_lock(l); p->p_nrlwps--; l->l_stat = LSSTOP;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: msaitoh Date: Fri Apr 24 05:45:48 UTC 2015 Modified Files: src/sys/kern [netbsd-5]: sys_select.c Log Message: Pull up following revision(s) (requested by prlw1 in ticket #1957): sys/kern/sys_select.c patch Limit nfds arg to poll() to a large enough value that user programs cannot allocate indefinite sized blocks of kvm. If the limit is exceeded, then return EINVAL instead of silently truncating the list. Addresses PR/17507. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.10.4.1 src/sys/kern/sys_select.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_select.c diff -u src/sys/kern/sys_select.c:1.10 src/sys/kern/sys_select.c:1.10.4.1 --- src/sys/kern/sys_select.c:1.10 Wed Oct 15 08:13:17 2008 +++ src/sys/kern/sys_select.c Fri Apr 24 05:45:48 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_select.c,v 1.10 2008/10/15 08:13:17 ad Exp $ */ +/* $NetBSD: sys_select.c,v 1.10.4.1 2015/04/24 05:45:48 msaitoh Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_select.c,v 1.10 2008/10/15 08:13:17 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_select.c,v 1.10.4.1 2015/04/24 05:45:48 msaitoh Exp $); #include sys/param.h #include sys/systm.h @@ -432,9 +432,17 @@ pollcommon(lwp_t *l, register_t *retval, struct timeval sleeptv; selcpu_t *sc; - if (nfds p-p_fd-fd_nfiles) { - /* forgiving; slightly wrong */ - nfds = p-p_fd-fd_nfiles; + if (nfds 1000 + p-p_fd-fd_nfiles) { + /* + * Either the user passed in a very sparse 'fds' or junk! + * The kmem_alloc() call below would be bad news. + * We could process the 'fds' array in chunks, but that + * is a lot of code that isn't normally useful. + * (Or just move the copyin/out into pollscan().) + * Historically the code silently truncated 'fds' to + * dt_nfiles entries - but that does cause issues. + */ + return EINVAL; } ni = nfds * sizeof(struct pollfd); if (ni sizeof(smallbits)) {
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: msaitoh Date: Mon Jul 14 09:08:42 UTC 2014 Modified Files: src/sys/kern [netbsd-5]: sys_module.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1914): sys/kern/sys_module.c: revision 1.15 via patch Fix a user-controlled memory allocation. kmem_alloc(0) will panic the system. ok christos@ To generate a diff of this commit: cvs rdiff -u -r1.8.4.1 -r1.8.4.2 src/sys/kern/sys_module.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_module.c diff -u src/sys/kern/sys_module.c:1.8.4.1 src/sys/kern/sys_module.c:1.8.4.2 --- src/sys/kern/sys_module.c:1.8.4.1 Sun May 3 13:07:39 2009 +++ src/sys/kern/sys_module.c Mon Jul 14 09:08:42 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_module.c,v 1.8.4.1 2009/05/03 13:07:39 bouyer Exp $ */ +/* $NetBSD: sys_module.c,v 1.8.4.2 2014/07/14 09:08:42 msaitoh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_module.c,v 1.8.4.1 2009/05/03 13:07:39 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_module.c,v 1.8.4.2 2014/07/14 09:08:42 msaitoh Exp $); #include sys/param.h #include sys/systm.h @@ -43,6 +43,11 @@ __KERNEL_RCSID(0, $NetBSD: sys_module.c #include sys/syscall.h #include sys/syscallargs.h +/* + * Arbitrary limit to avoid DoS for excessive memory allocation. + */ +#define MAXPROPSLEN 4096 + static int handle_modctl_load(modctl_load_t *ml) { @@ -63,6 +68,11 @@ handle_modctl_load(modctl_load_t *ml) if (error != 0) goto out2; + if (ml-ml_propslen MAXPROPSLEN) { + error = ENOMEM; + goto out2; + } + propslen = ml-ml_propslen + 1; props = (char *)kmem_alloc(propslen, KM_SLEEP); if (props == NULL) {
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: sborrill Date: Fri Dec 13 12:22:39 UTC 2013 Modified Files: src/sys/kern [netbsd-5]: uipc_syscalls.c Log Message: Pull up the following revisions(s) (requested by spz in ticket #1891): sys/kern/uipc_syscalls.c: revision 1.163 If the unix socket is closed before accept, the mbuf returned by m_get() will have an uninitialized length and contain junk from a previous call. Initialize m_len to be 0 to handle this case. Fixes PR/47591 To generate a diff of this commit: cvs rdiff -u -r1.134.4.3 -r1.134.4.4 src/sys/kern/uipc_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_syscalls.c diff -u src/sys/kern/uipc_syscalls.c:1.134.4.3 src/sys/kern/uipc_syscalls.c:1.134.4.4 --- src/sys/kern/uipc_syscalls.c:1.134.4.3 Sun Mar 28 15:32:00 2010 +++ src/sys/kern/uipc_syscalls.c Fri Dec 13 12:22:39 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.134.4.3 2010/03/28 15:32:00 snj Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.134.4.4 2013/12/13 12:22:39 sborrill Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_syscalls.c,v 1.134.4.3 2010/03/28 15:32:00 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_syscalls.c,v 1.134.4.4 2013/12/13 12:22:39 sborrill Exp $); #include opt_pipe.h @@ -182,6 +182,7 @@ do_sys_accept(struct lwp *l, int sock, s return (error); } nam = m_get(M_WAIT, MT_SONAME); + nam-m_len = 0; *new_sock = fd; so = fp-f_data; solock(so);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Wed Jun 19 07:55:44 UTC 2013 Modified Files: src/sys/kern [netbsd-5]: kern_drvctl.c Log Message: Pull up following revision(s) (requested by msaitoh in ticket #1859): sys/kern/kern_drvctl.c: revision 1.34 Fix memory leak on the following cases when device attached or detached: - No one open drvctl. - kmem_alloc() failed in devmon_insert(). To generate a diff of this commit: cvs rdiff -u -r1.19.6.3 -r1.19.6.4 src/sys/kern/kern_drvctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_drvctl.c diff -u src/sys/kern/kern_drvctl.c:1.19.6.3 src/sys/kern/kern_drvctl.c:1.19.6.4 --- src/sys/kern/kern_drvctl.c:1.19.6.3 Sun May 3 22:39:49 2009 +++ src/sys/kern/kern_drvctl.c Wed Jun 19 07:55:44 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_drvctl.c,v 1.19.6.3 2009/05/03 22:39:49 snj Exp $ */ +/* $NetBSD: kern_drvctl.c,v 1.19.6.4 2013/06/19 07:55:44 bouyer Exp $ */ /* * Copyright (c) 2004 @@ -27,7 +27,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_drvctl.c,v 1.19.6.3 2009/05/03 22:39:49 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_drvctl.c,v 1.19.6.4 2013/06/19 07:55:44 bouyer Exp $); #include sys/param.h #include sys/systm.h @@ -112,6 +112,7 @@ devmon_insert(const char *event, prop_di mutex_enter(drvctl_lock); if (drvctl_nopen == 0) { + prop_object_release(ev); mutex_exit(drvctl_lock); return; } @@ -125,6 +126,7 @@ devmon_insert(const char *event, prop_di dce = kmem_alloc(sizeof(*dce), KM_SLEEP); if (dce == NULL) { + prop_object_release(ev); mutex_exit(drvctl_lock); return; }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: riz Date: Tue Nov 6 20:07:34 UTC 2012 Modified Files: src/sys/kern [netbsd-5]: sys_descrip.c Log Message: Pull up following revision(s) (requested by he in ticket #1815): sys/kern/sys_descrip.c: revision 1.11 Fix the posix_fadvise return value... finally. Tested martin on sparc64/m68k and me on hppa. To generate a diff of this commit: cvs rdiff -u -r1.7.4.1 -r1.7.4.2 src/sys/kern/sys_descrip.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_descrip.c diff -u src/sys/kern/sys_descrip.c:1.7.4.1 src/sys/kern/sys_descrip.c:1.7.4.2 --- src/sys/kern/sys_descrip.c:1.7.4.1 Mon Feb 2 02:53:51 2009 +++ src/sys/kern/sys_descrip.c Tue Nov 6 20:07:33 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_descrip.c,v 1.7.4.1 2009/02/02 02:53:51 snj Exp $ */ +/* $NetBSD: sys_descrip.c,v 1.7.4.2 2012/11/06 20:07:33 riz Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_descrip.c,v 1.7.4.1 2009/02/02 02:53:51 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_descrip.c,v 1.7.4.2 2012/11/06 20:07:33 riz Exp $); #include sys/param.h #include sys/systm.h @@ -674,6 +674,8 @@ sys___posix_fadvise50(struct lwp *l, syscallarg(int) advice; } */ - return do_posix_fadvise(SCARG(uap, fd), SCARG(uap, offset), + *retval = do_posix_fadvise(SCARG(uap, fd), SCARG(uap, offset), SCARG(uap, len), SCARG(uap, advice)); + + return 0; }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Wed Aug 22 20:25:57 UTC 2012 Modified Files: src/sys/kern [netbsd-5]: vfs_bio.c Log Message: Pull up following revision(s) (requested by dsl in ticket #1770): sys/kern/vfs_bio.c: revision 1.239 Fix processing of vm.bufmem_lowater and vm.bufmem_hiwater on 64bit systems. Use CTLTYPE_LONG for bufmem_lowater and bufmem_hiwater. Use separate temporaries for the 'int' percentage and the 'long' water marks. Shows up on amd64 now that the sysctl values are marked as 64bit. sparc64 has been badly broken for ages. Fix part of PR kern/46536 To generate a diff of this commit: cvs rdiff -u -r1.210.4.1 -r1.210.4.2 src/sys/kern/vfs_bio.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_bio.c diff -u src/sys/kern/vfs_bio.c:1.210.4.1 src/sys/kern/vfs_bio.c:1.210.4.2 --- src/sys/kern/vfs_bio.c:1.210.4.1 Sun Feb 5 12:30:13 2012 +++ src/sys/kern/vfs_bio.c Wed Aug 22 20:25:57 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_bio.c,v 1.210.4.1 2012/02/05 12:30:13 bouyer Exp $ */ +/* $NetBSD: vfs_bio.c,v 1.210.4.2 2012/08/22 20:25:57 bouyer Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -109,7 +109,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_bio.c,v 1.210.4.1 2012/02/05 12:30:13 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_bio.c,v 1.210.4.2 2012/08/22 20:25:57 bouyer Exp $); #include fs_ffs.h #include opt_bufcache.h @@ -1816,39 +1816,47 @@ sysctl_dobuf(SYSCTLFN_ARGS) static int sysctl_bufvm_update(SYSCTLFN_ARGS) { - int t, error, rv; + int error, rv; struct sysctlnode node; + unsigned int temp_bufcache; + unsigned long temp_water; + /* Take a copy of the supplied node and its data */ node = *rnode; - node.sysctl_data = t; - t = *(int *)rnode-sysctl_data; + if (node.sysctl_data == bufcache) { + node.sysctl_data = temp_bufcache; + temp_bufcache = *(unsigned int *)rnode-sysctl_data; + } else { + node.sysctl_data = temp_water; + temp_water = *(unsigned long *)rnode-sysctl_data; + } + + /* Update the copy */ error = sysctl_lookup(SYSCTLFN_CALL(node)); if (error || newp == NULL) return (error); - if (t 0) - return EINVAL; if (rnode-sysctl_data == bufcache) { - if (t 100) + if (temp_bufcache 100) return (EINVAL); - bufcache = t; + bufcache = temp_bufcache; buf_setwm(); } else if (rnode-sysctl_data == bufmem_lowater) { - if (bufmem_hiwater - t 16) + if (bufmem_hiwater - temp_water 16) return (EINVAL); - bufmem_lowater = t; + bufmem_lowater = temp_water; } else if (rnode-sysctl_data == bufmem_hiwater) { - if (t - bufmem_lowater 16) + if (temp_water - bufmem_lowater 16) return (EINVAL); - bufmem_hiwater = t; + bufmem_hiwater = temp_water; } else return (EINVAL); /* Drain until below new high water mark */ sysctl_unlock(); mutex_enter(bufcache_lock); - while ((t = bufmem - bufmem_hiwater) = 0) { - rv = buf_drain(t / (2 * 1024)); + while (bufmem bufmem_hiwater) { + rv = buf_drain((bufmem - bufmem_hiwater) / (2 * 1024)); if (rv = 0) break; } @@ -1892,21 +1900,21 @@ SYSCTL_SETUP(sysctl_vm_buf_setup, sysct CTL_VM, CTL_CREATE, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT|CTLFLAG_READONLY, - CTLTYPE_INT, bufmem, + CTLTYPE_LONG, bufmem, SYSCTL_DESCR(Amount of kernel memory used by buffer cache), NULL, 0, bufmem, 0, CTL_VM, CTL_CREATE, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT|CTLFLAG_READWRITE, - CTLTYPE_INT, bufmem_lowater, + CTLTYPE_LONG, bufmem_lowater, SYSCTL_DESCR(Minimum amount of kernel memory to reserve for buffer cache), sysctl_bufvm_update, 0, bufmem_lowater, 0, CTL_VM, CTL_CREATE, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT|CTLFLAG_READWRITE, - CTLTYPE_INT, bufmem_hiwater, + CTLTYPE_LONG, bufmem_hiwater, SYSCTL_DESCR(Maximum amount of kernel memory to use for buffer cache), sysctl_bufvm_update, 0, bufmem_hiwater, 0,
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: jdc Date: Sun Jun 3 08:47:28 UTC 2012 Modified Files: src/sys/kern [netbsd-5]: uipc_usrreq.c Log Message: Pull up revision 1.137 (requested by martin in ticket #1766). Stopgap fix for PR kern/46463: disallow passing of kqueue descriptors via SCM_RIGHT anxiliary socket messages. To generate a diff of this commit: cvs rdiff -u -r1.119.4.4 -r1.119.4.5 src/sys/kern/uipc_usrreq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_usrreq.c diff -u src/sys/kern/uipc_usrreq.c:1.119.4.4 src/sys/kern/uipc_usrreq.c:1.119.4.5 --- src/sys/kern/uipc_usrreq.c:1.119.4.4 Sat Jun 18 16:42:04 2011 +++ src/sys/kern/uipc_usrreq.c Sun Jun 3 08:47:28 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.119.4.4 2011/06/18 16:42:04 bouyer Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.119.4.5 2012/06/03 08:47:28 jdc Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_usrreq.c,v 1.119.4.4 2011/06/18 16:42:04 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_usrreq.c,v 1.119.4.5 2012/06/03 08:47:28 jdc Exp $); #include sys/param.h #include sys/systm.h @@ -1356,7 +1356,10 @@ unp_internalize(struct mbuf **controlp) error = EAGAIN; goto out; } - if ((fp = fd_getfile(fd)) == NULL) { + if ((fp = fd_getfile(fd)) == NULL + || fp-f_type == DTYPE_KQUEUE) { + if (fp) + fd_putfile(fd); atomic_dec_uint(unp_rights); nfds = i; error = EBADF;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Mar 17 19:14:10 UTC 2012 Modified Files: src/sys/kern [netbsd-5]: kern_sig.c Log Message: Pull up following revision(s) (requested by christos in ticket #1741): sys/kern/kern_sig.c: revision 1.300 kpsignal2: do not make the signal pending twice when tracing the process, also update a comment and add an assert. Fixes PR/42309 by Nicolas Joly. To generate a diff of this commit: cvs rdiff -u -r1.289.4.7 -r1.289.4.8 src/sys/kern/kern_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_sig.c diff -u src/sys/kern/kern_sig.c:1.289.4.7 src/sys/kern/kern_sig.c:1.289.4.8 --- src/sys/kern/kern_sig.c:1.289.4.7 Sat Feb 4 16:57:58 2012 +++ src/sys/kern/kern_sig.c Sat Mar 17 19:14:08 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.289.4.7 2012/02/04 16:57:58 bouyer Exp $ */ +/* $NetBSD: kern_sig.c,v 1.289.4.8 2012/03/17 19:14:08 bouyer Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_sig.c,v 1.289.4.7 2012/02/04 16:57:58 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_sig.c,v 1.289.4.8 2012/03/17 19:14:08 bouyer Exp $); #include opt_ptrace.h #include opt_compat_sunos.h @@ -1393,15 +1393,13 @@ kpsignal2(struct proc *p, ksiginfo_t *ks goto out; } else { /* - * Process is stopped or stopping. If traced, then no - * further action is necessary. + * Process is stopped or stopping. + * - If traced, then no action is needed, unless killing. + * - Run the process only if sending SIGCONT or SIGKILL. */ - if ((p-p_slflag PSL_TRACED) != 0 signo != SIGKILL) + if ((p-p_slflag PSL_TRACED) != 0 signo != SIGKILL) { goto out; - - /* - * Run the process only if sending SIGCONT or SIGKILL. - */ + } if ((prop SA_CONT) != 0 || signo == SIGKILL) { /* * Re-adjust p_nstopchild if the process wasn't @@ -1409,9 +1407,13 @@ kpsignal2(struct proc *p, ksiginfo_t *ks */ p-p_stat = SACTIVE; p-p_sflag = ~PS_STOPPING; - if (!p-p_waited) + if (!p-p_waited) { p-p_pptr-p_nstopchild--; - + } + if (p-p_slflag PSL_TRACED) { +KASSERT(signo == SIGKILL); +goto deliver; + } /* * Do not make signal pending if SIGCONT is default. * @@ -1434,6 +1436,7 @@ kpsignal2(struct proc *p, ksiginfo_t *ks /* * Make signal pending. */ + KASSERT((p-p_slflag PSL_TRACED) == 0); sigput(p-p_sigpend, p, kp); deliver:
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sun Feb 5 12:28:08 UTC 2012 Modified Files: src/sys/kern [netbsd-5]: kern_fork.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1628): sys/kern/kern_fork.c: revision 1.184 via patch fork1: fix stop-on-fork case, lend a correct lock to LWP for LSSTOP state. Fixes PR/44935. To generate a diff of this commit: cvs rdiff -u -r1.171.4.1 -r1.171.4.2 src/sys/kern/kern_fork.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_fork.c diff -u src/sys/kern/kern_fork.c:1.171.4.1 src/sys/kern/kern_fork.c:1.171.4.2 --- src/sys/kern/kern_fork.c:1.171.4.1 Sat Jun 18 16:35:51 2011 +++ src/sys/kern/kern_fork.c Sun Feb 5 12:28:08 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_fork.c,v 1.171.4.1 2011/06/18 16:35:51 bouyer Exp $ */ +/* $NetBSD: kern_fork.c,v 1.171.4.2 2012/02/05 12:28:08 bouyer Exp $ */ /*- * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_fork.c,v 1.171.4.1 2011/06/18 16:35:51 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_fork.c,v 1.171.4.2 2012/02/05 12:28:08 bouyer Exp $); #include opt_ktrace.h @@ -509,13 +509,15 @@ fork1(struct lwp *l1, int flags, int exi p2-p_acflag = AFORK; lwp_lock(l2); if (p2-p_sflag PS_STOPFORK) { + struct schedstate_percpu *spc = l2-l_cpu-ci_schedstate; p2-p_nrlwps = 0; p2-p_stat = SSTOP; p2-p_waited = 0; p1-p_nstopchild++; l2-l_stat = LSSTOP; l2-l_flag |= tmp; - lwp_unlock(l2); + KASSERT(l2-l_wchan == NULL); + lwp_unlock_to(l2, spc-spc_lwplock); } else { p2-p_nrlwps = 1; p2-p_stat = SACTIVE; @@ -524,7 +526,6 @@ fork1(struct lwp *l1, int flags, int exi sched_enqueue(l2, false); lwp_unlock(l2); } - mutex_exit(p2-p_lock); /*
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sun Feb 5 12:30:13 UTC 2012 Modified Files: src/sys/kern [netbsd-5]: vfs_bio.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1718): sys/kern/vfs_bio.c: revision 1.233 sysctl_dobuf: re-acquire the sysctl lock on retry path. PR/45827. To generate a diff of this commit: cvs rdiff -u -r1.210 -r1.210.4.1 src/sys/kern/vfs_bio.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_bio.c diff -u src/sys/kern/vfs_bio.c:1.210 src/sys/kern/vfs_bio.c:1.210.4.1 --- src/sys/kern/vfs_bio.c:1.210 Thu Sep 11 09:14:46 2008 +++ src/sys/kern/vfs_bio.c Sun Feb 5 12:30:13 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_bio.c,v 1.210 2008/09/11 09:14:46 hannken Exp $ */ +/* $NetBSD: vfs_bio.c,v 1.210.4.1 2012/02/05 12:30:13 bouyer Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -109,7 +109,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_bio.c,v 1.210 2008/09/11 09:14:46 hannken Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_bio.c,v 1.210.4.1 2012/02/05 12:30:13 bouyer Exp $); #include fs_ffs.h #include opt_bufcache.h @@ -1788,6 +1788,7 @@ sysctl_dobuf(SYSCTLFN_ARGS) break; } mutex_exit(bufcache_lock); + sysctl_relock(); goto retry; } dp += elem_size;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: sborrill Date: Sat Nov 19 21:57:13 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: kern_event.c Log Message: Pull up the following revisions(s) (requested by rmind in ticket #1695): sys/kern/kern_event.c: revision 1.74 kqueue_register: avoid calling fd_getfile() with filedesc_t::fd_lock held. Fixes PR/45479 by KOGULE Ryo. To generate a diff of this commit: cvs rdiff -u -r1.60.6.3 -r1.60.6.4 src/sys/kern/kern_event.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_event.c diff -u src/sys/kern/kern_event.c:1.60.6.3 src/sys/kern/kern_event.c:1.60.6.4 --- src/sys/kern/kern_event.c:1.60.6.3 Fri Nov 18 23:17:53 2011 +++ src/sys/kern/kern_event.c Sat Nov 19 21:57:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_event.c,v 1.60.6.3 2011/11/18 23:17:53 sborrill Exp $ */ +/* $NetBSD: kern_event.c,v 1.60.6.4 2011/11/19 21:57:12 sborrill Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_event.c,v 1.60.6.3 2011/11/18 23:17:53 sborrill Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_event.c,v 1.60.6.4 2011/11/19 21:57:12 sborrill Exp $); #include sys/param.h #include sys/systm.h @@ -868,18 +868,16 @@ kqueue_register(struct kqueue *kq, struc return (EINVAL); } - mutex_enter(fdp-fd_lock); - /* search if knote already exists */ if (kfilter-filtops-f_isfd) { /* monitoring a file descriptor */ fd = kev-ident; if ((fp = fd_getfile(fd)) == NULL) { - mutex_exit(fdp-fd_lock); rw_exit(kqueue_filter_lock); kmem_free(newkn, sizeof(*newkn)); return EBADF; } + mutex_enter(fdp-fd_lock); ff = fdp-fd_ofiles[fd]; if (fd = fdp-fd_lastkqfile) { SLIST_FOREACH(kn, ff-ff_knlist, kn_link) { @@ -893,6 +891,7 @@ kqueue_register(struct kqueue *kq, struc * not monitoring a file descriptor, so * lookup knotes in internal hash table */ + mutex_enter(fdp-fd_lock); if (fdp-fd_knhashmask != 0) { list = fdp-fd_knhash[ KN_HASH((u_long)kev-ident, fdp-fd_knhashmask)];
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: sborrill Date: Fri Nov 18 23:17:53 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: kern_event.c Log Message: Pull up the following revisions(s) (requested by christos in ticket #1693): sys/kern/kern_event.c: revision 1.73 PR/45618: Motoyuki OHMORI: kqueue EVFILT_TIMER with smaller timeout value makes DIAGNOSTIC kernel panic. If the computed ticks are = 0 set it to 1. To generate a diff of this commit: cvs rdiff -u -r1.60.6.2 -r1.60.6.3 src/sys/kern/kern_event.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_event.c diff -u src/sys/kern/kern_event.c:1.60.6.2 src/sys/kern/kern_event.c:1.60.6.3 --- src/sys/kern/kern_event.c:1.60.6.2 Sat Jan 9 01:08:39 2010 +++ src/sys/kern/kern_event.c Fri Nov 18 23:17:53 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_event.c,v 1.60.6.2 2010/01/09 01:08:39 snj Exp $ */ +/* $NetBSD: kern_event.c,v 1.60.6.3 2011/11/18 23:17:53 sborrill Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_event.c,v 1.60.6.2 2010/01/09 01:08:39 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_event.c,v 1.60.6.3 2011/11/18 23:17:53 sborrill Exp $); #include sys/param.h #include sys/systm.h @@ -571,6 +571,8 @@ filt_timerexpire(void *knx) knote_activate(kn); if ((kn-kn_flags EV_ONESHOT) == 0) { tticks = mstohz(kn-kn_sdata); + if (tticks = 0) + tticks = 1; callout_schedule((callout_t *)kn-kn_hook, tticks); } mutex_exit(kqueue_misc_lock);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sun Jun 19 20:47:45 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: uipc_domain.c Log Message: Fix fallout from ticket 1633. Patch from plunky@, confirmed by manu@ (ticket author). To generate a diff of this commit: cvs rdiff -u -r1.76.12.1 -r1.76.12.2 src/sys/kern/uipc_domain.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_domain.c diff -u src/sys/kern/uipc_domain.c:1.76.12.1 src/sys/kern/uipc_domain.c:1.76.12.2 --- src/sys/kern/uipc_domain.c:1.76.12.1 Sat Jun 18 16:42:03 2011 +++ src/sys/kern/uipc_domain.c Sun Jun 19 20:47:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_domain.c,v 1.76.12.1 2011/06/18 16:42:03 bouyer Exp $ */ +/* $NetBSD: uipc_domain.c,v 1.76.12.2 2011/06/19 20:47:44 bouyer Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -32,7 +32,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_domain.c,v 1.76.12.1 2011/06/18 16:42:03 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_domain.c,v 1.76.12.2 2011/06/19 20:47:44 bouyer Exp $); #include sys/param.h #include sys/socket.h @@ -496,7 +496,7 @@ SYSCTL_DESCR(SOCK_SEQPACKET settings), NULL, 0, NULL, 0, CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_EOL); - sysctl_createv(domain_sysctllog, 0, NULL, NULL, + sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT, CTLTYPE_NODE, dgram, SYSCTL_DESCR(SOCK_DGRAM settings), @@ -516,7 +516,7 @@ block list), sysctl_unpcblist, 0, NULL, 0, CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_CREATE, CTL_EOL); - sysctl_createv(domain_sysctllog, 0, NULL, NULL, + sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT, CTLTYPE_STRUCT, pcblist, SYSCTL_DESCR(SOCK_DGRAM protocol control block list),
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Jun 18 16:35:51 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: kern_fork.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1629): sys/kern/kern_fork.c: revision 1.181 Inherit proc_t::p_mqueue_cnt on fork(). To generate a diff of this commit: cvs rdiff -u -r1.171 -r1.171.4.1 src/sys/kern/kern_fork.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_fork.c diff -u src/sys/kern/kern_fork.c:1.171 src/sys/kern/kern_fork.c:1.171.4.1 --- src/sys/kern/kern_fork.c:1.171 Sat Oct 11 13:40:57 2008 +++ src/sys/kern/kern_fork.c Sat Jun 18 16:35:51 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_fork.c,v 1.171 2008/10/11 13:40:57 pooka Exp $ */ +/* $NetBSD: kern_fork.c,v 1.171.4.1 2011/06/18 16:35:51 bouyer Exp $ */ /*- * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_fork.c,v 1.171 2008/10/11 13:40:57 pooka Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_fork.c,v 1.171.4.1 2011/06/18 16:35:51 bouyer Exp $); #include opt_ktrace.h @@ -343,6 +343,9 @@ else p2-p_fd = fd_copy(); + /* XXX racy */ + p2-p_mqueue_cnt = p1-p_mqueue_cnt; + if (flags FORK_SHARECWD) cwdshare(p2); else
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Jun 18 16:42:04 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: uipc_domain.c uipc_proto.c uipc_usrreq.c Log Message: Pull up following revision(s) (requested by manu in ticket #1633): sys/kern/uipc_domain.c: revision 1.86 sys/kern/uipc_usrreq.c: revision 1.134 sys/kern/uipc_proto.c: revision 1.22 Add SOCK_SEQPACKET to PL_LOCAL sockets. Based on patch from Jesse Off, submitted 8 years ago: http://mail-index.netbsd.org/tech-kern/2003/04/14/0006.html To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.76.12.1 src/sys/kern/uipc_domain.c cvs rdiff -u -r1.21 -r1.21.12.1 src/sys/kern/uipc_proto.c cvs rdiff -u -r1.119.4.3 -r1.119.4.4 src/sys/kern/uipc_usrreq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_domain.c diff -u src/sys/kern/uipc_domain.c:1.76 src/sys/kern/uipc_domain.c:1.76.12.1 --- src/sys/kern/uipc_domain.c:1.76 Thu Apr 24 11:38:36 2008 +++ src/sys/kern/uipc_domain.c Sat Jun 18 16:42:03 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_domain.c,v 1.76 2008/04/24 11:38:36 ad Exp $ */ +/* $NetBSD: uipc_domain.c,v 1.76.12.1 2011/06/18 16:42:03 bouyer Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -32,7 +32,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_domain.c,v 1.76 2008/04/24 11:38:36 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_domain.c,v 1.76.12.1 2011/06/18 16:42:03 bouyer Exp $); #include sys/param.h #include sys/socket.h @@ -492,6 +492,12 @@ CTL_NET, PF_LOCAL, SOCK_STREAM, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT, + CTLTYPE_NODE, seqpacket, + SYSCTL_DESCR(SOCK_SEQPACKET settings), + NULL, 0, NULL, 0, + CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_EOL); + sysctl_createv(domain_sysctllog, 0, NULL, NULL, + CTLFLAG_PERMANENT, CTLTYPE_NODE, dgram, SYSCTL_DESCR(SOCK_DGRAM settings), NULL, 0, NULL, 0, @@ -506,6 +512,13 @@ sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT, CTLTYPE_STRUCT, pcblist, + SYSCTL_DESCR(SOCK_SEQPACKET protocol control +block list), + sysctl_unpcblist, 0, NULL, 0, + CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_CREATE, CTL_EOL); + sysctl_createv(domain_sysctllog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_STRUCT, pcblist, SYSCTL_DESCR(SOCK_DGRAM protocol control block list), sysctl_unpcblist, 0, NULL, 0, CTL_NET, PF_LOCAL, SOCK_DGRAM, CTL_CREATE, CTL_EOL); Index: src/sys/kern/uipc_proto.c diff -u src/sys/kern/uipc_proto.c:1.21 src/sys/kern/uipc_proto.c:1.21.12.1 --- src/sys/kern/uipc_proto.c:1.21 Thu Apr 24 11:38:36 2008 +++ src/sys/kern/uipc_proto.c Sat Jun 18 16:42:04 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_proto.c,v 1.21 2008/04/24 11:38:36 ad Exp $ */ +/* $NetBSD: uipc_proto.c,v 1.21.12.1 2011/06/18 16:42:04 bouyer Exp $ */ /*- * Copyright (c) 1982, 1986, 1993 @@ -32,7 +32,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_proto.c,v 1.21 2008/04/24 11:38:36 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_proto.c,v 1.21.12.1 2011/06/18 16:42:04 bouyer Exp $); #include sys/param.h #include sys/socket.h @@ -65,6 +65,13 @@ .pr_ctloutput = uipc_ctloutput, .pr_usrreq = uipc_usrreq, }, { + .pr_type = SOCK_SEQPACKET, + .pr_domain = unixdomain, + .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS|PR_LISTEN| + PR_ATOMIC, + .pr_ctloutput = uipc_ctloutput, + .pr_usrreq = uipc_usrreq, + }, { .pr_input = raw_input, .pr_ctlinput = raw_ctlinput, .pr_usrreq = raw_usrreq, Index: src/sys/kern/uipc_usrreq.c diff -u src/sys/kern/uipc_usrreq.c:1.119.4.3 src/sys/kern/uipc_usrreq.c:1.119.4.4 --- src/sys/kern/uipc_usrreq.c:1.119.4.3 Sun Nov 8 21:47:45 2009 +++ src/sys/kern/uipc_usrreq.c Sat Jun 18 16:42:04 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.119.4.3 2009/11/08 21:47:45 snj Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.119.4.4 2011/06/18 16:42:04 bouyer Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_usrreq.c,v 1.119.4.3 2009/11/08 21:47:45 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_usrreq.c,v 1.119.4.4 2011/06/18 16:42:04 bouyer Exp $); #include sys/param.h #include sys/systm.h @@ -124,7 +124,7 @@ * Unix communications domain. * * TODO: - * SEQPACKET, RDM + * RDM * rethink name space problems * need a proper out-of-band * @@ -486,6 +486,7 @@ panic(uipc 1); /*NOTREACHED*/ + case SOCK_SEQPACKET: /* FALLTHROUGH */ case SOCK_STREAM: #define rcv (so-so_rcv) #define snd (so2-so_snd) @@ -566,6 +567,7 @@ break; } + case SOCK_SEQPACKET: /* FALLTHROUGH */ case SOCK_STREAM: #define rcv (so2-so_rcv) #define snd (so-so_snd) @@ -578,7 +580,7 @@
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Fri May 20 19:28:57 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: kern_acct.c Log Message: Pull up following revision(s) (requested by dholland in ticket #1618): sys/kern/kern_acct.c: revision 1.91 Fix up sign-compare issue checking for free space. Should fix PR 43413 where accounting doesn't suspend properly. To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.86.12.1 src/sys/kern/kern_acct.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_acct.c diff -u src/sys/kern/kern_acct.c:1.86 src/sys/kern/kern_acct.c:1.86.12.1 --- src/sys/kern/kern_acct.c:1.86 Thu Apr 24 18:39:23 2008 +++ src/sys/kern/kern_acct.c Fri May 20 19:28:56 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_acct.c,v 1.86 2008/04/24 18:39:23 ad Exp $ */ +/* $NetBSD: kern_acct.c,v 1.86.12.1 2011/05/20 19:28:56 bouyer Exp $ */ /*- * Copyright (c) 1982, 1986, 1989, 1993 @@ -71,7 +71,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_acct.c,v 1.86 2008/04/24 18:39:23 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_acct.c,v 1.86.12.1 2011/05/20 19:28:56 bouyer Exp $); #include sys/param.h #include sys/systm.h @@ -174,7 +174,7 @@ { int error; struct statvfs *sb; - int64_t bavail; + fsblkcnt_t bavail; sb = kmem_alloc(sizeof(*sb), KM_SLEEP); if (sb == NULL) @@ -185,7 +185,11 @@ return (error); } - bavail = sb-f_bfree - sb-f_bresvd; + if (sb-f_bfree sb-f_bresvd) { + bavail = 0; + } else { + bavail = sb-f_bfree - sb-f_bresvd; + } switch (acct_state) { case ACCT_SUSPENDED:
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sun Mar 20 21:19:57 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: vfs_syscalls.c Log Message: Pull up following revision(s) (requested by dholland in ticket #1567): sys/kern/vfs_syscalls.c: revision 1.415 via patch Check for bogus flags to access() up front. Otherwise we end up calling VOP_ACCESS with flags 0 and something asserts deep in the bowels of kauth. PR 44648 from Taylor Campbell. (I moved the check earlier relative to the suggested patch.) Pullup candidate. To generate a diff of this commit: cvs rdiff -u -r1.376.4.5 -r1.376.4.6 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.376.4.5 src/sys/kern/vfs_syscalls.c:1.376.4.6 --- src/sys/kern/vfs_syscalls.c:1.376.4.5 Sun Feb 14 13:27:45 2010 +++ src/sys/kern/vfs_syscalls.c Sun Mar 20 21:19:57 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.376.4.5 2010/02/14 13:27:45 bouyer Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.376.4.6 2011/03/20 21:19:57 bouyer Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_syscalls.c,v 1.376.4.5 2010/02/14 13:27:45 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_syscalls.c,v 1.376.4.6 2011/03/20 21:19:57 bouyer Exp $); #include opt_compat_netbsd.h #include opt_compat_43.h @@ -2390,6 +2390,11 @@ int error, flags; struct nameidata nd; + if ((SCARG(uap, flags) ~(R_OK | W_OK | X_OK)) != 0) { + /* nonsense flags */ + return EINVAL; + } + cred = kauth_cred_dup(l-l_cred); kauth_cred_seteuid(cred, kauth_cred_getuid(l-l_cred)); kauth_cred_setegid(cred, kauth_cred_getgid(l-l_cred));
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Mon Mar 7 17:08:28 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: init_sysctl.c Log Message: Apply patch (requested by joerg in ticket 1575): Sanitize arguments before memory allocation. To generate a diff of this commit: cvs rdiff -u -r1.149.4.7 -r1.149.4.8 src/sys/kern/init_sysctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/init_sysctl.c diff -u src/sys/kern/init_sysctl.c:1.149.4.7 src/sys/kern/init_sysctl.c:1.149.4.8 --- src/sys/kern/init_sysctl.c:1.149.4.7 Wed Jul 1 22:42:28 2009 +++ src/sys/kern/init_sysctl.c Mon Mar 7 17:08:28 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.149.4.7 2009/07/01 22:42:28 snj Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.149.4.8 2011/03/07 17:08:28 snj Exp $ */ /*- * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: init_sysctl.c,v 1.149.4.7 2009/07/01 22:42:28 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: init_sysctl.c,v 1.149.4.8 2011/03/07 17:08:28 snj Exp $); #include opt_sysv.h #include opt_compat_netbsd32.h @@ -2528,6 +2528,11 @@ #endif len = sizeof(char *) * nargv; + if (nargv 0 || len ARG_MAX || len (size_t)nargv) { + error = EINVAL; + goto done; + } + if ((argvlen = len) != 0) argv = kmem_alloc(len, KM_SLEEP);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: riz Date: Mon Mar 7 04:09:28 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: vfs_wapbl.c Log Message: Pull up following revision(s) (requested by bouyer in ticket #1543): sys/kern/vfs_wapbl.c: revision 1.27 sys/kern/vfs_wapbl.c: revision 1.28 Turn a KASSERT into a panic. I don't want us to be randomly overwriting memory on non-DIAGNOSTIC kernels if resource estimation fails. Add dealloccnt to list of things to be considered in the stetson-harrison decision making algorithm for flushing a wapbl transation. To generate a diff of this commit: cvs rdiff -u -r1.3.8.4 -r1.3.8.5 src/sys/kern/vfs_wapbl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_wapbl.c diff -u src/sys/kern/vfs_wapbl.c:1.3.8.4 src/sys/kern/vfs_wapbl.c:1.3.8.5 --- src/sys/kern/vfs_wapbl.c:1.3.8.4 Wed Feb 16 19:31:44 2011 +++ src/sys/kern/vfs_wapbl.c Mon Mar 7 04:09:28 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_wapbl.c,v 1.3.8.4 2011/02/16 19:31:44 bouyer Exp $ */ +/* $NetBSD: vfs_wapbl.c,v 1.3.8.5 2011/03/07 04:09:28 riz Exp $ */ /*- * Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ * This implements file system independent write ahead filesystem logging. */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_wapbl.c,v 1.3.8.4 2011/02/16 19:31:44 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_wapbl.c,v 1.3.8.5 2011/03/07 04:09:28 riz Exp $); #include sys/param.h @@ -829,16 +829,20 @@ wl-wl_bufbytes_max / 2) || ((wl-wl_bufcount + (lockcount * 10)) wl-wl_bufcount_max / 2) || - (wapbl_transaction_len(wl) wl-wl_circ_size / 2); + (wapbl_transaction_len(wl) wl-wl_circ_size / 2) || + (wl-wl_dealloccnt = + (wl-wl_dealloclim - (wl-wl_dealloclim 8))); mutex_exit(wl-wl_mtx); if (doflush) { WAPBL_PRINTF(WAPBL_PRINT_FLUSH, (force flush lockcnt=%d bufbytes=%zu - (max=%zu) bufcount=%zu (max=%zu)\n, + (max=%zu) bufcount=%zu (max=%zu) + dealloccnt %d (lim=%d)\n, lockcount, wl-wl_bufbytes, wl-wl_bufbytes_max, wl-wl_bufcount, - wl-wl_bufcount_max)); + wl-wl_bufcount_max, + wl-wl_dealloccnt, wl-wl_dealloclim)); } if (doflush) { @@ -1720,8 +1724,14 @@ mutex_enter(wl-wl_mtx); /* XXX should eventually instead tie this into resource estimation */ - /* XXX this KASSERT needs locking/mutex analysis */ - KASSERT(wl-wl_dealloccnt wl-wl_dealloclim); + /* + * XXX this panic needs locking/mutex analysis and the + * ability to cope with the failure. + */ + /* XXX this XXX doesn't have enough XXX */ + if (__predict_false(wl-wl_dealloccnt = wl-wl_dealloclim)) + panic(wapbl_register_deallocation: out of resources); + wl-wl_deallocblks[wl-wl_dealloccnt] = blk; wl-wl_dealloclens[wl-wl_dealloccnt] = len; wl-wl_dealloccnt++;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Wed Feb 16 19:31:44 UTC 2011 Modified Files: src/sys/kern [netbsd-5]: vfs_wapbl.c Log Message: Pull up following revision(s) (requested by tron in ticket #1535): sys/kern/vfs_wapbl.c: revision 1.39 via patch Add two sysctls one that does verbose transaction logging and a second one that disables flushing the disk cache (which is fast but dangerous for data integrity). From simon a long while back. To generate a diff of this commit: cvs rdiff -u -r1.3.8.3 -r1.3.8.4 src/sys/kern/vfs_wapbl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_wapbl.c diff -u src/sys/kern/vfs_wapbl.c:1.3.8.3 src/sys/kern/vfs_wapbl.c:1.3.8.4 --- src/sys/kern/vfs_wapbl.c:1.3.8.3 Mon Nov 22 02:52:29 2010 +++ src/sys/kern/vfs_wapbl.c Wed Feb 16 19:31:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_wapbl.c,v 1.3.8.3 2010/11/22 02:52:29 riz Exp $ */ +/* $NetBSD: vfs_wapbl.c,v 1.3.8.4 2011/02/16 19:31:44 bouyer Exp $ */ /*- * Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ * This implements file system independent write ahead filesystem logging. */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_wapbl.c,v 1.3.8.3 2010/11/22 02:52:29 riz Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_wapbl.c,v 1.3.8.4 2011/02/16 19:31:44 bouyer Exp $); #include sys/param.h @@ -41,6 +41,7 @@ #include sys/param.h #include sys/namei.h #include sys/proc.h +#include sys/sysctl.h #include sys/uio.h #include sys/vnode.h #include sys/file.h @@ -65,6 +66,10 @@ #define wapbl_free(a) free((a), M_WAPBL) #define wapbl_calloc(n, s) malloc((n)*(s), M_WAPBL, M_WAITOK | M_ZERO) +static struct sysctllog *wapbl_sysctl; +static int wapbl_flush_disk_cache = 1; +static int wapbl_verbose_commit = 0; + #else /* !_KERNEL */ #include assert.h #include errno.h @@ -245,8 +250,45 @@ void wapbl_init() { + int rv; + const struct sysctlnode *rnode, *cnode; malloc_type_attach(M_WAPBL); + + wapbl_sysctl = NULL; + + rv = sysctl_createv(wapbl_sysctl, 0, NULL, rnode, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, vfs, NULL, + NULL, 0, NULL, 0, + CTL_VFS, CTL_EOL); + if (rv) + return; + + rv = sysctl_createv(wapbl_sysctl, 0, rnode, rnode, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, wapbl, + SYSCTL_DESCR(WAPBL journaling options), + NULL, 0, NULL, 0, + CTL_CREATE, CTL_EOL); + if (rv) + return; + + rv = sysctl_createv(wapbl_sysctl, 0, rnode, cnode, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, flush_disk_cache, + SYSCTL_DESCR(flush disk cache), + NULL, 0, wapbl_flush_disk_cache, 0, + CTL_CREATE, CTL_EOL); + if (rv) + return; + + rv = sysctl_createv(wapbl_sysctl, 0, rnode, cnode, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, verbose_commit, + SYSCTL_DESCR(show time and size of wapbl log commits), + NULL, 0, wapbl_verbose_commit, 0, + CTL_CREATE, CTL_EOL); } int @@ -1322,6 +1364,13 @@ /* Calculate amount of space needed to flush */ flushsize = wapbl_transaction_len(wl); + if (wapbl_verbose_commit) { + struct timespec ts; + getnanotime(ts); + printf(%s: %lld.%06ld this transaction = %zu bytes\n, + __func__, (long long)ts.tv_sec, + (long)ts.tv_nsec, flushsize); + } if (flushsize (wl-wl_circ_size - wl-wl_reserved_bytes)) { /* @@ -1823,12 +1872,15 @@ int error; int force = 1; - /* XXX Calc checksum here, instead we do this for now */ - error = VOP_IOCTL(wl-wl_devvp, DIOCCACHESYNC, force, FWRITE, FSCRED); - if (error) { - WAPBL_PRINTF(WAPBL_PRINT_ERROR, - (wapbl_write_commit: DIOCCACHESYNC on dev 0x%x - returned %d\n, wl-wl_devvp-v_rdev, error)); + if (wapbl_flush_disk_cache) { + /* XXX Calc checksum here, instead we do this for now */ + error = VOP_IOCTL(wl-wl_devvp, DIOCCACHESYNC, force, + FWRITE, FSCRED); + if (error) { + WAPBL_PRINTF(WAPBL_PRINT_ERROR, + (wapbl_write_commit: DIOCCACHESYNC on dev 0x%x + returned %d\n, wl-wl_devvp-v_rdev, error)); + } } wc-wc_head = head; @@ -1853,11 +1905,14 @@ if (error) return error; - error = VOP_IOCTL(wl-wl_devvp, DIOCCACHESYNC, force, FWRITE, FSCRED); - if (error) { - WAPBL_PRINTF(WAPBL_PRINT_ERROR, - (wapbl_write_commit: DIOCCACHESYNC on dev 0x%x - returned %d\n, wl-wl_devvp-v_rdev, error)); + if (wapbl_flush_disk_cache) { + error = VOP_IOCTL(wl-wl_devvp, DIOCCACHESYNC, force, + FWRITE, FSCRED); + if (error) { + WAPBL_PRINTF(WAPBL_PRINT_ERROR, + (wapbl_write_commit: DIOCCACHESYNC on dev 0x%x + returned %d\n, wl-wl_devvp-v_rdev, error)); + } } /*
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: riz Date: Sun Nov 21 17:36:45 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: sys_lwp.c Log Message: Pull up following revision(s) (requested by skrll in ticket #1415): sys/kern/sys_lwp.c: revision 1.50 Follow the correct locking protocol when creating an LWP and the process is stopping. Problem found by running the gdb testsuite (gdb didn't have pthreads support) Thanks to rmind for help with this. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.43.4.1 src/sys/kern/sys_lwp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_lwp.c diff -u src/sys/kern/sys_lwp.c:1.43 src/sys/kern/sys_lwp.c:1.43.4.1 --- src/sys/kern/sys_lwp.c:1.43 Thu Oct 16 08:47:07 2008 +++ src/sys/kern/sys_lwp.c Sun Nov 21 17:36:45 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_lwp.c,v 1.43 2008/10/16 08:47:07 ad Exp $ */ +/* $NetBSD: sys_lwp.c,v 1.43.4.1 2010/11/21 17:36:45 riz Exp $ */ /*- * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_lwp.c,v 1.43 2008/10/16 08:47:07 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_lwp.c,v 1.43.4.1 2010/11/21 17:36:45 riz Exp $); #include sys/param.h #include sys/systm.h @@ -81,6 +81,7 @@ } */ struct proc *p = l-l_proc; struct lwp *l2; + struct schedstate_percpu *spc; vaddr_t uaddr; bool inmem; ucontext_t *newuc; @@ -134,20 +135,23 @@ */ mutex_enter(p-p_lock); lwp_lock(l2); + spc = l2-l_cpu-ci_schedstate; if ((SCARG(uap, flags) LWP_SUSPENDED) == 0 (l-l_flag (LW_WREBOOT | LW_WSUSPEND | LW_WEXIT)) == 0) { - if (p-p_stat == SSTOP || (p-p_sflag PS_STOPPING) != 0) + if (p-p_stat == SSTOP || (p-p_sflag PS_STOPPING) != 0) { + KASSERT(l2-l_wchan == NULL); l2-l_stat = LSSTOP; - else { - KASSERT(lwp_locked(l2, l2-l_cpu-ci_schedstate.spc_mutex)); + lwp_unlock_to(l2, spc-spc_lwplock); + } else { + KASSERT(lwp_locked(l2, spc-spc_mutex)); p-p_nrlwps++; l2-l_stat = LSRUN; sched_enqueue(l2, false); + lwp_unlock(l2); } - lwp_unlock(l2); } else { l2-l_stat = LSSUSPENDED; - lwp_unlock_to(l2, l2-l_cpu-ci_schedstate.spc_lwplock); + lwp_unlock_to(l2, spc-spc_lwplock); } mutex_exit(p-p_lock);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: riz Date: Sun Nov 21 21:48:29 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: subr_disk.c Log Message: Pull up following revision(s) (requested by mrg in ticket #1463): sys/kern/subr_disk.c: revision 1.100 add some (uint64_t) casts so avoid 32 bit overflows. this fixes my 3TB disk with 4KB sectors and disklabel (which looks like it would work upto 16TB.) idea from mlel...@. To generate a diff of this commit: cvs rdiff -u -r1.93.10.1 -r1.93.10.2 src/sys/kern/subr_disk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_disk.c diff -u src/sys/kern/subr_disk.c:1.93.10.1 src/sys/kern/subr_disk.c:1.93.10.2 --- src/sys/kern/subr_disk.c:1.93.10.1 Sat Apr 4 17:49:21 2009 +++ src/sys/kern/subr_disk.c Sun Nov 21 21:48:28 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_disk.c,v 1.93.10.1 2009/04/04 17:49:21 snj Exp $ */ +/* $NetBSD: subr_disk.c,v 1.93.10.2 2010/11/21 21:48:28 riz Exp $ */ /*- * Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: subr_disk.c,v 1.93.10.1 2009/04/04 17:49:21 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: subr_disk.c,v 1.93.10.2 2010/11/21 21:48:28 riz Exp $); #include sys/param.h #include sys/kernel.h @@ -348,8 +348,8 @@ return -1; } - p_size = p-p_size dk-dk_blkshift; - p_offset = p-p_offset dk-dk_blkshift; + p_size = (uint64_t)p-p_size dk-dk_blkshift; + p_offset = (uint64_t)p-p_offset dk-dk_blkshift; #if RAW_PART == 3 labelsector = lp-d_partitions[2].p_offset; #else
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: riz Date: Mon Nov 22 02:52:29 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: vfs_wapbl.c Log Message: Pull up following revision(s) (requested by hannken in ticket #1477): sys/kern/vfs_wapbl.c: revision 1.38 Wapbl_register_deallocation(): the taken reader lock is not sufficient to protect wl_dealloc* members. Take the mutex here and change the lock requirements of these fields to writer lock or mutex. This error lead to file system corruption and freeing free block panics. To generate a diff of this commit: cvs rdiff -u -r1.3.8.2 -r1.3.8.3 src/sys/kern/vfs_wapbl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_wapbl.c diff -u src/sys/kern/vfs_wapbl.c:1.3.8.2 src/sys/kern/vfs_wapbl.c:1.3.8.3 --- src/sys/kern/vfs_wapbl.c:1.3.8.2 Mon Sep 13 19:52:49 2010 +++ src/sys/kern/vfs_wapbl.c Mon Nov 22 02:52:29 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_wapbl.c,v 1.3.8.2 2010/09/13 19:52:49 snj Exp $ */ +/* $NetBSD: vfs_wapbl.c,v 1.3.8.3 2010/11/22 02:52:29 riz Exp $ */ /*- * Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ * This implements file system independent write ahead filesystem logging. */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_wapbl.c,v 1.3.8.2 2010/09/13 19:52:49 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_wapbl.c,v 1.3.8.3 2010/11/22 02:52:29 riz Exp $); #include sys/param.h @@ -95,6 +95,7 @@ * r = read-only after init * l = rwlock held * m = mutex held + * lm = rwlock held writing or mutex held * u = unlocked access ok * b = bufcache_lock held */ @@ -162,9 +163,9 @@ size_t wl_unsynced_bufbytes; /* Byte count of unsynced buffers */ #endif - daddr_t *wl_deallocblks;/* l: address of block */ - int *wl_dealloclens; /* l: size of block (fragments, kom ih�g) */ - int wl_dealloccnt; /* l: total count */ + daddr_t *wl_deallocblks;/* lm: address of block */ + int *wl_dealloclens; /* lm: size of block */ + int wl_dealloccnt; /* lm: total count */ int wl_dealloclim; /* l: max count */ /* hashtable of inode numbers for allocated but unlinked inodes */ @@ -1668,6 +1669,7 @@ wapbl_jlock_assert(wl); + mutex_enter(wl-wl_mtx); /* XXX should eventually instead tie this into resource estimation */ /* XXX this KASSERT needs locking/mutex analysis */ KASSERT(wl-wl_dealloccnt wl-wl_dealloclim); @@ -1676,6 +1678,7 @@ wl-wl_dealloccnt++; WAPBL_PRINTF(WAPBL_PRINT_ALLOC, (wapbl_register_deallocation: blk=%PRId64 len=%d\n, blk, len)); + mutex_exit(wl-wl_mtx); } //
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Mon Sep 13 19:52:49 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: vfs_wapbl.c Log Message: Apply patch (requested by drochner in ticket #1454): Fix inconsistencies in the wapbl replay process which can lead to a premature abort of the fsck run and possibly leave a corrupted filesystem. Addresses PR bin/43336. To generate a diff of this commit: cvs rdiff -u -r1.3.8.1 -r1.3.8.2 src/sys/kern/vfs_wapbl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_wapbl.c diff -u src/sys/kern/vfs_wapbl.c:1.3.8.1 src/sys/kern/vfs_wapbl.c:1.3.8.2 --- src/sys/kern/vfs_wapbl.c:1.3.8.1 Tue Feb 24 04:13:35 2009 +++ src/sys/kern/vfs_wapbl.c Mon Sep 13 19:52:49 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_wapbl.c,v 1.3.8.1 2009/02/24 04:13:35 snj Exp $ */ +/* $NetBSD: vfs_wapbl.c,v 1.3.8.2 2010/09/13 19:52:49 snj Exp $ */ /*- * Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ * This implements file system independent write ahead filesystem logging. */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_wapbl.c,v 1.3.8.1 2009/02/24 04:13:35 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_wapbl.c,v 1.3.8.2 2010/09/13 19:52:49 snj Exp $); #include sys/param.h @@ -2072,7 +2072,7 @@ for (hashsize = 1; hashsize size; hashsize = 1) continue; wr-wr_blkhash = wapbl_malloc(hashsize * sizeof(*wr-wr_blkhash)); - for (i = 0; i wr-wr_blkhashmask; i++) + for (i = 0; i hashsize; i++) LIST_INIT(wr-wr_blkhash[i]); wr-wr_blkhashmask = hashsize - 1; }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Tue Aug 31 10:55:00 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: exec_subr.c kern_pax.c Log Message: Pull up following revision(s) (requested by christos in ticket #1444): sys/kern/kern_pax.c: revision 1.24 sys/kern/exec_subr.c: revision 1.65 Fix issues with stack allocation and pax aslr: - since the size is unsigned, don't check just that it is 0, but limit it to the MAXSSIZ - if the stack size is reduced because of aslr, make sure we reduce the actual allocation by the same size so that the size does not wrap around. NB: Must be pulled up to 5.x! To generate a diff of this commit: cvs rdiff -u -r1.61.8.1 -r1.61.8.2 src/sys/kern/exec_subr.c cvs rdiff -u -r1.22 -r1.22.8.1 src/sys/kern/kern_pax.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/exec_subr.c diff -u src/sys/kern/exec_subr.c:1.61.8.1 src/sys/kern/exec_subr.c:1.61.8.2 --- src/sys/kern/exec_subr.c:1.61.8.1 Wed Apr 1 00:25:22 2009 +++ src/sys/kern/exec_subr.c Tue Aug 31 10:55:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_subr.c,v 1.61.8.1 2009/04/01 00:25:22 snj Exp $ */ +/* $NetBSD: exec_subr.c,v 1.61.8.2 2010/08/31 10:55:00 bouyer Exp $ */ /* * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou @@ -31,7 +31,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: exec_subr.c,v 1.61.8.1 2009/04/01 00:25:22 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: exec_subr.c,v 1.61.8.2 2010/08/31 10:55:00 bouyer Exp $); #include opt_pax.h @@ -386,6 +386,7 @@ epp-ep_minsaddr = USRSTACK; max_stack_size = MAXSSIZ; } + epp-ep_ssize = l-l_proc-p_rlimit[RLIMIT_STACK].rlim_cur; #ifdef PAX_ASLR pax_aslr_stack(l, epp, max_stack_size); @@ -395,7 +396,6 @@ epp-ep_maxsaddr = (u_long)STACK_GROW(epp-ep_minsaddr, max_stack_size); - epp-ep_ssize = l-l_proc-p_rlimit[RLIMIT_STACK].rlim_cur; /* * set up commands for stack. note that this takes *two*, one to @@ -410,11 +410,11 @@ noaccess_size = max_stack_size - access_size; noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp-ep_minsaddr, access_size), noaccess_size); - if (noaccess_size 0) { + if (noaccess_size 0 noaccess_size = MAXSSIZ) { NEW_VMCMD2(epp-ep_vmcmds, vmcmd_map_zero, noaccess_size, noaccess_linear_min, NULL, 0, VM_PROT_NONE, VMCMD_STACK); } - KASSERT(access_size 0); + KASSERT(access_size 0 access_size = MAXSSIZ); NEW_VMCMD2(epp-ep_vmcmds, vmcmd_map_zero, access_size, access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE, VMCMD_STACK); Index: src/sys/kern/kern_pax.c diff -u src/sys/kern/kern_pax.c:1.22 src/sys/kern/kern_pax.c:1.22.8.1 --- src/sys/kern/kern_pax.c:1.22 Wed Jun 4 12:26:20 2008 +++ src/sys/kern/kern_pax.c Tue Aug 31 10:55:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_pax.c,v 1.22 2008/06/04 12:26:20 ad Exp $ */ +/* $NetBSD: kern_pax.c,v 1.22.8.1 2010/08/31 10:55:00 bouyer Exp $ */ /*- * Copyright (c) 2006 Elad Efrat e...@netbsd.org @@ -28,7 +28,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_pax.c,v 1.22 2008/06/04 12:26:20 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_pax.c,v 1.22.8.1 2010/08/31 10:55:00 bouyer Exp $); #include opt_pax.h @@ -353,6 +353,8 @@ #endif epp-ep_minsaddr -= d; *max_stack_size -= d; + if (epp-ep_ssize *max_stack_size) + epp-ep_ssize = *max_stack_size; } } #endif /* PAX_ASLR */
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: riz Date: Sat Jun 12 00:59:57 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: vfs_xattr.c Log Message: Pull up following revision(s) (requested by pooka in ticket #1405): sys/kern/vfs_xattr.c: revision 1.21 via patch Don't namei while holding vnode lock. kern/43328 To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.19.6.1 src/sys/kern/vfs_xattr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_xattr.c diff -u src/sys/kern/vfs_xattr.c:1.19 src/sys/kern/vfs_xattr.c:1.19.6.1 --- src/sys/kern/vfs_xattr.c:1.19 Mon Jun 23 11:30:41 2008 +++ src/sys/kern/vfs_xattr.c Sat Jun 12 00:59:57 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_xattr.c,v 1.19 2008/06/23 11:30:41 ad Exp $ */ +/* $NetBSD: vfs_xattr.c,v 1.19.6.1 2010/06/12 00:59:57 riz Exp $ */ /*- * Copyright (c) 2005, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_xattr.c,v 1.19 2008/06/23 11:30:41 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_xattr.c,v 1.19.6.1 2010/06/12 00:59:57 riz Exp $); #include sys/param.h #include sys/systm.h @@ -149,7 +149,7 @@ syscallarg(int) attrnamespace; syscallarg(const char *) attrname; } */ - struct vnode *vp; + struct vnode *vp, *path_vp; struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; int error; @@ -161,30 +161,32 @@ return (error); } + NDINIT(nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path)); + error = namei(nd); + if (error) { + return (error); + } + path_vp = nd.ni_vp; + vp = NULL; if (SCARG(uap, filename) != NULL) { NDINIT(nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, SCARG(uap, filename)); error = namei(nd); - if (error) + if (error) { + vrele(path_vp); return (error); + } vp = nd.ni_vp; } - NDINIT(nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path)); - error = namei(nd); - if (error) { - if (vp != NULL) - vput(vp); - return (error); - } - - error = VFS_EXTATTRCTL(nd.ni_vp-v_mount, SCARG(uap, cmd), vp, + error = VFS_EXTATTRCTL(path_vp-v_mount, SCARG(uap, cmd), vp, SCARG(uap, attrnamespace), SCARG(uap, attrname) != NULL ? attrname : NULL); if (vp != NULL) vrele(vp); + vrele(path_vp); return (error); }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sun Mar 28 15:32:00 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: uipc_syscalls.c Log Message: Apply patch (requested by jakllsch in ticket #1352): In do_sys_recvmsg(), call free(9) with the same type malloc(9) used. To generate a diff of this commit: cvs rdiff -u -r1.134.4.2 -r1.134.4.3 src/sys/kern/uipc_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_syscalls.c diff -u src/sys/kern/uipc_syscalls.c:1.134.4.2 src/sys/kern/uipc_syscalls.c:1.134.4.3 --- src/sys/kern/uipc_syscalls.c:1.134.4.2 Sat Apr 4 23:36:28 2009 +++ src/sys/kern/uipc_syscalls.c Sun Mar 28 15:32:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.134.4.2 2009/04/04 23:36:28 snj Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.134.4.3 2010/03/28 15:32:00 snj Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_syscalls.c,v 1.134.4.2 2009/04/04 23:36:28 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_syscalls.c,v 1.134.4.3 2010/03/28 15:32:00 snj Exp $); #include opt_pipe.h @@ -858,7 +858,7 @@ } out: if (iov != aiov) - free(iov, M_TEMP); + free(iov, M_IOV); fd_putfile(s); return (error); }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sun Feb 14 13:37:42 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: kern_malloc.c Log Message: Pull up following revision(s) (requested by hubertf in ticket #1292): sys/kern/kern_malloc.c: revision 1.128 Let kernel build when MALLOCLOG is defined but DIAGNOSTIC is not. Else, hitmlog() is defined but not used, which triggers a warning. To generate a diff of this commit: cvs rdiff -u -r1.121 -r1.121.4.1 src/sys/kern/kern_malloc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_malloc.c diff -u src/sys/kern/kern_malloc.c:1.121 src/sys/kern/kern_malloc.c:1.121.4.1 --- src/sys/kern/kern_malloc.c:1.121 Sun Oct 26 12:23:28 2008 +++ src/sys/kern/kern_malloc.c Sun Feb 14 13:37:42 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_malloc.c,v 1.121 2008/10/26 12:23:28 blymn Exp $ */ +/* $NetBSD: kern_malloc.c,v 1.121.4.1 2010/02/14 13:37:42 bouyer Exp $ */ /* * Copyright (c) 1987, 1991, 1993 @@ -66,7 +66,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_malloc.c,v 1.121 2008/10/26 12:23:28 blymn Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_malloc.c,v 1.121.4.1 2010/02/14 13:37:42 bouyer Exp $); #include sys/param.h #include sys/proc.h @@ -215,6 +215,7 @@ malloclogptr = 0; } +#ifdef DIAGNOSTIC static void hitmlog(void *a) { @@ -271,6 +272,7 @@ #undef PRT } +#endif /* DIAGNOSTIC */ #endif /* MALLOCLOG */ #ifdef DIAGNOSTIC
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sat Jan 30 19:53:21 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: sys_aio.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1286): sys/kern/sys_aio.c: revision 1.25 aio_suspend1: fix a double free bug. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.19.8.1 src/sys/kern/sys_aio.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_aio.c diff -u src/sys/kern/sys_aio.c:1.19 src/sys/kern/sys_aio.c:1.19.8.1 --- src/sys/kern/sys_aio.c:1.19 Mon May 26 17:45:51 2008 +++ src/sys/kern/sys_aio.c Sat Jan 30 19:53:21 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_aio.c,v 1.19 2008/05/26 17:45:51 rmind Exp $ */ +/* $NetBSD: sys_aio.c,v 1.19.8.1 2010/01/30 19:53:21 snj Exp $ */ /* * Copyright (c) 2007, Mindaugas Rasiukevicius rmind at NetBSD org @@ -32,7 +32,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_aio.c,v 1.19 2008/05/26 17:45:51 rmind Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_aio.c,v 1.19.8.1 2010/01/30 19:53:21 snj Exp $); #include opt_ddb.h @@ -801,9 +801,6 @@ mutex_enter(aio-aio_mtx); continue; } - -kmem_free(aiocbp_list, -nent * sizeof(struct aio_job)); return error; } }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sat Jan 30 21:19:19 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: sys_aio.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1288): sys/kern/sys_aio.c: revision 1.28 via patch sys_aio_suspend, sys_lio_listio: - fix the buffer sizes. - use kmem_alloc instead of kmem_zalloc for buffers which we will overwrite soon. To generate a diff of this commit: cvs rdiff -u -r1.19.8.2 -r1.19.8.3 src/sys/kern/sys_aio.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_aio.c diff -u src/sys/kern/sys_aio.c:1.19.8.2 src/sys/kern/sys_aio.c:1.19.8.3 --- src/sys/kern/sys_aio.c:1.19.8.2 Sat Jan 30 20:46:20 2010 +++ src/sys/kern/sys_aio.c Sat Jan 30 21:19:19 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_aio.c,v 1.19.8.2 2010/01/30 20:46:20 snj Exp $ */ +/* $NetBSD: sys_aio.c,v 1.19.8.3 2010/01/30 21:19:19 snj Exp $ */ /* * Copyright (c) 2007, Mindaugas Rasiukevicius rmind at NetBSD org @@ -32,7 +32,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_aio.c,v 1.19.8.2 2010/01/30 20:46:20 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_aio.c,v 1.19.8.3 2010/01/30 21:19:19 snj Exp $); #include opt_ddb.h @@ -761,11 +761,11 @@ timo = 0; /* Get the list from user-space */ - aiocbp_list = kmem_zalloc(nent * sizeof(struct aio_job), KM_SLEEP); + aiocbp_list = kmem_alloc(nent * sizeof(*aiocbp_list), KM_SLEEP); error = copyin(SCARG(uap, list), aiocbp_list, - nent * sizeof(struct aiocb)); + nent * sizeof(*aiocbp_list)); if (error) { - kmem_free(aiocbp_list, nent * sizeof(struct aio_job)); + kmem_free(aiocbp_list, nent * sizeof(*aiocbp_list)); return error; } @@ -803,7 +803,7 @@ } kmem_free(aiocbp_list, -nent * sizeof(struct aio_job)); +nent * sizeof(*aiocbp_list)); return error; } } @@ -818,7 +818,7 @@ } mutex_exit(aio-aio_mtx); - kmem_free(aiocbp_list, nent * sizeof(struct aio_job)); + kmem_free(aiocbp_list, nent * sizeof(*aiocbp_list)); return error; } @@ -898,9 +898,9 @@ } /* Get the list from user-space */ - aiocbp_list = kmem_zalloc(nent * sizeof(struct aio_job), KM_SLEEP); + aiocbp_list = kmem_alloc(nent * sizeof(*aiocbp_list), KM_SLEEP); error = copyin(SCARG(uap, list), aiocbp_list, - nent * sizeof(struct aiocb)); + nent * sizeof(*aiocbp_list)); if (error) { mutex_enter(aio-aio_mtx); goto err; @@ -945,7 +945,7 @@ aio_sendsig(p, lio-sig); pool_put(aio_lio_pool, lio); } - kmem_free(aiocbp_list, nent * sizeof(struct aio_job)); + kmem_free(aiocbp_list, nent * sizeof(*aiocbp_list)); return error; }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Jan 16 17:32:52 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: kern_sig.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1238): sys/kern/kern_sig.c: revision 1.302 sigactsunshare(): set reference count in a case of new sigacts allocation. Bug (e.g. memory leak) can happen when using clone(2) call. To generate a diff of this commit: cvs rdiff -u -r1.289.4.5 -r1.289.4.6 src/sys/kern/kern_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_sig.c diff -u src/sys/kern/kern_sig.c:1.289.4.5 src/sys/kern/kern_sig.c:1.289.4.6 --- src/sys/kern/kern_sig.c:1.289.4.5 Wed Apr 1 21:56:50 2009 +++ src/sys/kern/kern_sig.c Sat Jan 16 17:32:52 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.289.4.5 2009/04/01 21:56:50 snj Exp $ */ +/* $NetBSD: kern_sig.c,v 1.289.4.6 2010/01/16 17:32:52 bouyer Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_sig.c,v 1.289.4.5 2009/04/01 21:56:50 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_sig.c,v 1.289.4.6 2010/01/16 17:32:52 bouyer Exp $); #include opt_ptrace.h #include opt_compat_sunos.h @@ -200,24 +200,19 @@ struct sigacts * sigactsinit(struct proc *pp, int share) { - struct sigacts *ps, *ps2; + struct sigacts *ps = pp-p_sigacts, *ps2; - ps = pp-p_sigacts; - - if (share) { + if (__predict_false(share)) { atomic_inc_uint(ps-sa_refcnt); - ps2 = ps; - } else { - ps2 = pool_cache_get(sigacts_cache, PR_WAITOK); - /* XXXAD get rid of this */ - mutex_init(ps2-sa_mutex, MUTEX_DEFAULT, IPL_SCHED); - mutex_enter(ps-sa_mutex); - memcpy(ps2-sa_sigdesc, ps-sa_sigdesc, - sizeof(ps2-sa_sigdesc)); - mutex_exit(ps-sa_mutex); - ps2-sa_refcnt = 1; + return ps; } + ps2 = pool_cache_get(sigacts_cache, PR_WAITOK); + mutex_init(ps2-sa_mutex, MUTEX_DEFAULT, IPL_SCHED); + ps2-sa_refcnt = 1; + mutex_enter(ps-sa_mutex); + memcpy(ps2-sa_sigdesc, ps-sa_sigdesc, sizeof(ps2-sa_sigdesc)); + mutex_exit(ps-sa_mutex); return ps2; } @@ -230,15 +225,16 @@ void sigactsunshare(struct proc *p) { - struct sigacts *ps, *oldps; + struct sigacts *ps, *oldps = p-p_sigacts; - oldps = p-p_sigacts; - if (oldps-sa_refcnt == 1) + if (__predict_true(oldps-sa_refcnt == 1)) return; + ps = pool_cache_get(sigacts_cache, PR_WAITOK); - /* XXXAD get rid of this */ mutex_init(ps-sa_mutex, MUTEX_DEFAULT, IPL_SCHED); - memset(ps-sa_sigdesc, 0, sizeof(ps-sa_sigdesc)); + memset(ps-sa_sigdesc, 0, sizeof(ps-sa_sigdesc)); + ps-sa_refcnt = 1; + p-p_sigacts = ps; sigactsfree(oldps); }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Jan 16 17:39:01 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: kern_runq.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1240): sys/kern/kern_runq.c: revision 1.28 sched_catchlwp: fix the case when other CPU might see curlwp-l_cpu != curcpu() while LWP is finishing context switch. Should fix PR/42539, tested by mar...@. To generate a diff of this commit: cvs rdiff -u -r1.22.4.3 -r1.22.4.4 src/sys/kern/kern_runq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_runq.c diff -u src/sys/kern/kern_runq.c:1.22.4.3 src/sys/kern/kern_runq.c:1.22.4.4 --- src/sys/kern/kern_runq.c:1.22.4.3 Mon Mar 2 19:51:01 2009 +++ src/sys/kern/kern_runq.c Sat Jan 16 17:39:01 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_runq.c,v 1.22.4.3 2009/03/02 19:51:01 snj Exp $ */ +/* $NetBSD: kern_runq.c,v 1.22.4.4 2010/01/16 17:39:01 bouyer Exp $ */ /* * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius rmind at NetBSD org @@ -27,7 +27,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_runq.c,v 1.22.4.3 2009/03/02 19:51:01 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_runq.c,v 1.22.4.4 2010/01/16 17:39:01 bouyer Exp $); #include sys/param.h #include sys/kernel.h @@ -482,6 +482,17 @@ /* Grab the thread, and move to the local run queue */ sched_dequeue(l); + + /* + * If LWP is still context switching, we may need to + * spin-wait before changing its CPU. + */ + if (__predict_false(l-l_ctxswtch != 0)) { + u_int count; + count = SPINLOCK_BACKOFF_MIN; + while (l-l_ctxswtch) +SPINLOCK_BACKOFF(count); + } l-l_cpu = curci; ci_rq-r_ev_pull.ev_count++; lwp_unlock_to(l, curspc-spc_mutex);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Jan 16 17:41:14 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: kern_softint.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1241): sys/kern/kern_softint.c: revision 1.30 softint_execute: release/re-acquire kernel-lock depending on SOFTINT_MPSAFE flag. Keeping it held for MP-safe cases break the lock order assumptions. Per discussion with martin. To generate a diff of this commit: cvs rdiff -u -r1.23.4.2 -r1.23.4.3 src/sys/kern/kern_softint.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_softint.c diff -u src/sys/kern/kern_softint.c:1.23.4.2 src/sys/kern/kern_softint.c:1.23.4.3 --- src/sys/kern/kern_softint.c:1.23.4.2 Mon Feb 2 03:40:11 2009 +++ src/sys/kern/kern_softint.c Sat Jan 16 17:41:14 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_softint.c,v 1.23.4.2 2009/02/02 03:40:11 snj Exp $ */ +/* $NetBSD: kern_softint.c,v 1.23.4.3 2010/01/16 17:41:14 bouyer Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -176,7 +176,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_softint.c,v 1.23.4.2 2009/02/02 03:40:11 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_softint.c,v 1.23.4.3 2010/01/16 17:41:14 bouyer Exp $); #include sys/param.h #include sys/malloc.h @@ -527,7 +527,12 @@ splx(s); /* Run the handler. */ - if ((sh-sh_flags SOFTINT_MPSAFE) == 0 !havelock) { + if (sh-sh_flags SOFTINT_MPSAFE) { + if (havelock) { +KERNEL_UNLOCK_ONE(l); +havelock = false; + } + } else if (!havelock) { KERNEL_LOCK(1, l); havelock = true; }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Mon Jan 11 00:02:09 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: vfs_subr.c Log Message: Pull up following revision(s) (requested by pooka in ticket #1226): sys/kern/vfs_subr.c: revision 1.393 Make sure struct vattr contains no random bits of kernel memory after vattr_null(). This is especially nice considering things like puffs, where the contents are copied to userspace. To generate a diff of this commit: cvs rdiff -u -r1.357.4.8 -r1.357.4.9 src/sys/kern/vfs_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_subr.c diff -u src/sys/kern/vfs_subr.c:1.357.4.8 src/sys/kern/vfs_subr.c:1.357.4.9 --- src/sys/kern/vfs_subr.c:1.357.4.8 Sat Nov 28 18:59:11 2009 +++ src/sys/kern/vfs_subr.c Mon Jan 11 00:02:09 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_subr.c,v 1.357.4.8 2009/11/28 18:59:11 sborrill Exp $ */ +/* $NetBSD: vfs_subr.c,v 1.357.4.9 2010/01/11 00:02:09 snj Exp $ */ /*- * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc. @@ -91,7 +91,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_subr.c,v 1.357.4.8 2009/11/28 18:59:11 sborrill Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_subr.c,v 1.357.4.9 2010/01/11 00:02:09 snj Exp $); #include opt_ddb.h #include opt_compat_netbsd.h @@ -2546,6 +2546,8 @@ vattr_null(struct vattr *vap) { + memset(vap, 0, sizeof(*vap)); + vap-va_type = VNON; /* @@ -2572,7 +2574,6 @@ vap-va_flags = VNOVAL; vap-va_rdev = VNOVAL; vap-va_bytes = VNOVAL; - vap-va_vaflags = 0; } #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sat Jan 9 01:08:39 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: kern_event.c Log Message: Pull up following revision(s) (requested by dsl in ticket #1208): sys/kern/kern_event.c: revision 1.69 Use sizeof correct type, not pointer to wrong type. Fixes PR/42498. This has been wrong since the initial import! To generate a diff of this commit: cvs rdiff -u -r1.60.6.1 -r1.60.6.2 src/sys/kern/kern_event.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_event.c diff -u src/sys/kern/kern_event.c:1.60.6.1 src/sys/kern/kern_event.c:1.60.6.2 --- src/sys/kern/kern_event.c:1.60.6.1 Sat Apr 4 23:36:27 2009 +++ src/sys/kern/kern_event.c Sat Jan 9 01:08:39 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_event.c,v 1.60.6.1 2009/04/04 23:36:27 snj Exp $ */ +/* $NetBSD: kern_event.c,v 1.60.6.2 2010/01/09 01:08:39 snj Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_event.c,v 1.60.6.1 2009/04/04 23:36:27 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_event.c,v 1.60.6.2 2010/01/09 01:08:39 snj Exp $); #include sys/param.h #include sys/systm.h @@ -291,7 +291,7 @@ if (user_kfilterc + 1 user_kfiltermaxc) { /* Grow in KFILTER_EXTENT chunks. */ user_kfiltermaxc += KFILTER_EXTENT; - len = user_kfiltermaxc * sizeof(struct filter *); + len = user_kfiltermaxc * sizeof(*kfilter); kfilter = kmem_alloc(len, KM_SLEEP); memset((char *)kfilter + user_kfiltersz, 0, len - user_kfiltersz); if (user_kfilters != NULL) {
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Thu Jan 7 07:04:51 UTC 2010 Modified Files: src/sys/kern [netbsd-5]: sys_sig.c Log Message: Pull up following revision(s) (requested by rmind in ticket #1199): sys/kern/sys_sig.c: revision 1.24 sigtimedwait: fix a memory leak (which happens since newlock2 times). Allocate ksiginfo on stack since it is safe and sigget() assumes that it is not allocated from pool (pending signals via sigput()/sigget() mill should be dynamically allocated, however). Might be useful to revisit later. Likely the cause of PR/40750 and indirect cause of PR/39283. To generate a diff of this commit: cvs rdiff -u -r1.17.4.2 -r1.17.4.3 src/sys/kern/sys_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_sig.c diff -u src/sys/kern/sys_sig.c:1.17.4.2 src/sys/kern/sys_sig.c:1.17.4.3 --- src/sys/kern/sys_sig.c:1.17.4.2 Wed Apr 1 21:43:53 2009 +++ src/sys/kern/sys_sig.c Thu Jan 7 07:04:50 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_sig.c,v 1.17.4.2 2009/04/01 21:43:53 snj Exp $ */ +/* $NetBSD: sys_sig.c,v 1.17.4.3 2010/01/07 07:04:50 snj Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_sig.c,v 1.17.4.2 2009/04/01 21:43:53 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_sig.c,v 1.17.4.3 2010/01/07 07:04:50 snj Exp $); #include opt_ptrace.h #include opt_compat_netbsd.h @@ -622,7 +622,7 @@ int error, signum; int timo = 0; struct timespec ts, tsstart, tsnow; - ksiginfo_t *ksi; + ksiginfo_t ksi; memset(tsstart, 0, sizeof tsstart); /* XXX gcc */ @@ -660,13 +660,6 @@ */ sigminusset(sigcantmask, l-l_sigwaitset); - /* - * Allocate a ksi up front. We can't sleep with the mutex held. - */ - ksi = ksiginfo_alloc(p, NULL, PR_WAITOK); - if (ksi == NULL) - return (ENOMEM); - mutex_enter(p-p_lock); /* @@ -678,8 +671,8 @@ goto out; } - if ((signum = sigget(p-p_sigpend, ksi, 0, l-l_sigwaitset)) == 0) - signum = sigget(l-l_sigpend, ksi, 0, l-l_sigwaitset); + if ((signum = sigget(p-p_sigpend, ksi, 0, l-l_sigwaitset)) == 0) + signum = sigget(l-l_sigpend, ksi, 0, l-l_sigwaitset); if (signum != 0) { /* @@ -692,7 +685,7 @@ /* * Set up the sigwait list. */ - l-l_sigwaited = ksi; + l-l_sigwaited = ksi; LIST_INSERT_HEAD(p-p_sigwaiters, l, l_sigwaiter); /* @@ -747,10 +740,8 @@ */ out: if (error == 0) - error = (*put_info)(ksi-ksi_info, SCARG(uap, info), - sizeof(ksi-ksi_info)); - - ksiginfo_free(ksi); + error = (*put_info)(ksi.ksi_info, SCARG(uap, info), + sizeof(ksi.ksi_info)); return error; }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Thu Dec 10 23:08:43 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sys_mqueue.c Log Message: Pull up following revision(s) (requested by drochner in ticket #1188): sys/kern/sys_mqueue.c: revision 1.28 via patch fix some security critical bugs: -an invalid signal number passed to mq_notify(2) could crash the kernel on delivery -- add a boundary check -mq_receive(2) from an empty queue crashed the kernel by NULL dereference in timeout calculation -- handle the NULL case -likewise for mq_send(2) to a full queue -a user could set mq_maxmsg (the maximal number of messages in a queue) to a huge value on mq_open(O_CREAT) and later use up all kernel memory by mq_send(2) -- add a sysctl'able limit which defaults to 16*mq_def_maxmsg (mq_notify(2) should get some more checks, and SIGEV_* values other than SIGEV_SIGNAL should be handled somehow, but this doesn't look security critical) To generate a diff of this commit: cvs rdiff -u -r1.12.4.5 -r1.12.4.6 src/sys/kern/sys_mqueue.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_mqueue.c diff -u src/sys/kern/sys_mqueue.c:1.12.4.5 src/sys/kern/sys_mqueue.c:1.12.4.6 --- src/sys/kern/sys_mqueue.c:1.12.4.5 Fri Oct 16 06:37:51 2009 +++ src/sys/kern/sys_mqueue.c Thu Dec 10 23:08:43 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_mqueue.c,v 1.12.4.5 2009/10/16 06:37:51 snj Exp $ */ +/* $NetBSD: sys_mqueue.c,v 1.12.4.6 2009/12/10 23:08:43 snj Exp $ */ /* * Copyright (c) 2007-2009 Mindaugas Rasiukevicius rmind at NetBSD org @@ -42,7 +42,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_mqueue.c,v 1.12.4.5 2009/10/16 06:37:51 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_mqueue.c,v 1.12.4.6 2009/12/10 23:08:43 snj Exp $); #include sys/param.h #include sys/types.h @@ -77,6 +77,7 @@ static u_int mq_max_msgsize = 16 * MQ_DEF_MSGSIZE; static u_int mq_def_maxmsg = 32; +static u_int mq_max_maxmsg = 16 * 32; static kmutex_t mqlist_mtx; static pool_cache_t mqmsg_cache; @@ -331,7 +332,9 @@ kmem_free(name, MQ_NAMELEN); return error; } - if (attr.mq_maxmsg = 0 || attr.mq_msgsize = 0 || + if (attr.mq_maxmsg = 0 || + attr.mq_maxmsg mq_max_maxmsg || + attr.mq_msgsize = 0 || attr.mq_msgsize mq_max_msgsize) { kmem_free(name, MQ_NAMELEN); return EINVAL; @@ -506,10 +509,12 @@ error = EAGAIN; goto error; } - error = abstimeout2timo(ts, t); - if (error) { - goto error; - } + if (ts) { + error = abstimeout2timo(ts, t); + if (error) +goto error; + } else + t = 0; /* * Block until someone sends the message. * While doing this, notification should not be sent. @@ -672,10 +677,12 @@ error = EAGAIN; goto error; } - error = abstimeout2timo(ts, t); - if (error) { - goto error; - } + if (ts) { + error = abstimeout2timo(ts, t); + if (error) +goto error; + } else + t = 0; /* Block until queue becomes available */ error = cv_timedwait_sig(mq-mq_recv_cv, mq-mq_mtx, t); if (error || (mq-mq_attrib.mq_flags MQ_UNLINK)) { @@ -696,7 +703,8 @@ /* Check for the notify */ if (mq-mq_attrib.mq_curmsgs == 0 mq-mq_notify_proc - (mq-mq_attrib.mq_flags MQ_RECEIVE) == 0) { + (mq-mq_attrib.mq_flags MQ_RECEIVE) == 0 + mq-mq_sig_notify.sigev_notify == SIGEV_SIGNAL) { /* Initialize the signal */ KSI_INIT(ksi); ksi.ksi_signo = mq-mq_sig_notify.sigev_signo; @@ -791,6 +799,9 @@ sizeof(struct sigevent)); if (error) return error; + if (sig.sigev_notify == SIGEV_SIGNAL + (sig.sigev_signo =0 || sig.sigev_signo = NSIG)) + return EINVAL; } error = mqueue_get(SCARG(uap, mqdes), fp); @@ -1013,6 +1024,12 @@ SYSCTL_DESCR(Default maximal message count), NULL, 0, mq_def_maxmsg, 0, CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, node, NULL, + CTLFLAG_PERMANENT | CTLFLAG_READWRITE, + CTLTYPE_INT, mq_max_maxmsg, + SYSCTL_DESCR(Maximal allowed message count), + NULL, 0, mq_max_maxmsg, 0, + CTL_CREATE, CTL_EOL); } /*
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Thu Dec 10 23:10:38 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_time.c Log Message: Pull up following revision(s) (requested by drochner in ticket #1189): sys/kern/kern_time.c: revision 1.163 If a struct sigevent with SIGEV_SIGNAL is passed to timer_create(2), check the signal number to be in the allowed range. An invalid signal number could crash the kernel by overflowing the sigset_t array. More checks would be good, and SIGEV_THREAD shouldn't be dropped silently, but this fixes at least the local DOS vulnerability. To generate a diff of this commit: cvs rdiff -u -r1.155.4.2 -r1.155.4.3 src/sys/kern/kern_time.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_time.c diff -u src/sys/kern/kern_time.c:1.155.4.2 src/sys/kern/kern_time.c:1.155.4.3 --- src/sys/kern/kern_time.c:1.155.4.2 Sun Feb 8 20:38:49 2009 +++ src/sys/kern/kern_time.c Thu Dec 10 23:10:38 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_time.c,v 1.155.4.2 2009/02/08 20:38:49 snj Exp $ */ +/* $NetBSD: kern_time.c,v 1.155.4.3 2009/12/10 23:10:38 snj Exp $ */ /*- * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_time.c,v 1.155.4.2 2009/02/08 20:38:49 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_time.c,v 1.155.4.3 2009/12/10 23:10:38 snj Exp $); #include sys/param.h #include sys/resourcevar.h @@ -536,7 +536,10 @@ if (((error = (*fetch_event)(evp, pt-pt_ev, sizeof(pt-pt_ev))) != 0) || ((pt-pt_ev.sigev_notify SIGEV_NONE) || - (pt-pt_ev.sigev_notify SIGEV_SA))) { + (pt-pt_ev.sigev_notify SIGEV_SA)) || + (pt-pt_ev.sigev_notify == SIGEV_SIGNAL + (pt-pt_ev.sigev_signo = 0 || + pt-pt_ev.sigev_signo = NSIG))) { pool_put(ptimer_pool, pt); return (error ? error : EINVAL); }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: sborrill Date: Sat Nov 28 18:59:11 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: vfs_subr.c Log Message: Pull up the following revisions(s) (requested by bouyer in ticket #1171): sys/kern/vfs_subr.c:revision 1.392 Previous caused a deadlock with layered FS: the vrele thread can sleep on the vnode lock, while vget is sleeping on the VI_INACTNOW flag (or the vget caller is looping on vget returning failure because of the VI_INACTNOW flag). With layered FSes, the upper and lower vnodes share the same lock, so the vget() caller above can be already holding the vnode lock. Fix by dropping VI_INACTNOW before sleeping on the vnode lock in vrelel(), and check the ref count again once we have the lock. If the vnode has more than one reference, don't VOP_INACTIVE it. Fix PR kern/42318 and PR kern/42377 To generate a diff of this commit: cvs rdiff -u -r1.357.4.7 -r1.357.4.8 src/sys/kern/vfs_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_subr.c diff -u src/sys/kern/vfs_subr.c:1.357.4.7 src/sys/kern/vfs_subr.c:1.357.4.8 --- src/sys/kern/vfs_subr.c:1.357.4.7 Sat Nov 21 20:07:49 2009 +++ src/sys/kern/vfs_subr.c Sat Nov 28 18:59:11 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_subr.c,v 1.357.4.7 2009/11/21 20:07:49 snj Exp $ */ +/* $NetBSD: vfs_subr.c,v 1.357.4.8 2009/11/28 18:59:11 sborrill Exp $ */ /*- * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc. @@ -91,7 +91,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_subr.c,v 1.357.4.7 2009/11/21 20:07:49 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_subr.c,v 1.357.4.8 2009/11/28 18:59:11 sborrill Exp $); #include opt_ddb.h #include opt_compat_netbsd.h @@ -1411,14 +1411,30 @@ /* The pagedaemon can't wait around; defer. */ defer = true; } else if (curlwp == vrele_lwp) { - /* We have to try harder. */ - vp-v_iflag = ~VI_INACTREDO; + /* + * We have to try harder. But we can't sleep + * with VI_INACTNOW as vget() may be waiting on it. + */ + vp-v_iflag = ~(VI_INACTREDO|VI_INACTNOW); + cv_broadcast(vp-v_cv); error = vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK | LK_RETRY); if (error != 0) { /* XXX */ vpanic(vp, vrele: unable to lock %p); } + mutex_enter(vp-v_interlock); + /* + * if we did get another reference while + * sleeping, don't try to inactivate it yet. + */ + if (__predict_false(vtryrele(vp))) { +VOP_UNLOCK(vp, 0); +mutex_exit(vp-v_interlock); +return; + } + vp-v_iflag |= VI_INACTNOW; + mutex_exit(vp-v_interlock); defer = false; } else if ((vp-v_iflag VI_LAYER) != 0) { /*
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: sborrill Date: Fri Nov 27 09:15:27 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: tty_subr.c Log Message: Pull up the following revisions(s) (requested by dsl in ticket #1141): sys/kern/tty_subr.c:revision 1.38 Fix clrbits() so that it doesn't mask no bits out of the byte after the range (when the last bit to be cleared is the msb of a byte). Fixes PR/42312. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.34.4.1 src/sys/kern/tty_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/tty_subr.c diff -u src/sys/kern/tty_subr.c:1.34 src/sys/kern/tty_subr.c:1.34.4.1 --- src/sys/kern/tty_subr.c:1.34 Wed Jul 16 18:27:49 2008 +++ src/sys/kern/tty_subr.c Fri Nov 27 09:15:27 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: tty_subr.c,v 1.34 2008/07/16 18:27:49 drochner Exp $ */ +/* $NetBSD: tty_subr.c,v 1.34.4.1 2009/11/27 09:15:27 sborrill Exp $ */ /* * Copyright (c) 1993, 1994 Theo de Raadt @@ -29,7 +29,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: tty_subr.c,v 1.34 2008/07/16 18:27:49 drochner Exp $); +__KERNEL_RCSID(0, $NetBSD: tty_subr.c,v 1.34.4.1 2009/11/27 09:15:27 sborrill Exp $); #include sys/param.h #include sys/systm.h @@ -316,10 +316,11 @@ return; } + len--; sby = off / NBBY; sbi = off % NBBY; eby = (off+len) / NBBY; - ebi = (off+len) % NBBY; + ebi = (off+len) % NBBY + 1; if (sby == eby) { mask = ((1 (ebi - sbi)) - 1) sbi; cp[sby] = ~mask;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sat Nov 21 20:07:49 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: vfs_subr.c Log Message: Pull up following revision(s) (requested by bouyer in ticket #1129): sys/kern/vfs_subr.c: revision 1.387 Fix getcleanvnode() in previous: in the if (vp-v_usecount != 0) case we didn't bump the refcount, so don't decrease it through vrelel(). call mutex_exit() on v_interlock directly instead. To generate a diff of this commit: cvs rdiff -u -r1.357.4.6 -r1.357.4.7 src/sys/kern/vfs_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_subr.c diff -u src/sys/kern/vfs_subr.c:1.357.4.6 src/sys/kern/vfs_subr.c:1.357.4.7 --- src/sys/kern/vfs_subr.c:1.357.4.6 Sun Nov 8 22:49:05 2009 +++ src/sys/kern/vfs_subr.c Sat Nov 21 20:07:49 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_subr.c,v 1.357.4.6 2009/11/08 22:49:05 snj Exp $ */ +/* $NetBSD: vfs_subr.c,v 1.357.4.7 2009/11/21 20:07:49 snj Exp $ */ /*- * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc. @@ -91,7 +91,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_subr.c,v 1.357.4.6 2009/11/08 22:49:05 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_subr.c,v 1.357.4.7 2009/11/21 20:07:49 snj Exp $); #include opt_ddb.h #include opt_compat_netbsd.h @@ -376,7 +376,7 @@ * Don't return to freelist - the holder of the last * reference will destroy it. */ - vrelel(vp, 0); /* releases vp-v_interlock */ + mutex_exit(vp-v_interlock); mutex_enter(vnode_free_list_lock); goto retry; }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sun Nov 8 21:47:45 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: uipc_usrreq.c Log Message: Pull up following revision(s) (requested by bouyer in ticket #932): sys/kern/uipc_usrreq.c: revision 1.127 In uipc_usrreq(PRU_ACCEPT), grab the unp_streamlock before unp_setpeerlocks(). This fixes a race where, for a short period of time, so-so_lock and so2-so_lock are not sync. This makes solocked2() and solocked() unreliable and cause DIAGNOSTIC kernel panics. This also fixes a possible panic in unp_setaddr() which expects the socket locked. Should fix kern/38968, fix proposed in http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005863.html To generate a diff of this commit: cvs rdiff -u -r1.119.4.2 -r1.119.4.3 src/sys/kern/uipc_usrreq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_usrreq.c diff -u src/sys/kern/uipc_usrreq.c:1.119.4.2 src/sys/kern/uipc_usrreq.c:1.119.4.3 --- src/sys/kern/uipc_usrreq.c:1.119.4.2 Wed Mar 18 05:33:23 2009 +++ src/sys/kern/uipc_usrreq.c Sun Nov 8 21:47:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.119.4.2 2009/03/18 05:33:23 snj Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.119.4.3 2009/11/08 21:47:45 snj Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_usrreq.c,v 1.119.4.2 2009/03/18 05:33:23 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_usrreq.c,v 1.119.4.3 2009/11/08 21:47:45 snj Exp $); #include sys/param.h #include sys/systm.h @@ -251,6 +251,11 @@ unp-unp_streamlock = NULL; mutex_obj_hold(lock); membar_exit(); + /* + * possible race if lock is not held - see comment in + * uipc_usrreq(PRU_ACCEPT). + */ + KASSERT(mutex_owned(lock)); solockreset(so, lock); solockreset(so2, lock); } @@ -327,6 +332,7 @@ struct unpcb *unp; bool ext; + KASSERT(solocked(so)); unp = sotounpcb(so); ext = false; @@ -443,7 +449,17 @@ * If the connection is fully established, break the * association with uipc_lock and give the connected * pair a seperate lock to share. + * There is a race here: sotounpcb(so2)-unp_streamlock + * is not locked, so when changing so2-so_lock + * another thread can grab it while so-so_lock is still + * pointing to the (locked) uipc_lock. + * this should be harmless, exept that this makes + * solocked2() and solocked() unreliable. + * Another problem is that unp_setaddr() expects the + * the socket locked. Grabing sotounpcb(so2)-unp_streamlock + * fixes both issues. */ + mutex_enter(sotounpcb(so2)-unp_streamlock); unp_setpeerlocks(so2, so); /* * Only now return peer's address, as we may need to @@ -454,6 +470,8 @@ * error == 0 and sun_noname as the peer address. */ unp_setaddr(so, nam, true); + /* so_lock now points to unp_streamlock */ + mutex_exit(so2-so_lock); break; case PRU_SHUTDOWN:
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: sborrill Date: Sun Oct 11 18:03:22 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: tty.c Log Message: Pull up the following revisions(s) (requested by dsl in ticket #1087): sys/kern/tty.c: revision 1.234 Check for zero length read here - and return zero. Without this there is a simple local-user panic in ureadc(). To generate a diff of this commit: cvs rdiff -u -r1.227.4.1 -r1.227.4.2 src/sys/kern/tty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/tty.c diff -u src/sys/kern/tty.c:1.227.4.1 src/sys/kern/tty.c:1.227.4.2 --- src/sys/kern/tty.c:1.227.4.1 Fri Feb 6 02:05:18 2009 +++ src/sys/kern/tty.c Sun Oct 11 18:03:21 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.227.4.1 2009/02/06 02:05:18 snj Exp $ */ +/* $NetBSD: tty.c,v 1.227.4.2 2009/10/11 18:03:21 sborrill Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: tty.c,v 1.227.4.1 2009/02/06 02:05:18 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: tty.c,v 1.227.4.2 2009/10/11 18:03:21 sborrill Exp $); #include sys/param.h #include sys/systm.h @@ -1655,6 +1655,9 @@ long lflag, slp; struct timeval now, stime; + if (uio-uio_resid == 0) + return 0; + stime.tv_usec = 0; /* XXX gcc */ stime.tv_sec = 0; /* XXX gcc */
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Mon Sep 28 01:38:24 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_turnstile.c Log Message: Pull up following revision(s) (requested by bouyer in ticket #1028): sys/kern/kern_turnstile.c: revision 1.25 via patch PR kern/41923: assertion cur != owner failed In the for(;;) loop of turnstile_block(), the lock owner can change while cur's lock is released (cur's lock is also the tschain_t's mutex). Remove the KASSERT about owner being invariant and try to deal with the fact that the owner can change instead. http://mail-index.netbsd.org/tech-kern/2009/08/24/msg005957.html and followups. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.23.4.1 src/sys/kern/kern_turnstile.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_turnstile.c diff -u src/sys/kern/kern_turnstile.c:1.23 src/sys/kern/kern_turnstile.c:1.23.4.1 --- src/sys/kern/kern_turnstile.c:1.23 Tue Aug 12 14:13:34 2008 +++ src/sys/kern/kern_turnstile.c Mon Sep 28 01:38:24 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_turnstile.c,v 1.23 2008/08/12 14:13:34 thorpej Exp $ */ +/* $NetBSD: kern_turnstile.c,v 1.23.4.1 2009/09/28 01:38:24 snj Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_turnstile.c,v 1.23 2008/08/12 14:13:34 thorpej Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_turnstile.c,v 1.23.4.1 2009/09/28 01:38:24 snj Exp $); #include sys/param.h #include sys/lockdebug.h @@ -253,6 +253,7 @@ sq = ts-ts_sleepq[q]; ts-ts_waiters[q]++; sleepq_enter(sq, l, tc-tc_mutex); + /* now tc-tc_mutex is also cur-l_mutex and l-l_mutex */ LOCKDEBUG_BARRIER(tc-tc_mutex, 1); l-l_kpriority = true; obase = l-l_kpribase; @@ -275,6 +276,7 @@ * compiling a kernel with LOCKDEBUG to pinpoint the problem. */ prio = lwp_eprio(l); + for (;;) { bool dolock; @@ -285,9 +287,24 @@ if (owner == NULL) break; - KASSERT(l != owner); - KASSERT(cur != owner); + /* The owner may have changed as we have dropped the tc lock */ + if (cur == owner) { + /* + * we own the lock: stop here, sleepq_block() + * should wake up immediatly + */ + break; + } + if (l == owner) { + /* owner has changed, restart from curlwp */ + lwp_unlock(l); + l = cur; + lwp_lock(l); + prio = lwp_eprio(l); + continue; + } + if (l-l_mutex != owner-l_mutex) dolock = true; else @@ -295,6 +312,10 @@ if (dolock !lwp_trylock(owner)) { /* * restart from curlwp. + * Note that there may be a livelock here: + * the owner may try grabing cur's lock (which is + * the tc lock) while we're trying to grab + * the owner's lock. */ lwp_unlock(l); l = cur;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Sep 5 11:37:21 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_ktrace.c Log Message: Pull up following revision(s) (requested by dsl in ticket #901): sys/kern/kern_ktrace.c: revision 1.149 Fix ktrace of data from iovec based system calls. Fixes PR/41819 To generate a diff of this commit: cvs rdiff -u -r1.147 -r1.147.4.1 src/sys/kern/kern_ktrace.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_ktrace.c diff -u src/sys/kern/kern_ktrace.c:1.147 src/sys/kern/kern_ktrace.c:1.147.4.1 --- src/sys/kern/kern_ktrace.c:1.147 Wed Oct 15 06:51:20 2008 +++ src/sys/kern/kern_ktrace.c Sat Sep 5 11:37:21 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ktrace.c,v 1.147 2008/10/15 06:51:20 wrstuden Exp $ */ +/* $NetBSD: kern_ktrace.c,v 1.147.4.1 2009/09/05 11:37:21 bouyer Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_ktrace.c,v 1.147 2008/10/15 06:51:20 wrstuden Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_ktrace.c,v 1.147.4.1 2009/09/05 11:37:21 bouyer Exp $); #include sys/param.h #include sys/systm.h @@ -664,7 +664,7 @@ struct ktrace_entry *kte; struct ktr_genio *ktp; size_t resid = len, cnt, buflen; - void *cp; + char *cp; next: buflen = min(PAGE_SIZE, resid + sizeof(struct ktr_genio)); @@ -684,6 +684,7 @@ if (copyin(iov-iov_base, cp, cnt) != 0) goto out; kte-kte_kth.ktr_len += cnt; + cp += cnt; buflen -= cnt; resid -= cnt; iov-iov_len -= cnt;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Sep 5 13:04:26 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: subr_tftproot.c Log Message: Pull up following revision(s) (requested by manu in ticket #929): sys/kern/subr_tftproot.c: revisions 1.9, 1.10 When netbooting, rootspec is now md0a, and it has no chance to match an interface name, so do not give it a try. Back out previous change: do not skip the test on rootspec, but make it a simple attempt instead of an authoritative answer. The failure of the rootspec test could me machine-dependant. Thanks to martin@ for pointing that out. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.5.12.1 src/sys/kern/subr_tftproot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_tftproot.c diff -u src/sys/kern/subr_tftproot.c:1.5 src/sys/kern/subr_tftproot.c:1.5.12.1 --- src/sys/kern/subr_tftproot.c:1.5 Thu Apr 24 11:38:36 2008 +++ src/sys/kern/subr_tftproot.c Sat Sep 5 13:04:26 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_tftproot.c,v 1.5 2008/04/24 11:38:36 ad Exp $ */ +/* $NetBSD: subr_tftproot.c,v 1.5.12.1 2009/09/05 13:04:26 bouyer Exp $ */ /*- * Copyright (c) 2007 Emmanuel Dreyfus, all rights reserved. @@ -39,7 +39,7 @@ #include opt_md.h #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: subr_tftproot.c,v 1.5 2008/04/24 11:38:36 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: subr_tftproot.c,v 1.5.12.1 2009/09/05 13:04:26 bouyer Exp $); #include sys/param.h #include sys/types.h @@ -134,7 +134,10 @@ IFNET_FOREACH(ifp) if (strcmp(rootspec, ifp-if_xname) == 0) break; - } else if ((bootdv != NULL device_class(bootdv) == DV_IFNET)) { + } + + if ((ifp == NULL) + (bootdv != NULL device_class(bootdv) == DV_IFNET)) { IFNET_FOREACH(ifp) if (strcmp(device_xname(bootdv), ifp-if_xname) == 0) break;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Fri Aug 14 21:15:16 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_resource.c Log Message: Pull up following revision(s) (requested by dsl in ticket #893): sys/kern/kern_resource.c: revision 1.152 PR/41489: Stathis Kamperis: setpriority(2) returns EACCES instead of EPERM Per discussion on the PR's audit trail, put back original checks for now. To generate a diff of this commit: cvs rdiff -u -r1.147.4.1 -r1.147.4.2 src/sys/kern/kern_resource.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_resource.c diff -u src/sys/kern/kern_resource.c:1.147.4.1 src/sys/kern/kern_resource.c:1.147.4.2 --- src/sys/kern/kern_resource.c:1.147.4.1 Wed Apr 1 00:25:22 2009 +++ src/sys/kern/kern_resource.c Fri Aug 14 21:15:16 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_resource.c,v 1.147.4.1 2009/04/01 00:25:22 snj Exp $ */ +/* $NetBSD: kern_resource.c,v 1.147.4.2 2009/08/14 21:15:16 snj Exp $ */ /*- * Copyright (c) 1982, 1986, 1991, 1993 @@ -37,7 +37,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_resource.c,v 1.147.4.1 2009/04/01 00:25:22 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_resource.c,v 1.147.4.2 2009/08/14 21:15:16 snj Exp $); #include sys/param.h #include sys/systm.h @@ -229,6 +229,11 @@ KASSERT(mutex_owned(chgp-p_lock)); + if (kauth_cred_geteuid(cred) kauth_cred_getuid(cred) + kauth_cred_geteuid(cred) != kauth_cred_geteuid(chgp-p_cred) + kauth_cred_getuid(cred) != kauth_cred_geteuid(chgp-p_cred)) + return (EPERM); + if (n PRIO_MAX) n = PRIO_MAX; if (n PRIO_MIN)
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Tue Jul 21 00:23:01 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sys_mqueue.c Log Message: Pull up following revision(s) (requested by rmind in ticket #857): sys/kern/sys_mqueue.c: revision 1.21 via patch mq_send/mq_receive: while permission may allow that, return EBADF if sending to read-only queue, or receiving from write-only queue. From Stathis Kamperis, thanks! To generate a diff of this commit: cvs rdiff -u -r1.12.4.3 -r1.12.4.4 src/sys/kern/sys_mqueue.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_mqueue.c diff -u src/sys/kern/sys_mqueue.c:1.12.4.3 src/sys/kern/sys_mqueue.c:1.12.4.4 --- src/sys/kern/sys_mqueue.c:1.12.4.3 Wed May 27 21:32:05 2009 +++ src/sys/kern/sys_mqueue.c Tue Jul 21 00:23:01 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_mqueue.c,v 1.12.4.3 2009/05/27 21:32:05 snj Exp $ */ +/* $NetBSD: sys_mqueue.c,v 1.12.4.4 2009/07/21 00:23:01 snj Exp $ */ /* * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius rmind at NetBSD org @@ -42,7 +42,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_mqueue.c,v 1.12.4.3 2009/05/27 21:32:05 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_mqueue.c,v 1.12.4.4 2009/07/21 00:23:01 snj Exp $); #include sys/param.h #include sys/types.h @@ -482,9 +482,14 @@ /* Get the message queue */ error = mqueue_get(mqdes, fp); - if (error) + if (error) { return error; + } mq = fp-f_data; + if ((fp-f_flag FREAD) == 0) { + error = EBADF; + goto error; + } /* Check the message size limits */ if (msg_len mq-mq_attrib.mq_msgsize) { @@ -642,6 +647,10 @@ return error; } mq = fp-f_data; + if ((fp-f_flag FWRITE) == 0) { + error = EBADF; + goto error; + } /* Check the message size limit */ if (msg_len = 0 || msg_len mq-mq_attrib.mq_msgsize) {
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jul 1 22:27:24 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: init_sysctl.c Log Message: Pull up following revision(s) (requested by rmind in ticket #835): sys/kern/init_sysctl.c: revision 1.161 sysctl_doeproc: fix a bug in rev.1.135. don't forget to mark our marker process PK_MARKER. this fixes crashes in sched_pstats, etc. To generate a diff of this commit: cvs rdiff -u -r1.149.4.4 -r1.149.4.5 src/sys/kern/init_sysctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/init_sysctl.c diff -u src/sys/kern/init_sysctl.c:1.149.4.4 src/sys/kern/init_sysctl.c:1.149.4.5 --- src/sys/kern/init_sysctl.c:1.149.4.4 Wed Apr 1 00:25:22 2009 +++ src/sys/kern/init_sysctl.c Wed Jul 1 22:27:23 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.149.4.4 2009/04/01 00:25:22 snj Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.149.4.5 2009/07/01 22:27:23 snj Exp $ */ /*- * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: init_sysctl.c,v 1.149.4.4 2009/04/01 00:25:22 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: init_sysctl.c,v 1.149.4.5 2009/07/01 22:27:23 snj Exp $); #include opt_sysv.h #include opt_compat_netbsd32.h @@ -2200,6 +2200,7 @@ kproc2 = kmem_alloc(sizeof(*kproc2), KM_SLEEP); } marker = kmem_alloc(sizeof(*marker), KM_SLEEP); + marker-p_flag = PK_MARKER; mutex_enter(proc_lock); mmmbrains = false;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jul 1 22:30:30 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_exit.c Log Message: Pull up following revision(s) (requested by rmind in ticket #836): sys/kern/kern_exit.c: revision 1.221 exit1: fix a race with do_sys_wait/proc_free. To generate a diff of this commit: cvs rdiff -u -r1.214.4.1 -r1.214.4.2 src/sys/kern/kern_exit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_exit.c diff -u src/sys/kern/kern_exit.c:1.214.4.1 src/sys/kern/kern_exit.c:1.214.4.2 --- src/sys/kern/kern_exit.c:1.214.4.1 Mon Feb 2 02:32:57 2009 +++ src/sys/kern/kern_exit.c Wed Jul 1 22:30:30 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exit.c,v 1.214.4.1 2009/02/02 02:32:57 snj Exp $ */ +/* $NetBSD: kern_exit.c,v 1.214.4.2 2009/07/01 22:30:30 snj Exp $ */ /*- * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_exit.c,v 1.214.4.1 2009/02/02 02:32:57 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_exit.c,v 1.214.4.2 2009/07/01 22:30:30 snj Exp $); #include opt_ktrace.h #include opt_perfctrs.h @@ -550,8 +550,8 @@ * Drop debugger/procfs lock; no new references can be gained. */ cv_broadcast(p-p_pptr-p_waitcv); - mutex_exit(proc_lock); rw_exit(p-p_reflock); + mutex_exit(proc_lock); /* Verify that we hold no locks other than the kernel lock. */ LOCKDEBUG_BARRIER(kernel_lock, 0);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jul 1 22:32:42 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_rwlock.c Log Message: Pull up following revision(s) (requested by rmind in ticket #837): sys/kern/kern_rwlock.c: revision 1.31 lockdebug fixes for rw_tryupgrade/rw_downgrade. To generate a diff of this commit: cvs rdiff -u -r1.28.4.1 -r1.28.4.2 src/sys/kern/kern_rwlock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_rwlock.c diff -u src/sys/kern/kern_rwlock.c:1.28.4.1 src/sys/kern/kern_rwlock.c:1.28.4.2 --- src/sys/kern/kern_rwlock.c:1.28.4.1 Wed May 13 00:33:32 2009 +++ src/sys/kern/kern_rwlock.c Wed Jul 1 22:32:42 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_rwlock.c,v 1.28.4.1 2009/05/13 00:33:32 snj Exp $ */ +/* $NetBSD: kern_rwlock.c,v 1.28.4.2 2009/07/01 22:32:42 snj Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_rwlock.c,v 1.28.4.1 2009/05/13 00:33:32 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_rwlock.c,v 1.28.4.2 2009/07/01 22:32:42 snj Exp $); #define __RWLOCK_PRIVATE @@ -648,6 +648,7 @@ } } + RW_WANTLOCK(rw, RW_READER, false); RW_LOCKED(rw, RW_READER); RW_DASSERT(rw, (rw-rw_owner RW_WRITE_LOCKED) == 0); RW_DASSERT(rw, RW_COUNT(rw) != 0); @@ -666,7 +667,7 @@ curthread = (uintptr_t)curlwp; RW_ASSERT(rw, curthread != 0); - RW_WANTLOCK(rw, RW_WRITER, true); + RW_ASSERT(rw, rw_read_held(rw)); for (owner = rw-rw_owner;; owner = next) { RW_ASSERT(rw, (owner RW_WRITE_LOCKED) == 0); @@ -683,6 +684,7 @@ } RW_UNLOCKED(rw, RW_READER); + RW_WANTLOCK(rw, RW_WRITER, true); RW_LOCKED(rw, RW_WRITER); RW_DASSERT(rw, rw-rw_owner RW_WRITE_LOCKED); RW_DASSERT(rw, RW_OWNER(rw) == curthread);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jul 1 22:39:20 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: init_sysctl.c vfs_trans.c Log Message: Pull up following revision(s) (requested by rmind in ticket #838): sys/kern/init_sysctl.c: revision 1.162 sys/kern/vfs_trans.c: revision 1.25 don't forget to skip marker processes. To generate a diff of this commit: cvs rdiff -u -r1.149.4.5 -r1.149.4.6 src/sys/kern/init_sysctl.c cvs rdiff -u -r1.23 -r1.23.4.1 src/sys/kern/vfs_trans.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/init_sysctl.c diff -u src/sys/kern/init_sysctl.c:1.149.4.5 src/sys/kern/init_sysctl.c:1.149.4.6 --- src/sys/kern/init_sysctl.c:1.149.4.5 Wed Jul 1 22:27:23 2009 +++ src/sys/kern/init_sysctl.c Wed Jul 1 22:39:20 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.149.4.5 2009/07/01 22:27:23 snj Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.149.4.6 2009/07/01 22:39:20 snj Exp $ */ /*- * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: init_sysctl.c,v 1.149.4.5 2009/07/01 22:27:23 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: init_sysctl.c,v 1.149.4.6 2009/07/01 22:39:20 snj Exp $); #include opt_sysv.h #include opt_compat_netbsd32.h @@ -1693,7 +1693,7 @@ sysctl_unlock(); if (pid == -1) { mutex_enter(proc_lock); - LIST_FOREACH(p, allproc, p_list) { + PROCLIST_FOREACH(p, allproc) { /* Grab a hold on the process. */ if (!rw_tryenter(p-p_reflock, RW_READER)) { continue; @@ -2021,7 +2021,7 @@ return (EINVAL); sysctl_unlock(); mutex_enter(proc_lock); - LIST_FOREACH(p, allproc, p_list) { + PROCLIST_FOREACH(p, allproc) { if (p-p_stat == SIDL) { /* skip embryonic processes */ continue; @@ -2214,6 +2214,8 @@ break; } next = LIST_NEXT(p, p_list); + if ((p-p_flag PK_MARKER) != 0) + continue; /* * Skip embryonic processes. Index: src/sys/kern/vfs_trans.c diff -u src/sys/kern/vfs_trans.c:1.23 src/sys/kern/vfs_trans.c:1.23.4.1 --- src/sys/kern/vfs_trans.c:1.23 Wed Sep 17 14:49:25 2008 +++ src/sys/kern/vfs_trans.c Wed Jul 1 22:39:20 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_trans.c,v 1.23 2008/09/17 14:49:25 hannken Exp $ */ +/* $NetBSD: vfs_trans.c,v 1.23.4.1 2009/07/01 22:39:20 snj Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_trans.c,v 1.23 2008/09/17 14:49:25 hannken Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_trans.c,v 1.23.4.1 2009/07/01 22:39:20 snj Exp $); /* * File system transaction operations. @@ -486,7 +486,7 @@ printf(Fstrans locks by lwp:\n); for (pd = proclists; pd-pd_list != NULL; pd++) - LIST_FOREACH(p, pd-pd_list, p_list) + PROCLIST_FOREACH(p, pd-pd_list) LIST_FOREACH(l, p-p_lwps, l_sibling) fstrans_print_lwp(p, l, full == 1);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jul 1 22:42:29 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: init_sysctl.c Log Message: Pull up following revision(s) (requested by rmind in ticket #839): sys/kern/init_sysctl.c: revision 1.163 sysctl_doeproc: - simplify. - KERN_PROC: fix possible stale proc pointer dereference. - KERN_PROC: don't do copyout with proc_lock held. To generate a diff of this commit: cvs rdiff -u -r1.149.4.6 -r1.149.4.7 src/sys/kern/init_sysctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/init_sysctl.c diff -u src/sys/kern/init_sysctl.c:1.149.4.6 src/sys/kern/init_sysctl.c:1.149.4.7 --- src/sys/kern/init_sysctl.c:1.149.4.6 Wed Jul 1 22:39:20 2009 +++ src/sys/kern/init_sysctl.c Wed Jul 1 22:42:28 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.149.4.6 2009/07/01 22:39:20 snj Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.149.4.7 2009/07/01 22:42:28 snj Exp $ */ /*- * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: init_sysctl.c,v 1.149.4.6 2009/07/01 22:39:20 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: init_sysctl.c,v 1.149.4.7 2009/07/01 22:42:28 snj Exp $); #include opt_sysv.h #include opt_compat_netbsd32.h @@ -2152,21 +2152,21 @@ static int sysctl_doeproc(SYSCTLFN_ARGS) { - struct eproc *eproc; - struct kinfo_proc2 *kproc2; - struct kinfo_proc *dp; + union { + struct kinfo_proc kproc; + struct kinfo_proc2 kproc2; + } *kbuf; struct proc *p, *next, *marker; - char *where, *dp2; + char *where, *dp; int type, op, arg, error; - u_int elem_size, elem_count; + u_int elem_size, kelem_size, elem_count; size_t buflen, needed; bool match, zombie, mmmbrains; if (namelen == 1 name[0] == CTL_QUERY) return (sysctl_query(SYSCTLFN_CALL(rnode))); - dp = oldp; - dp2 = where = oldp; + dp = where = oldp; buflen = where != NULL ? *oldlenp : 0; error = 0; needed = 0; @@ -2180,7 +2180,8 @@ arg = name[1]; else arg = 0; /* Quell compiler warning */ - elem_size = elem_count = 0; /* Ditto */ + elem_count = 0; /* Ditto */ + kelem_size = elem_size = sizeof(kbuf-kproc); } else { if (namelen != 4) return (EINVAL); @@ -2188,17 +2189,12 @@ arg = name[1]; elem_size = name[2]; elem_count = name[3]; + kelem_size = sizeof(kbuf-kproc2); } sysctl_unlock(); - if (type == KERN_PROC) { - eproc = kmem_alloc(sizeof(*eproc), KM_SLEEP); - kproc2 = NULL; - } else { - eproc = NULL; - kproc2 = kmem_alloc(sizeof(*kproc2), KM_SLEEP); - } + kbuf = kmem_alloc(sizeof(*kbuf), KM_SLEEP); marker = kmem_alloc(sizeof(*marker), KM_SLEEP); marker-p_flag = PK_MARKER; @@ -2312,51 +2308,32 @@ LIST_INSERT_AFTER(p, marker, p_list); } - if (type == KERN_PROC) { - if (buflen = sizeof(struct kinfo_proc)) { -fill_eproc(p, eproc, zombie); -mutex_exit(p-p_lock); -mutex_exit(proc_lock); -error = dcopyout(l, p, dp-kp_proc, -sizeof(struct proc)); -mutex_enter(proc_lock); -if (error) { - goto bah; -} -error = dcopyout(l, eproc, dp-kp_eproc, -sizeof(*eproc)); -if (error) { - goto bah; -} -dp++; -buflen -= sizeof(struct kinfo_proc); + if (buflen = elem_size + (type == KERN_PROC || elem_count 0)) { + if (type == KERN_PROC) { +kbuf-kproc.kp_proc = *p; +fill_eproc(p, kbuf-kproc.kp_eproc, zombie); } else { -mutex_exit(p-p_lock); - } - needed += sizeof(struct kinfo_proc); - } else { /* KERN_PROC2 */ - if (buflen = elem_size elem_count 0) { -fill_kproc2(p, kproc2, zombie); -mutex_exit(p-p_lock); -mutex_exit(proc_lock); -/* - * Copy out elem_size, but not larger than - * the size of a struct kinfo_proc2. - */ -error = dcopyout(l, kproc2, dp2, -min(sizeof(*kproc2), elem_size)); -mutex_enter(proc_lock); -if (error) { - goto bah; -} -dp2 += elem_size; -buflen -= elem_size; +fill_kproc2(p, kbuf-kproc2, zombie); elem_count--; - } else { -mutex_exit(p-p_lock); } - needed += elem_size; + mutex_exit(p-p_lock); + mutex_exit(proc_lock); + /* + * Copy out elem_size, but not larger than kelem_size + */ + error = dcopyout(l, kbuf, dp, + min(kelem_size, elem_size)); + mutex_enter(proc_lock); + if (error) { +goto bah; + } + dp += elem_size; + buflen -= elem_size; + } else { + mutex_exit(p-p_lock); } + needed += elem_size; /* * Release reference to process. @@ -2371,10 +2348,7 @@ mutex_exit(proc_lock); if (where != NULL) { - if (type == KERN_PROC) - *oldlenp = (char *)dp - where; - else - *oldlenp = dp2 - where; + *oldlenp = dp - where; if (needed *oldlenp) { error = ENOMEM; goto out; @@ -2383,10 +2357,8 @@ needed += KERN_PROCSLOP; *oldlenp = needed; } - if
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jul 1 22:45:03 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: vfs_lockf.c Log Message: Pull up following revision(s) (requested by rmind in ticket #840): sys/kern/vfs_lockf.c: revision 1.70 lf_split: cv_destroy a condvar before clobbering it. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.69.4.1 src/sys/kern/vfs_lockf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_lockf.c diff -u src/sys/kern/vfs_lockf.c:1.69 src/sys/kern/vfs_lockf.c:1.69.4.1 --- src/sys/kern/vfs_lockf.c:1.69 Sat Oct 11 13:40:57 2008 +++ src/sys/kern/vfs_lockf.c Wed Jul 1 22:45:03 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_lockf.c,v 1.69 2008/10/11 13:40:57 pooka Exp $ */ +/* $NetBSD: vfs_lockf.c,v 1.69.4.1 2009/07/01 22:45:03 snj Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -35,7 +35,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_lockf.c,v 1.69 2008/10/11 13:40:57 pooka Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_lockf.c,v 1.69.4.1 2009/07/01 22:45:03 snj Exp $); #include sys/param.h #include sys/systm.h @@ -383,6 +383,7 @@ */ splitlock = *sparelock; *sparelock = NULL; + cv_destroy(splitlock-lf_cv); memcpy(splitlock, lock1, sizeof(*splitlock)); cv_init(splitlock-lf_cv, lockstr);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jul 1 22:47:06 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: vfs_syscalls.c Log Message: Pull up following revision(s) (requested by rmind in ticket #841): sys/kern/vfs_syscalls.c: revision 1.392 do_sys_utimes: fix a bug introduced by rev.1.367. VA_UTIMES_NULL is in va_vaflags, not va_flags. To generate a diff of this commit: cvs rdiff -u -r1.376.4.2 -r1.376.4.3 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.376.4.2 src/sys/kern/vfs_syscalls.c:1.376.4.3 --- src/sys/kern/vfs_syscalls.c:1.376.4.2 Mon Feb 16 03:33:17 2009 +++ src/sys/kern/vfs_syscalls.c Wed Jul 1 22:47:05 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.376.4.2 2009/02/16 03:33:17 snj Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.376.4.3 2009/07/01 22:47:05 snj Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_syscalls.c,v 1.376.4.2 2009/02/16 03:33:17 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_syscalls.c,v 1.376.4.3 2009/07/01 22:47:05 snj Exp $); #include opt_compat_netbsd.h #include opt_compat_43.h @@ -3051,7 +3051,7 @@ if (setbirthtime) vattr.va_birthtime = ts[1]; if (vanull) - vattr.va_flags |= VA_UTIMES_NULL; + vattr.va_vaflags |= VA_UTIMES_NULL; error = VOP_SETATTR(vp, vattr, l-l_cred); VOP_UNLOCK(vp, 0);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jul 1 22:49:43 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: vfs_lockf.c Log Message: Pull up following revision(s) (requested by rmind in ticket #842): sys/kern/vfs_lockf.c: revision 1.71 don't make F_GETLK or the common case of F_UNLCK fail for per-user limit. To generate a diff of this commit: cvs rdiff -u -r1.69.4.1 -r1.69.4.2 src/sys/kern/vfs_lockf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_lockf.c diff -u src/sys/kern/vfs_lockf.c:1.69.4.1 src/sys/kern/vfs_lockf.c:1.69.4.2 --- src/sys/kern/vfs_lockf.c:1.69.4.1 Wed Jul 1 22:45:03 2009 +++ src/sys/kern/vfs_lockf.c Wed Jul 1 22:49:43 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_lockf.c,v 1.69.4.1 2009/07/01 22:45:03 snj Exp $ */ +/* $NetBSD: vfs_lockf.c,v 1.69.4.2 2009/07/01 22:49:43 snj Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -35,7 +35,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_lockf.c,v 1.69.4.1 2009/07/01 22:45:03 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_lockf.c,v 1.69.4.2 2009/07/01 22:49:43 snj Exp $); #include sys/param.h #include sys/systm.h @@ -190,11 +190,12 @@ * 0 - always allocate. 1 - cutoff at limit. 2 - cutoff at double limit. */ static struct lockf * -lf_alloc(uid_t uid, int allowfail) +lf_alloc(int allowfail) { struct uidinfo *uip; struct lockf *lock; u_long lcnt; + const uid_t uid = kauth_cred_geteuid(kauth_cred_get()); uip = uid_find(uid); lcnt = atomic_inc_ulong_nv(uip-ui_lockcnt); @@ -807,7 +808,6 @@ int lf_advlock(struct vop_advlock_args *ap, struct lockf **head, off_t size) { - struct lwp *l = curlwp; struct flock *fl = ap-a_fl; struct lockf *lock = NULL; struct lockf *sparelock; @@ -852,7 +852,7 @@ /* * Byte-range lock might need one more lock. */ - sparelock = lf_alloc(kauth_cred_geteuid(l-l_cred), 0); + sparelock = lf_alloc(0); if (sparelock == NULL) { error = ENOMEM; goto quit; @@ -869,8 +869,28 @@ return EINVAL; } - lock = lf_alloc(kauth_cred_geteuid(l-l_cred), - ap-a_op != F_UNLCK ? 1 : 2); + if (fl-l_len == 0) + end = -1; + else + end = start + fl-l_len - 1; + + switch (ap-a_op) { + case F_SETLK: + lock = lf_alloc(1); + break; + case F_UNLCK: + if (start == 0 || end == -1) { + /* never split */ + lock = lf_alloc(0); + } else { + /* might split */ + lock = lf_alloc(2); + } + break; + case F_GETLK: + lock = lf_alloc(0); + break; + } if (lock == NULL) { error = ENOMEM; goto quit; @@ -889,10 +909,6 @@ } } - if (fl-l_len == 0) - end = -1; - else - end = start + fl-l_len - 1; /* * Create the lockf structure. */
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Wed Jun 17 20:17:37 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: tty_pty.c Log Message: Pull up following revision(s) (requested by plunky in ticket #807): sys/kern/tty_pty.c: revision 1.117 Writes on the controlling tty were not being awoken from blocks, use the correct condvar to make this happen. this fixes PR/41566 To generate a diff of this commit: cvs rdiff -u -r1.112 -r1.112.4.1 src/sys/kern/tty_pty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/tty_pty.c diff -u src/sys/kern/tty_pty.c:1.112 src/sys/kern/tty_pty.c:1.112.4.1 --- src/sys/kern/tty_pty.c:1.112 Wed Sep 3 16:47:34 2008 +++ src/sys/kern/tty_pty.c Wed Jun 17 20:17:37 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: tty_pty.c,v 1.112 2008/09/03 16:47:34 drochner Exp $ */ +/* $NetBSD: tty_pty.c,v 1.112.4.1 2009/06/17 20:17:37 bouyer Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -37,7 +37,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: tty_pty.c,v 1.112 2008/09/03 16:47:34 drochner Exp $); +__KERNEL_RCSID(0, $NetBSD: tty_pty.c,v 1.112.4.1 2009/06/17 20:17:37 bouyer Exp $); #include opt_compat_sunos.h #include opt_ptm.h @@ -779,7 +779,7 @@ error = cnt == 0 ? EWOULDBLOCK : 0; goto out; } - error = cv_wait_sig(tp-t_rawcv, tty_lock); + error = cv_wait_sig(tp-t_rawcvf, tty_lock); mutex_spin_exit(tty_lock); if (error) { /* adjust for data copied in but not written */
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Wed Jun 17 20:49:00 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sys_generic.c Log Message: Pull up following revision(s) (requested by rmind in ticket #811): sys/kern/sys_generic.c: revision 1.122 via patch Updates to f_flag need to be made with atomics. To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.120.6.1 src/sys/kern/sys_generic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_generic.c diff -u src/sys/kern/sys_generic.c:1.120 src/sys/kern/sys_generic.c:1.120.6.1 --- src/sys/kern/sys_generic.c:1.120 Wed Jul 2 16:45:20 2008 +++ src/sys/kern/sys_generic.c Wed Jun 17 20:49:00 2009 @@ -1,7 +1,7 @@ -/* $NetBSD: sys_generic.c,v 1.120 2008/07/02 16:45:20 matt Exp $ */ +/* $NetBSD: sys_generic.c,v 1.120.6.1 2009/06/17 20:49:00 bouyer Exp $ */ /*- - * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. + * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -70,7 +70,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_generic.c,v 1.120 2008/07/02 16:45:20 matt Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_generic.c,v 1.120.6.1 2009/06/17 20:49:00 bouyer Exp $); #include sys/param.h #include sys/systm.h @@ -89,6 +89,7 @@ #include sys/mount.h #include sys/syscallargs.h #include sys/ktrace.h +#include sys/atomic.h #include uvm/uvm_extern.h @@ -593,22 +594,20 @@ switch (com) { case FIONBIO: - FILE_LOCK(fp); + /* XXX Code block is not atomic */ if (*(int *)data != 0) - fp-f_flag |= FNONBLOCK; + atomic_or_uint(fp-f_flag, FNONBLOCK); else - fp-f_flag = ~FNONBLOCK; - FILE_UNLOCK(fp); + atomic_and_uint(fp-f_flag, ~FNONBLOCK); error = (*fp-f_ops-fo_ioctl)(fp, FIONBIO, data); break; case FIOASYNC: - FILE_LOCK(fp); + /* XXX Code block is not atomic */ if (*(int *)data != 0) - fp-f_flag |= FASYNC; + atomic_or_uint(fp-f_flag, FASYNC); else - fp-f_flag = ~FASYNC; - FILE_UNLOCK(fp); + atomic_and_uint(fp-f_flag, ~FASYNC); error = (*fp-f_ops-fo_ioctl)(fp, FIOASYNC, data); break;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sat Jun 6 22:12:44 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sched_4bsd.c Log Message: Pull up following revision(s) (requested by rmind in ticket #791): sys/kern/sched_4bsd.c: revision 1.25 sched_pstats_hook: fix estcpu decay. this makes my desktop usable when running make -j4. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.24.4.1 src/sys/kern/sched_4bsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sched_4bsd.c diff -u src/sys/kern/sched_4bsd.c:1.24 src/sys/kern/sched_4bsd.c:1.24.4.1 --- src/sys/kern/sched_4bsd.c:1.24 Tue Oct 7 09:48:27 2008 +++ src/sys/kern/sched_4bsd.c Sat Jun 6 22:12:44 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sched_4bsd.c,v 1.24 2008/10/07 09:48:27 rmind Exp $ */ +/* $NetBSD: sched_4bsd.c,v 1.24.4.1 2009/06/06 22:12:44 bouyer Exp $ */ /*- * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sched_4bsd.c,v 1.24 2008/10/07 09:48:27 rmind Exp $); +__KERNEL_RCSID(0, $NetBSD: sched_4bsd.c,v 1.24.4.1 2009/06/06 22:12:44 bouyer Exp $); #include opt_ddb.h #include opt_lockdebug.h @@ -288,17 +288,22 @@ void sched_pstats_hook(struct lwp *l, int batch) { + fixpt_t loadfac; /* * If the LWP has slept an entire second, stop recalculating * its priority until it wakes up. */ KASSERT(lwp_locked(l, NULL)); - if (l-l_slptime 0) { - fixpt_t loadfac = 2 * (averunnable.ldavg[0]); - l-l_estcpu = decay_cpu(loadfac, l-l_estcpu); - resetpriority(l); + if (l-l_stat == LSSLEEP || l-l_stat == LSSTOP || + l-l_stat == LSSUSPENDED) { + if (l-l_slptime 1) { + return; + } } + loadfac = 2 * (averunnable.ldavg[0]); + l-l_estcpu = decay_cpu(loadfac, l-l_estcpu); + resetpriority(l); } /*
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed May 27 21:32:05 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sys_mqueue.c Log Message: Pull up following revision(s) (requested by rmind in ticket #779): sys/kern/sys_mqueue.c: revision 1.18 - Slightly rework the way permissions are checked. Neither mq_receive() not mq_send() should fail due to permissions. Noted by Stathis Kamperis! - Check for empty message queue name (POSIX does not allow this for regular files, and it's weird), check for DTYPE_MQUEUE, fix permission check in mq_unlink(), clean up. To generate a diff of this commit: cvs rdiff -u -r1.12.4.2 -r1.12.4.3 src/sys/kern/sys_mqueue.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_mqueue.c diff -u src/sys/kern/sys_mqueue.c:1.12.4.2 src/sys/kern/sys_mqueue.c:1.12.4.3 --- src/sys/kern/sys_mqueue.c:1.12.4.2 Mon May 18 19:47:32 2009 +++ src/sys/kern/sys_mqueue.c Wed May 27 21:32:05 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_mqueue.c,v 1.12.4.2 2009/05/18 19:47:32 bouyer Exp $ */ +/* $NetBSD: sys_mqueue.c,v 1.12.4.3 2009/05/27 21:32:05 snj Exp $ */ /* * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius rmind at NetBSD org @@ -42,7 +42,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_mqueue.c,v 1.12.4.2 2009/05/18 19:47:32 bouyer Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_mqueue.c,v 1.12.4.3 2009/05/27 21:32:05 snj Exp $); #include sys/param.h #include sys/types.h @@ -86,8 +86,6 @@ static int mq_poll_fop(file_t *, int); static int mq_close_fop(file_t *); -#define FNOVAL -1 - static const struct fileops mqops = { .fo_read = fbadop_read, .fo_write = fbadop_write, @@ -166,57 +164,28 @@ } /* - * Check access against message queue. - */ -static inline int -mqueue_access(struct lwp *l, struct mqueue *mq, int access) -{ - mode_t acc_mode = 0; - - KASSERT(mutex_owned(mq-mq_mtx)); - KASSERT(access != FNOVAL); - - /* Note the difference between VREAD/VWRITE and FREAD/FWRITE */ - if (access FREAD) - acc_mode |= VREAD; - if (access FWRITE) - acc_mode |= VWRITE; - - return vaccess(VNON, mq-mq_mode, mq-mq_euid, mq-mq_egid, - acc_mode, l-l_cred); -} - -/* - * Get the mqueue from the descriptor. - * = locks the message queue, if found - * = increments the reference on file entry + * mqueue_get: get the mqueue from the descriptor. + * = locks the message queue, if found. + * = holds a reference on the file descriptor. */ static int -mqueue_get(struct lwp *l, mqd_t mqd, int access, file_t **fpr) +mqueue_get(mqd_t mqd, file_t **fpr) { - file_t *fp; struct mqueue *mq; + file_t *fp; - /* Get the file and descriptor */ fp = fd_getfile((int)mqd); - if (fp == NULL) + if (__predict_false(fp == NULL)) { return EBADF; - - /* Increment the reference of file entry, and lock the mqueue */ - mq = fp-f_data; - *fpr = fp; - mutex_enter(mq-mq_mtx); - if (access == FNOVAL) { - KASSERT(mutex_owned(mq-mq_mtx)); - return 0; } - - /* Check the access mode and permission */ - if ((fp-f_flag access) != access || mqueue_access(l, mq, access)) { - mutex_exit(mq-mq_mtx); + if (__predict_false(fp-f_type != DTYPE_MQUEUE)) { fd_putfile((int)mqd); - return EPERM; + return EBADF; } + mq = fp-f_data; + mutex_enter(mq-mq_mtx); + + *fpr = fp; return 0; } @@ -347,6 +316,12 @@ return EMFILE; } + /* Empty name is invalid */ + if (name[0] == '\0') { + kmem_free(name, MQ_NAMELEN); + return EINVAL; + } + /* Check for mqueue attributes */ if (SCARG(uap, attr)) { error = copyin(SCARG(uap, attr), attr, @@ -383,7 +358,9 @@ strlcpy(mq_new-mq_name, name, MQ_NAMELEN); memcpy(mq_new-mq_attrib, attr, sizeof(struct mq_attr)); - mq_new-mq_attrib.mq_flags = oflag; + + CTASSERT((O_MASK (MQ_UNLINK | MQ_RECEIVE)) == 0); + mq_new-mq_attrib.mq_flags = (O_MASK oflag); /* Store mode and effective UID with GID */ mq_new-mq_mode = ((SCARG(uap, mode) @@ -408,6 +385,8 @@ mutex_enter(mqlist_mtx); mq = mqueue_lookup(name); if (mq) { + mode_t acc_mode; + KASSERT(mutex_owned(mq-mq_mtx)); /* Check if mqueue is not marked as unlinking */ @@ -420,8 +399,20 @@ error = EEXIST; goto exit; } - /* Check the permission */ - if (mqueue_access(l, mq, fp-f_flag)) { + + /* + * Check the permissions. Note the difference between + * VREAD/VWRITE and FREAD/FWRITE. + */ + acc_mode = 0; + if (fp-f_flag FREAD) { + acc_mode |= VREAD; + } + if (fp-f_flag FWRITE) { + acc_mode |= VWRITE; + } + if (vaccess(VNON, mq-mq_mode, mq-mq_euid, mq-mq_egid, + acc_mode, l-l_cred)) { error = EACCES; goto exit; } @@ -490,7 +481,7 @@ int error; /* Get the message queue */ - error = mqueue_get(l, mqdes, FREAD, fp); + error = mqueue_get(mqdes, fp); if (error) return error; mq = fp-f_data; @@ -645,7 +636,7 @@ msg-msg_prio = msg_prio; /* Get the mqueue */ - error = mqueue_get(l,
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed May 27 21:42:08 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_physio.c Log Message: Pull up following revision(s) (requested by hannken in ticket #781): sys/kern/kern_physio.c: revision 1.91 PR kern/39536: bufq related problem when writing DVDR and DVDRWs. Remove a race where physio_done() may use memory already freed. Observed by Hans Rosenfeld rosenf...@grumpf.hope-2000.org. To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.88.4.1 src/sys/kern/kern_physio.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_physio.c diff -u src/sys/kern/kern_physio.c:1.88 src/sys/kern/kern_physio.c:1.88.4.1 --- src/sys/kern/kern_physio.c:1.88 Wed Sep 24 08:19:19 2008 +++ src/sys/kern/kern_physio.c Wed May 27 21:42:08 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_physio.c,v 1.88 2008/09/24 08:19:19 hannken Exp $ */ +/* $NetBSD: kern_physio.c,v 1.88.4.1 2009/05/27 21:42:08 snj Exp $ */ /*- * Copyright (c) 1982, 1986, 1990, 1993 @@ -71,7 +71,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_physio.c,v 1.88 2008/09/24 08:19:19 hannken Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_physio.c,v 1.88.4.1 2009/05/27 21:42:08 snj Exp $); #include sys/param.h #include sys/systm.h @@ -117,6 +117,7 @@ size_t todo = bp-b_bufsize; size_t done = bp-b_bcount - bp-b_resid; struct physio_stat *ps = bp-b_private; + bool is_iobuf; KASSERT(bp-b_work == wk); KASSERT(bp-b_bcount = todo); @@ -128,6 +129,7 @@ uvm_vsunlock(bp-b_proc-p_vmspace, bp-b_data, todo); mutex_enter(ps-ps_lock); + is_iobuf = (bp != ps-ps_orig_bp); if (__predict_false(done != todo)) { off_t endoffset = dbtob(bp-b_blkno) + done; @@ -163,7 +165,7 @@ cv_signal(ps-ps_cv); mutex_exit(ps-ps_lock); - if (bp != ps-ps_orig_bp) + if (is_iobuf) putiobuf(bp); }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Mon May 18 19:47:32 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sys_mqueue.c Log Message: Pull up following revision(s) (requested by rmind in ticket #762): sys/kern/sys_mqueue.c: revision 1.17 sys_mq_open: remove broken access flag check. Noted by Stathis Kamperis. To generate a diff of this commit: cvs rdiff -u -r1.12.4.1 -r1.12.4.2 src/sys/kern/sys_mqueue.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_mqueue.c diff -u src/sys/kern/sys_mqueue.c:1.12.4.1 src/sys/kern/sys_mqueue.c:1.12.4.2 --- src/sys/kern/sys_mqueue.c:1.12.4.1 Sat Apr 4 23:36:27 2009 +++ src/sys/kern/sys_mqueue.c Mon May 18 19:47:32 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_mqueue.c,v 1.12.4.1 2009/04/04 23:36:27 snj Exp $ */ +/* $NetBSD: sys_mqueue.c,v 1.12.4.2 2009/05/18 19:47:32 bouyer Exp $ */ /* * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius rmind at NetBSD org @@ -42,7 +42,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_mqueue.c,v 1.12.4.1 2009/04/04 23:36:27 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_mqueue.c,v 1.12.4.2 2009/05/18 19:47:32 bouyer Exp $); #include sys/param.h #include sys/types.h @@ -327,10 +327,7 @@ char *name; int mqd, error, oflag; - /* Check access mode flags */ oflag = SCARG(uap, oflag); - if ((oflag O_ACCMODE) == 0) - return EINVAL; /* Get the name from the user-space */ name = kmem_zalloc(MQ_NAMELEN, KM_SLEEP);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed May 13 00:33:32 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_rwlock.c Log Message: Pull up following revision(s) (requested by ad in ticket #725): sys/kern/kern_rwlock.c: revision 1.30 A workaround for a bug with some Opteron revisions where locked operations sometimes do not serve as memory barriers, allowing memory references to bleed outside of critical sections. It is possible that this is the reason for pkgbuild's longstanding crashiness. For rwlocks, always enable the explicit membars. They were disabled only on x86, and since they are not in the fast-path it's not a big deal. TODO: convert these to an atomic_membar_foo() or similar that does ordering between regular data references and atomic references. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.28.4.1 src/sys/kern/kern_rwlock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_rwlock.c diff -u src/sys/kern/kern_rwlock.c:1.28 src/sys/kern/kern_rwlock.c:1.28.4.1 --- src/sys/kern/kern_rwlock.c:1.28 Tue Jul 29 16:13:39 2008 +++ src/sys/kern/kern_rwlock.c Wed May 13 00:33:32 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_rwlock.c,v 1.28 2008/07/29 16:13:39 thorpej Exp $ */ +/* $NetBSD: kern_rwlock.c,v 1.28.4.1 2009/05/13 00:33:32 snj Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_rwlock.c,v 1.28 2008/07/29 16:13:39 thorpej Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_rwlock.c,v 1.28.4.1 2009/05/13 00:33:32 snj Exp $); #define __RWLOCK_PRIVATE @@ -329,9 +329,7 @@ ~RW_WRITE_WANTED); if (__predict_true(next == owner)) { /* Got it! */ -#ifndef __HAVE_ATOMIC_AS_MEMBAR membar_enter(); -#endif break; } @@ -453,9 +451,7 @@ * proceed to do direct handoff if there are waiters, and if the * lock would become unowned. */ -#ifndef __HAVE_ATOMIC_AS_MEMBAR membar_exit(); -#endif for (;;) { new = (owner - decr); if ((new (RW_THREAD | RW_HAS_WAITERS)) == RW_HAS_WAITERS) @@ -555,13 +551,11 @@ next = rw_cas(rw, owner, owner + incr); if (__predict_true(next == owner)) { /* Got it! */ + membar_enter(); break; } } -#ifndef __HAVE_ATOMIC_AS_MEMBAR - membar_enter(); -#endif RW_WANTLOCK(rw, op, true); RW_LOCKED(rw, op); RW_DASSERT(rw, (op != RW_READER RW_OWNER(rw) == curthread) || @@ -588,10 +582,7 @@ RW_ASSERT(rw, RW_OWNER(rw) == curthread); RW_UNLOCKED(rw, RW_WRITER); -#ifndef __HAVE_ATOMIC_AS_MEMBAR membar_producer(); -#endif - owner = rw-rw_owner; if ((owner RW_HAS_WAITERS) == 0) { /* @@ -685,8 +676,10 @@ } new = curthread | RW_WRITE_LOCKED | (owner ~RW_THREAD); next = rw_cas(rw, owner, new); - if (__predict_true(next == owner)) + if (__predict_true(next == owner)) { + membar_producer(); break; + } } RW_UNLOCKED(rw, RW_READER); @@ -694,10 +687,6 @@ RW_DASSERT(rw, rw-rw_owner RW_WRITE_LOCKED); RW_DASSERT(rw, RW_OWNER(rw) == curthread); -#ifndef __HAVE_ATOMIC_AS_MEMBAR - membar_producer(); -#endif - return 1; }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sun May 3 13:07:39 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sys_module.c Log Message: Pull up following revision(s) (requested by skrll in ticket #729): sys/kern/sys_module.c: revision 1.9 copyin the modctl_load_t for the non-x86 world. Fixes PR/41294. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.8.4.1 src/sys/kern/sys_module.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_module.c diff -u src/sys/kern/sys_module.c:1.8 src/sys/kern/sys_module.c:1.8.4.1 --- src/sys/kern/sys_module.c:1.8 Wed Oct 22 11:16:29 2008 +++ src/sys/kern/sys_module.c Sun May 3 13:07:39 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_module.c,v 1.8 2008/10/22 11:16:29 ad Exp $ */ +/* $NetBSD: sys_module.c,v 1.8.4.1 2009/05/03 13:07:39 bouyer Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_module.c,v 1.8 2008/10/22 11:16:29 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_module.c,v 1.8.4.1 2009/05/03 13:07:39 bouyer Exp $); #include sys/param.h #include sys/systm.h @@ -44,10 +44,8 @@ #include sys/syscallargs.h static int -handle_modctl_load(void *arg) +handle_modctl_load(modctl_load_t *ml) { - modctl_load_t *ml = (modctl_load_t *)arg; - char *path; char *props; int error; @@ -111,6 +109,7 @@ vaddr_t addr; size_t size; struct iovec iov; + modctl_load_t ml; int error; void *arg; @@ -118,7 +117,10 @@ switch (SCARG(uap, cmd)) { case MODCTL_LOAD: - error = handle_modctl_load(arg); + error = copyin(arg, ml, sizeof(ml)); + if (error != 0) + break; + error = handle_modctl_load(ml); break; case MODCTL_UNLOAD:
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sun May 3 13:18:55 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: uipc_socket.c Log Message: Pull up following revision(s) (requested by ad in ticket #731): sys/kern/uipc_socket.c: revision 1.189 PR kern/41311: Mutex error: mutex_vector_enter: locking against myself To generate a diff of this commit: cvs rdiff -u -r1.177.4.2 -r1.177.4.3 src/sys/kern/uipc_socket.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_socket.c diff -u src/sys/kern/uipc_socket.c:1.177.4.2 src/sys/kern/uipc_socket.c:1.177.4.3 --- src/sys/kern/uipc_socket.c:1.177.4.2 Sat Apr 4 23:36:27 2009 +++ src/sys/kern/uipc_socket.c Sun May 3 13:18:55 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.177.4.2 2009/04/04 23:36:27 snj Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.177.4.3 2009/05/03 13:18:55 bouyer Exp $ */ /*- * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_socket.c,v 1.177.4.2 2009/04/04 23:36:27 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_socket.c,v 1.177.4.3 2009/05/03 13:18:55 bouyer Exp $); #include opt_sock_counters.h #include opt_sosend_loan.h @@ -2043,7 +2043,7 @@ { fownsignal(so-so_pgid, SIGURG, POLL_PRI, POLLPRI|POLLRDBAND, so); - selnotify(so-so_rcv.sb_sel, POLLPRI | POLLRDBAND, 0); + selnotify(so-so_rcv.sb_sel, POLLPRI | POLLRDBAND, NOTE_SUBMIT); } static void
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: bouyer Date: Sun May 3 13:21:36 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: vfs_dirhash.c Log Message: Pull up following revision(s) (requested by martin in ticket #732): sys/kern/vfs_dirhash.c: revision 1.10 PR port-vax/41315: Previous code ususally works since compiler won't put gap between those struct members but there is no reason to rely on that. While here, I rewrite the loop using an usual idiom. It shaves both source and object code. To generate a diff of this commit: cvs rdiff -u -r1.4.2.5 -r1.4.2.6 src/sys/kern/vfs_dirhash.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_dirhash.c diff -u src/sys/kern/vfs_dirhash.c:1.4.2.5 src/sys/kern/vfs_dirhash.c:1.4.2.6 --- src/sys/kern/vfs_dirhash.c:1.4.2.5 Tue Jan 6 23:01:49 2009 +++ src/sys/kern/vfs_dirhash.c Sun May 3 13:21:36 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_dirhash.c,v 1.4.2.5 2009/01/06 23:01:49 snj Exp $ */ +/* $NetBSD: vfs_dirhash.c,v 1.4.2.6 2009/05/03 13:21:36 bouyer Exp $ */ /* * Copyright (c) 2008 Reinoud Zandijk @@ -28,7 +28,7 @@ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: vfs_dirhash.c,v 1.4.2.5 2009/01/06 23:01:49 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: vfs_dirhash.c,v 1.4.2.6 2009/05/03 13:21:36 bouyer Exp $); /* CLEAN UP! */ #include sys/param.h @@ -151,19 +151,16 @@ return; for (hashline = 0; hashline DIRHASH_HASHSIZE; hashline++) { - dirh_e = LIST_FIRST(dirh-entries[hashline]); - while (dirh_e) { + while ((dirh_e = + LIST_FIRST(dirh-entries[hashline])) != NULL) { LIST_REMOVE(dirh_e, next); pool_put(dirhash_entry_pool, dirh_e); - dirh_e = LIST_FIRST(dirh-entries[hashline]); } } - dirh_e = LIST_FIRST(dirh-free_entries); - while (dirh_e) { + while ((dirh_e = LIST_FIRST(dirh-free_entries)) != NULL) { LIST_REMOVE(dirh_e, next); pool_put(dirhash_entry_pool, dirh_e); - dirh_e = LIST_FIRST(dirh-entries[hashline]); } dirh-flags = ~DIRH_COMPLETE;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sun May 3 22:39:50 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_drvctl.c Log Message: Pull up following revision(s) (requested by joerg in ticket #675): sys/kern/kern_drvctl.c: revision 1.24 Allow querying for root devices in the tree by specifying an empty device name. Ensure that l_devname is NUL-terminated and fail otherwise. OK cube@ To generate a diff of this commit: cvs rdiff -u -r1.19.6.2 -r1.19.6.3 src/sys/kern/kern_drvctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_drvctl.c diff -u src/sys/kern/kern_drvctl.c:1.19.6.2 src/sys/kern/kern_drvctl.c:1.19.6.3 --- src/sys/kern/kern_drvctl.c:1.19.6.2 Sat Apr 4 23:36:27 2009 +++ src/sys/kern/kern_drvctl.c Sun May 3 22:39:49 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_drvctl.c,v 1.19.6.2 2009/04/04 23:36:27 snj Exp $ */ +/* $NetBSD: kern_drvctl.c,v 1.19.6.3 2009/05/03 22:39:49 snj Exp $ */ /* * Copyright (c) 2004 @@ -27,7 +27,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_drvctl.c,v 1.19.6.2 2009/04/04 23:36:27 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_drvctl.c,v 1.19.6.3 2009/05/03 22:39:49 snj Exp $); #include sys/param.h #include sys/systm.h @@ -198,7 +198,11 @@ deviter_t di; int cnt = 0, idx, error = 0; - if ((d = device_find_by_xname(l-l_devname)) == NULL) + if (*l-l_devname == '\0') + d = (device_t)NULL; + else if (memchr(l-l_devname, 0, sizeof(l-l_devname)) == NULL) + return EINVAL; + else if ((d = device_find_by_xname(l-l_devname)) == NULL) return ENXIO; for (child = deviter_first(di, 0); child != NULL;
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Thu Apr 23 17:47:13 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_synch.c Log Message: Pull up following revision(s) (requested by yamt in ticket #720): sys/kern/kern_synch.c: revision 1.262 kpreempt: report a failure of cpu_kpreempt_enter. otherwise x86 trap() loops infinitely. PR/41202. To generate a diff of this commit: cvs rdiff -u -r1.254.2.5 -r1.254.2.6 src/sys/kern/kern_synch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_synch.c diff -u src/sys/kern/kern_synch.c:1.254.2.5 src/sys/kern/kern_synch.c:1.254.2.6 --- src/sys/kern/kern_synch.c:1.254.2.5 Fri Feb 6 01:56:19 2009 +++ src/sys/kern/kern_synch.c Thu Apr 23 17:47:13 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_synch.c,v 1.254.2.5 2009/02/06 01:56:19 snj Exp $ */ +/* $NetBSD: kern_synch.c,v 1.254.2.6 2009/04/23 17:47:13 snj Exp $ */ /*- * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009 @@ -69,7 +69,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_synch.c,v 1.254.2.5 2009/02/06 01:56:19 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_synch.c,v 1.254.2.6 2009/04/23 17:47:13 snj Exp $); #include opt_kstack.h #include opt_perfctrs.h @@ -376,6 +376,7 @@ static char in_critical_section; static char kernel_lock_held; static char is_softint; +static char cpu_kpreempt_enter_fail; bool kpreempt(uintptr_t where) @@ -434,6 +435,7 @@ * interrupt to retry later. */ splx(s); + failed = (uintptr_t)cpu_kpreempt_enter_fail; break; } /* Do it! */
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Tue Apr 7 23:43:16 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: uipc_mbuf.c Log Message: Pull up following revision(s) (requested by bouyer in ticket #674): sys/kern/uipc_mbuf.c: revision 1.132 m_split0(): If the newly allocated mbuf holds only the header, don't forget to set m_len to 0. Otherwise whatever will compute the size of this chain (including s_split() itself if called again on this chain) will get it wrong, leading to various issues. Bug exposed by the NFS server code with linux clients using TCP mounts. To generate a diff of this commit: cvs rdiff -u -r1.128 -r1.128.6.1 src/sys/kern/uipc_mbuf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_mbuf.c diff -u src/sys/kern/uipc_mbuf.c:1.128 src/sys/kern/uipc_mbuf.c:1.128.6.1 --- src/sys/kern/uipc_mbuf.c:1.128 Wed Jul 2 14:47:34 2008 +++ src/sys/kern/uipc_mbuf.c Tue Apr 7 23:43:16 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_mbuf.c,v 1.128 2008/07/02 14:47:34 matt Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.128.6.1 2009/04/07 23:43:16 snj Exp $ */ /*- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: uipc_mbuf.c,v 1.128 2008/07/02 14:47:34 matt Exp $); +__KERNEL_RCSID(0, $NetBSD: uipc_mbuf.c,v 1.128.6.1 2009/04/07 23:43:16 snj Exp $); #include opt_mbuftrace.h #include opt_ddb.h @@ -1048,6 +1048,7 @@ if (remain MHLEN) { /* m can't be the lead packet */ MH_ALIGN(n, 0); + n-m_len = 0; n-m_next = m_split(m, len, wait); if (n-m_next == 0) { (void) m_free(n);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Sat Apr 4 16:58:26 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: subr_workqueue.c Log Message: Pull up following revision(s) (requested by ad in ticket #651): sys/kern/subr_workqueue.c: revision 1.27 workqueue_finiqueue: our stack could be swapped out while enqueued to a worker thread. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.26.4.1 src/sys/kern/subr_workqueue.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_workqueue.c diff -u src/sys/kern/subr_workqueue.c:1.26 src/sys/kern/subr_workqueue.c:1.26.4.1 --- src/sys/kern/subr_workqueue.c:1.26 Mon Sep 15 10:43:29 2008 +++ src/sys/kern/subr_workqueue.c Sat Apr 4 16:58:25 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_workqueue.c,v 1.26 2008/09/15 10:43:29 rmind Exp $ */ +/* $NetBSD: subr_workqueue.c,v 1.26.4.1 2009/04/04 16:58:25 snj Exp $ */ /*- * Copyright (c)2002, 2005, 2006, 2007 YAMAMOTO Takashi, @@ -27,7 +27,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: subr_workqueue.c,v 1.26 2008/09/15 10:43:29 rmind Exp $); +__KERNEL_RCSID(0, $NetBSD: subr_workqueue.c,v 1.26.4.1 2009/04/04 16:58:25 snj Exp $); #include sys/param.h #include sys/cpu.h @@ -40,6 +40,8 @@ #include sys/condvar.h #include sys/queue.h +#include uvm/uvm_extern.h + typedef struct work_impl { SIMPLEQ_ENTRY(work_impl) wk_entry; } work_impl_t; @@ -203,12 +205,15 @@ workqueue_finiqueue(struct workqueue *wq, struct workqueue_queue *q) { struct workqueue_exitargs wqe; + lwp_t *l; KASSERT(wq-wq_func == workqueue_exit); wqe.wqe_q = q; KASSERT(SIMPLEQ_EMPTY(q-q_queue)); KASSERT(q-q_worker != NULL); + l = curlwp; + uvm_lwp_hold(l); mutex_enter(q-q_mutex); SIMPLEQ_INSERT_TAIL(q-q_queue, wqe.wqe_wk, wk_entry); cv_signal(q-q_cv); @@ -216,6 +221,7 @@ cv_wait(q-q_cv, q-q_mutex); } mutex_exit(q-q_mutex); + uvm_lwp_rele(l); mutex_destroy(q-q_mutex); cv_destroy(q-q_cv); }
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Apr 1 21:03:04 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_exec.c Log Message: Pull up following revision(s) (requested by christos in ticket #573): sys/kern/kern_exec.c: revision 1.286 don't enforce maxproc resource limits for root. To generate a diff of this commit: cvs rdiff -u -r1.280.4.2 -r1.280.4.3 src/sys/kern/kern_exec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_exec.c diff -u src/sys/kern/kern_exec.c:1.280.4.2 src/sys/kern/kern_exec.c:1.280.4.3 --- src/sys/kern/kern_exec.c:1.280.4.2 Wed Apr 1 00:25:22 2009 +++ src/sys/kern/kern_exec.c Wed Apr 1 21:03:04 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exec.c,v 1.280.4.2 2009/04/01 00:25:22 snj Exp $ */ +/* $NetBSD: kern_exec.c,v 1.280.4.3 2009/04/01 21:03:04 snj Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_exec.c,v 1.280.4.2 2009/04/01 00:25:22 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_exec.c,v 1.280.4.3 2009/04/01 21:03:04 snj Exp $); #include opt_ktrace.h #include opt_syscall_debug.h @@ -498,6 +498,7 @@ ksiginfoq_t kq; char *pathbuf; size_t pathbuflen; + uid_t uid; p = l-l_proc; @@ -517,9 +518,8 @@ * to call exec in order to do something useful. */ - if ((p-p_flag PK_SUGID) - chgproccnt(kauth_cred_getuid(l-l_cred), 0) - p-p_rlimit[RLIMIT_NPROC].rlim_cur) + if ((p-p_flag PK_SUGID) (uid = kauth_cred_getuid(l-l_cred)) != 0 + chgproccnt(uid, 0) p-p_rlimit[RLIMIT_NPROC].rlim_cur) return EAGAIN; oldlwpflags = l-l_flag (LW_SA | LW_SA_UPCALL);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Apr 1 21:25:35 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sys_sig.c Log Message: Pull up following revision(s) (requested by rmind in ticket #632): sys/kern/sys_sig.c: revision 1.22 PR/41094: Matteo Beccati: sigtimedwait returns EAGAIN instead of EINVAL if timeout is invalid To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.17.4.1 src/sys/kern/sys_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_sig.c diff -u src/sys/kern/sys_sig.c:1.17 src/sys/kern/sys_sig.c:1.17.4.1 --- src/sys/kern/sys_sig.c:1.17 Wed Oct 15 06:51:20 2008 +++ src/sys/kern/sys_sig.c Wed Apr 1 21:25:35 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_sig.c,v 1.17 2008/10/15 06:51:20 wrstuden Exp $ */ +/* $NetBSD: sys_sig.c,v 1.17.4.1 2009/04/01 21:25:35 snj Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_sig.c,v 1.17 2008/10/15 06:51:20 wrstuden Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_sig.c,v 1.17.4.1 2009/04/01 21:25:35 snj Exp $); #include opt_ptrace.h #include opt_compat_netbsd.h @@ -640,7 +640,7 @@ if (timo == 0 ts.tv_sec == 0 ts.tv_nsec 0) timo = 1; if (timo = 0) - return (EAGAIN); + return EINVAL; /* * Remember current uptime, it would be used in
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Apr 1 21:43:53 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: sys_sig.c Log Message: Pull up following revision(s) (requested by christos in ticket #638): sys/kern/sys_sig.c: revision 1.23 - use itimespecfix to detect invalid timespecs - use tstohz instead of mstohz to prevent overflow. To generate a diff of this commit: cvs rdiff -u -r1.17.4.1 -r1.17.4.2 src/sys/kern/sys_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_sig.c diff -u src/sys/kern/sys_sig.c:1.17.4.1 src/sys/kern/sys_sig.c:1.17.4.2 --- src/sys/kern/sys_sig.c:1.17.4.1 Wed Apr 1 21:25:35 2009 +++ src/sys/kern/sys_sig.c Wed Apr 1 21:43:53 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_sig.c,v 1.17.4.1 2009/04/01 21:25:35 snj Exp $ */ +/* $NetBSD: sys_sig.c,v 1.17.4.2 2009/04/01 21:43:53 snj Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: sys_sig.c,v 1.17.4.1 2009/04/01 21:25:35 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: sys_sig.c,v 1.17.4.2 2009/04/01 21:43:53 snj Exp $); #include opt_ptrace.h #include opt_compat_netbsd.h @@ -630,17 +630,16 @@ * Calculate timeout, if it was specified. */ if (SCARG(uap, timeout)) { - uint64_t ms; + error = (*fetch_timeout)(SCARG(uap, timeout), ts, sizeof(ts)); + if (error) + return error; - if ((error = (*fetch_timeout)(SCARG(uap, timeout), ts, sizeof(ts - return (error); + if ((error = itimespecfix(ts)) != 0) + return error; - ms = (ts.tv_sec * 1000) + (ts.tv_nsec / 100); - timo = mstohz(ms); - if (timo == 0 ts.tv_sec == 0 ts.tv_nsec 0) - timo = 1; - if (timo = 0) - return EINVAL; + timo = tstohz(ts); + if (timo == 0 ts.tv_sec == 0 ts.tv_nsec != 0) + timo++; /* * Remember current uptime, it would be used in
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Wed Apr 1 21:56:51 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_sig.c Log Message: Pull up following revision(s) (requested by drochner in ticket #640): sys/kern/kern_sig.c: revision 1.296 In sigput(), save the siginfo no matter whether SA_SIGINFO is set or not. There are also sigtimedwait(2) et al. to catch signals without invoking a signal handler. Fixes PR kern/41076 by Matteo Beccati (the first test case, where the signal is sent before sigwaitinfo(2) gets called). To generate a diff of this commit: cvs rdiff -u -r1.289.4.4 -r1.289.4.5 src/sys/kern/kern_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_sig.c diff -u src/sys/kern/kern_sig.c:1.289.4.4 src/sys/kern/kern_sig.c:1.289.4.5 --- src/sys/kern/kern_sig.c:1.289.4.4 Tue Mar 31 23:41:23 2009 +++ src/sys/kern/kern_sig.c Wed Apr 1 21:56:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.289.4.4 2009/03/31 23:41:23 snj Exp $ */ +/* $NetBSD: kern_sig.c,v 1.289.4.5 2009/04/01 21:56:50 snj Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_sig.c,v 1.289.4.4 2009/03/31 23:41:23 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_sig.c,v 1.289.4.5 2009/04/01 21:56:50 snj Exp $); #include opt_ptrace.h #include opt_compat_sunos.h @@ -543,14 +543,12 @@ /* * sigput: * - * Append a new ksiginfo element to the list of pending ksiginfo's, if - * we need to (e.g. SA_SIGINFO was requested). + * Append a new ksiginfo element to the list of pending ksiginfo's. */ static void sigput(sigpend_t *sp, struct proc *p, ksiginfo_t *ksi) { ksiginfo_t *kp; - struct sigaction *sa = SIGACTION_PS(p-p_sigacts, ksi-ksi_signo); KASSERT(mutex_owned(p-p_lock)); KASSERT((ksi-ksi_flags KSI_QUEUED) == 0); @@ -558,11 +556,9 @@ sigaddset(sp-sp_set, ksi-ksi_signo); /* - * If there is no siginfo, or is not required (and we don't add - * it for the benefit of ktrace, we are done). + * If there is no siginfo, we are done. */ - if (KSI_EMPTY_P(ksi) || - (!KTRPOINT(p, KTR_PSIG) (sa-sa_flags SA_SIGINFO) == 0)) + if (KSI_EMPTY_P(ksi)) return; KASSERT((ksi-ksi_flags KSI_FROMPOOL) != 0);
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Tue Mar 31 23:41:23 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_sig.c Log Message: Pull up following revision(s) (requested by rmind in ticket #620): sys/kern/kern_sig.c: revision 1.297 kpsignal2: do not start process (when it is stopped) for all termination signals (i.e. SA_KILL), just if SIGKILL (or SIGCONT). Improve comments. Make some functions static, remove unused sigrealloc() prototype. Fixes PR/39814. Similar patch reviewed by ad. To generate a diff of this commit: cvs rdiff -u -r1.289.4.3 -r1.289.4.4 src/sys/kern/kern_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_sig.c diff -u src/sys/kern/kern_sig.c:1.289.4.3 src/sys/kern/kern_sig.c:1.289.4.4 --- src/sys/kern/kern_sig.c:1.289.4.3 Mon Feb 2 19:50:20 2009 +++ src/sys/kern/kern_sig.c Tue Mar 31 23:41:23 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.289.4.3 2009/02/02 19:50:20 snj Exp $ */ +/* $NetBSD: kern_sig.c,v 1.289.4.4 2009/03/31 23:41:23 snj Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_sig.c,v 1.289.4.3 2009/02/02 19:50:20 snj Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_sig.c,v 1.289.4.4 2009/03/31 23:41:23 snj Exp $); #include opt_ptrace.h #include opt_compat_sunos.h @@ -106,13 +106,11 @@ static void ksiginfo_exechook(struct proc *, void *); static void proc_stop_callout(void *); - -int sigunwait(struct proc *, const ksiginfo_t *); -void sigput(sigpend_t *, struct proc *, ksiginfo_t *); -int sigpost(struct lwp *, sig_t, int, int, int); -int sigchecktrace(void); -void sigswitch(bool, int, int); -void sigrealloc(ksiginfo_t *); +static int sigchecktrace(void); +static int sigpost(struct lwp *, sig_t, int, int, int); +static void sigput(sigpend_t *, struct proc *, ksiginfo_t *); +static int sigunwait(struct proc *, const ksiginfo_t *); +static void sigswitch(bool, int, int); sigset_t contsigmask, stopsigmask, sigcantmask; static pool_cache_t sigacts_cache; /* memory pool for sigacts structures */ @@ -548,7 +546,7 @@ * Append a new ksiginfo element to the list of pending ksiginfo's, if * we need to (e.g. SA_SIGINFO was requested). */ -void +static void sigput(sigpend_t *sp, struct proc *p, ksiginfo_t *ksi) { ksiginfo_t *kp; @@ -883,10 +881,11 @@ KASSERT(!cpu_intr_p()); KASSERT(mutex_owned(proc_lock)); - if (pgrp) - LIST_FOREACH(p, pgrp-pg_members, p_pglist) - if (checkctty == 0 || p-p_lflag PL_CONTROLT) -kpsignal(p, ksi, data); + if (__predict_false(pgrp == 0)) + return; + LIST_FOREACH(p, pgrp-pg_members, p_pglist) + if (checkctty == 0 || p-p_lflag PL_CONTROLT) + kpsignal(p, ksi, data); } /* @@ -1037,7 +1036,7 @@ * Post a pending signal to an LWP. Returns non-zero if the LWP may * be able to take the signal. */ -int +static int sigpost(struct lwp *l, sig_t action, int prop, int sig, int idlecheck) { int rv, masked; @@ -1069,13 +1068,14 @@ } /* - * SIGCONT can be masked, but must always restart stopped LWPs. + * SIGCONT can be masked, but if LWP is stopped, it needs restart. + * Note: SIGKILL and SIGSTOP cannot be masked. */ #if KERN_SA if (p-p_sa != NULL) masked = sigismember(p-p_sa-sa_sigmask, sig); else -#endif /* KERN_SA */ +#endif masked = sigismember(l-l_sigmask, sig); if (masked ((prop SA_CONT) == 0 || l-l_stat != LSSTOP)) { lwp_unlock(l); @@ -1173,7 +1173,7 @@ * Find an LWP within process p that is waiting on signal ksi, and hand * it on. */ -int +static int sigunwait(struct proc *p, const ksiginfo_t *ksi) { struct lwp *l; @@ -1388,8 +1388,6 @@ */ if ((prop SA_CONT) != 0 action == SIG_DFL) goto out; - - sigput(p-p_sigpend, p, kp); } else { /* * Process is stopped or stopping. If traced, then no @@ -1398,7 +1396,10 @@ if ((p-p_slflag PSL_TRACED) != 0 signo != SIGKILL) goto out; - if ((prop (SA_CONT | SA_KILL)) != 0) { + /* + * Run the process only if sending SIGCONT or SIGKILL. + */ + if ((prop SA_CONT) != 0 || signo == SIGKILL) { /* * Re-adjust p_nstopchild if the process wasn't * collected by its parent. @@ -1409,27 +1410,28 @@ p-p_pptr-p_nstopchild--; /* - * If SIGCONT is default (or ignored), we continue - * the process but don't leave the signal in - * ps_siglist, as it has no further action. If - * SIGCONT is held, we continue the process and - * leave the signal in ps_siglist. If the process - * catches SIGCONT, let it handle the signal itself. - * If it isn't waiting on an event, then it goes - * back to run state. Otherwise, process goes back - * to sleep state. + * Do not make signal pending if SIGCONT is default. + * + * If the process catches SIGCONT, let it handle the + * signal itself (if waiting on event -
CVS commit: [netbsd-5] src/sys/kern
Module Name:src Committed By: snj Date: Thu Mar 26 17:17:31 UTC 2009 Modified Files: src/sys/kern [netbsd-5]: kern_uidinfo.c Log Message: Pull up following revision(s) (requested by ad in ticket #601): sys/kern/kern_uidinfo.c: revision 1.5 uid_init: maxproc - maxcpus To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.3.6.1 src/sys/kern/kern_uidinfo.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_uidinfo.c diff -u src/sys/kern/kern_uidinfo.c:1.3 src/sys/kern/kern_uidinfo.c:1.3.6.1 --- src/sys/kern/kern_uidinfo.c:1.3 Tue Oct 14 09:17:23 2008 +++ src/sys/kern/kern_uidinfo.c Thu Mar 26 17:17:31 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_uidinfo.c,v 1.3 2008/10/14 09:17:23 ad Exp $ */ +/* $NetBSD: kern_uidinfo.c,v 1.3.6.1 2009/03/26 17:17:31 snj Exp $ */ /*- * Copyright (c) 1982, 1986, 1991, 1993 @@ -35,7 +35,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: kern_uidinfo.c,v 1.3 2008/10/14 09:17:23 ad Exp $); +__KERNEL_RCSID(0, $NetBSD: kern_uidinfo.c,v 1.3.6.1 2009/03/26 17:17:31 snj Exp $); #include sys/param.h #include sys/systm.h @@ -43,6 +43,7 @@ #include sys/proc.h #include sys/atomic.h #include sys/uidinfo.h +#include sys/cpu.h static SLIST_HEAD(uihashhead, uidinfo) *uihashtbl; static u_long uihash; @@ -58,7 +59,7 @@ * write-back for every modified 'uidinfo', thus we try to keep the * lists short. */ - const u_int uihash_sz = (maxproc 1 ? 1024 : 64); + const u_int uihash_sz = (maxcpus 1 ? 1024 : 64); uihashtbl = hashinit(uihash_sz, HASH_SLIST, true, uihash);