CVS commit: [netbsd-7] src/sys/kern

2019-11-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 25 15:46:39 UTC 2019

Modified Files:
src/sys/kern [netbsd-7]: subr_cprng.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1714):

sys/kern/subr_cprng.c: revision 1.33

Use cprng_strong, not cprng_fast, for sysctl kern.arnd.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.2 -r1.24.2.3 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.2.2 src/sys/kern/subr_cprng.c:1.24.2.3
--- src/sys/kern/subr_cprng.c:1.24.2.2	Tue Sep  3 12:20:43 2019
+++ src/sys/kern/subr_cprng.c	Mon Nov 25 15:46:39 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_cprng.c,v 1.24.2.2 2019/09/03 12:20:43 martin Exp $ */
+/*	$NetBSD: subr_cprng.c,v 1.24.2.3 2019/11/25 15:46:39 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.2.2 2019/09/03 12:20:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.24.2.3 2019/11/25 15:46:39 martin Exp $");
 
 #include 
 #include 
@@ -508,6 +508,7 @@ cprng_strong_rndsink_callback(void *cont
 	mutex_exit(>cs_lock);
 }
 
+static ONCE_DECL(sysctl_prng_once);
 static cprng_strong_t *sysctl_prng;
 
 static int
@@ -527,10 +528,9 @@ makeprng(void)
 static int
 sysctl_kern_urnd(SYSCTLFN_ARGS)
 {
-	static ONCE_DECL(control);
 	int v, rv;
 
-	RUN_ONCE(, makeprng);
+	RUN_ONCE(_prng_once, makeprng);
 	rv = cprng_strong(sysctl_prng, , sizeof(v), 0);
 	if (rv == sizeof(v)) {
 		struct sysctlnode node = *rnode;
@@ -559,6 +559,7 @@ sysctl_kern_arnd(SYSCTLFN_ARGS)
 	int error;
 	void *v;
 	struct sysctlnode node = *rnode;
+	size_t n __diagused;
 
 	switch (*oldlenp) {
 	case 0:
@@ -567,8 +568,10 @@ sysctl_kern_arnd(SYSCTLFN_ARGS)
 		if (*oldlenp > 256) {
 			return E2BIG;
 		}
+		RUN_ONCE(_prng_once, makeprng);
 		v = kmem_alloc(*oldlenp, KM_SLEEP);
-		cprng_fast(v, *oldlenp);
+		n = cprng_strong(sysctl_prng, v, *oldlenp, 0);
+		KASSERT(n == *oldlenp);
 		node.sysctl_data = v;
 		node.sysctl_size = *oldlenp;
 		error = sysctl_lookup(SYSCTLFN_CALL());



CVS commit: [netbsd-7] src/sys/kern

2019-11-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 25 15:46:39 UTC 2019

Modified Files:
src/sys/kern [netbsd-7]: subr_cprng.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1714):

sys/kern/subr_cprng.c: revision 1.33

Use cprng_strong, not cprng_fast, for sysctl kern.arnd.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.2 -r1.24.2.3 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.



Re: CVS commit: [netbsd-7] src/sys/kern

2019-05-02 Thread Michael van Elst
On Thu, May 02, 2019 at 09:23:15PM +0200, Kamil Rytarowski wrote:
> There was a regression with ATF pipe(2) tests.. I cannot find now the
> references, but it could help to the issue triggered by syzkaller as well.

bin/54068


-- 
Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: CVS commit: [netbsd-7] src/sys/kern

2019-05-02 Thread Michael van Elst
On Thu, May 02, 2019 at 08:59:28PM +0200, Maxime Villard wrote:
> > Clean up pipe structure before recycling it.
> > Handle half-closed pipes in FIONWRITE and FIONSPACE.
> 
> This fixed this bug [1], right?
> 
> [1] 
> https://syzkaller.appspot.com/bug?id=d16eb57ee450d86a0d0c02a3ff7e6837da2ab26f

No idea. This was to fix a problem with the hanging pipe2_consume ATF test.

But looking at the syzkaller trace, it could be caused by the same issue.


Greetings,
-- 
Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: CVS commit: [netbsd-7] src/sys/kern

2019-05-02 Thread Kamil Rytarowski
On 02.05.2019 20:59, Maxime Villard wrote:
> Le 01/05/2019 à 11:48, Martin Husemann a écrit :
>> 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.
> 
> This fixed this bug [1], right?
> 
> [1]
> https://syzkaller.appspot.com/bug?id=d16eb57ee450d86a0d0c02a3ff7e6837da2ab26f
> 

There was a regression with ATF pipe(2) tests.. I cannot find now the
references, but it could help to the issue triggered by syzkaller as well.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: [netbsd-7] src/sys/kern

2019-05-02 Thread Maxime Villard

Le 01/05/2019 à 11:48, Martin Husemann a écrit :

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.


This fixed this bug [1], right?

[1] 
https://syzkaller.appspot.com/bug?id=d16eb57ee450d86a0d0c02a3ff7e6837da2ab26f


CVS commit: [netbsd-7] src/sys/kern

2019-05-01 Thread Martin Husemann
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

2019-05-01 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2019-04-15 Thread SAITOH Masanobu
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.



CVS commit: [netbsd-7] src/sys/kern

2019-04-15 Thread SAITOH Masanobu
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

2019-02-24 Thread Martin Husemann
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_ch, CALLOUT_MPSAFE);
 		else
 			pt->pt_active = 0;



CVS commit: [netbsd-7] src/sys/kern

2019-02-24 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2019-02-01 Thread Martin Husemann
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(, 0, sizeof(atv));
 		microtime();
 		error = copyout(, 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(_lock);
 		olddelta->tv_sec = time_adjtime / 100;
 		olddelta->tv_usec = time_adjtime % 100;



CVS commit: [netbsd-7] src/sys/kern

2019-02-01 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2019-01-24 Thread Martin Husemann
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(_lock);
 	nanotime(>time);



CVS commit: [netbsd-7] src/sys/kern

2019-01-24 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-12-27 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-12-27 Thread Martin Husemann
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(, 0, sizeof(aitv));
 	error = dogetitimer(p, SCARG(uap, which), );
 	if (error)
 		return error;



CVS commit: [netbsd-7] src/sys/kern

2018-12-12 Thread Martin Husemann
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(, >l_sigwaitset);
 
+	memset(_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

2018-12-12 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-11-30 Thread Martin Husemann
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 ?
-	_allocator : NULL, IPL_NONE, NULL, NULL, NULL);
+	_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

2018-11-30 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-11-29 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-11-28 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-11-28 Thread Martin Husemann
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(>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

2018-11-21 Thread Martin Husemann
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(, 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

2018-11-21 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-05-22 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-05-22 Thread Martin Husemann
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_pkthdr, 0, sizeof(m->m_pkthdr));



CVS commit: [netbsd-7] src/sys/kern

2018-05-06 Thread Martin Husemann
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, , NULL,
 		CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		CTLTYPE_INT, "average_weight",
+		SYSCTL_DESCR("Thread count averaging weight (in percent)"),
+		NULL, 0, _weight, 0,
+		CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, , NULL,
+		CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
 		CTLTYPE_INT, "min_catch",
 		SYSCTL_DESCR("Minimal count of threads for catching"),
 		NULL, 0, _catch, 0,



CVS commit: [netbsd-7] src/sys/kern

2018-05-06 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-05-03 Thread Martin Husemann
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

2018-05-03 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-04-17 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2018-04-17 Thread Martin Husemann
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_pkthdr, 0, sizeof(m->m_pkthdr));



CVS commit: [netbsd-7] src/sys/kern

2018-02-25 Thread Soren Jacobsen
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

2018-02-25 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2018-01-03 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2018-01-03 Thread Soren Jacobsen
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

2017-08-18 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2017-08-18 Thread Soren Jacobsen
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

2017-08-11 Thread Soren Jacobsen
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

2017-08-11 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2017-08-09 Thread Soren Jacobsen
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

2017-08-09 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2017-07-10 Thread Martin Husemann
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

2017-07-10 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2017-06-03 Thread Soren Jacobsen
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

2017-06-03 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2017-03-17 Thread Soren Jacobsen
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 = [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

2017-03-17 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2016-12-11 Thread Soren Jacobsen
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(>xc_lock, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(>xc_busy, "xclocv");
-	xc_tailp = 0;
 
 	memset(xchi, 0, sizeof(xc_state_t));
 	mutex_init(>xc_lock, MUTEX_DEFAULT, IPL_SOFTSERIAL);
@@ -256,7 +254,7 @@ xc_lowpri(xcfunc_t func, void *arg1, voi
 	uint64_t where;
 
 	mutex_enter(>xc_lock);
-	while (xc->xc_headp != xc_tailp) {
+	while (xc->xc_headp != xc->xc_donep) {
 		cv_wait(>xc_busy, >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_data.cpu_xcall);
 	}
-	KASSERT(xc_tailp < xc->xc_headp);
+	KASSERT(xc->xc_donep < xc->xc_headp);
 	where = xc->xc_headp;
 	mutex_exit(>xc_lock);
 
@@ -302,7 +300,7 @@ xc_thread(void *cookie)
 	mutex_enter(>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_busy);
 			}
 			cv_wait(>ci_data.cpu_xcall, >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_lock);
 
 		KASSERT(func != NULL);



CVS commit: [netbsd-7] src/sys/kern

2016-11-01 Thread Soren Jacobsen
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

2016-11-01 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2016-07-10 Thread Martin Husemann
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 == _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_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

2016-07-10 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2016-07-05 Thread Soren Jacobsen
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

2016-07-05 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2016-03-06 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2016-03-06 Thread Martin Husemann
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

2016-03-03 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2016-03-03 Thread Martin Husemann
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, , )) != 0)
-		return error == ETIMEDOUT ? 0 : error;
+	if ((error = ts2timo(clock_id, flags, rqt, , )) != 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

2016-03-03 Thread Martin Husemann
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", [shdr[i].sh_name]);
+			printf("ksyms: checking %s\n", [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, _symtabs, sd_queue) {
+	ksyms_symsz = ksyms_strsz = 0;
+	TAILQ_FOREACH(st, _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 @@ ksyms_hdr_init(void 

CVS commit: [netbsd-7] src/sys/kern

2016-03-03 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2016-01-26 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2016-01-26 Thread Soren Jacobsen
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, );
+		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(, -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

2016-01-25 Thread Jeff Rizzo
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.



CVS commit: [netbsd-7] src/sys/kern

2016-01-25 Thread Jeff Rizzo
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

2016-01-25 Thread Jeff Rizzo
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.




CVS commit: [netbsd-7] src/sys/kern

2016-01-25 Thread Jeff Rizzo
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_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_vmspace->vm_map.flags, n);
+		}
 	} else
 		addr = *last; /* may be ELF_LINK_ADDR */
 



