CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Wed May 1 09:48:56 UTC 2019 Modified Files: src/sys/kern [netbsd-7]: sys_pipe.c Log Message: Pull up following revision(s) (requested by mlelstv in ticket #1692): sys/kern/sys_pipe.c: revision 1.147 sys/kern/sys_pipe.c: revision 1.148 Clean up pipe structure before recycling it. Handle half-closed pipes in FIONWRITE and FIONSPACE. To generate a diff of this commit: cvs rdiff -u -r1.138 -r1.138.4.1 src/sys/kern/sys_pipe.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_pipe.c diff -u src/sys/kern/sys_pipe.c:1.138 src/sys/kern/sys_pipe.c:1.138.4.1 --- src/sys/kern/sys_pipe.c:1.138 Tue Feb 25 18:30:11 2014 +++ src/sys/kern/sys_pipe.c Wed May 1 09:48:56 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_pipe.c,v 1.138 2014/02/25 18:30:11 pooka Exp $ */ +/* $NetBSD: sys_pipe.c,v 1.138.4.1 2019/05/01 09:48:56 martin Exp $ */ /*- * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.138 2014/02/25 18:30:11 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.138.4.1 2019/05/01 09:48:56 martin Exp $"); #include #include @@ -1107,10 +1107,12 @@ pipe_ioctl(file_t *fp, u_long cmd, void case FIONWRITE: /* Look at other side */ - pipe = pipe->pipe_peer; mutex_enter(lock); + pipe = pipe->pipe_peer; + if (pipe == NULL) + *(int *)data = 0; #ifndef PIPE_NODIRECT - if (pipe->pipe_state & PIPE_DIRECTW) + else if (pipe->pipe_state & PIPE_DIRECTW) *(int *)data = pipe->pipe_map.cnt; else #endif @@ -1120,8 +1122,11 @@ pipe_ioctl(file_t *fp, u_long cmd, void case FIONSPACE: /* Look at other side */ - pipe = pipe->pipe_peer; mutex_enter(lock); + pipe = pipe->pipe_peer; + if (pipe == NULL) + *(int *)data = 0; + else #ifndef PIPE_NODIRECT /* * If we're in direct-mode, we don't really have a @@ -1346,6 +1351,8 @@ pipeclose(struct pipe *pipe) free_resources: pipe->pipe_pgid = 0; pipe->pipe_state = PIPE_SIGNALR; + pipe->pipe_peer = NULL; + pipe->pipe_lock = NULL; pipe_free_kmem(pipe); if (pipe->pipe_kmem != 0) { pool_cache_put(pipe_rd_cache, pipe);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: msaitoh Date: Tue Apr 16 03:52:34 UTC 2019 Modified Files: src/sys/kern [netbsd-7]: sys_mqueue.c Log Message: Pull up following revision(s) (requested by martin in ticket #1688): sys/kern/sys_mqueue.c: revision 1.44 mq_send1: fix argument validation and reject too large lengths early. Discovered by Andy Nguyen. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.36.4.1 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.36 src/sys/kern/sys_mqueue.c:1.36.4.1 --- src/sys/kern/sys_mqueue.c:1.36 Tue Feb 25 18:30:11 2014 +++ src/sys/kern/sys_mqueue.c Tue Apr 16 03:52:34 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_mqueue.c,v 1.36 2014/02/25 18:30:11 pooka Exp $ */ +/* $NetBSD: sys_mqueue.c,v 1.36.4.1 2019/04/16 03:52:34 msaitoh Exp $ */ /* * Copyright (c) 2007-2011 Mindaugas Rasiukevicius @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.36 2014/02/25 18:30:11 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.36.4.1 2019/04/16 03:52:34 msaitoh Exp $"); #include #include @@ -794,6 +794,8 @@ mq_send1(mqd_t mqdes, const char *msg_pt return EINVAL; /* Allocate a new message */ + if (msg_len > mq_max_msgsize) + return EMSGSIZE; size = sizeof(struct mq_msg) + msg_len; if (size > mq_max_msgsize) return EMSGSIZE;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sun Feb 24 10:53:32 UTC 2019 Modified Files: src/sys/kern [netbsd-7]: kern_time.c Log Message: Pull up following revision(s) (requested by mlelstv in ticket #1196): sys/kern/kern_time.c: revision 1.196 The callout is used by any nonvirtual timer including CLOCK_MONOTONIC and needs to be initialized. Detected by [syzkaller]. To generate a diff of this commit: cvs rdiff -u -r1.179.8.5 -r1.179.8.6 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.179.8.5 src/sys/kern/kern_time.c:1.179.8.6 --- src/sys/kern/kern_time.c:1.179.8.5 Fri Feb 1 11:06:20 2019 +++ src/sys/kern/kern_time.c Sun Feb 24 10:53:32 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_time.c,v 1.179.8.5 2019/02/01 11:06:20 martin Exp $ */ +/* $NetBSD: kern_time.c,v 1.179.8.6 2019/02/24 10:53:32 martin Exp $ */ /*- * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.5 2019/02/01 11:06:20 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.6 2019/02/24 10:53:32 martin Exp $"); #include #include @@ -1141,7 +1141,7 @@ dosetitimer(struct proc *p, int which, s pt->pt_type = which; pt->pt_entry = which; pt->pt_queued = false; - if (pt->pt_type == CLOCK_REALTIME) + if (!CLOCK_VIRTUAL_P(which)) callout_init(&pt->pt_ch, CALLOUT_MPSAFE); else pt->pt_active = 0;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Fri Feb 1 11:06:20 UTC 2019 Modified Files: src/sys/kern [netbsd-7]: kern_time.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1678): sys/kern/kern_time.c: revision 1.190 sys/kern/kern_time.c: revision 1.194 Fix stack info leak. There are 4 bytes of padding in struct timeval. Looks like there are other leaks related to timeval in this file. [ 133.414352] kleak: Possible leak in copyout: [len=16, leaked=4] [ 133.414352] #0 0x80224d0a in kleak_note [ 133.424360] #1 0x80224d8a in kleak_copyout [ 133.434361] #2 0x80b5fd79 in sys___gettimeofday50 [ 133.434361] #3 0x8025a89c in sy_call [ 133.444351] #4 0x8025aace in sy_invoke [ 133.454365] #5 0x8025ab54 in syscall - Fix kernel info leaks. To generate a diff of this commit: cvs rdiff -u -r1.179.8.4 -r1.179.8.5 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.179.8.4 src/sys/kern/kern_time.c:1.179.8.5 --- src/sys/kern/kern_time.c:1.179.8.4 Thu Dec 27 12:00:10 2018 +++ src/sys/kern/kern_time.c Fri Feb 1 11:06:20 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_time.c,v 1.179.8.4 2018/12/27 12:00:10 martin Exp $ */ +/* $NetBSD: kern_time.c,v 1.179.8.5 2019/02/01 11:06:20 martin Exp $ */ /*- * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.4 2018/12/27 12:00:10 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.5 2019/02/01 11:06:20 martin Exp $"); #include #include @@ -388,6 +388,7 @@ sys___gettimeofday50(struct lwp *l, cons struct timezone tzfake; if (SCARG(uap, tp)) { + memset(&atv, 0, sizeof(atv)); microtime(&atv); error = copyout(&atv, SCARG(uap, tp), sizeof(atv)); if (error) @@ -487,6 +488,7 @@ adjtime1(const struct timeval *delta, st extern int64_t time_adjtime; /* in kern_ntptime.c */ if (olddelta) { + memset(olddelta, 0, sizeof(*olddelta)); mutex_spin_enter(&timecounter_lock); olddelta->tv_sec = time_adjtime / 100; olddelta->tv_usec = time_adjtime % 100;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Thu Jan 24 14:14:13 UTC 2019 Modified Files: src/sys/kern [netbsd-7]: kern_ntptime.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1675): sys/kern/kern_ntptime.c: revision 1.60 Zero out the ntptimeval structure to prevent a 4 byte kernel stack disclosure. Reported by Thomas Barabosch. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.55.4.1 src/sys/kern/kern_ntptime.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_ntptime.c diff -u src/sys/kern/kern_ntptime.c:1.55 src/sys/kern/kern_ntptime.c:1.55.4.1 --- src/sys/kern/kern_ntptime.c:1.55 Tue Feb 25 18:30:11 2014 +++ src/sys/kern/kern_ntptime.c Thu Jan 24 14:14:13 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ntptime.c,v 1.55 2014/02/25 18:30:11 pooka Exp $ */ +/* $NetBSD: kern_ntptime.c,v 1.55.4.1 2019/01/24 14:14:13 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ #include /* __FBSDID("$FreeBSD: src/sys/kern/kern_ntptime.c,v 1.59 2005/05/28 14:34:41 rwatson Exp $"); */ -__KERNEL_RCSID(0, "$NetBSD: kern_ntptime.c,v 1.55 2014/02/25 18:30:11 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_ntptime.c,v 1.55.4.1 2019/01/24 14:14:13 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_ntp.h" @@ -239,6 +239,7 @@ static void hardupdate(long offset); void ntp_gettime(struct ntptimeval *ntv) { + memset(ntv, 0, sizeof(*ntv)); mutex_spin_enter(&timecounter_lock); nanotime(&ntv->time);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Thu Dec 27 12:00:10 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: kern_time.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1667): sys/kern/kern_time.c: revision 1.191 Fix kernel info leak. There are 2x4 bytes of padding in struct itimerval. [ 738.451860] kleak: Possible leak in copyout: [len=32, leaked=8] [ 738.481840] #0 0x80b7c42a in kleak_note [ 738.491821] #1 0x80b7c4aa in kleak_copyout [ 738.501806] #2 0x80b6154e in sys___getitimer50 [ 738.511778] #3 0x80b61e39 in sys___setitimer50 [ 738.521781] #4 0x8025ab3c in sy_call [ 738.521781] #5 0x8025ad6e in sy_invoke [ 738.531808] #6 0x8025adf4 in syscall To generate a diff of this commit: cvs rdiff -u -r1.179.8.3 -r1.179.8.4 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.179.8.3 src/sys/kern/kern_time.c:1.179.8.4 --- src/sys/kern/kern_time.c:1.179.8.3 Fri Dec 14 12:04:26 2018 +++ src/sys/kern/kern_time.c Thu Dec 27 12:00:10 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_time.c,v 1.179.8.3 2018/12/14 12:04:26 martin Exp $ */ +/* $NetBSD: kern_time.c,v 1.179.8.4 2018/12/27 12:00:10 martin Exp $ */ /*- * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.3 2018/12/14 12:04:26 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.4 2018/12/27 12:00:10 martin Exp $"); #include #include @@ -1030,6 +1030,7 @@ sys___getitimer50(struct lwp *l, const s struct itimerval aitv; int error; + memset(&aitv, 0, sizeof(aitv)); error = dogetitimer(p, SCARG(uap, which), &aitv); if (error) return error;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Wed Dec 12 11:35:41 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: sys_sig.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1664): sys/kern/sys_sig.c: revision 1.47 Fix kernel info leak, 4 bytes of padding in struct _ksiginfo. Maybe we should just set _pad to zero on LP64? + Possible info leak: [len=40, leaked=4] | #0 0x80baf397 in kleak_copyout | #1 0x80bda817 in sigtimedwait1 | #2 0x80bdab95 in sys_sigtimedwait50 | #3 0x80259c42 in syscall To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.42.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.42 src/sys/kern/sys_sig.c:1.42.4.1 --- src/sys/kern/sys_sig.c:1.42 Fri Feb 14 16:35:11 2014 +++ src/sys/kern/sys_sig.c Wed Dec 12 11:35:41 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_sig.c,v 1.42 2014/02/14 16:35:11 christos Exp $ */ +/* $NetBSD: sys_sig.c,v 1.42.4.1 2018/12/12 11:35:41 martin Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.42 2014/02/14 16:35:11 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.42.4.1 2018/12/12 11:35:41 martin Exp $"); #include #include @@ -759,6 +759,8 @@ sigtimedwait1(struct lwp *l, const struc */ sigminusset(&sigcantmask, &l->l_sigwaitset); + memset(&ksi.ksi_info, 0, sizeof(ksi.ksi_info)); + mutex_enter(p->p_lock); /* Check for pending signals in the process, if no - then in LWP. */
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Fri Nov 30 10:36:09 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: kern_sig.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1661): sys/kern/kern_sig.c: revision 1.350 Fix kernel info leak, 4 bytes of padding at the end of struct sigaction. + Possible info leak: [len=32, leaked=4] | #0 0x80baf327 in kleak_copyout | #1 0x80bd9ca8 in sys___sigaction_sigtramp | #2 0x80259c42 in syscall To generate a diff of this commit: cvs rdiff -u -r1.319.4.1 -r1.319.4.2 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.319.4.1 src/sys/kern/kern_sig.c:1.319.4.2 --- src/sys/kern/kern_sig.c:1.319.4.1 Thu Nov 5 09:21:30 2015 +++ src/sys/kern/kern_sig.c Fri Nov 30 10:36:09 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.319.4.1 2015/11/05 09:21:30 snj Exp $ */ +/* $NetBSD: kern_sig.c,v 1.319.4.2 2018/11/30 10:36:09 martin Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.319.4.1 2015/11/05 09:21:30 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.319.4.2 2018/11/30 10:36:09 martin Exp $"); #include "opt_ptrace.h" #include "opt_compat_sunos.h" @@ -191,6 +191,13 @@ signal_listener_cb(kauth_cred_t cred, ka return result; } +static int +sigacts_ctor(void *arg __unused, void *obj, int flags __unused) +{ + memset(obj, 0, sizeof(struct sigacts)); + return 0; +} + /* * signal_init: * @@ -204,7 +211,7 @@ signal_init(void) sigacts_cache = pool_cache_init(sizeof(struct sigacts), 0, 0, 0, "sigacts", sizeof(struct sigacts) > PAGE_SIZE ? - &sigactspool_allocator : NULL, IPL_NONE, NULL, NULL, NULL); + &sigactspool_allocator : NULL, IPL_NONE, sigacts_ctor, NULL, NULL); ksiginfo_cache = pool_cache_init(sizeof(ksiginfo_t), 0, 0, 0, "ksiginfo", NULL, IPL_VM, NULL, NULL, NULL);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Thu Nov 29 08:56:45 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: kern_time.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1660): sys/kern/kern_time.c: revision 1.192 Fix kernel info leak. + Possible info leak: [len=32, leaked=16] | #0 0x80baf3a7 in kleak_copyout | #1 0x80b940f8 in sys___timer_settime50 | #2 0x80259c42 in syscall To generate a diff of this commit: cvs rdiff -u -r1.179.8.1 -r1.179.8.2 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.179.8.1 src/sys/kern/kern_time.c:1.179.8.2 --- src/sys/kern/kern_time.c:1.179.8.1 Thu Mar 3 15:42:26 2016 +++ src/sys/kern/kern_time.c Thu Nov 29 08:56:45 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_time.c,v 1.179.8.1 2016/03/03 15:42:26 martin Exp $ */ +/* $NetBSD: kern_time.c,v 1.179.8.2 2018/11/29 08:56:45 martin Exp $ */ /*- * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.1 2016/03/03 15:42:26 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.2 2018/11/29 08:56:45 martin Exp $"); #include #include @@ -566,6 +566,7 @@ timer_create1(timer_t *tid, clockid_t id pts = timers_alloc(p); pt = pool_get(&ptimer_pool, PR_WAITOK); + memset(pt, 0, sizeof(*pt)); if (evp != NULL) { if (((error = (*fetch_event)(evp, &pt->pt_ev, sizeof(pt->pt_ev))) != 0) ||
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Wed Nov 28 19:39:56 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: kern_exec.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1658): sys/kern/kern_exec.c: revision 1.462 Fix stack info leak. There are 2x4 bytes of padding in struct ps_strings. [ 223.896199] kleak: Possible leak in copyout: [len=32, leaked=8] [ 223.906430] #0 0x80224d0a in kleak_note [ 223.906430] #1 0x80224d8a in kleak_copyout [ 223.918363] #2 0x80b1e26c in copyoutpsstrs [ 223.926560] #3 0x80b1e331 in copyoutargs [ 223.936216] #4 0x80b21768 in execve_runproc [ 223.946225] #5 0x80b21cc9 in execve1 [ 223.946225] #6 0x8025a89c in sy_call [ 223.956225] #7 0x8025aace in sy_invoke [ 223.966232] #8 0x8025ab54 in syscall To generate a diff of this commit: cvs rdiff -u -r1.408.2.5 -r1.408.2.6 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.408.2.5 src/sys/kern/kern_exec.c:1.408.2.6 --- src/sys/kern/kern_exec.c:1.408.2.5 Sun Feb 25 21:16:07 2018 +++ src/sys/kern/kern_exec.c Wed Nov 28 19:39:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exec.c,v 1.408.2.5 2018/02/25 21:16:07 snj Exp $ */ +/* $NetBSD: kern_exec.c,v 1.408.2.6 2018/11/28 19:39:56 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.408.2.5 2018/02/25 21:16:07 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.408.2.6 2018/11/28 19:39:56 martin Exp $"); #include "opt_exec.h" #include "opt_execfmt.h" @@ -1391,6 +1391,8 @@ copyoutargs(struct execve_data * restric struct proc *p = l->l_proc; int error; + memset(&data->ed_arginfo, 0, sizeof(data->ed_arginfo)); + /* remember information about the process */ data->ed_arginfo.ps_nargvstr = data->ed_argc; data->ed_arginfo.ps_nenvstr = data->ed_envc;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Wed Nov 21 12:12:15 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: kern_event.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1653): sys/kern/kern_event.c: revision 1.104 Fix kernel info leak. There are 4 bytes of padding in struct kevent. [ 287.537676] kleak: Possible leak in copyout: [len=40, leaked=4] [ 287.537676] #0 0x80b7c41a in kleak_note [ 287.547673] #1 0x80b7c49a in kleak_copyout [ 287.557677] #2 0x80b1d32d in kqueue_scan.isra.1.constprop.2 [ 287.557677] #3 0x80b1dc6a in kevent1 [ 287.567683] #4 0x80b1dcb0 in sys___kevent50 [ 287.567683] #5 0x8025ab3c in sy_call [ 287.577688] #6 0x8025ad6e in sy_invoke [ 287.587693] #7 0x8025adf4 in syscall To generate a diff of this commit: cvs rdiff -u -r1.80.2.2 -r1.80.2.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.80.2.2 src/sys/kern/kern_event.c:1.80.2.3 --- src/sys/kern/kern_event.c:1.80.2.2 Sat Jul 8 16:53:24 2017 +++ src/sys/kern/kern_event.c Wed Nov 21 12:12:15 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_event.c,v 1.80.2.2 2017/07/08 16:53:24 snj Exp $ */ +/* $NetBSD: kern_event.c,v 1.80.2.3 2018/11/21 12:12:15 martin Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.80.2.2 2017/07/08 16:53:24 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.80.2.3 2018/11/21 12:12:15 martin Exp $"); #include #include @@ -584,6 +584,7 @@ filt_proc(struct knote *kn, long hint) * event with the parent's pid. Register knote with new * process. */ + memset(&kev, 0, sizeof(kev)); kev.ident = hint & NOTE_PDATAMASK; /* pid */ kev.filter = kn->kn_filter; kev.flags = kn->kn_flags | EV_ADD | EV_ENABLE | EV_FLAG1;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Tue May 22 17:35:38 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: uipc_mbuf.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1606): sys/kern/uipc_mbuf.c: revision 1.214 Revert my rev1.190, remove the M_READONLY check. The initial code was correct: what is read-only is the mbuf storage, not the mbuf itself. The storage contains the packet payload, and never has anything related to mbufs. So it is fine to remove M_PKTHDR on mbufs that have a read-only storage. In fact it was kind of obvious, since several places already manually remove M_PKTHDR without taking care of the external storage. To generate a diff of this commit: cvs rdiff -u -r1.158.4.4 -r1.158.4.5 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.158.4.4 src/sys/kern/uipc_mbuf.c:1.158.4.5 --- src/sys/kern/uipc_mbuf.c:1.158.4.4 Thu May 3 15:13:36 2018 +++ src/sys/kern/uipc_mbuf.c Tue May 22 17:35:38 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_mbuf.c,v 1.158.4.4 2018/05/03 15:13:36 martin Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.158.4.5 2018/05/22 17:35:38 martin Exp $ */ /*- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.158.4.4 2018/05/03 15:13:36 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.158.4.5 2018/05/22 17:35:38 martin Exp $"); #include "opt_mbuftrace.h" #include "opt_nmbclusters.h" @@ -458,11 +458,6 @@ m_pkthdr_remove(struct mbuf *m) { KASSERT(m->m_flags & M_PKTHDR); - if (M_READONLY(m)) { - /* Nothing we can do. */ - return; - } - m_tag_delete_chain(m, NULL); m->m_flags &= ~M_PKTHDR; memset(&m->m_pkthdr, 0, sizeof(m->m_pkthdr));
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sun May 6 09:53:27 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: kern_runq.c Log Message: Pull up following revision(s) (requested by mlelstv in ticket #1603): sys/kern/kern_runq.c: revision 1.46 When balancing threads over multiple CPUs, use fixpoint arithmetic for averages. Otherwise the decisions can be heavily biased by rounding errors. Add sysctl kern.sched_average_weight to change the weight of historical data, the default is 50%. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.43.2.1 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.43 src/sys/kern/kern_runq.c:1.43.2.1 --- src/sys/kern/kern_runq.c:1.43 Sun Aug 3 19:14:24 2014 +++ src/sys/kern/kern_runq.c Sun May 6 09:53:27 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_runq.c,v 1.43 2014/08/03 19:14:24 wiz Exp $ */ +/* $NetBSD: kern_runq.c,v 1.43.2.1 2018/05/06 09:53:27 martin Exp $ */ /* * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.43 2014/08/03 19:14:24 wiz Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.43.2.1 2018/05/06 09:53:27 martin Exp $"); #include #include @@ -78,7 +78,7 @@ typedef struct { uint32_t r_bitmap[PRI_COUNT >> BITMAP_SHIFT]; /* Counters */ u_int r_count; /* Count of the threads */ - u_int r_avgcount; /* Average count of threads */ + u_int r_avgcount; /* Average count of threads (* 256) */ u_int r_mcount; /* Count of migratable threads */ /* Runqueues */ queue_t r_rt_queue[PRI_RT_COUNT]; @@ -116,6 +116,7 @@ int sched_kpreempt_pri = 1000; static u_int cacheht_time; /* Cache hotness time */ static u_int min_catch; /* Minimal LWP count for catching */ static u_int balance_period; /* Balance period */ +static u_int average_weight; /* Weight old thread count average */ static struct cpu_info *worker_ci; /* Victim CPU */ #ifdef MULTIPROCESSOR static struct callout balance_ch; /* Callout of balancer */ @@ -132,6 +133,8 @@ runq_init(void) /* Minimal count of LWPs for catching */ min_catch = 1; + /* Weight of historical average */ + average_weight = 50; /* 0.5 */ /* Initialize balancing callout and run it */ #ifdef MULTIPROCESSOR @@ -519,6 +522,10 @@ sched_balance(void *nocallout) runqueue_t *ci_rq; CPU_INFO_ITERATOR cii; u_int highest; + u_int weight; + + /* sanitize sysctl value */ + weight = MIN(average_weight, 100); hci = curcpu(); highest = 0; @@ -527,8 +534,15 @@ sched_balance(void *nocallout) for (CPU_INFO_FOREACH(cii, ci)) { ci_rq = ci->ci_schedstate.spc_sched_info; - /* Average count of the threads */ - ci_rq->r_avgcount = (ci_rq->r_avgcount + ci_rq->r_mcount) >> 1; + /* + * Average count of the threads + * + * The average is computed as a fixpoint number with + * 8 fractional bits. + */ + ci_rq->r_avgcount = ( + weight * ci_rq->r_avgcount + (100 - weight) * 256 * ci_rq->r_mcount + ) / 100; /* Look for CPU with the highest average */ if (ci_rq->r_avgcount > highest) { @@ -831,6 +845,12 @@ SYSCTL_SETUP(sysctl_sched_setup, "sysctl CTL_CREATE, CTL_EOL); sysctl_createv(clog, 0, &node, NULL, CTLFLAG_PERMANENT | CTLFLAG_READWRITE, + CTLTYPE_INT, "average_weight", + SYSCTL_DESCR("Thread count averaging weight (in percent)"), + NULL, 0, &average_weight, 0, + CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, &node, NULL, + CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "min_catch", SYSCTL_DESCR("Minimal count of threads for catching"), NULL, 0, &min_catch, 0,
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Thu May 3 15:13:36 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: uipc_mbuf.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1602): sys/kern/uipc_mbuf.c: revision 1.211 (via patch) Modify m_defrag, so that it never frees the first mbuf of the chain. While here use the given 'flags' argument, and not M_DONTWAIT. We have a problem with several drivers: they poll an mbuf chain from their queues and call m_defrag on them, but m_defrag could update the mbuf pointer, so the mbuf in the queue is no longer valid. It is not easy to fix each driver, because doing pop+push will reorder the queue, and we don't really want that to happen. This problem was independently spotted by me, Kengo, Masanobu, and other people too it seems (perhaps PR/53218). Now m_defrag leaves the first mbuf in place, and compresses the chain only starting from the second mbuf in the chain. It is important not to compress the first mbuf with hacks, because the storage of this first mbuf may be shared with other mbufs. To generate a diff of this commit: cvs rdiff -u -r1.158.4.3 -r1.158.4.4 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.158.4.3 src/sys/kern/uipc_mbuf.c:1.158.4.4 --- src/sys/kern/uipc_mbuf.c:1.158.4.3 Tue Apr 17 08:27:18 2018 +++ src/sys/kern/uipc_mbuf.c Thu May 3 15:13:36 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_mbuf.c,v 1.158.4.3 2018/04/17 08:27:18 martin Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.158.4.4 2018/05/03 15:13:36 martin Exp $ */ /*- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.158.4.3 2018/04/17 08:27:18 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.158.4.4 2018/05/03 15:13:36 martin Exp $"); #include "opt_mbuftrace.h" #include "opt_nmbclusters.h" @@ -1376,30 +1376,35 @@ m_makewritable(struct mbuf **mp, int off } /* - * Copy the mbuf chain to a new mbuf chain that is as short as possible. - * Return the new mbuf chain on success, NULL on failure. On success, - * free the old mbuf chain. + * Compress the mbuf chain. Return the new mbuf chain on success, NULL on + * failure. The first mbuf is preserved, and on success the pointer returned + * is the same as the one passed. */ struct mbuf * m_defrag(struct mbuf *mold, int flags) { struct mbuf *m0, *mn, *n; - size_t sz = mold->m_pkthdr.len; + int sz; #ifdef DIAGNOSTIC if ((mold->m_flags & M_PKTHDR) == 0) panic("m_defrag: not a mbuf chain header"); #endif - m0 = m_gethdr(flags, MT_DATA); + if (mold->m_next == NULL) + return mold; + + m0 = m_get(flags, MT_DATA); if (m0 == NULL) return NULL; - M_COPY_PKTHDR(m0, mold); mn = m0; + sz = mold->m_pkthdr.len - mold->m_len; + KASSERT(sz >= 0); + do { - if (sz > MHLEN) { - MCLGET(mn, M_DONTWAIT); + if (sz > MLEN) { + MCLGET(mn, flags); if ((mn->m_flags & M_EXT) == 0) { m_freem(m0); return NULL; @@ -1415,7 +1420,7 @@ m_defrag(struct mbuf *mold, int flags) if (sz > 0) { /* need more mbufs */ - n = m_get(M_NOWAIT, MT_DATA); + n = m_get(flags, MT_DATA); if (n == NULL) { m_freem(m0); return NULL; @@ -1426,9 +1431,10 @@ m_defrag(struct mbuf *mold, int flags) } } while (sz > 0); - m_freem(mold); + m_freem(mold->m_next); + mold->m_next = m0; - return m0; + return mold; } int
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Tue Apr 17 08:27:18 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: uipc_mbuf.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1598): sys/kern/uipc_mbuf.c: revision 1.190 If the mbuf is shared leave M_PKTHDR in place. Given where this function is called from that's not supposed to happen, but I'm growing unconfident about our mbuf code. To generate a diff of this commit: cvs rdiff -u -r1.158.4.2 -r1.158.4.3 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.158.4.2 src/sys/kern/uipc_mbuf.c:1.158.4.3 --- src/sys/kern/uipc_mbuf.c:1.158.4.2 Thu Apr 5 11:48:13 2018 +++ src/sys/kern/uipc_mbuf.c Tue Apr 17 08:27:18 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_mbuf.c,v 1.158.4.2 2018/04/05 11:48:13 martin Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.158.4.3 2018/04/17 08:27:18 martin Exp $ */ /*- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.158.4.2 2018/04/05 11:48:13 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.158.4.3 2018/04/17 08:27:18 martin Exp $"); #include "opt_mbuftrace.h" #include "opt_nmbclusters.h" @@ -458,6 +458,11 @@ m_pkthdr_remove(struct mbuf *m) { KASSERT(m->m_flags & M_PKTHDR); + if (M_READONLY(m)) { + /* Nothing we can do. */ + return; + } + m_tag_delete_chain(m, NULL); m->m_flags &= ~M_PKTHDR; memset(&m->m_pkthdr, 0, sizeof(m->m_pkthdr));
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Sun Feb 25 23:27:17 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: subr_tftproot.c Log Message: Pull up following revision(s) (requested by manu in ticket #1573): sys/kern/subr_tftproot.c: 1.20 Fix md(4) double attachment in TFTPROOT option The mdattach() call in tftproot_dhcpboot() has probably always been useless, but it seems it became harmful, as it causes 7.1.1 to deadlock during boot. To generate a diff of this commit: cvs rdiff -u -r1.12.12.2 -r1.12.12.3 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.12.12.2 src/sys/kern/subr_tftproot.c:1.12.12.3 --- src/sys/kern/subr_tftproot.c:1.12.12.2 Mon Apr 6 01:37:29 2015 +++ src/sys/kern/subr_tftproot.c Sun Feb 25 23:27:17 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_tftproot.c,v 1.12.12.2 2015/04/06 01:37:29 snj Exp $ */ +/* $NetBSD: subr_tftproot.c,v 1.12.12.3 2018/02/25 23:27:17 snj Exp $ */ /*- * Copyright (c) 2007 Emmanuel Dreyfus, all rights reserved. @@ -39,7 +39,7 @@ #include "opt_md.h" #include -__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.12.12.2 2015/04/06 01:37:29 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.12.12.3 2018/02/25 23:27:17 snj Exp $"); #include #include @@ -65,8 +65,6 @@ __KERNEL_RCSID(0, "$NetBSD: subr_tftproo #include #include -extern void mdattach(int); - /* * Copied from */ @@ -333,7 +331,6 @@ tftproot_getfile(struct tftproot_handle DPRINTF(("%s():%d RAMdisk loaded: %ld@%p\n", __func__, __LINE__, trh->trh_len, trh->trh_base)); md_root_setconf(trh->trh_base, trh->trh_len); - mdattach(0); error = 0; out:
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Wed Jan 3 21:11:41 UTC 2018 Modified Files: src/sys/kern [netbsd-7]: subr_kobj.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #1539): sys/kern/subr_kobj.c: revision 1.52 Compare names of duplicate symbols properly, so we correctly return an error status. Fixes PR kern/45125 with patch supplied by Akinobu Mita To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.50.2.1 src/sys/kern/subr_kobj.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_kobj.c diff -u src/sys/kern/subr_kobj.c:1.50 src/sys/kern/subr_kobj.c:1.50.2.1 --- src/sys/kern/subr_kobj.c:1.50 Wed Jul 16 13:26:33 2014 +++ src/sys/kern/subr_kobj.c Wed Jan 3 21:11:40 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj.c,v 1.50 2014/07/16 13:26:33 maxv Exp $ */ +/* $NetBSD: subr_kobj.c,v 1.50.2.1 2018/01/03 21:11:40 snj Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.50 2014/07/16 13:26:33 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.50.2.1 2018/01/03 21:11:40 snj Exp $"); #include "opt_modular.h" @@ -904,7 +904,7 @@ kobj_checksyms(kobj_t ko, bool undefined strcmp(name, "__end") == 0 || strcmp(name, "__end__") == 0 || strncmp(name, "__start_link_set_", 17) == 0 || - strncmp(name, "__stop_link_set_", 16)) { + strncmp(name, "__stop_link_set_", 16) == 0) { continue; } kobj_error(ko, "global symbol `%s' redefined",
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Sat Aug 19 05:22:00 UTC 2017 Modified Files: src/sys/kern [netbsd-7]: kern_ktrace.c Log Message: Pull up following revision(s) (requested by mrg in ticket #1481): sys/kern/kern_ktrace.c: 1.171 via patch Clamp the length we use, not the length we don't. Avoids uninitialized memory disclosure to userland. >From Ilja Van Sprundel. To generate a diff of this commit: cvs rdiff -u -r1.164.4.1 -r1.164.4.2 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.164.4.1 src/sys/kern/kern_ktrace.c:1.164.4.2 --- src/sys/kern/kern_ktrace.c:1.164.4.1 Mon Dec 1 11:38:42 2014 +++ src/sys/kern/kern_ktrace.c Sat Aug 19 05:21:59 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ktrace.c,v 1.164.4.1 2014/12/01 11:38:42 martin Exp $ */ +/* $NetBSD: kern_ktrace.c,v 1.164.4.2 2017/08/19 05:21:59 snj Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.164.4.1 2014/12/01 11:38:42 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.164.4.2 2017/08/19 05:21:59 snj Exp $"); #include #include @@ -931,7 +931,7 @@ ktruser(const char *id, void *addr, size user_dta = (void *)(ktp + 1); if ((error = copyin(addr, (void *)user_dta, len)) != 0) - len = 0; + kte->kte_kth.ktr_len = 0; ktraddentry(l, kte, KTA_WAITOK); return error;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Sat Aug 12 04:12:11 UTC 2017 Modified Files: src/sys/kern [netbsd-7]: vfs_getcwd.c Log Message: Pull up following revision(s) (requested by mrg in ticket #1478): sys/kern/vfs_getcwd.c: revision 1.52 Don't walk off the end of the dirent buffer. >From Ilja Van Sprundel. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.50.4.1 src/sys/kern/vfs_getcwd.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_getcwd.c diff -u src/sys/kern/vfs_getcwd.c:1.50 src/sys/kern/vfs_getcwd.c:1.50.4.1 --- src/sys/kern/vfs_getcwd.c:1.50 Fri Feb 7 15:29:22 2014 +++ src/sys/kern/vfs_getcwd.c Sat Aug 12 04:12:10 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_getcwd.c,v 1.50 2014/02/07 15:29:22 hannken Exp $ */ +/* $NetBSD: vfs_getcwd.c,v 1.50.4.1 2017/08/12 04:12:10 snj Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_getcwd.c,v 1.50 2014/02/07 15:29:22 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_getcwd.c,v 1.50.4.1 2017/08/12 04:12:10 snj Exp $"); #include #include @@ -211,7 +211,8 @@ unionread: reclen = dp->d_reclen; /* check for malformed directory.. */ -if (reclen < _DIRENT_MINSIZE(dp)) { +if (reclen < _DIRENT_MINSIZE(dp) || +reclen > len) { error = EINVAL; goto out; }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Wed Aug 9 06:32:49 UTC 2017 Modified Files: src/sys/kern [netbsd-7]: kern_malloc.c Log Message: Pull up following revision(s) (requested by martin in ticket #1461): sys/kern/kern_malloc.c: revision 1.146 Avoid integer overflow in kern_malloc(). Reported by Ilja Van Sprundel. To generate a diff of this commit: cvs rdiff -u -r1.143.2.1 -r1.143.2.2 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.143.2.1 src/sys/kern/kern_malloc.c:1.143.2.2 --- src/sys/kern/kern_malloc.c:1.143.2.1 Wed Mar 25 16:54:37 2015 +++ src/sys/kern/kern_malloc.c Wed Aug 9 06:32:49 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_malloc.c,v 1.143.2.1 2015/03/25 16:54:37 snj Exp $ */ +/* $NetBSD: kern_malloc.c,v 1.143.2.2 2017/08/09 06:32:49 snj Exp $ */ /* * Copyright (c) 1987, 1991, 1993 @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.143.2.1 2015/03/25 16:54:37 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.143.2.2 2017/08/09 06:32:49 snj Exp $"); #include #include @@ -105,7 +105,10 @@ kern_malloc(unsigned long size, int flag void *p; if (size >= PAGE_SIZE) { - allocsize = PAGE_SIZE + size; /* for page alignment */ + if (size > (ULONG_MAX-PAGE_SIZE)) + allocsize = ULONG_MAX; /* this will fail later */ + else + allocsize = PAGE_SIZE + size; /* for page alignment */ hdroffset = PAGE_SIZE - sizeof(struct malloc_header); } else { allocsize = sizeof(struct malloc_header) + size;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Mon Jul 10 13:12:04 UTC 2017 Modified Files: src/sys/kern [netbsd-7]: vfs_lookup.c Log Message: Pull up following revision(s) (requested by dh in ticket #1451): sys/kern/vfs_lookup.c: revision 1.208 Fix vnode leak on error, introduced by the openat family changes in -r1.200. >From mjg@freebsd. To generate a diff of this commit: cvs rdiff -u -r1.201 -r1.201.4.1 src/sys/kern/vfs_lookup.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_lookup.c diff -u src/sys/kern/vfs_lookup.c:1.201 src/sys/kern/vfs_lookup.c:1.201.4.1 --- src/sys/kern/vfs_lookup.c:1.201 Fri Feb 7 15:29:22 2014 +++ src/sys/kern/vfs_lookup.c Mon Jul 10 13:12:04 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_lookup.c,v 1.201 2014/02/07 15:29:22 hannken Exp $ */ +/* $NetBSD: vfs_lookup.c,v 1.201.4.1 2017/07/10 13:12:04 martin Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.201 2014/02/07 15:29:22 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.201.4.1 2017/07/10 13:12:04 martin Exp $"); #include "opt_magiclinks.h" @@ -678,8 +678,10 @@ namei_start(struct namei_state *state, i } /* NDAT may feed us with a non directory namei_getstartdir */ - if (startdir->v_type != VDIR) + if (startdir->v_type != VDIR) { + vrele(startdir); return ENOTDIR; + } vn_lock(startdir, LK_EXCLUSIVE | LK_RETRY);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Sat Jun 3 16:58:01 UTC 2017 Modified Files: src/sys/kern [netbsd-7]: kern_descrip.c Log Message: Pull up following revision(s) (requested by riastradh in ticket #1425): sys/kern/kern_descrip.c: revision 1.230 Explicitly set the flags instead of masking set values in. This fixes FNONBLOCK weirdness seen in audio.c OK christos@ and martin@. To generate a diff of this commit: cvs rdiff -u -r1.225.2.1 -r1.225.2.2 src/sys/kern/kern_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/kern_descrip.c diff -u src/sys/kern/kern_descrip.c:1.225.2.1 src/sys/kern/kern_descrip.c:1.225.2.2 --- src/sys/kern/kern_descrip.c:1.225.2.1 Tue Aug 4 17:24:59 2015 +++ src/sys/kern/kern_descrip.c Sat Jun 3 16:58:01 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_descrip.c,v 1.225.2.1 2015/08/04 17:24:59 snj Exp $ */ +/* $NetBSD: kern_descrip.c,v 1.225.2.2 2017/06/03 16:58:01 snj Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.225.2.1 2015/08/04 17:24:59 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.225.2.2 2017/06/03 16:58:01 snj Exp $"); #include #include @@ -1864,7 +1864,7 @@ fd_clone(file_t *fp, unsigned fd, int fl fdfile_t *ff; filedesc_t *fdp; - fp->f_flag |= flag & FMASK; + fp->f_flag = flag & FMASK; fdp = curproc->p_fd; ff = fdp->fd_dt->dt_ff[fd]; KASSERT(ff != NULL);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Sat Mar 18 05:22:18 UTC 2017 Modified Files: src/sys/kern [netbsd-7]: exec_elf.c Log Message: Pull up following revision(s) (requested by uwe in ticket #1368): sys/kern/exec_elf.c: revision 1.88 via patch netbsd_elf_signature - look at note segments (phdrs) not note sections. They point to the same data in the file, but sections are for linkers and are not necessarily present in an executable. The original switch from phdrs to shdrs seems to be just a cop-out to avoid parsing multiple notes per segment, which doesn't really avoid the problem b/c sections also can contain multiple notes. To generate a diff of this commit: cvs rdiff -u -r1.69.2.4 -r1.69.2.5 src/sys/kern/exec_elf.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_elf.c diff -u src/sys/kern/exec_elf.c:1.69.2.4 src/sys/kern/exec_elf.c:1.69.2.5 --- src/sys/kern/exec_elf.c:1.69.2.4 Tue Jan 26 01:18:37 2016 +++ src/sys/kern/exec_elf.c Sat Mar 18 05:22:18 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf.c,v 1.69.2.4 2016/01/26 01:18:37 riz Exp $ */ +/* $NetBSD: exec_elf.c,v 1.69.2.5 2017/03/18 05:22:18 snj Exp $ */ /*- * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69.2.4 2016/01/26 01:18:37 riz Exp $"); +__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69.2.5 2017/03/18 05:22:18 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_pax.h" @@ -95,6 +95,7 @@ extern struct emul emul_netbsd; #define elf_load_psection ELFNAME(load_psection) #define exec_elf_makecmds ELFNAME2(exec,makecmds) #define netbsd_elf_signature ELFNAME2(netbsd,signature) +#define netbsd_elf_note ELFNAME2(netbsd,note) #define netbsd_elf_probe ELFNAME2(netbsd,probe) #define coredump ELFNAMEEND(coredump) #define elf_free_emul_arg ELFNAME(free_emul_arg) @@ -107,6 +108,8 @@ elf_load_psection(struct exec_vmcmd_set Elf_Addr *, u_long *, int); int netbsd_elf_signature(struct lwp *, struct exec_package *, Elf_Ehdr *); +int netbsd_elf_note(struct exec_package *, const Elf_Nhdr *, const char *, + const char *); int netbsd_elf_probe(struct lwp *, struct exec_package *, void *, char *, vaddr_t *); @@ -885,186 +888,200 @@ netbsd_elf_signature(struct lwp *l, stru Elf_Ehdr *eh) { size_t i; - Elf_Shdr *sh; - Elf_Nhdr *np; - size_t shsize, nsize; + Elf_Phdr *ph; + size_t phsize; + char *nbuf; int error; int isnetbsd = 0; - char *ndata, *ndesc; - -#ifdef DIAGNOSTIC - const char *badnote; -#define BADNOTE(n) badnote = (n) -#else -#define BADNOTE(n) -#endif epp->ep_pax_flags = 0; - if (eh->e_shnum > ELF_MAXSHNUM || eh->e_shnum == 0) + + if (eh->e_phnum > ELF_MAXPHNUM || eh->e_phnum == 0) return ENOEXEC; - shsize = eh->e_shnum * sizeof(Elf_Shdr); - sh = kmem_alloc(shsize, KM_SLEEP); - error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize); + phsize = eh->e_phnum * sizeof(Elf_Phdr); + ph = kmem_alloc(phsize, KM_SLEEP); + error = exec_read_from(l, epp->ep_vp, eh->e_phoff, ph, phsize); if (error) goto out; - np = kmem_alloc(ELF_MAXNOTESIZE, KM_SLEEP); - for (i = 0; i < eh->e_shnum; i++) { - Elf_Shdr *shp = &sh[i]; - - if (shp->sh_type != SHT_NOTE || - shp->sh_size > ELF_MAXNOTESIZE || - shp->sh_size < sizeof(Elf_Nhdr) + ELF_NOTE_NETBSD_NAMESZ) + nbuf = kmem_alloc(ELF_MAXNOTESIZE, KM_SLEEP); + for (i = 0; i < eh->e_phnum; i++) { + const char *nptr; + size_t nlen; + + if (ph[i].p_type != PT_NOTE || + ph[i].p_filesz > ELF_MAXNOTESIZE) continue; - error = exec_read_from(l, epp->ep_vp, shp->sh_offset, np, - shp->sh_size); + nlen = ph[i].p_filesz; + error = exec_read_from(l, epp->ep_vp, ph[i].p_offset, + nbuf, nlen); if (error) continue; - /* Point to the note, skip the header */ - ndata = (char *)(np + 1); - - /* - * Padding is present if necessary to ensure 4-byte alignment. - * The actual section size is therefore: - *header size + 4-byte aligned name + 4-byte aligned desc - * Ensure this size is consistent with what is indicated - * in sh_size. The first check avoids integer overflows. - * - * Binaries from before NetBSD 1.6 have two notes in the same - * note section. The second note was never used, so as long as - * the section is at least as big as it should be, it's ok. - * These binaries also have a second note section with a note of - * type ELF_NOTE_TYPE_NETBSD_TAG, which can be ignored as well. - */ - if (np->n_namesz > shp->sh_size || np->n_descsz > shp->sh_size) { - BADNOTE("note size limit"); - goto bad; - } - nsize = sizeof(*np) + roundup(np->n_namesz, 4) + - roundup(np->n_descsz, 4); - if (nsize > shp->sh_size) { - BADNOTE("note size"); - goto bad; - } - ndesc = ndata + roundup(np->n_namesz, 4); - - switch (np->n_type) { - case ELF_NOTE_TYPE_NETBSD_TAG: -
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Mon Dec 12 07:29:16 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: subr_xcall.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #1306): sys/kern/subr_xcall.c: revision 1.19 Fix a race condition of low priority xcall xc_lowpri and xc_thread are racy and xc_wait may return during/before executing all xcall callbacks, resulting in a kernel panic at worst. xc_lowpri serializes multiple jobs by a mutex and a cv. If all xcall callbacks are done, xc_wait returns and also xc_lowpri accepts a next job. The problem is that a counter that counts the number of finished xcall callbacks is incremented *before* actually executing a xcall callback (see xc_tailp++ in xc_thread). So xc_lowpri accepts a next job before all xcall callbacks complete and a next job begins to run its xcall callbacks. Even worse the counter is global and shared between jobs, so if a xcall callback of the next job completes, the shared counter is incremented, which confuses wc_wait of the previous job as all xcall callbacks of the previous job are done and wc_wait of the previous job returns during/before executing its xcall callbacks. How to fix: there are actually two counters that count the number of finished xcall callbacks for low priority xcall for historical reasons (I guess): xc_tailp and xc_low_pri.xc_donep. xc_low_pri.xc_donep is incremented correctly while xc_tailp is incremented wrongly, i.e., before executing a xcall callback. We can fix the issue by dropping xc_tailp and using only xc_low_pri.xc_donep. PR kern/51632 To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.18.4.1 src/sys/kern/subr_xcall.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_xcall.c diff -u src/sys/kern/subr_xcall.c:1.18 src/sys/kern/subr_xcall.c:1.18.4.1 --- src/sys/kern/subr_xcall.c:1.18 Tue Nov 26 21:13:05 2013 +++ src/sys/kern/subr_xcall.c Mon Dec 12 07:29:16 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_xcall.c,v 1.18 2013/11/26 21:13:05 rmind Exp $ */ +/* $NetBSD: subr_xcall.c,v 1.18.4.1 2016/12/12 07:29:16 snj Exp $ */ /*- * Copyright (c) 2007-2010 The NetBSD Foundation, Inc. @@ -74,7 +74,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_xcall.c,v 1.18 2013/11/26 21:13:05 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_xcall.c,v 1.18.4.1 2016/12/12 07:29:16 snj Exp $"); #include #include @@ -105,7 +105,6 @@ typedef struct { /* Low priority xcall structures. */ static xc_state_t xc_low_pri __cacheline_aligned; -static uint64_t xc_tailp __cacheline_aligned; /* High priority xcall structures. */ static xc_state_t xc_high_pri __cacheline_aligned; @@ -134,7 +133,6 @@ xc_init(void) memset(xclo, 0, sizeof(xc_state_t)); mutex_init(&xclo->xc_lock, MUTEX_DEFAULT, IPL_NONE); cv_init(&xclo->xc_busy, "xclocv"); - xc_tailp = 0; memset(xchi, 0, sizeof(xc_state_t)); mutex_init(&xchi->xc_lock, MUTEX_DEFAULT, IPL_SOFTSERIAL); @@ -256,7 +254,7 @@ xc_lowpri(xcfunc_t func, void *arg1, voi uint64_t where; mutex_enter(&xc->xc_lock); - while (xc->xc_headp != xc_tailp) { + while (xc->xc_headp != xc->xc_donep) { cv_wait(&xc->xc_busy, &xc->xc_lock); } xc->xc_arg1 = arg1; @@ -277,7 +275,7 @@ xc_lowpri(xcfunc_t func, void *arg1, voi ci->ci_data.cpu_xcall_pending = true; cv_signal(&ci->ci_data.cpu_xcall); } - KASSERT(xc_tailp < xc->xc_headp); + KASSERT(xc->xc_donep < xc->xc_headp); where = xc->xc_headp; mutex_exit(&xc->xc_lock); @@ -302,7 +300,7 @@ xc_thread(void *cookie) mutex_enter(&xc->xc_lock); for (;;) { while (!ci->ci_data.cpu_xcall_pending) { - if (xc->xc_headp == xc_tailp) { + if (xc->xc_headp == xc->xc_donep) { cv_broadcast(&xc->xc_busy); } cv_wait(&ci->ci_data.cpu_xcall, &xc->xc_lock); @@ -312,7 +310,6 @@ xc_thread(void *cookie) func = xc->xc_func; arg1 = xc->xc_arg1; arg2 = xc->xc_arg2; - xc_tailp++; mutex_exit(&xc->xc_lock); KASSERT(func != NULL);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Tue Nov 1 20:08:15 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: uipc_usrreq.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1268): sys/kern/uipc_usrreq.c: revision 1.181 Memory leak, found by Mootja. It is easily triggerable from userland. To generate a diff of this commit: cvs rdiff -u -r1.169.2.3 -r1.169.2.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_usrreq.c diff -u src/sys/kern/uipc_usrreq.c:1.169.2.3 src/sys/kern/uipc_usrreq.c:1.169.2.4 --- src/sys/kern/uipc_usrreq.c:1.169.2.3 Tue Apr 14 04:44:41 2015 +++ src/sys/kern/uipc_usrreq.c Tue Nov 1 20:08:15 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.169.2.3 2015/04/14 04:44:41 snj Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.169.2.4 2016/11/01 20:08:15 snj Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169.2.3 2015/04/14 04:44:41 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169.2.4 2016/11/01 20:08:15 snj Exp $"); #include #include @@ -1173,11 +1173,11 @@ unp_connect(struct socket *so, struct mb goto bad2; } vp = nd.ni_vp; + pathbuf_destroy(pb); if (vp->v_type != VSOCK) { error = ENOTSOCK; goto bad; } - pathbuf_destroy(pb); if ((error = VOP_ACCESS(vp, VWRITE, l->l_cred)) != 0) goto bad; /* Acquire v_interlock to protect against unp_detach(). */
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sun Jul 10 09:38:38 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: kern_module.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #1183): sys/kern/kern_module.c: revision 1.111 Check for duplicate module names before loading modules that were "pushed" by the boot loader. The boot loader pushes the module name for the root file system (unless the root file system is ffs) even if the file system module is built into the kernel. When this happens, we get a lot of "redefined symbol" error messages. This fix does not alter the behavior of pushing the file system name. It simply avoids the redefined symbol errors by detecting that the module is already built-in to the kernel and not trying to load another copy. While here, differentiate the error message text between "failed to load" and "failed to fetch_info" conditions. Addresses PR kern/50357 To generate a diff of this commit: cvs rdiff -u -r1.97.2.2 -r1.97.2.3 src/sys/kern/kern_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/kern_module.c diff -u src/sys/kern/kern_module.c:1.97.2.2 src/sys/kern/kern_module.c:1.97.2.3 --- src/sys/kern/kern_module.c:1.97.2.2 Thu Mar 3 14:47:08 2016 +++ src/sys/kern/kern_module.c Sun Jul 10 09:38:38 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_module.c,v 1.97.2.2 2016/03/03 14:47:08 martin Exp $ */ +/* $NetBSD: kern_module.c,v 1.97.2.3 2016/07/10 09:38:38 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.97.2.2 2016/03/03 14:47:08 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.97.2.3 2016/07/10 09:38:38 martin Exp $"); #define _MODULE_INTERNAL @@ -1235,6 +1235,8 @@ module_do_unload(const char *name, bool int module_prime(const char *name, void *base, size_t size) { + __link_set_decl(modules, modinfo_t); + modinfo_t *const *mip; module_t *mod; int error; @@ -1243,6 +1245,18 @@ module_prime(const char *name, void *bas return ENOMEM; } + /* Check for duplicate modules */ + + __link_set_foreach(mip, modules) { + if (*mip == &module_dummy) + continue; + if (strcmp((*mip)->mi_name, name) == 0) { + module_error("module `%s' pushed by boot loader " + "already exists", name); + kmem_free(mod, sizeof(*mod)); + return EEXIST; + } + } error = kobj_load_mem(&mod->mod_kobj, name, base, size); if (error != 0) { kmem_free(mod, sizeof(*mod)); @@ -1254,8 +1268,8 @@ module_prime(const char *name, void *bas if (error != 0) { kobj_unload(mod->mod_kobj); kmem_free(mod, sizeof(*mod)); - module_error("unable to load `%s' pushed by boot loader, " - "error %d", name, error); + module_error("unable to fetch_info for `%s' pushed by boot " + "loader, error %d", name, error); return error; }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Tue Jul 5 19:06:48 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: kern_subr.c Log Message: Pull up following revision(s) (requested by mlelstv in ticket #1185): sys/kern/kern_subr.c: revision 1.215 don't crash if rootspec is invalid To generate a diff of this commit: cvs rdiff -u -r1.214 -r1.214.4.1 src/sys/kern/kern_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/kern_subr.c diff -u src/sys/kern/kern_subr.c:1.214 src/sys/kern/kern_subr.c:1.214.4.1 --- src/sys/kern/kern_subr.c:1.214 Mon Dec 9 16:49:43 2013 +++ src/sys/kern/kern_subr.c Tue Jul 5 19:06:48 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_subr.c,v 1.214 2013/12/09 16:49:43 pooka Exp $ */ +/* $NetBSD: kern_subr.c,v 1.214.4.1 2016/07/05 19:06:48 snj Exp $ */ /*- * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc. @@ -79,7 +79,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.214 2013/12/09 16:49:43 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.214.4.1 2016/07/05 19:06:48 snj Exp $"); #include "opt_ddb.h" #include "opt_md.h" @@ -422,7 +422,8 @@ setroot(device_t bootdv, int bootpartiti } if (rootdev == NODEV && - device_class(dv) == DV_DISK && device_is_a(dv, "dk") && + dv != NULL && device_class(dv) == DV_DISK && + device_is_a(dv, "dk") && (majdev = devsw_name2blk(device_xname(dv), NULL, 0)) >= 0) rootdev = makedev(majdev, device_unit(dv));
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sun Mar 6 17:32:02 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: subr_pool.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #1103): sys/kern/subr_pool.c: revision 1.206 fix: "vmstat -C" CpuLayer showed only the last cpu values. To generate a diff of this commit: cvs rdiff -u -r1.203 -r1.203.2.1 src/sys/kern/subr_pool.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_pool.c diff -u src/sys/kern/subr_pool.c:1.203 src/sys/kern/subr_pool.c:1.203.2.1 --- src/sys/kern/subr_pool.c:1.203 Fri Jun 13 19:09:07 2014 +++ src/sys/kern/subr_pool.c Sun Mar 6 17:32:02 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_pool.c,v 1.203 2014/06/13 19:09:07 joerg Exp $ */ +/* $NetBSD: subr_pool.c,v 1.203.2.1 2016/03/06 17:32:02 martin Exp $ */ /*- * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014 @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.203 2014/06/13 19:09:07 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.203.2.1 2016/03/06 17:32:02 martin Exp $"); #include "opt_ddb.h" #include "opt_lockdebug.h" @@ -2814,8 +2814,8 @@ pool_sysctl(SYSCTLFN_ARGS) cc = pc->pc_cpus[i]; if (cc == NULL) continue; -data.pr_cache_nmiss_pcpu = cc->cc_misses; -data.pr_cache_nhit_pcpu = cc->cc_hits; +data.pr_cache_nmiss_pcpu += cc->cc_misses; +data.pr_cache_nhit_pcpu += cc->cc_hits; } } else { data.pr_cache_meta_size = 0;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Thu Mar 3 15:42:26 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: kern_time.c Log Message: Pull up following revision(s) (requested by uwe in ticket #1128): sys/kern/kern_time.c: revision 1.184 Don't leak garabage from the kernel stack on sleep(0) and equivalents. Hat tip to perl's ext/POSIX/t/wrappers.t To generate a diff of this commit: cvs rdiff -u -r1.179 -r1.179.8.1 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.179 src/sys/kern/kern_time.c:1.179.8.1 --- src/sys/kern/kern_time.c:1.179 Wed May 22 16:00:52 2013 +++ src/sys/kern/kern_time.c Thu Mar 3 15:42:26 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_time.c,v 1.179 2013/05/22 16:00:52 christos Exp $ */ +/* $NetBSD: kern_time.c,v 1.179.8.1 2016/03/03 15:42:26 martin Exp $ */ /*- * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179 2013/05/22 16:00:52 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.179.8.1 2016/03/03 15:42:26 martin Exp $"); #include #include @@ -328,8 +328,14 @@ nanosleep1(struct lwp *l, clockid_t cloc struct timespec rmtstart; int error, timo; - if ((error = ts2timo(clock_id, flags, rqt, &timo, &rmtstart)) != 0) - return error == ETIMEDOUT ? 0 : error; + if ((error = ts2timo(clock_id, flags, rqt, &timo, &rmtstart)) != 0) { + if (error == ETIMEDOUT) { + error = 0; + if (rmt != NULL) +rmt->tv_sec = rmt->tv_nsec = 0; + } + return error; + } /* * Avoid inadvertently sleeping forever
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Thu Mar 3 14:47:08 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: kern_ksyms.c kern_module.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #1108): sys/kern/kern_module.c: revision 1.107-1.110 sys/kern/kern_ksyms.c: revision 1.82 Add some additional status messages for kern.module.verbose=TRUE Remove extraneous ')' from previous. KNF In module_do_load(), consolidate checking for a pre-existing module, and return a single error value EEXIST. When making a recursive call (to load required modules), treat a pre-existing module as success. Without this change, when a module was loaded by specific request (as opposed to being loaded as a requirement of some other module), we would always load the module from the file-system, and then after making various sanity/compatability checks we would destroy the new copy if there was a pre-existing copy. Fixes PR kern/40764 XXX Note that if the module exists, we bypass all of the various XXX "compatability" checks, including whether or not the existing XXX module is of any particular class! (In the previous code, we XXX checked to see if the newly-loaded copy had the correct class, XXX but not the pre-existing copy, which could have been loaded XXX from a different path/filename.) To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.72.2.1 src/sys/kern/kern_ksyms.c cvs rdiff -u -r1.97.2.1 -r1.97.2.2 src/sys/kern/kern_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/kern_ksyms.c diff -u src/sys/kern/kern_ksyms.c:1.72 src/sys/kern/kern_ksyms.c:1.72.2.1 --- src/sys/kern/kern_ksyms.c:1.72 Fri Jul 25 08:10:40 2014 +++ src/sys/kern/kern_ksyms.c Thu Mar 3 14:47:08 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ksyms.c,v 1.72 2014/07/25 08:10:40 dholland Exp $ */ +/* $NetBSD: kern_ksyms.c,v 1.72.2.1 2016/03/03 14:47:08 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.72 2014/07/25 08:10:40 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.72.2.1 2016/03/03 14:47:08 martin Exp $"); #if defined(_KERNEL) && defined(_KERNEL_OPT) #include "opt_ddb.h" @@ -324,7 +324,7 @@ addsymtab(const char *name, void *symsta nglob = 0; for (i = n = 0; i < nsyms; i++) { - /* This breaks CTF mapping, so don't do it when + /* This breaks CTF mapping, so don't do it when * DTrace is enabled */ #ifndef KDTRACE_HOOKS @@ -389,7 +389,7 @@ addsymtab(const char *name, void *symsta panic("addsymtab"); #ifdef KDTRACE_HOOKS - /* + /* * Build the mapping from original symbol id to new symbol table. * Deleted symbols will have a zero map, indices will be one based * instead of zero based. @@ -481,7 +481,7 @@ ksyms_addsyms_elf(int symsize, void *sta shdr[ehdr->e_shstrndx].sh_offset; for (i = 1; i < ehdr->e_shnum; i++) { #ifdef DEBUG - printf("ksyms: checking %s\n", &shstr[shdr[i].sh_name]); + printf("ksyms: checking %s\n", &shstr[shdr[i].sh_name]); #endif if (shdr[i].sh_type != SHT_PROGBITS) continue; @@ -499,7 +499,7 @@ ksyms_addsyms_elf(int symsize, void *sta } #ifdef DEBUG } else { - printf("ksyms: e_shstrndx == 0\n"); + printf("ksyms: e_shstrndx == 0\n"); #endif } #endif @@ -527,9 +527,8 @@ ksyms_addsyms_elf(int symsize, void *sta */ void ksyms_addsyms_explicit(void *ehdr, void *symstart, size_t symsize, - void *strstart, size_t strsize) +void *strstart, size_t strsize) { - if (!ksyms_verify(symstart, strstart)) return; @@ -549,7 +548,7 @@ ksyms_addsyms_explicit(void *ehdr, void */ int ksyms_getval_unlocked(const char *mod, const char *sym, unsigned long *val, - int type) +int type) { struct ksyms_symtab *st; Elf_Sym *es; @@ -717,7 +716,7 @@ ksyms_getname(const char **mod, const ch */ void ksyms_modload(const char *name, void *symstart, vsize_t symsize, - char *strstart, vsize_t strsize) +char *strstart, vsize_t strsize) { struct ksyms_symtab *st; @@ -827,20 +826,20 @@ ksyms_sift(char *mod, char *sym, int mod static void ksyms_sizes_calc(void) { -struct ksyms_symtab *st; + struct ksyms_symtab *st; int i, delta; -ksyms_symsz = ksyms_strsz = 0; -TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) { + ksyms_symsz = ksyms_strsz = 0; + TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) { delta = ksyms_strsz - st->sd_usroffset; if (delta != 0) { for (i = 0; i < st->sd_symsize/sizeof(Elf_Sym); i++) st->sd_symstart[i].st_name += delta; st->sd_usroffset = ksyms_strsz; } -ksyms_symsz += st->sd_symsize; -ksyms_strsz += st->sd_strsize; -} + ksyms_symsz += st->sd_symsize; + ksyms_strsz += st->sd_strsize; + } } static void @@ -922,7 +921,6 @@ ksy
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Tue Jan 26 23:43:34 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: vfs_vnode.c Log Message: Pull up following revision(s) (requested by hannken in ticket #1070): sys/kern/vfs_vnode.c: revision 1.46 via patch Take the vnode lock before the vnode is marked VI_CHANGING and fed to vclean(). Prevents a deadlock with two null mounts on the same physical mount where one thread tries to vclean() a layer node and another thread tries to vget() a layer node pointing to the same physical node. Fixes PR kern/50375 layerfs (nullfs) locking problem leading to livelock To generate a diff of this commit: cvs rdiff -u -r1.37.2.1 -r1.37.2.2 src/sys/kern/vfs_vnode.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_vnode.c diff -u src/sys/kern/vfs_vnode.c:1.37.2.1 src/sys/kern/vfs_vnode.c:1.37.2.2 --- src/sys/kern/vfs_vnode.c:1.37.2.1 Sun Oct 19 10:02:59 2014 +++ src/sys/kern/vfs_vnode.c Tue Jan 26 23:43:34 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnode.c,v 1.37.2.1 2014/10/19 10:02:59 martin Exp $ */ +/* $NetBSD: vfs_vnode.c,v 1.37.2.2 2016/01/26 23:43:34 snj Exp $ */ /*- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. @@ -116,7 +116,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.37.2.1 2014/10/19 10:02:59 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.37.2.2 2016/01/26 23:43:34 snj Exp $"); #define _VFS_VNODE_PRIVATE @@ -328,15 +328,17 @@ try_nextlist: KASSERT((vp->v_iflag & VI_CLEAN) == 0); KASSERT(vp->v_freelisthd == listhd); - if (!mutex_tryenter(vp->v_interlock)) + if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT) != 0) continue; - if ((vp->v_iflag & VI_XLOCK) != 0) { - mutex_exit(vp->v_interlock); + if (!mutex_tryenter(vp->v_interlock)) { + VOP_UNLOCK(vp); continue; } + KASSERT((vp->v_iflag & VI_XLOCK) == 0); mp = vp->v_mount; if (fstrans_start_nowait(mp, FSTRANS_SHARED) != 0) { mutex_exit(vp->v_interlock); + VOP_UNLOCK(vp); continue; } break; @@ -735,6 +737,11 @@ vrelel(vnode_t *vp, int flags) * Note that VOP_INACTIVE() will drop the vnode lock. */ VOP_INACTIVE(vp, &recycle); + if (recycle) { + /* vclean() below will drop the lock. */ + if (vn_lock(vp, LK_EXCLUSIVE) != 0) +recycle = false; + } mutex_enter(vp->v_interlock); if (!recycle) { if (vtryrele(vp)) { @@ -959,6 +966,7 @@ holdrelel(vnode_t *vp) /* * Disassociate the underlying file system from a vnode. * + * Must be called with vnode locked and will return unlocked. * Must be called with the interlock held, and will return with it held. */ static void @@ -968,28 +976,21 @@ vclean(vnode_t *vp) bool recycle, active, doclose; int error; + KASSERT((vp->v_vflag & VV_LOCKSWORK) == 0 || + VOP_ISLOCKED(vp) == LK_EXCLUSIVE); KASSERT(mutex_owned(vp->v_interlock)); KASSERT((vp->v_iflag & VI_MARKER) == 0); + KASSERT((vp->v_iflag & (VI_XLOCK | VI_CLEAN)) == 0); KASSERT(vp->v_usecount != 0); - /* If already clean, nothing to do. */ - if ((vp->v_iflag & VI_CLEAN) != 0) { - return; - } - active = (vp->v_usecount > 1); doclose = ! (active && vp->v_type == VBLK && spec_node_getmountedfs(vp) != NULL); - mutex_exit(vp->v_interlock); - - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* * Prevent the vnode from being recycled or brought into use * while we clean it out. */ - mutex_enter(vp->v_interlock); - KASSERT((vp->v_iflag & (VI_XLOCK | VI_CLEAN)) == 0); vp->v_iflag |= VI_XLOCK; if (vp->v_iflag & VI_EXECMAP) { atomic_add_int(&uvmexp.execpages, -vp->v_uobj.uo_npages); @@ -1073,23 +1074,26 @@ bool vrecycle(vnode_t *vp) { + if (vn_lock(vp, LK_EXCLUSIVE) != 0) + return false; + mutex_enter(vp->v_interlock); KASSERT((vp->v_iflag & VI_MARKER) == 0); if (vp->v_usecount != 1) { mutex_exit(vp->v_interlock); + VOP_UNLOCK(vp); return false; } if ((vp->v_iflag & VI_CHANGING) != 0) vwait(vp, VI_CHANGING); if (vp->v_usecount != 1) { mutex_exit(vp->v_interlock); + VOP_UNLOCK(vp); return false; - } else if ((vp->v_iflag & VI_CLEAN) != 0) { - mutex_exit(vp->v_interlock); - return true; } + KASSERT((vp->v_iflag & VI_CLEAN) == 0); vp->v_iflag |= VI_CHANGING; vclean(vp); vrelel(vp, VRELEL_CHANGING_SET); @@ -1137,6 +1141,11 @@ void vgone(vnode_t *vp) { + if (vn_lock(vp, LK_EXCLUSIVE) != 0) { + KASSERT((vp->v_iflag & VI_CLEAN) != 0); + vrele(vp); + } + mutex_enter(vp->v_interlock); if ((vp->v_iflag & VI_CHANGING) != 0) vwait(vp, VI_CHANGING);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: riz Date: Tue Jan 26 04:50:22 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: kern_softint.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #1067): sys/kern/kern_softint.c: revision 1.42 fix the following softint parallel operation problem. (0) softint handler "handler A" is established (1) CPU#X does softint_schedule() for "handler A" - the softhand_t is set SOFTINT_PENDING flag - the softhand_t is NOT set SOFTINT_ACTIVE flag yet (2) CPU#X begins other H/W interrupt processing (3) CPU#Y does softint_disestablish() for "handler A" - waits until softhand_t's SOFTINT_ACTIVE of all CPUs is clear - the softhand_t is set not SOFTINT_ACTIVE but SOFTINT_PENDING, so CPU#Y does not wait - unset the function of "handler A" (4) CPU#X does softint_execute() - the function of "handler A" is already clear, so panic To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.41.2.1 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.41 src/sys/kern/kern_softint.c:1.41.2.1 --- src/sys/kern/kern_softint.c:1.41 Sun May 25 15:42:01 2014 +++ src/sys/kern/kern_softint.c Tue Jan 26 04:50:22 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_softint.c,v 1.41 2014/05/25 15:42:01 rmind Exp $ */ +/* $NetBSD: kern_softint.c,v 1.41.2.1 2016/01/26 04:50:22 riz Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -170,7 +170,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.41 2014/05/25 15:42:01 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.41.2.1 2016/01/26 04:50:22 riz Exp $"); #include #include @@ -442,8 +442,8 @@ softint_disestablish(void *arg) KASSERT(sh->sh_func != NULL); flags |= sh->sh_flags; } - /* Inactive on all CPUs? */ - if ((flags & SOFTINT_ACTIVE) == 0) { + /* Neither pending nor active on all CPUs? */ + if ((flags & (SOFTINT_PENDING | SOFTINT_ACTIVE)) == 0) { break; } /* Oops, still active. Wait for it to clear. */
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: riz Date: Tue Jan 26 01:18:37 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: exec_elf.c Log Message: Apply patch (requested by martin in ticket #1062): sys/kern/exec_elf.c patch Restore binary compatibility on sparc64 for old binaries. [martin, ticket #1062] To generate a diff of this commit: cvs rdiff -u -r1.69.2.3 -r1.69.2.4 src/sys/kern/exec_elf.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_elf.c diff -u src/sys/kern/exec_elf.c:1.69.2.3 src/sys/kern/exec_elf.c:1.69.2.4 --- src/sys/kern/exec_elf.c:1.69.2.3 Sun Nov 8 00:57:09 2015 +++ src/sys/kern/exec_elf.c Tue Jan 26 01:18:37 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf.c,v 1.69.2.3 2015/11/08 00:57:09 riz Exp $ */ +/* $NetBSD: exec_elf.c,v 1.69.2.4 2016/01/26 01:18:37 riz Exp $ */ /*- * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69.2.3 2015/11/08 00:57:09 riz Exp $"); +__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69.2.4 2016/01/26 01:18:37 riz Exp $"); #ifdef _KERNEL_OPT #include "opt_pax.h" @@ -77,6 +77,7 @@ __KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v #include #include #include +#include #include #include @@ -409,20 +410,18 @@ elf_load_interp(struct lwp *l, struct ex u_long phsize; Elf_Addr addr = *last; struct proc *p; - bool use_topdown; + bool use_topdown, restore_topdown; p = l->l_proc; KASSERT(p->p_vmspace); - if (__predict_true(p->p_vmspace != proc0.p_vmspace)) { - use_topdown = p->p_vmspace->vm_map.flags & VM_MAP_TOPDOWN; - } else { + KASSERT(p->p_vmspace != proc0.p_vmspace); + restore_topdown = false; #ifdef __USE_TOPDOWN_VM - use_topdown = epp->ep_flags & EXEC_TOPDOWN_VM; + use_topdown = epp->ep_flags & EXEC_TOPDOWN_VM; #else - use_topdown = false; + use_topdown = false; #endif - } /* * 1. open file @@ -537,9 +536,36 @@ elf_load_interp(struct lwp *l, struct ex /* * Now compute the size and load address. */ + if (__predict_false( + /* vmspace is marked as topdown */ + (((p->p_vmspace->vm_map.flags & VM_MAP_TOPDOWN) != 0) + != + /* but this differs from the topdown usage we need */ + use_topdown))) { + /* + * The vmmap might be shared, but this flag is + * considered r/o and we will restore it immediately + * after calculating the load address. + */ + int flags = p->p_vmspace->vm_map.flags; + int n = use_topdown +? (flags | VM_MAP_TOPDOWN) +: (flags & ~VM_MAP_TOPDOWN); + + restore_topdown = true; + atomic_swap_32(&p->p_vmspace->vm_map.flags, n); + } addr = (*epp->ep_esch->es_emul->e_vm_default_addr)(p, epp->ep_daddr, round_page(limit) - trunc_page(base_ph->p_vaddr)); + if (__predict_false(restore_topdown)) { + int flags = p->p_vmspace->vm_map.flags; + int n = !use_topdown +? (flags | VM_MAP_TOPDOWN) +: (flags & ~VM_MAP_TOPDOWN); + + atomic_swap_32(&p->p_vmspace->vm_map.flags, n); + } } else addr = *last; /* may be ELF_LINK_ADDR */
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Tue Jan 5 22:16:44 UTC 2016 Modified Files: src/sys/kern [netbsd-7]: kern_lock.c Log Message: Pull up following revision(s) (requested by skrll in ticket #1056): sys/kern/kern_lock.c: revision 1.156 Allow sleeping in the idle lwp if the cpu isn't running yet. OK'ed by rmind a while ago. To generate a diff of this commit: cvs rdiff -u -r1.155 -r1.155.4.1 src/sys/kern/kern_lock.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_lock.c diff -u src/sys/kern/kern_lock.c:1.155 src/sys/kern/kern_lock.c:1.155.4.1 --- src/sys/kern/kern_lock.c:1.155 Sat Sep 14 20:24:22 2013 +++ src/sys/kern/kern_lock.c Tue Jan 5 22:16:44 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_lock.c,v 1.155 2013/09/14 20:24:22 martin Exp $ */ +/* $NetBSD: kern_lock.c,v 1.155.4.1 2016/01/05 22:16:44 snj Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.155 2013/09/14 20:24:22 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.155.4.1 2016/01/05 22:16:44 snj Exp $"); #include #include @@ -78,7 +78,8 @@ assert_sleepable(void) } while (pctr != lwp_pctr()); reason = NULL; - if (idle && !cold) { + if (idle && !cold && + kcpuset_isset(kcpuset_running, cpu_index(curcpu( { reason = "idle"; } if (cpu_intr_p()) {
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: msaitoh Date: Mon Nov 16 14:40:41 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: subr_autoconf.c Log Message: Pull up following revision(s) (requested by joerg in ticket #1030): sys/kern/subr_autoconf.c: revision 1.236 Add the parent device (if present) to the device properties, making it easier to identify devices in the tree with drvctl(8). To generate a diff of this commit: cvs rdiff -u -r1.231.2.1 -r1.231.2.2 src/sys/kern/subr_autoconf.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_autoconf.c diff -u src/sys/kern/subr_autoconf.c:1.231.2.1 src/sys/kern/subr_autoconf.c:1.231.2.2 --- src/sys/kern/subr_autoconf.c:1.231.2.1 Mon Mar 9 08:56:01 2015 +++ src/sys/kern/subr_autoconf.c Mon Nov 16 14:40:41 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_autoconf.c,v 1.231.2.1 2015/03/09 08:56:01 snj Exp $ */ +/* $NetBSD: subr_autoconf.c,v 1.231.2.2 2015/11/16 14:40:41 msaitoh Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.231.2.1 2015/03/09 08:56:01 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.231.2.2 2015/11/16 14:40:41 msaitoh Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -1434,6 +1434,10 @@ config_devalloc(const device_t parent, c "device-driver", dev->dv_cfdriver->cd_name); prop_dictionary_set_uint16(dev->dv_properties, "device-unit", dev->dv_unit); + if (parent != NULL) { + prop_dictionary_set_cstring(dev->dv_properties, + "device-parent", device_xname(parent)); + } if (dev->dv_cfdriver->cd_attrs != NULL) config_add_attrib_dict(dev);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: riz Date: Sun Nov 8 00:55:11 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: uipc_syscalls.c Log Message: Pull up following revision(s) (requested by christos in ticket #1018): sys/kern/uipc_syscalls.c: revision 1.181 Don't overwrite the user iov pointer in sendmmsg. Make the send and receive code look the same. To generate a diff of this commit: cvs rdiff -u -r1.172.2.1 -r1.172.2.2 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.172.2.1 src/sys/kern/uipc_syscalls.c:1.172.2.2 --- src/sys/kern/uipc_syscalls.c:1.172.2.1 Sat Aug 8 15:45:47 2015 +++ src/sys/kern/uipc_syscalls.c Sun Nov 8 00:55:11 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.172.2.1 2015/08/08 15:45:47 martin Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.172.2.2 2015/11/08 00:55:11 riz Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.172.2.1 2015/08/08 15:45:47 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.172.2.2 2015/11/08 00:55:11 riz Exp $"); #include "opt_pipe.h" @@ -568,10 +568,10 @@ do_sys_sendmsg_so(struct lwp *l, int s, if (error) goto bad; } - mp->msg_iov = iov; - } + auio.uio_iov = iov; + } else + auio.uio_iov = mp->msg_iov; - auio.uio_iov = mp->msg_iov; auio.uio_iovcnt = mp->msg_iovlen; auio.uio_rw = UIO_WRITE; auio.uio_offset = 0; /* XXX */ @@ -579,7 +579,8 @@ do_sys_sendmsg_so(struct lwp *l, int s, KASSERT(l == curlwp); auio.uio_vmspace = l->l_proc->p_vmspace; - for (i = 0, tiov = mp->msg_iov; i < mp->msg_iovlen; i++, tiov++) { + tiov = auio.uio_iov; + for (i = 0; i < auio.uio_iovcnt; i++, tiov++) { /* * Writes return ssize_t because -1 is returned on error. * Therefore, we must restrict the length to SSIZE_MAX to @@ -955,7 +956,7 @@ do_sys_recvmsg_so(struct lwp *l, int s, auio.uio_vmspace = l->l_proc->p_vmspace; tiov = auio.uio_iov; - for (i = 0; i < mp->msg_iovlen; i++, tiov++) { + for (i = 0; i < auio.uio_iovcnt; i++, tiov++) { /* * Reads return ssize_t because -1 is returned on error. * Therefore we must restrict the length to SSIZE_MAX to
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Thu Nov 5 09:30:11 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: kern_exit.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #999): 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.244.2.1 -r1.244.2.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.244.2.1 src/sys/kern/kern_exit.c:1.244.2.2 --- src/sys/kern/kern_exit.c:1.244.2.1 Thu Nov 5 09:04:55 2015 +++ src/sys/kern/kern_exit.c Thu Nov 5 09:30:10 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exit.c,v 1.244.2.1 2015/11/05 09:04:55 snj Exp $ */ +/* $NetBSD: kern_exit.c,v 1.244.2.2 2015/11/05 09:30:10 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.244.2.1 2015/11/05 09:04:55 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.244.2.2 2015/11/05 09:30:10 snj Exp $"); #include "opt_ktrace.h" #include "opt_perfctrs.h" @@ -235,8 +235,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-7] src/sys/kern
Module Name:src Committed By: snj Date: Thu Nov 5 09:21:30 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: kern_sig.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #997): 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.319 -r1.319.4.1 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.319 src/sys/kern/kern_sig.c:1.319.4.1 --- src/sys/kern/kern_sig.c:1.319 Fri Nov 22 21:04:11 2013 +++ src/sys/kern/kern_sig.c Thu Nov 5 09:21:30 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.319 2013/11/22 21:04:11 christos Exp $ */ +/* $NetBSD: kern_sig.c,v 1.319.4.1 2015/11/05 09:21:30 snj Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.319 2013/11/22 21:04:11 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.319.4.1 2015/11/05 09:21:30 snj Exp $"); #include "opt_ptrace.h" #include "opt_compat_sunos.h" @@ -1364,14 +1364,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-7] src/sys/kern
Module Name:src Committed By: snj Date: Thu Nov 5 09:04:55 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: kern_exec.c kern_exit.c kern_synch.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #996): sys/kern/kern_exec.c: revisions 1.419, 1.420 sys/kern/kern_exit.c: revisions 1.246, 1.247 sys/kern/kern_synch.c: revision 1.309 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 -- In spawn_return() we temporarily move the process state to SSTOP, but without updating its p_waited value or its parent's p_nstopchild counter. Later, we restore the original state, again without any adjustment of the related values. This leaves a relatively short window when the values are inconsistent and could interfere with the proper operation of sys_wait() for the parent (if it manages to be scheduled; it's not totally clear what, if anything, prevents scheduling/execution of the parent). If during this window, any of the checks being made result in an error, we call exit1() which will eventually migrate the process's state to SDEAD (with an intermediate transition to SDYING). At this point the other variables get updated, and we finally restore a consistent state. This change updates the p_waited and parent's p_nstopchild at each step to eliminate any windows during which the values could lead to incorrect decisions. Fixes PR kern/50330 To generate a diff of this commit: cvs rdiff -u -r1.408.2.3 -r1.408.2.4 src/sys/kern/kern_exec.c cvs rdiff -u -r1.244 -r1.244.2.1 src/sys/kern/kern_exit.c cvs rdiff -u -r1.308 -r1.308.4.1 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.408.2.3 src/sys/kern/kern_exec.c:1.408.2.4 --- src/sys/kern/kern_exec.c:1.408.2.3 Tue Apr 14 05:12:17 2015 +++ src/sys/kern/kern_exec.c Thu Nov 5 09:04:55 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exec.c,v 1.408.2.3 2015/04/14 05:12:17 snj Exp $ */ +/* $NetBSD: kern_exec.c,v 1.408.2.4 2015/11/05 09:04:55 snj Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.408.2.3 2015/04/14 05:12:17 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.408.2.4 2015/11/05 09:04:55 snj Exp $"); #include "opt_exec.h" #include "opt_execfmt.h" @@ -1260,7 +1260,7 @@ execve_runproc(struct lwp *l, struct exe KERNEL_UNLOCK_ALL(l, &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(&kq); sigclearall(p, &contsigmask, &kq); @@ -1961,6 +1961,7 @@ spawn_return(void *arg) struct spawn_exec_data *spawn_data = arg; struct lwp *l = curlwp; int error, newfd; + int ostat; size_t i; const struct posix_spawn_file_actions_entry *fae; pid_t ppid; @@ -2033,7 +2034,6 @@ spawn_return(void *arg) /* handle posix_spawnattr */ if (spawn_data->sed_attrs != NULL) { - int ostat; struct sigaction sigact; sigact._sa_u._sa_handler = SIG_DFL; sigact.sa_flags = 0; @@ -2042,8 +2042,18 @@ spawn_return(void *arg) * set state to SSTOP so that this proc can be found by pid. * see proc_enterprp, do_sched_setparam below */ + mutex_enter(proc_lock); + /* + * p_stat should be SACTIVE, so we need to adjust the + * parent's p_nstopchild here. For safety, just make + * we're on the good side of SDEAD before we adjust. + */ ostat = l->l_proc->p_stat; + KASSERT(ostat < SSTOP); l->l_proc->p_stat = SSTOP; + l->l_proc->p
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: riz Date: Wed Nov 4 18:00:34 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: kern_cpu.c Log Message: Pull up following revision(s) (requested by maxv in ticket #965): sys/kern/kern_cpu.c: revision 1.71 Don't decrement the number of offline cpus if we fail to shut down one. ok christos@, via tech-kern@ To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.66.2.1 src/sys/kern/kern_cpu.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_cpu.c diff -u src/sys/kern/kern_cpu.c:1.66 src/sys/kern/kern_cpu.c:1.66.2.1 --- src/sys/kern/kern_cpu.c:1.66 Fri Jul 25 08:10:40 2014 +++ src/sys/kern/kern_cpu.c Wed Nov 4 18:00:34 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_cpu.c,v 1.66 2014/07/25 08:10:40 dholland Exp $ */ +/* $NetBSD: kern_cpu.c,v 1.66.2.1 2015/11/04 18:00:34 riz Exp $ */ /*- * Copyright (c) 2007, 2008, 2009, 2010, 2012 The NetBSD Foundation, Inc. @@ -56,7 +56,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.66 2014/07/25 08:10:40 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.66.2.1 2015/11/04 18:00:34 riz Exp $"); #include "opt_cpu_ucode.h" #include "opt_compat_netbsd.h" @@ -444,7 +444,6 @@ cpu_setstate(struct cpu_info *ci, bool o if ((spc->spc_flags & SPCF_OFFLINE) == 0) return 0; func = (xcfunc_t)cpu_xc_online; - ncpuonline++; } else { if ((spc->spc_flags & SPCF_OFFLINE) != 0) return 0; @@ -463,16 +462,19 @@ cpu_setstate(struct cpu_info *ci, bool o if (nonline == 1) return EBUSY; func = (xcfunc_t)cpu_xc_offline; - ncpuonline--; } where = xc_unicast(0, func, ci, NULL, ci); xc_wait(where); if (online) { KASSERT((spc->spc_flags & SPCF_OFFLINE) == 0); - } else if ((spc->spc_flags & SPCF_OFFLINE) == 0) { - /* If was not set offline, then it is busy */ - return EBUSY; + ncpuonline++; + } else { + if ((spc->spc_flags & SPCF_OFFLINE) == 0) { + /* If was not set offline, then it is busy */ + return EBUSY; + } + ncpuonline--; } spc->spc_lastmod = time_second;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: riz Date: Wed Nov 4 17:55:23 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: vfs_mount.c Log Message: Pull up following revision(s) (requested by manu in ticket #962): sys/kern/vfs_mount.c: revision 1.36 Do not VFS_SYNC before VFS_UNMOUNT on force unmount VFS_SYNC does not consider whether we are performing a force unmount or not, and therefore it can wait for a while if the filesytstem is misbehaving. Removing VFS_SYNC before VFS_UNMOUNT on forced unmount fixes the problem. This should not cause harm as the VFS_SYNC seems just useless. As noted by Chuck Silvers in http://mail-index.netbsd.org/tech-kern/2015/07/13/msg019156.html - Nothing seems to prevent vnodes from getting dirty again after VFS_SYNC call. - Filesystems do flush data through vflush() in VFS_UNMOUNT anyway. As a consequence, the VFS_SYNC call in do_unmount() could probably be completely removed. But since such a change is quite dangerous, we just remove it in the case of forced unmounts, which are situations where the risk of data loss is known to the operator. To generate a diff of this commit: cvs rdiff -u -r1.30.2.2 -r1.30.2.3 src/sys/kern/vfs_mount.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_mount.c diff -u src/sys/kern/vfs_mount.c:1.30.2.2 src/sys/kern/vfs_mount.c:1.30.2.3 --- src/sys/kern/vfs_mount.c:1.30.2.2 Fri Jan 9 14:50:35 2015 +++ src/sys/kern/vfs_mount.c Wed Nov 4 17:55:23 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_mount.c,v 1.30.2.2 2015/01/09 14:50:35 martin Exp $ */ +/* $NetBSD: vfs_mount.c,v 1.30.2.3 2015/11/04 17:55:23 riz Exp $ */ /*- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.30.2.2 2015/01/09 14:50:35 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.30.2.3 2015/11/04 17:55:23 riz Exp $"); #define _VFS_VNODE_PRIVATE @@ -835,7 +835,7 @@ dounmount(struct mount *mp, int flags, s if (mp->mnt_syncer != NULL) vfs_deallocate_syncvnode(mp); error = 0; - if ((mp->mnt_flag & MNT_RDONLY) == 0) { + if (((mp->mnt_flag & MNT_RDONLY) == 0) && ((flags & MNT_FORCE) == 0)) { error = VFS_SYNC(mp, MNT_WAIT, l->l_cred); } if (error == 0 || (flags & MNT_FORCE)) {
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sun Aug 9 10:15:15 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: vfs_wapbl.c Log Message: Pull up following revision(s) (requested by mlelstv in ticket #943): sys/kern/vfs_wapbl.c: revision 1.62 Refactor disk address calculation from physical block numbers in the journal into a function. Make that function work correctly with sector sizes != DEV_BSIZE when compiled outside the kernel (i.e. fsck_ffs). Fixes PR bin/45933 To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.59.4.1 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.59 src/sys/kern/vfs_wapbl.c:1.59.4.1 --- src/sys/kern/vfs_wapbl.c:1.59 Tue Feb 25 18:30:11 2014 +++ src/sys/kern/vfs_wapbl.c Sun Aug 9 10:15:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_wapbl.c,v 1.59 2014/02/25 18:30:11 pooka Exp $ */ +/* $NetBSD: vfs_wapbl.c,v 1.59.4.1 2015/08/09 10:15:15 martin Exp $ */ /*- * Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #define WAPBL_INTERNAL #include -__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.59 2014/02/25 18:30:11 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.59.4.1 2015/08/09 10:15:15 martin Exp $"); #include #include @@ -2602,6 +2602,32 @@ wapbl_replay_isopen1(struct wapbl_replay } #endif +/* + * calculate the disk address for the i'th block in the wc_blockblist + * offset by j blocks of size blen. + * + * wc_daddr is always a kernel disk address in DEV_BSIZE units that + * was written to the journal. + * + * The kernel needs that address plus the offset in DEV_BSIZE units. + * + * Userland needs that address plus the offset in blen units. + * + */ +static daddr_t +wapbl_block_daddr(struct wapbl_wc_blocklist *wc, int i, int j, int blen) +{ + daddr_t pbn; + +#ifdef _KERNEL + pbn = wc->wc_blocks[i].wc_daddr + btodb(j * blen); +#else + pbn = dbtob(wc->wc_blocks[i].wc_daddr) / blen + j; +#endif + + return pbn; +} + static void wapbl_replay_process_blocks(struct wapbl_replay *wr, off_t *offp) { @@ -2616,7 +2642,7 @@ wapbl_replay_process_blocks(struct wapbl */ n = wc->wc_blocks[i].wc_dlen >> wr->wr_fs_dev_bshift; for (j = 0; j < n; j++) { - wapbl_blkhash_ins(wr, wc->wc_blocks[i].wc_daddr + btodb(j * fsblklen), + wapbl_blkhash_ins(wr, wapbl_block_daddr(wc, i, j, fsblklen), *offp); wapbl_circ_advance(wr, fsblklen, offp); } @@ -2637,7 +2663,7 @@ wapbl_replay_process_revocations(struct */ n = wc->wc_blocks[i].wc_dlen >> wr->wr_fs_dev_bshift; for (j = 0; j < n; j++) - wapbl_blkhash_rem(wr, wc->wc_blocks[i].wc_daddr + btodb(j * fsblklen)); + wapbl_blkhash_rem(wr, wapbl_block_daddr(wc, i, j, fsblklen)); } } @@ -2773,7 +2799,7 @@ wapbl_replay_verify(struct wapbl_replay for (j = 0; j < n; j++) { struct wapbl_blk *wb = wapbl_blkhash_get(wr, - wc->wc_blocks[i].wc_daddr + btodb(j * fsblklen)); + wapbl_block_daddr(wc, i, j, fsblklen)); if (wb && (wb->wb_off == off)) { foundcnt++; error = @@ -2817,7 +2843,7 @@ wapbl_replay_verify(struct wapbl_replay for (j = 0; j < n; j++) { struct wapbl_blk *wb = wapbl_blkhash_get(wr, - wc->wc_blocks[i].wc_daddr + btodb(j * fsblklen)); + wapbl_block_daddr(wc, i, j, fsblklen)); if (wb && (wb->wb_off == off)) { wapbl_blkhash_rem(wr, wb->wb_blk);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sat Aug 8 15:45:47 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: uipc_syscalls.c Log Message: Pull up following revision(s) (requested by maxv in ticket #942): sys/kern/uipc_syscalls.c: revision 1.179 Memory leak. Triggerable from an unprivileged user via COMPAT_43. To generate a diff of this commit: cvs rdiff -u -r1.172 -r1.172.2.1 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.172 src/sys/kern/uipc_syscalls.c:1.172.2.1 --- src/sys/kern/uipc_syscalls.c:1.172 Sat Aug 9 05:33:00 2014 +++ src/sys/kern/uipc_syscalls.c Sat Aug 8 15:45:47 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.172 2014/08/09 05:33:00 rtr Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.172.2.1 2015/08/08 15:45:47 martin Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.172 2014/08/09 05:33:00 rtr Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.172.2.1 2015/08/08 15:45:47 martin Exp $"); #include "opt_pipe.h" @@ -665,9 +665,16 @@ do_sys_sendmsg(struct lwp *l, int s, str struct socket *so; file_t *fp; - if ((error = fd_getsock1(s, &so, &fp)) != 0) + if ((error = fd_getsock1(s, &so, &fp)) != 0) { + /* We have to free msg_name and msg_control ourselves */ + if (mp->msg_flags & MSG_NAMEMBUF) + m_freem(mp->msg_name); + if (mp->msg_flags & MSG_CONTROLMBUF) + m_freem(mp->msg_control); return error; + } error = do_sys_sendmsg_so(l, s, so, fp, mp, flags, retsize); + /* msg_name and msg_control freed */ fd_putfile(s); return error; }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Thu Aug 6 21:47:11 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: sys_pset.c Log Message: Pull up following revision(s) (requested by maxv in ticket #912): sys/kern/sys_pset.c: revision 1.19 Don't forget to unlock the LWP. ok rmind@ To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.18.4.1 src/sys/kern/sys_pset.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_pset.c diff -u src/sys/kern/sys_pset.c:1.18 src/sys/kern/sys_pset.c:1.18.4.1 --- src/sys/kern/sys_pset.c:1.18 Tue Feb 25 18:30:11 2014 +++ src/sys/kern/sys_pset.c Thu Aug 6 21:47:11 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_pset.c,v 1.18 2014/02/25 18:30:11 pooka Exp $ */ +/* $NetBSD: sys_pset.c,v 1.18.4.1 2015/08/06 21:47:11 snj Exp $ */ /* * Copyright (c) 2008, Mindaugas Rasiukevicius @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_pset.c,v 1.18 2014/02/25 18:30:11 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_pset.c,v 1.18.4.1 2015/08/06 21:47:11 snj Exp $"); #include @@ -380,6 +380,7 @@ sys_pset_assign(struct lwp *l, const str mutex_exit(&cpu_lock); return EPERM; } + lwp_unlock(t); } /* * Set the processor-set ID.
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Tue Aug 4 17:24:59 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: kern_descrip.c Log Message: Pull up following revision(s) (requested by christos in ticket #933): sys/kern/kern_descrip.c: revision 1.229 1. mask fflags so we don't tack on whateve oflags were passed from userland 2. honor O_CLOEXEC, so the children of daemons that use cloning devices, don't end up with the parents descriptors fd_clone and in general the fd approach of 'allocate' > 'play with guts' > 'attach' should be converted to be more constructor like. To generate a diff of this commit: cvs rdiff -u -r1.225 -r1.225.2.1 src/sys/kern/kern_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/kern_descrip.c diff -u src/sys/kern/kern_descrip.c:1.225 src/sys/kern/kern_descrip.c:1.225.2.1 --- src/sys/kern/kern_descrip.c:1.225 Fri Jul 25 08:10:40 2014 +++ src/sys/kern/kern_descrip.c Tue Aug 4 17:24:59 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_descrip.c,v 1.225 2014/07/25 08:10:40 dholland Exp $ */ +/* $NetBSD: kern_descrip.c,v 1.225.2.1 2015/08/04 17:24:59 snj Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.225 2014/07/25 08:10:40 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.225.2.1 2015/08/04 17:24:59 snj Exp $"); #include #include @@ -1861,8 +1861,14 @@ int fd_clone(file_t *fp, unsigned fd, int flag, const struct fileops *fops, void *data) { + fdfile_t *ff; + filedesc_t *fdp; - fp->f_flag = flag; + fp->f_flag |= flag & FMASK; + fdp = curproc->p_fd; + ff = fdp->fd_dt->dt_ff[fd]; + KASSERT(ff != NULL); + ff->ff_exclose = (flag & O_CLOEXEC) != 0; fp->f_type = DTYPE_MISC; fp->f_ops = fops; fp->f_data = data;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Tue May 19 04:53:02 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: subr_disk.c Log Message: Pull up following revision(s) (requested by chs in ticket #766): sys/kern/subr_disk.c: revision 1.113 in bounds_check_with_*, reject negative block numbers and avoid a potential overflow in calculating the size of the request. To generate a diff of this commit: cvs rdiff -u -r1.103 -r1.103.4.1 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.103 src/sys/kern/subr_disk.c:1.103.4.1 --- src/sys/kern/subr_disk.c:1.103 Sat Oct 19 22:36:57 2013 +++ src/sys/kern/subr_disk.c Tue May 19 04:53:02 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_disk.c,v 1.103 2013/10/19 22:36:57 mlelstv Exp $ */ +/* $NetBSD: subr_disk.c,v 1.103.4.1 2015/05/19 04:53:02 snj Exp $ */ /*- * Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.103 2013/10/19 22:36:57 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.103.4.1 2015/05/19 04:53:02 snj Exp $"); #include #include @@ -323,7 +323,18 @@ bounds_check_with_mediasize(struct buf * { int64_t sz; - sz = howmany(bp->b_bcount, secsize); + if (bp->b_blkno < 0) { + /* Reject negative offsets immediately. */ + bp->b_error = EINVAL; + return 0; + } + + sz = howmany((int64_t)bp->b_bcount, secsize); + + /* + * bp->b_bcount is a 32-bit value, and we rejected a negative + * bp->b_blkno already, so "bp->b_blkno + sz" cannot overflow. + */ if (bp->b_blkno + sz > mediasize) { sz = mediasize - bp->b_blkno; @@ -357,6 +368,12 @@ bounds_check_with_label(struct disk *dk, uint64_t p_size, p_offset, labelsector; int64_t sz; + if (bp->b_blkno < 0) { + /* Reject negative offsets immediately. */ + bp->b_error = EINVAL; + return -1; + } + /* Protect against division by zero. XXX: Should never happen?!?! */ if (lp->d_secpercyl == 0) { bp->b_error = EINVAL; @@ -372,8 +389,14 @@ bounds_check_with_label(struct disk *dk, #endif labelsector = (labelsector + dk->dk_labelsector) << dk->dk_blkshift; - sz = howmany(bp->b_bcount, DEV_BSIZE); - if ((bp->b_blkno + sz) > p_size) { + sz = howmany((int64_t)bp->b_bcount, DEV_BSIZE); + + /* + * bp->b_bcount is a 32-bit value, and we rejected a negative + * bp->b_blkno already, so "bp->b_blkno + sz" cannot overflow. + */ + + if (bp->b_blkno + sz > p_size) { sz = p_size - bp->b_blkno; if (sz == 0) { /* If exactly at end of disk, return EOF. */
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Tue Apr 14 04:44:41 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: uipc_usrreq.c Log Message: Pull up following revision(s) (requested by christos in ticket #678): sys/kern/uipc_usrreq.c: revision 1.175 PR/39918: ITOH Yasufumi: Replace KASSERT with continue, since the file descriptor can be closed since closef() does not pay attention to FDEFER. XXX: Pullup-7 To generate a diff of this commit: cvs rdiff -u -r1.169.2.2 -r1.169.2.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.169.2.2 src/sys/kern/uipc_usrreq.c:1.169.2.3 --- src/sys/kern/uipc_usrreq.c:1.169.2.2 Wed Feb 4 06:29:07 2015 +++ src/sys/kern/uipc_usrreq.c Tue Apr 14 04:44:41 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.169.2.2 2015/02/04 06:29:07 snj Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.169.2.3 2015/04/14 04:44:41 snj Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169.2.2 2015/02/04 06:29:07 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169.2.3 2015/04/14 04:44:41 snj Exp $"); #include #include @@ -1710,7 +1710,14 @@ unp_gc(file_t *dp) if ((fp->f_flag & FDEFER) != 0) { atomic_and_uint(&fp->f_flag, ~FDEFER); unp_defer--; -KASSERT(fp->f_count != 0); +if (fp->f_count == 0) { + /* + * XXX: closef() doesn't pay attention + * to FDEFER + */ + mutex_exit(&fp->f_lock); + continue; +} } else { if (fp->f_count == 0 || (fp->f_flag & FMARK) != 0 ||
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Wed Feb 18 06:35:58 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: vfs_syscalls.c Log Message: Pull up following revision(s) (requested by martin in ticket #523): sys/kern/vfs_syscalls.c: revision 1.493 A syscall like posix_fallocate() that is not supposed to set errno in userland needs to always return 0 and store the error code *retval. To generate a diff of this commit: cvs rdiff -u -r1.490.2.1 -r1.490.2.2 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.490.2.1 src/sys/kern/vfs_syscalls.c:1.490.2.2 --- src/sys/kern/vfs_syscalls.c:1.490.2.1 Mon Dec 1 09:54:50 2014 +++ src/sys/kern/vfs_syscalls.c Wed Feb 18 06:35:58 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.490.2.1 2014/12/01 09:54:50 martin Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.490.2.2 2015/02/18 06:35:58 snj Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.490.2.1 2014/12/01 09:54:50 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.490.2.2 2015/02/18 06:35:58 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -4716,12 +4716,14 @@ sys_posix_fallocate(struct lwp *l, const len = SCARG(uap, len); if (pos < 0 || len < 0 || len > OFF_T_MAX - pos) { - return EINVAL; + *retval = EINVAL; + return 0; } error = fd_getvnode(fd, &fp); if (error) { - return error; + *retval = error; + return 0; } if ((fp->f_flag & FWRITE) == 0) { error = EBADF; @@ -4739,7 +4741,8 @@ sys_posix_fallocate(struct lwp *l, const fail: fd_putfile(fd); - return error; + *retval = error; + return 0; } /*
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Mon Feb 9 09:46:01 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: uipc_mbuf.c Log Message: Pull up following revision(s) (requested by mlelstv in ticket #501): sys/kern/uipc_mbuf.c: revision 1.161 Correct m_len calculation for m_dup() with mbuf clusters. Fixes kern/49650. To generate a diff of this commit: cvs rdiff -u -r1.158 -r1.158.4.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.158 src/sys/kern/uipc_mbuf.c:1.158.4.1 --- src/sys/kern/uipc_mbuf.c:1.158 Tue Feb 25 18:30:11 2014 +++ src/sys/kern/uipc_mbuf.c Mon Feb 9 09:46:01 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_mbuf.c,v 1.158 2014/02/25 18:30:11 pooka Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.158.4.1 2015/02/09 09:46:01 martin Exp $ */ /*- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.158 2014/02/25 18:30:11 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.158.4.1 2015/02/09 09:46:01 martin Exp $"); #include "opt_mbuftrace.h" #include "opt_nmbclusters.h" @@ -777,8 +777,13 @@ m_copym0(struct mbuf *m, int off0, int l /* * we are unsure about the way m was allocated. * copy into multiple MCLBYTES cluster mbufs. + * + * recompute m_len, it is no longer valid if MCLGET() + * fails to allocate a cluster. Then we try to split + * the source into normal sized mbufs. */ MCLGET(n, wait); +n->m_len = 0; n->m_len = M_TRAILINGSPACE(n); n->m_len = m_copylen(len, n->m_len); n->m_len = min(n->m_len, m->m_len - off);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Wed Feb 4 06:29:07 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: uipc_usrreq.c Log Message: Pull up following revision(s) (requested by jmcneill in ticket #474): sys/kern/uipc_usrreq.c: revision 1.173 Handle LOCAL_PEERID for socketpair() connected sockets which connect through connect2(). 1. move the code that sets the peerid structure into connect1(). This handles so2. The datagram code calls connect2 twice with flipped so arguments so both sockets get set. 2. in connect2 copy the peerid structure from so2 to so, so that that both stream sockets get set. To generate a diff of this commit: cvs rdiff -u -r1.169.2.1 -r1.169.2.2 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.169.2.1 src/sys/kern/uipc_usrreq.c:1.169.2.2 --- src/sys/kern/uipc_usrreq.c:1.169.2.1 Sat Oct 11 16:16:44 2014 +++ src/sys/kern/uipc_usrreq.c Wed Feb 4 06:29:07 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.169.2.1 2014/10/11 16:16:44 snj Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.169.2.2 2015/02/04 06:29:07 snj Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169.2.1 2014/10/11 16:16:44 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169.2.2 2015/02/04 06:29:07 snj Exp $"); #include #include @@ -1075,7 +1075,7 @@ unp_abort(struct socket *so) } static int -unp_connect1(struct socket *so, struct socket *so2) +unp_connect1(struct socket *so, struct socket *so2, struct lwp *l) { struct unpcb *unp = sotounpcb(so); struct unpcb *unp2; @@ -1099,6 +1099,18 @@ unp_connect1(struct socket *so, struct s unp2 = sotounpcb(so2); unp->unp_conn = unp2; + + if ((so->so_proto->pr_flags & PR_CONNREQUIRED) != 0) { + unp2->unp_connid.unp_pid = l->l_proc->p_pid; + unp2->unp_connid.unp_euid = kauth_cred_geteuid(l->l_cred); + unp2->unp_connid.unp_egid = kauth_cred_getegid(l->l_cred); + unp2->unp_flags |= UNP_EIDSVALID; + if (unp2->unp_flags & UNP_EIDSBIND) { + unp->unp_connid = unp2->unp_connid; + unp->unp_flags |= UNP_EIDSVALID; + } + } + switch (so->so_type) { case SOCK_DGRAM: @@ -1208,17 +1220,9 @@ unp_connect(struct socket *so, struct mb unp3->unp_addrlen = unp2->unp_addrlen; } unp3->unp_flags = unp2->unp_flags; - unp3->unp_connid.unp_pid = l->l_proc->p_pid; - unp3->unp_connid.unp_euid = kauth_cred_geteuid(l->l_cred); - unp3->unp_connid.unp_egid = kauth_cred_getegid(l->l_cred); - unp3->unp_flags |= UNP_EIDSVALID; - if (unp2->unp_flags & UNP_EIDSBIND) { - unp->unp_connid = unp2->unp_connid; - unp->unp_flags |= UNP_EIDSVALID; - } so2 = so3; } - error = unp_connect1(so, so2); + error = unp_connect1(so, so2, l); if (error) { sounlock(so); goto bad; @@ -1269,7 +1273,7 @@ unp_connect2(struct socket *so, struct s KASSERT(solocked2(so, so2)); - error = unp_connect1(so, so2); + error = unp_connect1(so, so2, curlwp); if (error) return error; @@ -1285,6 +1289,10 @@ unp_connect2(struct socket *so, struct s case SOCK_SEQPACKET: /* FALLTHROUGH */ case SOCK_STREAM: unp2->unp_conn = unp; + if ((so->so_proto->pr_flags & PR_CONNREQUIRED) != 0) { + unp->unp_connid = unp2->unp_connid; + unp->unp_flags |= UNP_EIDSVALID; + } soisconnected(so); soisconnected(so2); break;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Fri Jan 9 14:50:35 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: vfs_mount.c Log Message: Pull up following revision(s) (requested by hannken in ticket #398): sys/kern/vfs_mount.c: revision 1.32 vfs_vnode_iterator_destroy: set v_usecount of marker to zero to prevent an assertion from vnfree(). To generate a diff of this commit: cvs rdiff -u -r1.30.2.1 -r1.30.2.2 src/sys/kern/vfs_mount.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_mount.c diff -u src/sys/kern/vfs_mount.c:1.30.2.1 src/sys/kern/vfs_mount.c:1.30.2.2 --- src/sys/kern/vfs_mount.c:1.30.2.1 Tue Nov 18 18:40:06 2014 +++ src/sys/kern/vfs_mount.c Fri Jan 9 14:50:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_mount.c,v 1.30.2.1 2014/11/18 18:40:06 snj Exp $ */ +/* $NetBSD: vfs_mount.c,v 1.30.2.2 2015/01/09 14:50:35 martin Exp $ */ /*- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.30.2.1 2014/11/18 18:40:06 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.30.2.2 2015/01/09 14:50:35 martin Exp $"); #define _VFS_VNODE_PRIVATE @@ -365,8 +365,10 @@ vfs_vnode_iterator_destroy(struct vnode_ mutex_enter(&mntvnode_lock); KASSERT(ISSET(mvp->v_iflag, VI_MARKER)); - if (mvp->v_usecount != 0) + if (mvp->v_usecount != 0) { TAILQ_REMOVE(&mvp->v_mount->mnt_vnodelist, mvp, v_mntvnodes); + mvp->v_usecount = 0; + } mutex_exit(&mntvnode_lock); vnfree(mvp); }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Fri Jan 9 14:06:55 UTC 2015 Modified Files: src/sys/kern [netbsd-7]: kern_rndq.c Log Message: Pull up following revision(s) (requested by christos in ticket #397): sys/kern/kern_rndq.c: revision 1.29 PR 49104: Jarle Greipsland: Don't use cpu_counter32() unconditionally. PR 49124: Soekris net4501 panics during boot after merge of "tls-earlyentropy" to HEAD To generate a diff of this commit: cvs rdiff -u -r1.26.2.2 -r1.26.2.3 src/sys/kern/kern_rndq.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_rndq.c diff -u src/sys/kern/kern_rndq.c:1.26.2.2 src/sys/kern/kern_rndq.c:1.26.2.3 --- src/sys/kern/kern_rndq.c:1.26.2.2 Sun Nov 2 09:47:04 2014 +++ src/sys/kern/kern_rndq.c Fri Jan 9 14:06:55 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_rndq.c,v 1.26.2.2 2014/11/02 09:47:04 martin Exp $ */ +/* $NetBSD: kern_rndq.c,v 1.26.2.3 2015/01/09 14:06:55 martin Exp $ */ /*- * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.26.2.2 2014/11/02 09:47:04 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.26.2.3 2015/01/09 14:06:55 martin Exp $"); #include #include @@ -222,7 +222,8 @@ rnd_counter(void) uint32_t ret; #if defined(__HAVE_CPU_COUNTER) - return (cpu_counter32()); + if (cpu_hascounter()) + return cpu_counter32(); #endif if (rnd_ready) { nanouptime(&ts);
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Mon Dec 1 09:54:50 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: vfs_syscalls.c Log Message: Pull up following revision(s) (requested by manu in ticket #276): sys/kern/vfs_syscalls.c: revision 1.492 Do not follow symlinks in sys_unmount() There are situations where the underlying filesystem is unreachable (e.g: NFS) causing symlink resolution to hang. Such a situation should be avoided by using umount -f -R (force and raw), but while -R causes the symlink resolution to be skipped in umount(8), the kernel was still doing it in sys_unmount(). This changes fixes that. When the -R flag is not given, umount(8) does symlinks resolution through realpath(3) before calling unmount(2), hence not doing it in the kernel would not change behavior. To generate a diff of this commit: cvs rdiff -u -r1.490 -r1.490.2.1 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.490 src/sys/kern/vfs_syscalls.c:1.490.2.1 --- src/sys/kern/vfs_syscalls.c:1.490 Fri Jul 25 16:28:12 2014 +++ src/sys/kern/vfs_syscalls.c Mon Dec 1 09:54:50 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.490 2014/07/25 16:28:12 maxv Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.490.2.1 2014/12/01 09:54:50 martin Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.490 2014/07/25 16:28:12 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.490.2.1 2014/12/01 09:54:50 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -574,7 +574,7 @@ sys_unmount(struct lwp *l, const struct return error; } - NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb); + NDINIT(&nd, LOOKUP, LOCKLEAF | TRYEMULROOT, pb); if ((error = namei(&nd)) != 0) { pathbuf_destroy(pb); return error;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Tue Nov 25 14:53:23 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: sys_process.c Log Message: Pull up following revision(s) (requested by christos in ticket #262): sys/kern/sys_process.c: revision 1.165 Don't return early when the incorrect size is passed to some of the ptrace actions. Leaves locks dangling and causes panics with lockdebug. To generate a diff of this commit: cvs rdiff -u -r1.163 -r1.163.4.1 src/sys/kern/sys_process.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_process.c diff -u src/sys/kern/sys_process.c:1.163 src/sys/kern/sys_process.c:1.163.4.1 --- src/sys/kern/sys_process.c:1.163 Sat Jan 4 00:10:03 2014 +++ src/sys/kern/sys_process.c Tue Nov 25 14:53:23 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_process.c,v 1.163 2014/01/04 00:10:03 dsl Exp $ */ +/* $NetBSD: sys_process.c,v 1.163.4.1 2014/11/25 14:53:23 martin Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -118,7 +118,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.163 2014/01/04 00:10:03 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.163.4.1 2014/11/25 14:53:23 martin Exp $"); #include "opt_ptrace.h" #include "opt_ktrace.h" @@ -140,6 +140,13 @@ __KERNEL_RCSID(0, "$NetBSD: sys_process. #include #ifdef PTRACE + +# ifdef DEBUG +# define DPRINTF(a) uprintf a +# else +# define DPRINTF(a) +# endif + static kauth_listener_t ptrace_listener; static int @@ -398,7 +405,7 @@ sys_ptrace(struct lwp *l, const struct s * different signal delivery semantics), */ if (ISSET(t->p_slflag, PSL_FSTRACE)) { - uprintf("file system traced\n"); + DPRINTF(("file system traced\n")); error = EBUSY; break; } @@ -407,8 +414,8 @@ sys_ptrace(struct lwp *l, const struct s * (3) it's not being traced by _you_, or */ if (t->p_pptr != p) { - uprintf("parent %d != %d\n", t->p_pptr->p_pid, - p->p_pid); + DPRINTF(("parent %d != %d\n", t->p_pptr->p_pid, + p->p_pid)); error = EBUSY; break; } @@ -417,8 +424,8 @@ sys_ptrace(struct lwp *l, const struct s * (4) it's not currently stopped. */ if (t->p_stat != SSTOP || !t->p_waited /* XXXSMP */) { - uprintf("stat %d flag %d\n", t->p_stat, - !t->p_waited); + DPRINTF(("stat %d flag %d\n", t->p_stat, + !t->p_waited)); error = EBUSY; break; } @@ -770,17 +777,25 @@ sys_ptrace(struct lwp *l, const struct s goto sendsig; case PT_GET_EVENT_MASK: - if (SCARG(uap, data) != sizeof(pe)) - return EINVAL; + if (SCARG(uap, data) != sizeof(pe)) { + DPRINTF(("ptrace(%d): %d != %zu\n", req, + SCARG(uap, data), sizeof(pe))); + error = EINVAL; + break; + } memset(&pe, 0, sizeof(pe)); pe.pe_set_event = ISSET(t->p_slflag, PSL_TRACEFORK) ? - PTRACE_FORK : 0; + PTRACE_FORK : 0; error = copyout(&pe, SCARG(uap, addr), sizeof(pe)); break; case PT_SET_EVENT_MASK: - if (SCARG(uap, data) != sizeof(pe)) - return EINVAL; + if (SCARG(uap, data) != sizeof(pe)) { + DPRINTF(("ptrace(%d): %d != %zu\n", req, + SCARG(uap, data), sizeof(pe))); + error = EINVAL; + break; + } if ((error = copyin(SCARG(uap, addr), &pe, sizeof(pe))) != 0) return error; if (pe.pe_set_event & PTRACE_FORK) @@ -790,8 +805,12 @@ sys_ptrace(struct lwp *l, const struct s break; case PT_GET_PROCESS_STATE: - if (SCARG(uap, data) != sizeof(ps)) - return EINVAL; + if (SCARG(uap, data) != sizeof(ps)) { + DPRINTF(("ptrace(%d): %d != %zu\n", req, + SCARG(uap, data), sizeof(ps))); + error = EINVAL; + break; + } memset(&ps, 0, sizeof(ps)); if (t->p_fpid) { ps.pe_report_event = PTRACE_FORK; @@ -802,6 +821,8 @@ sys_ptrace(struct lwp *l, const struct s case PT_LWPINFO: if (SCARG(uap, data) != sizeof(pl)) { + DPRINTF(("ptrace(%d): %d != %zu\n", req, + SCARG(uap, data), sizeof(pl))); error = EINVAL; break; }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sat Oct 25 10:00:47 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: kern_exec.c Log Message: Pull up following revision(s) (requested by dholland in ticket #156): sys/kern/kern_exec.c: revision 1.409 PR/49287: David Holland: Skip the right number of bytes to go over the first argument in the argv vector. Fixes netbsd32 script execution, where you lost the first argument because it skipped 8 bytes instead of 4. To generate a diff of this commit: cvs rdiff -u -r1.408 -r1.408.2.1 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.408 src/sys/kern/kern_exec.c:1.408.2.1 --- src/sys/kern/kern_exec.c:1.408 Sun Jun 22 17:23:34 2014 +++ src/sys/kern/kern_exec.c Sat Oct 25 10:00:47 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exec.c,v 1.408 2014/06/22 17:23:34 maxv Exp $ */ +/* $NetBSD: kern_exec.c,v 1.408.2.1 2014/10/25 10:00:47 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.408 2014/06/22 17:23:34 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.408.2.1 2014/10/25 10:00:47 martin Exp $"); #include "opt_exec.h" #include "opt_execfmt.h" @@ -1336,6 +1336,12 @@ execve1(struct lwp *l, const char *path, } static size_t +ptrsz(const struct exec_package *epp) +{ + return (epp->ep_flags & EXEC_32) ? sizeof(int) : sizeof(char *); +} + +static size_t calcargs(struct execve_data * restrict data, const size_t argenvstrlen) { struct exec_package * const epp = &data->ed_pack; @@ -1348,10 +1354,7 @@ calcargs(struct execve_data * restrict d 1 +/* \0 */ epp->ep_esch->es_arglen; /* auxinfo */ - const size_t ptrsz = (epp->ep_flags & EXEC_32) ? - sizeof(int) : sizeof(char *); - - return (nargenvptrs * ptrsz) + argenvstrlen; + return (nargenvptrs * ptrsz(epp)) + argenvstrlen; } static size_t @@ -1506,7 +1509,7 @@ copyinargs(struct execve_data * restrict return EINVAL; } if (epp->ep_flags & EXEC_SKIPARG) - args++; + args = (const void *)((const char *)args + ptrsz(epp)); i = 0; error = copyinargstrs(data, args, fetch_element, &dp, &i, ktr_execarg); if (error != 0) {
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sun Oct 19 10:02:59 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: vfs_vnode.c Log Message: Pull up following revision(s) (requested by hannken in ticket #150): sys/kern/vfs_vnode.c: revision 1.39 When creating a vnode with vcache_get() mark the vnode VI_CHANGING until it is fully initialised. It may be on the specnode list before it is fully initialised and revoking it then would panic. Should prevent the panic from PR kern/49171 (panic when closing a pty). To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.37.2.1 src/sys/kern/vfs_vnode.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_vnode.c diff -u src/sys/kern/vfs_vnode.c:1.37 src/sys/kern/vfs_vnode.c:1.37.2.1 --- src/sys/kern/vfs_vnode.c:1.37 Sat Jul 5 09:33:15 2014 +++ src/sys/kern/vfs_vnode.c Sun Oct 19 10:02:59 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnode.c,v 1.37 2014/07/05 09:33:15 hannken Exp $ */ +/* $NetBSD: vfs_vnode.c,v 1.37.2.1 2014/10/19 10:02:59 martin Exp $ */ /*- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. @@ -116,7 +116,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.37 2014/07/05 09:33:15 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.37.2.1 2014/10/19 10:02:59 martin Exp $"); #define _VFS_VNODE_PRIVATE @@ -1292,6 +1292,7 @@ again: } /* Load the fs node. Exclusive as new_node->vn_vnode is NULL. */ + vp->v_iflag |= VI_CHANGING; error = VFS_LOADVNODE(mp, vp, key, key_len, &new_key); if (error) { mutex_enter(&vcache.lock); @@ -1319,6 +1320,10 @@ again: new_node->vn_key.vk_key = new_key; new_node->vn_vnode = vp; mutex_exit(&vcache.lock); + mutex_enter(vp->v_interlock); + vp->v_iflag &= ~VI_CHANGING; + cv_broadcast(&vp->v_cv); + mutex_exit(vp->v_interlock); *vpp = vp; return 0; }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: snj Date: Sat Oct 11 16:16:44 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: uipc_usrreq.c Log Message: Pull up following revision(s) (requested by taca in ticket #132): sys/kern/uipc_usrreq.c: revision 1.172 Make behavior of getsockname(2) (and maybe getpeername(2)) as the same as NetBSD 6.1_STABLE and other operating system (OS X 10.9.5). * sa_len of sockaddr_un strucrure is always set to sizeof(sun_path). * pathname stored in sun_path is alwasys '\0' terminated (except length of sun_path is sizeof(sun_path)?). Should be fix PR kern/49247, runtime problem of lmtp service of dovecot2 on NetBSD current and NetBSD 7.0_BETA. To generate a diff of this commit: cvs rdiff -u -r1.169 -r1.169.2.1 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.169 src/sys/kern/uipc_usrreq.c:1.169.2.1 --- src/sys/kern/uipc_usrreq.c:1.169 Sat Aug 9 05:33:00 2014 +++ src/sys/kern/uipc_usrreq.c Sat Oct 11 16:16:44 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.169 2014/08/09 05:33:00 rtr Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.169.2.1 2014/10/11 16:16:44 snj Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169 2014/08/09 05:33:00 rtr Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169.2.1 2014/10/11 16:16:44 snj Exp $"); #include #include @@ -927,8 +927,6 @@ makeun(struct mbuf *nam, size_t *addrlen sun = malloc(*addrlen, M_SONAME, M_WAITOK); m_copydata(nam, 0, nam->m_len, (void *)sun); *(((char *)sun) + nam->m_len) = '\0'; - sun->sun_len = strlen(sun->sun_path) + - offsetof(struct sockaddr_un, sun_path); return sun; }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Sat Aug 30 14:09:53 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: subr_tftproot.c Log Message: Pull up following revision(s) (requested by manu in ticket #69): sys/kern/subr_tftproot.c: revision 1.13 Fix build with TFTPROOT option enabled To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.12.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.12 src/sys/kern/subr_tftproot.c:1.12.12.1 --- src/sys/kern/subr_tftproot.c:1.12 Sat Dec 1 11:41:50 2012 +++ src/sys/kern/subr_tftproot.c Sat Aug 30 14:09:53 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_tftproot.c,v 1.12 2012/12/01 11:41:50 mbalmer Exp $ */ +/* $NetBSD: subr_tftproot.c,v 1.12.12.1 2014/08/30 14:09:53 martin Exp $ */ /*- * Copyright (c) 2007 Emmanuel Dreyfus, all rights reserved. @@ -39,10 +39,11 @@ #include "opt_md.h" #include -__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.12 2012/12/01 11:41:50 mbalmer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.12.12.1 2014/08/30 14:09:53 martin Exp $"); #include #include +#include #include #include #include
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Mon Aug 18 07:37:04 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: exec_elf.c Log Message: Pull up following revision(s) (requested by chs in ticket #32): sys/kern/exec_elf.c: revision 1.70 eliminate COMPAT_OLDNOTE and just always recognize the old notes. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.69.2.1 src/sys/kern/exec_elf.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_elf.c diff -u src/sys/kern/exec_elf.c:1.69 src/sys/kern/exec_elf.c:1.69.2.1 --- src/sys/kern/exec_elf.c:1.69 Tue Jul 8 17:16:25 2014 +++ src/sys/kern/exec_elf.c Mon Aug 18 07:37:04 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf.c,v 1.69 2014/07/08 17:16:25 maxv Exp $ */ +/* $NetBSD: exec_elf.c,v 1.69.2.1 2014/08/18 07:37:04 martin Exp $ */ /*- * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69 2014/07/08 17:16:25 maxv Exp $"); +__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69.2.1 2014/08/18 07:37:04 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_pax.h" @@ -863,9 +863,6 @@ netbsd_elf_signature(struct lwp *l, stru int error; int isnetbsd = 0; char *ndata, *ndesc; -#ifdef COMPAT_OLDNOTE - int compat_oldnote = -1; -#endif #ifdef DIAGNOSTIC const char *badnote; @@ -907,6 +904,12 @@ netbsd_elf_signature(struct lwp *l, stru *header size + 4-byte aligned name + 4-byte aligned desc * Ensure this size is consistent with what is indicated * in sh_size. The first check avoids integer overflows. + * + * Binaries from before NetBSD 1.6 have two notes in the same + * note section. The second note was never used, so as long as + * the section is at least as big as it should be, it's ok. + * These binaries also have a second note section with a note of + * type ELF_NOTE_TYPE_NETBSD_TAG, which can be ignored as well. */ if (np->n_namesz > shp->sh_size || np->n_descsz > shp->sh_size) { BADNOTE("note size limit"); @@ -914,11 +917,8 @@ netbsd_elf_signature(struct lwp *l, stru } nsize = sizeof(*np) + roundup(np->n_namesz, 4) + roundup(np->n_descsz, 4); - if (nsize != shp->sh_size) { + if (nsize > shp->sh_size) { BADNOTE("note size"); -#ifdef COMPAT_OLDNOTE - if (nsize > shp->sh_size || compat_oldnote == 0) -#endif goto bad; } ndesc = ndata + roundup(np->n_namesz, 4); @@ -933,9 +933,6 @@ netbsd_elf_signature(struct lwp *l, stru memcpy(&epp->ep_osversion, ndesc, ELF_NOTE_NETBSD_DESCSZ); isnetbsd = 1; -#ifdef COMPAT_OLDNOTE -compat_oldnote = epp->ep_osversion == 199905; -#endif break; } @@ -947,10 +944,6 @@ netbsd_elf_signature(struct lwp *l, stru memcmp(ndata, ELF_NOTE_SUSE_NAME, ELF_NOTE_SUSE_NAMESZ) == 0) break; -#ifdef COMPAT_OLDNOTE - if (compat_oldnote == 1) -break; -#endif BADNOTE("NetBSD tag"); goto bad;
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: riz Date: Fri Aug 15 23:57:51 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: subr_prf.c Log Message: Pull up following revision(s) (requested by apb in ticket #26): sys/kern/subr_prf.c: revision 1.156 If mutex_tryenter() fails, don't call mutex_exit(). To generate a diff of this commit: cvs rdiff -u -r1.154.2.1 -r1.154.2.2 src/sys/kern/subr_prf.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_prf.c diff -u src/sys/kern/subr_prf.c:1.154.2.1 src/sys/kern/subr_prf.c:1.154.2.2 --- src/sys/kern/subr_prf.c:1.154.2.1 Fri Aug 15 13:00:48 2014 +++ src/sys/kern/subr_prf.c Fri Aug 15 23:57:51 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_prf.c,v 1.154.2.1 2014/08/15 13:00:48 martin Exp $ */ +/* $NetBSD: subr_prf.c,v 1.154.2.2 2014/08/15 23:57:51 riz Exp $ */ /*- * Copyright (c) 1986, 1988, 1991, 1993 @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.154.2.1 2014/08/15 13:00:48 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.154.2.2 2014/08/15 23:57:51 riz Exp $"); #include "opt_ddb.h" #include "opt_ipkdb.h" @@ -161,8 +161,8 @@ static void kprintf_rnd_get(size_t bytes /* This is optional but seems useful. */ SHA512_Update(&kprnd_sha, kprnd_accum, sizeof(kprnd_accum)); + mutex_exit(&kprintf_mtx); } - mutex_exit(&kprintf_mtx); } }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Fri Aug 15 13:00:48 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: subr_prf.c Log Message: Pull up following revision(s) (requested by mrg in ticket #24): sys/kern/subr_prf.c: revision 1.155 avoid calling into time code when cold, and avoid calling nanotime() if we're not going to use the result anyway. XXX: not necessarily the best fix, but better than crashing *early* boot due to too-early nanotime() calls. XXX: pullup. To generate a diff of this commit: cvs rdiff -u -r1.154 -r1.154.2.1 src/sys/kern/subr_prf.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_prf.c diff -u src/sys/kern/subr_prf.c:1.154 src/sys/kern/subr_prf.c:1.154.2.1 --- src/sys/kern/subr_prf.c:1.154 Sun Aug 10 16:44:36 2014 +++ src/sys/kern/subr_prf.c Fri Aug 15 13:00:48 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_prf.c,v 1.154 2014/08/10 16:44:36 tls Exp $ */ +/* $NetBSD: subr_prf.c,v 1.154.2.1 2014/08/15 13:00:48 martin Exp $ */ /*- * Copyright (c) 1986, 1988, 1991, 1993 @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.154 2014/08/10 16:44:36 tls Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.154.2.1 2014/08/15 13:00:48 martin Exp $"); #include "opt_ddb.h" #include "opt_ipkdb.h" @@ -1200,7 +1200,6 @@ kprintf(const char *fmt0, int oflags, vo const char *xdigs; /* digits for [xX] conversion */ char bf[KPRINTF_BUFSIZE]; /* space for %c, %[diouxX] */ char *tailp; /* tail pointer for snprintf */ - struct timespec ts; if (oflags == TOBUFONLY && (vp != NULL)) tailp = *(char **)vp; @@ -1549,9 +1548,12 @@ done: *(char **)vp = sbuf; (*v_flush)(); - (void)nanotime(&ts); #ifdef RND_PRINTF - SHA512_Update(&kprnd_sha, (char *)&ts, sizeof(ts)); + if (!cold) { + struct timespec ts; + (void)nanotime(&ts); + SHA512_Update(&kprnd_sha, (char *)&ts, sizeof(ts)); + } #endif return ret; }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Fri Aug 15 12:56:24 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: subr_cprng.c Log Message: Pull up following revision(s) (requested by riastradh in ticket #22): sys/kern/subr_cprng.c: revision 1.25 Lock cprng->cs_lock around rndsink_request to avoid race with callback. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.24.2.1 src/sys/kern/subr_cprng.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_cprng.c diff -u src/sys/kern/subr_cprng.c:1.24 src/sys/kern/subr_cprng.c:1.24.2.1 --- src/sys/kern/subr_cprng.c:1.24 Sun Aug 10 16:44:36 2014 +++ src/sys/kern/subr_cprng.c Fri Aug 15 12:56:24 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_cprng.c,v 1.24 2014/08/10 16:44:36 tls Exp $ */ +/* $NetBSD: subr_cprng.c,v 1.24.2.1 2014/08/15 12:56:24 martin Exp $ */ /*- * Copyright (c) 2011-2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.24 2014/08/10 16:44:36 tls Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.24.2.1 2014/08/15 12:56:24 martin Exp $"); #include #include @@ -151,6 +151,7 @@ cprng_strong_create(const char *name, in /* Get some initial entropy. Record whether it is full entropy. */ uint8_t seed[NIST_BLOCK_KEYLEN_BYTES]; + mutex_enter(&cprng->cs_lock); cprng->cs_ready = rndsink_request(cprng->cs_rndsink, seed, sizeof(seed)); if (nist_ctr_drbg_instantiate(&cprng->cs_drbg, seed, sizeof(seed), @@ -168,6 +169,7 @@ cprng_strong_create(const char *name, in if (!cprng->cs_ready && !ISSET(flags, CPRNG_INIT_ANY)) printf("cprng %s: creating with partial entropy\n", cprng->cs_name); + mutex_exit(&cprng->cs_lock); return cprng; }
CVS commit: [netbsd-7] src/sys/kern
Module Name:src Committed By: martin Date: Mon Aug 11 15:38:27 UTC 2014 Modified Files: src/sys/kern [netbsd-7]: kern_rndpool.c kern_rndq.c Log Message: Pull up following revision(s) (requested by riastradh in ticket #4): sys/kern/kern_rndq.c: revision 1.27 sys/kern/kern_rndpool.c: revision 1.7 buf is not guaranteed to be aligned; don't *(uint32_t *) it. done is not guaranteed to be aligned; don't *(uint32_t *) it. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.6.2.1 src/sys/kern/kern_rndpool.c cvs rdiff -u -r1.26 -r1.26.2.1 src/sys/kern/kern_rndq.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_rndpool.c diff -u src/sys/kern/kern_rndpool.c:1.6 src/sys/kern/kern_rndpool.c:1.6.2.1 --- src/sys/kern/kern_rndpool.c:1.6 Sun Aug 10 16:44:36 2014 +++ src/sys/kern/kern_rndpool.c Mon Aug 11 15:38:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_rndpool.c,v 1.6 2014/08/10 16:44:36 tls Exp $*/ +/* $NetBSD: kern_rndpool.c,v 1.6.2.1 2014/08/11 15:38:27 martin Exp $*/ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_rndpool.c,v 1.6 2014/08/10 16:44:36 tls Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_rndpool.c,v 1.6.2.1 2014/08/11 15:38:27 martin Exp $"); #include #include @@ -212,8 +212,7 @@ rndpool_add_data(rndpool_t *rp, buf = p; for (; len > 3; len -= 4) { - val = *((const u_int32_t *)buf); - + (void)memcpy(&val, buf, 4); rndpool_add_one_word(rp, val); buf += 4; } Index: src/sys/kern/kern_rndq.c diff -u src/sys/kern/kern_rndq.c:1.26 src/sys/kern/kern_rndq.c:1.26.2.1 --- src/sys/kern/kern_rndq.c:1.26 Mon Aug 11 04:26:53 2014 +++ src/sys/kern/kern_rndq.c Mon Aug 11 15:38:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_rndq.c,v 1.26 2014/08/11 04:26:53 riastradh Exp $ */ +/* $NetBSD: kern_rndq.c,v 1.26.2.1 2014/08/11 15:38:27 martin Exp $ */ /*- * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.26 2014/08/11 04:26:53 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.26.2.1 2014/08/11 15:38:27 martin Exp $"); #include #include @@ -816,7 +816,8 @@ rnd_add_data_ts(krndsource_t *rs, const u_int32_t entropy, uint32_t ts) { rnd_sample_t *state = NULL; - const uint32_t *dint = data; + const uint8_t *p = data; + uint32_t dint; int todo, done, filled = 0; int sample_count; SIMPLEQ_HEAD(, _rnd_sample_t) tmp_samples = @@ -828,7 +829,7 @@ rnd_add_data_ts(krndsource_t *rs, const RND_FLAG_COLLECT_VALUE) { return; } - todo = len / sizeof(*dint); + todo = len / sizeof(dint); /* * Let's try to be efficient: if we are warm, and a source * is adding entropy at a rate of at least 1 bit every 10 seconds, @@ -874,7 +875,8 @@ rnd_add_data_ts(krndsource_t *rs, const } state->ts[state->cursor] = ts; - state->values[state->cursor] = dint[done]; + (void)memcpy(&dint, &p[done*4], 4); + state->values[state->cursor] = dint; state->cursor++; if (state->cursor == sample_count) {