CVS commit: [netbsd-7] src/sys/kern

2016-01-05 Thread Soren Jacobsen
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

2016-01-05 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-11-16 Thread SAITOH Masanobu
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.



CVS commit: [netbsd-7] src/sys/kern

2015-11-16 Thread SAITOH Masanobu
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

2015-11-07 Thread Jeff Rizzo
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

2015-11-07 Thread Jeff Rizzo
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.



CVS commit: [netbsd-7] src/sys/kern

2015-11-05 Thread Soren Jacobsen
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

2015-11-05 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-11-05 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-11-05 Thread Soren Jacobsen
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_biglocks);
 		p->p_pptr->p_nstopchild++;
-		p->p_pptr->p_waited = 0;
+		p->p_waited = 0;
 		mutex_enter(p->p_lock);
 		ksiginfo_queue_init();
 		sigclearall(p, , );
@@ -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_waited = 0;
+		

CVS commit: [netbsd-7] src/sys/kern

2015-11-05 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-11-05 Thread Soren Jacobsen
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

2015-11-04 Thread Jeff Rizzo
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

2015-11-04 Thread Jeff Rizzo
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.



CVS commit: [netbsd-7] src/sys/kern

2015-11-04 Thread Jeff Rizzo
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

2015-11-04 Thread Jeff Rizzo
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.



CVS commit: [netbsd-7] src/sys/kern

2015-08-09 Thread Martin Husemann
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 sys/cdefs.h
-__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 sys/param.h
 #include sys/bitops.h
@@ -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

2015-08-09 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2015-08-08 Thread Martin Husemann
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 sys/cdefs.h
-__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

2015-08-08 Thread Martin Husemann
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.



CVS commit: [netbsd-7] src/sys/kern

2015-08-06 Thread Soren Jacobsen
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 rmind at NetBSD org
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__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 sys/param.h
 
@@ -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

2015-08-06 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-08-04 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-08-04 Thread Soren Jacobsen
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 sys/cdefs.h
-__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 sys/param.h
 #include sys/systm.h
@@ -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

2015-05-18 Thread Soren Jacobsen
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 sys/cdefs.h
-__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 sys/param.h
 #include sys/kernel.h
@@ -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

2015-05-18 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-04-13 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-02-17 Thread Soren Jacobsen
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 sys/cdefs.h
-__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

2015-02-17 Thread Soren Jacobsen
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.



CVS commit: [netbsd-7] src/sys/kern

2015-02-09 Thread Martin Husemann
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 sys/cdefs.h
-__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);



  1   2   >