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

2024-03-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Mar 11 18:04:54 UTC 2024

Modified Files:
src/sys/kern [netbsd-8]: sysv_shm.c

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

sys/kern/sysv_shm.c: revision 1.142 (patch)

Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.

Should fix PR 57979


To generate a diff of this commit:
cvs rdiff -u -r1.131.10.2 -r1.131.10.3 src/sys/kern/sysv_shm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2024-03-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Mar 11 18:04:54 UTC 2024

Modified Files:
src/sys/kern [netbsd-8]: sysv_shm.c

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

sys/kern/sysv_shm.c: revision 1.142 (patch)

Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.

Should fix PR 57979


To generate a diff of this commit:
cvs rdiff -u -r1.131.10.2 -r1.131.10.3 src/sys/kern/sysv_shm.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/sysv_shm.c
diff -u src/sys/kern/sysv_shm.c:1.131.10.2 src/sys/kern/sysv_shm.c:1.131.10.3
--- src/sys/kern/sysv_shm.c:1.131.10.2	Tue Jan 21 18:12:54 2020
+++ src/sys/kern/sysv_shm.c	Mon Mar 11 18:04:54 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysv_shm.c,v 1.131.10.2 2020/01/21 18:12:54 martin Exp $	*/
+/*	$NetBSD: sysv_shm.c,v 1.131.10.3 2024/03/11 18:04:54 martin Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.131.10.2 2020/01/21 18:12:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.131.10.3 2024/03/11 18:04:54 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sysv.h"
@@ -1004,10 +1004,10 @@ shminit(struct sysctllog **clog)
 	ALIGN(shminfo.shmmni * sizeof(struct shmid_ds)));
 
 	if (shminfo.shmmax == 0)
-		shminfo.shmmax = max(physmem / 4, 1024) * PAGE_SIZE;
+		shminfo.shmall = max(physmem / 4, 1024);
 	else
-		shminfo.shmmax *= PAGE_SIZE;
-	shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
+		shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
+	shminfo.shmmax = (uint64_t)shminfo.shmall * PAGE_SIZE;
 
 	for (i = 0; i < shminfo.shmmni; i++) {
 		cv_init(&shm_cv[i], "shmwait");
@@ -1129,7 +1129,7 @@ sysctl_ipc_shmmax(SYSCTLFN_ARGS)
 		return EINVAL;
 
 	shminfo.shmmax = round_page(newsize);
-	shminfo.shmall = shminfo.shmmax >> PAGE_SHIFT;
+	shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
 
 	return 0;
 }



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

2023-11-29 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Nov 29 12:29:06 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: exec_subr.c

Log Message:
Additionally pull up the following for ticket #1920:

sys/kern/exec_subr.c1.87

Fix build for kernels w/o PAX_MPROTECT.


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.4 -r1.78.2.5 src/sys/kern/exec_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/exec_subr.c
diff -u src/sys/kern/exec_subr.c:1.78.2.4 src/sys/kern/exec_subr.c:1.78.2.5
--- src/sys/kern/exec_subr.c:1.78.2.4	Tue Nov 28 13:00:52 2023
+++ src/sys/kern/exec_subr.c	Wed Nov 29 12:29:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_subr.c,v 1.78.2.4 2023/11/28 13:00:52 martin Exp $	*/
+/*	$NetBSD: exec_subr.c,v 1.78.2.5 2023/11/29 12:29:05 martin Exp $	*/
 
 /*
  * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.78.2.4 2023/11/28 13:00:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.78.2.5 2023/11/29 12:29:05 martin Exp $");
 
 #include "opt_pax.h"
 
@@ -162,7 +162,7 @@ static int
 vmcmd_get_prot(struct lwp *l, const struct exec_vmcmd *cmd, vm_prot_t *prot,
 vm_prot_t *maxprot)
 {
-	vm_prot_t extraprot = PROT_MPROTECT_EXTRACT(cmd->ev_prot);
+	vm_prot_t extraprot __unused = PROT_MPROTECT_EXTRACT(cmd->ev_prot);
 
 	*prot = cmd->ev_prot & UVM_PROT_ALL;
 	*maxprot = PAX_MPROTECT_MAXPROTECT(l, *prot, extraprot, UVM_PROT_ALL);



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

2023-11-29 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Nov 29 12:29:06 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: exec_subr.c

Log Message:
Additionally pull up the following for ticket #1920:

sys/kern/exec_subr.c1.87

Fix build for kernels w/o PAX_MPROTECT.


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.4 -r1.78.2.5 src/sys/kern/exec_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2023-08-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Aug  4 13:58:11 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: init_main.c

Log Message:
Apply patch, requested by riastradh in ticket #1882 (issue solved differently
in -current):

sys/kern/init_main.c(apply patch)

PR kern/55906: create the aiodone workqueue before running mountroothooks.


To generate a diff of this commit:
cvs rdiff -u -r1.490.6.2 -r1.490.6.3 src/sys/kern/init_main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2023-08-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Aug  4 13:58:11 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: init_main.c

Log Message:
Apply patch, requested by riastradh in ticket #1882 (issue solved differently
in -current):

sys/kern/init_main.c(apply patch)

PR kern/55906: create the aiodone workqueue before running mountroothooks.


To generate a diff of this commit:
cvs rdiff -u -r1.490.6.2 -r1.490.6.3 src/sys/kern/init_main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.490.6.2 src/sys/kern/init_main.c:1.490.6.3
--- src/sys/kern/init_main.c:1.490.6.2	Sat Feb  6 15:22:19 2021
+++ src/sys/kern/init_main.c	Fri Aug  4 13:58:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.490.6.2 2021/02/06 15:22:19 martin Exp $	*/
+/*	$NetBSD: init_main.c,v 1.490.6.3 2023/08/04 13:58:11 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.490.6.2 2021/02/06 15:22:19 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.490.6.3 2023/08/04 13:58:11 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -638,6 +638,11 @@ main(void)
 	cpu_rootconf();
 	cpu_dumpconf();
 
+	/* Create the aiodone daemon kernel thread. */
+	if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
+	uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE))
+		panic("fork aiodoned");
+
 	/* Mount the root file system. */
 	do {
 		domountroothook(root_device);
@@ -697,11 +702,6 @@ main(void)
 	NULL, NULL, "ioflush"))
 		panic("fork syncer");
 
-	/* Create the aiodone daemon kernel thread. */
-	if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
-	uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE))
-		panic("fork aiodoned");
-
 	/* Wait for final configure threads to complete. */
 	config_finalize_mountroot();
 



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

2023-07-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 31 16:29:56 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: uipc_domain.c

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

sys/kern/uipc_domain.c: revision 1.109

sockaddr_alloc(9): Avoid uninitialized buffer in sockaddr_checklen.

Manifests only under DIAGNOSTIC because the DIAGNOSTIC check itself
uses an uninitialized buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.96.10.2 -r1.96.10.3 src/sys/kern/uipc_domain.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/uipc_domain.c
diff -u src/sys/kern/uipc_domain.c:1.96.10.2 src/sys/kern/uipc_domain.c:1.96.10.3
--- src/sys/kern/uipc_domain.c:1.96.10.2	Tue Jan 16 13:04:33 2018
+++ src/sys/kern/uipc_domain.c	Mon Jul 31 16:29:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_domain.c,v 1.96.10.2 2018/01/16 13:04:33 martin Exp $	*/
+/*	$NetBSD: uipc_domain.c,v 1.96.10.3 2023/07/31 16:29:56 martin Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.96.10.2 2018/01/16 13:04:33 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.96.10.3 2023/07/31 16:29:56 martin Exp $");
 
 #include 
 #include 
@@ -322,6 +322,15 @@ sockaddr_alloc(sa_family_t af, socklen_t
 	struct sockaddr *sa;
 	socklen_t reallen = MAX(socklen, offsetof(struct sockaddr, sa_data[0]));
 
+#ifdef DIAGNOSTIC
+	/*
+	 * sockaddr_checklen passes sa to sockaddr_format which
+	 * requires it to be fully initialized.
+	 *
+	 * XXX This should be factored better.
+	 */
+	flags |= M_ZERO;
+#endif
 	if ((sa = malloc(reallen, M_SOCKADDR, flags)) == NULL)
 		return NULL;
 



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

2023-07-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 31 16:29:56 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: uipc_domain.c

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

sys/kern/uipc_domain.c: revision 1.109

sockaddr_alloc(9): Avoid uninitialized buffer in sockaddr_checklen.

Manifests only under DIAGNOSTIC because the DIAGNOSTIC check itself
uses an uninitialized buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.96.10.2 -r1.96.10.3 src/sys/kern/uipc_domain.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2023-07-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 31 14:49:37 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: kern_rwlock.c

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

sys/kern/kern_rwlock.c: revision 1.68 (patch)

rwlock(9): Fix membars.

rw_downgrade must be a release operation, and rw_tryupgrade must be
an acquire operation.  membar_producer is not enough -- need to use
membar_release and membar_acquire.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/02/22/msg028726.html


To generate a diff of this commit:
cvs rdiff -u -r1.46.6.3 -r1.46.6.4 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.46.6.3 src/sys/kern/kern_rwlock.c:1.46.6.4
--- src/sys/kern/kern_rwlock.c:1.46.6.3	Mon Jul 31 14:42:45 2023
+++ src/sys/kern/kern_rwlock.c	Mon Jul 31 14:49:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.46.6.3 2023/07/31 14:42:45 martin Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.46.6.4 2023/07/31 14:49:37 martin Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.46.6.3 2023/07/31 14:42:45 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.46.6.4 2023/07/31 14:49:37 martin Exp $");
 
 #define	__RWLOCK_PRIVATE
 
@@ -592,8 +592,7 @@ rw_downgrade(krwlock_t *rw)
 	__USE(curthread);
 #endif
 
-
-	membar_producer();
+	membar_exit();
 	owner = rw->rw_owner;
 	if ((owner & RW_HAS_WAITERS) == 0) {
 		/*
@@ -689,7 +688,7 @@ rw_tryupgrade(krwlock_t *rw)
 		newown = curthread | RW_WRITE_LOCKED | (owner & ~RW_THREAD);
 		next = rw_cas(rw, owner, newown);
 		if (__predict_true(next == owner)) {
-			membar_producer();
+			membar_enter(); /* XXX membar_acquire */
 			break;
 		}
 	}



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

2023-07-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 31 14:49:37 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: kern_rwlock.c

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

sys/kern/kern_rwlock.c: revision 1.68 (patch)

rwlock(9): Fix membars.

rw_downgrade must be a release operation, and rw_tryupgrade must be
an acquire operation.  membar_producer is not enough -- need to use
membar_release and membar_acquire.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/02/22/msg028726.html


To generate a diff of this commit:
cvs rdiff -u -r1.46.6.3 -r1.46.6.4 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2023-07-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 31 14:42:46 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: kern_lock.c kern_mutex.c kern_rwlock.c

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

sys/kern/kern_rwlock.c: revision 1.67
sys/kern/kern_lock.c: revision 1.182
sys/kern/kern_mutex.c: revision 1.102
(all via patch)

Sprinkle __predict_{true,false} for panicstr checks


To generate a diff of this commit:
cvs rdiff -u -r1.158.6.2 -r1.158.6.3 src/sys/kern/kern_lock.c
cvs rdiff -u -r1.65.2.2 -r1.65.2.3 src/sys/kern/kern_mutex.c
cvs rdiff -u -r1.46.6.2 -r1.46.6.3 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lock.c
diff -u src/sys/kern/kern_lock.c:1.158.6.2 src/sys/kern/kern_lock.c:1.158.6.3
--- src/sys/kern/kern_lock.c:1.158.6.2	Sat Jan 13 21:57:11 2018
+++ src/sys/kern/kern_lock.c	Mon Jul 31 14:42:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lock.c,v 1.158.6.2 2018/01/13 21:57:11 snj Exp $	*/
+/*	$NetBSD: kern_lock.c,v 1.158.6.3 2023/07/31 14:42:45 martin 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.158.6.2 2018/01/13 21:57:11 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.158.6.3 2023/07/31 14:42:45 martin Exp $");
 
 #include 
 #include 
@@ -63,7 +63,7 @@ assert_sleepable(void)
 	uint64_t pctr;
 	bool idle;
 
-	if (panicstr != NULL) {
+	if (__predict_false(panicstr != NULL)) {
 		return;
 	}
 

Index: src/sys/kern/kern_mutex.c
diff -u src/sys/kern/kern_mutex.c:1.65.2.2 src/sys/kern/kern_mutex.c:1.65.2.3
--- src/sys/kern/kern_mutex.c:1.65.2.2	Mon Apr  2 09:07:52 2018
+++ src/sys/kern/kern_mutex.c	Mon Jul 31 14:42:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex.c,v 1.65.2.2 2018/04/02 09:07:52 martin Exp $	*/
+/*	$NetBSD: kern_mutex.c,v 1.65.2.3 2023/07/31 14:42:45 martin Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define	__MUTEX_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.65.2.2 2018/04/02 09:07:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.65.2.3 2023/07/31 14:42:45 martin Exp $");
 
 #include 
 #include 
@@ -516,7 +516,7 @@ mutex_vector_enter(kmutex_t *mtx)
 	MUTEX_ASSERT(mtx, curthread != 0);
 	MUTEX_WANTLOCK(mtx);
 
-	if (panicstr == NULL) {
+	if (__predict_true(panicstr == NULL)) {
 		LOCKDEBUG_BARRIER(&kernel_lock, 1);
 	}
 

Index: src/sys/kern/kern_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.46.6.2 src/sys/kern/kern_rwlock.c:1.46.6.3
--- src/sys/kern/kern_rwlock.c:1.46.6.2	Mon Apr  2 09:07:52 2018
+++ src/sys/kern/kern_rwlock.c	Mon Jul 31 14:42:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.46.6.2 2018/04/02 09:07:52 martin Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.46.6.3 2023/07/31 14:42:45 martin Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.46.6.2 2018/04/02 09:07:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.46.6.3 2023/07/31 14:42:45 martin Exp $");
 
 #define	__RWLOCK_PRIVATE
 
@@ -186,7 +186,7 @@ static void __noinline
 rw_abort(const char *func, size_t line, krwlock_t *rw, const char *msg)
 {
 
-	if (panicstr != NULL)
+	if (__predict_false(panicstr != NULL))
 		return;
 
 	LOCKDEBUG_ABORT(func, line, rw, &rwlock_lockops, msg);
@@ -290,7 +290,7 @@ rw_vector_enter(krwlock_t *rw, const krw
 	RW_ASSERT(rw, curthread != 0);
 	RW_WANTLOCK(rw, op);
 
-	if (panicstr == NULL) {
+	if (__predict_true(panicstr == NULL)) {
 		LOCKDEBUG_BARRIER(&kernel_lock, 1);
 	}
 



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

2023-07-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 31 14:42:46 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: kern_lock.c kern_mutex.c kern_rwlock.c

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

sys/kern/kern_rwlock.c: revision 1.67
sys/kern/kern_lock.c: revision 1.182
sys/kern/kern_mutex.c: revision 1.102
(all via patch)

Sprinkle __predict_{true,false} for panicstr checks


To generate a diff of this commit:
cvs rdiff -u -r1.158.6.2 -r1.158.6.3 src/sys/kern/kern_lock.c
cvs rdiff -u -r1.65.2.2 -r1.65.2.3 src/sys/kern/kern_mutex.c
cvs rdiff -u -r1.46.6.2 -r1.46.6.3 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2023-04-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Apr 17 18:13:44 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: subr_prf.c

Log Message:
Fix merge mishap in applying the changes from rev 1.171 in ticket #1804:
patch accidently applied the change to a nearby very similar function
(aprint_verbose_internal instead of aprint_error_internal).


To generate a diff of this commit:
cvs rdiff -u -r1.160.8.1 -r1.160.8.2 src/sys/kern/subr_prf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_prf.c
diff -u src/sys/kern/subr_prf.c:1.160.8.1 src/sys/kern/subr_prf.c:1.160.8.2
--- src/sys/kern/subr_prf.c:1.160.8.1	Fri Feb 24 14:17:18 2023
+++ src/sys/kern/subr_prf.c	Mon Apr 17 18:13:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_prf.c,v 1.160.8.1 2023/02/24 14:17:18 martin Exp $	*/
+/*	$NetBSD: subr_prf.c,v 1.160.8.2 2023/04/17 18:13:44 martin Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1988, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.160.8.1 2023/02/24 14:17:18 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.160.8.2 2023/04/17 18:13:44 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -804,6 +804,7 @@ aprint_error_internal(const char *prefix
 
 	if (prefix)
 		kprintf_internal("%s: ", flags, NULL, NULL, prefix);
+	kprintf_internal("autoconfiguration error: ", TOLOG, NULL, NULL);
 	kprintf(fmt, flags, NULL, NULL, ap);
 
 	kprintf_unlock();
@@ -907,7 +908,6 @@ aprint_verbose_internal(const char *pref
 
 	if (prefix)
 		kprintf_internal("%s: ", flags, NULL, NULL, prefix);
-	kprintf_internal("autoconfiguration error: ", TOLOG, NULL, NULL);
 	kprintf(fmt, flags, NULL, NULL, ap);
 
 	kprintf_unlock();



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

2023-04-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Apr 17 18:13:44 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: subr_prf.c

Log Message:
Fix merge mishap in applying the changes from rev 1.171 in ticket #1804:
patch accidently applied the change to a nearby very similar function
(aprint_verbose_internal instead of aprint_error_internal).


To generate a diff of this commit:
cvs rdiff -u -r1.160.8.1 -r1.160.8.2 src/sys/kern/subr_prf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2023-03-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar  7 20:02:57 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: vfs_syscalls.c

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

sys/kern/vfs_syscalls.c: revision 1.557

open(2): Don't map ERESTART to EINTR.

If a file or device's open function returns ERESTART, respect that --
restart the syscall; don't pretend a signal has been delivered when
it was not.  If an SA_RESTART signal was delivered, POSIX does not
allow it to fail with EINTR:

SA_RESTART
This flag affects the behavior of interruptible functions;
that is, those specified to fail with errno set to [EINTR].
If set, and a function specified as interruptible is
interrupted by this signal, the function shall restart and
shall not fail with [EINTR] unless otherwise specified.  If
an interruptible function which uses a timeout is restarted,
the duration of the timeout following the restart is set to
an unspecified value that does not exceed the original
timeout value.  If the flag is not set, interruptible
functions interrupted by this signal shall fail with errno
set to [EINTR].

https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html

Nothing in the POSIX definition of open specifies otherwise.

In 1990, Kirk McKusick added these lines with a mysterious commit
message:
Author: Kirk McKusick 
Date:   Tue Apr 10 19:36:33 1990 -0800
eliminate longjmp from the kernel (for karels)
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 7bc7b39bbf..d572d3a32d 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#)vfs_syscalls.c  7.42 (Berkeley) 3/26/90
+ * @(#)vfs_syscalls.c  7.43 (Berkeley) 4/10/90
  */
 #include "param.h"
@@ -530,8 +530,10 @@ copen(scp, fmode, cmode, ndp, resultfd)
if (error = vn_open(ndp, fmode, (cmode & 0) &~ S_ISVTX)) {
crfree(fp->f_cred);
fp->f_count--;
-   if (error == -1)/* XXX from fdopen */
-   return (0); /* XXX from fdopen */
+   if (error == EJUSTRETURN)   /* XXX from fdopen */
+   return (0); /* XXX from fdopen */
+   if (error == ERESTART)
+   error = EINTR;
scp->sc_ofile[indx] = NULL;
return (error);
}

(found via this git import of the CSRG history:
https://github.com/robohack/ucb-csrg-bsd/commit/cce2869b7ae5d360921eb411005b328a29c4a3fe

This change appears to have served two related purposes:
1. The fdopen function (the erstwhile open routine for /dev/fd/N)
   used to return -1 as a hack to mean it had just duplicated the fd;
   it was recently changed by Mike Karels, in kern_descrip.c 7.9, to
   return EJUSTRETURN, now defined to be -2, presumably to avoid a
   conflict with ERESTART, defined to be -1.  So this change finished
   part of the change by Mike Karels to use a different magic return
   code from fdopen.
   Of course, today we use still another disgusting hack, EDUPFD, for
   the same purpose, so none of this is relevant any more.
2. Prior to April 1990, the kernel handled signals during tsleep(9)
   by longjmping out to the system call entry point or similar.  In
   April 1990, Mike Karels worked to convert all of that into
   explicit unwind logic by passing through EINTR or ERESTART as
   appropriate, instead of setjmp at each entry point.

However, it's not clear to me why this setjmp/longjmp and
fdopen/-1/EJUSTRETURN renovation justifies unconditional logic to map
ERESTART to EINTR in open(2).  I suspect it was a mistake.

In 2013, the corresponding logic to map ERESTART to EINTR in open(2)
was removed from FreeBSD:

   r246472 | kib | 2013-02-07 14:53:33 + (Thu, 07 Feb 2013) | 11 lines
   Stop translating the ERESTART error from the open(2) into EINTR.
   Posix requires that open(2) is restartable for SA_RESTART.
   For non-posix objects, in particular, devfs nodes, still disable
   automatic restart of the opens. The open call to a driver could have
   significant side effects for the hardware.
   Noted and reviewed by:  jilles
   Discussed with: bde
   MFC after:  2 weeks

Index: vfs_syscalls.c
===
--- vfs_syscalls.c  (revision 246471)
+++ vfs_syscalls.c  (revision 246472)
@@ -1106,8 +1106,6 @@
goto success;
}
-   if (error == ERESTART)
-   error = EINTR;
goto bad;
}
td->td_dupfd = 0;

https://cgit.freebsd.org/src/commit/sys/kern/vfs_syscalls.c?id=2ca49983425886121b506cb5126

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

2023-03-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar  7 20:02:57 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: vfs_syscalls.c

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

sys/kern/vfs_syscalls.c: revision 1.557

open(2): Don't map ERESTART to EINTR.

If a file or device's open function returns ERESTART, respect that --
restart the syscall; don't pretend a signal has been delivered when
it was not.  If an SA_RESTART signal was delivered, POSIX does not
allow it to fail with EINTR:

SA_RESTART
This flag affects the behavior of interruptible functions;
that is, those specified to fail with errno set to [EINTR].
If set, and a function specified as interruptible is
interrupted by this signal, the function shall restart and
shall not fail with [EINTR] unless otherwise specified.  If
an interruptible function which uses a timeout is restarted,
the duration of the timeout following the restart is set to
an unspecified value that does not exceed the original
timeout value.  If the flag is not set, interruptible
functions interrupted by this signal shall fail with errno
set to [EINTR].

https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html

Nothing in the POSIX definition of open specifies otherwise.

In 1990, Kirk McKusick added these lines with a mysterious commit
message:
Author: Kirk McKusick 
Date:   Tue Apr 10 19:36:33 1990 -0800
eliminate longjmp from the kernel (for karels)
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 7bc7b39bbf..d572d3a32d 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#)vfs_syscalls.c  7.42 (Berkeley) 3/26/90
+ * @(#)vfs_syscalls.c  7.43 (Berkeley) 4/10/90
  */
 #include "param.h"
@@ -530,8 +530,10 @@ copen(scp, fmode, cmode, ndp, resultfd)
if (error = vn_open(ndp, fmode, (cmode & 0) &~ S_ISVTX)) {
crfree(fp->f_cred);
fp->f_count--;
-   if (error == -1)/* XXX from fdopen */
-   return (0); /* XXX from fdopen */
+   if (error == EJUSTRETURN)   /* XXX from fdopen */
+   return (0); /* XXX from fdopen */
+   if (error == ERESTART)
+   error = EINTR;
scp->sc_ofile[indx] = NULL;
return (error);
}

(found via this git import of the CSRG history:
https://github.com/robohack/ucb-csrg-bsd/commit/cce2869b7ae5d360921eb411005b328a29c4a3fe

This change appears to have served two related purposes:
1. The fdopen function (the erstwhile open routine for /dev/fd/N)
   used to return -1 as a hack to mean it had just duplicated the fd;
   it was recently changed by Mike Karels, in kern_descrip.c 7.9, to
   return EJUSTRETURN, now defined to be -2, presumably to avoid a
   conflict with ERESTART, defined to be -1.  So this change finished
   part of the change by Mike Karels to use a different magic return
   code from fdopen.
   Of course, today we use still another disgusting hack, EDUPFD, for
   the same purpose, so none of this is relevant any more.
2. Prior to April 1990, the kernel handled signals during tsleep(9)
   by longjmping out to the system call entry point or similar.  In
   April 1990, Mike Karels worked to convert all of that into
   explicit unwind logic by passing through EINTR or ERESTART as
   appropriate, instead of setjmp at each entry point.

However, it's not clear to me why this setjmp/longjmp and
fdopen/-1/EJUSTRETURN renovation justifies unconditional logic to map
ERESTART to EINTR in open(2).  I suspect it was a mistake.

In 2013, the corresponding logic to map ERESTART to EINTR in open(2)
was removed from FreeBSD:

   r246472 | kib | 2013-02-07 14:53:33 + (Thu, 07 Feb 2013) | 11 lines
   Stop translating the ERESTART error from the open(2) into EINTR.
   Posix requires that open(2) is restartable for SA_RESTART.
   For non-posix objects, in particular, devfs nodes, still disable
   automatic restart of the opens. The open call to a driver could have
   significant side effects for the hardware.
   Noted and reviewed by:  jilles
   Discussed with: bde
   MFC after:  2 weeks

Index: vfs_syscalls.c
===
--- vfs_syscalls.c  (revision 246471)
+++ vfs_syscalls.c  (revision 246472)
@@ -1106,8 +1106,6 @@
goto success;
}
-   if (error == ERESTART)
-   error = EINTR;
goto bad;
}
td->td_dupfd = 0;

https://cgit.freebsd.org/src/commit/sys/kern/vfs_syscalls.c?id=2ca49983425886121b506cb5126

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

2023-02-24 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Feb 24 14:17:18 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: subr_prf.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1804):

sys/kern/subr_prf.c: revision 1.171

Make identification of accounted aprint_error()s possible by putting a
big ugly "autoconfiguration error: " in the log when they occur.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.160.8.1 src/sys/kern/subr_prf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_prf.c
diff -u src/sys/kern/subr_prf.c:1.160 src/sys/kern/subr_prf.c:1.160.8.1
--- src/sys/kern/subr_prf.c:1.160	Wed Jul 27 09:57:26 2016
+++ src/sys/kern/subr_prf.c	Fri Feb 24 14:17:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_prf.c,v 1.160 2016/07/27 09:57:26 skrll Exp $	*/
+/*	$NetBSD: subr_prf.c,v 1.160.8.1 2023/02/24 14:17:18 martin Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1988, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.160 2016/07/27 09:57:26 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.160.8.1 2023/02/24 14:17:18 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -907,6 +907,7 @@ aprint_verbose_internal(const char *pref
 
 	if (prefix)
 		kprintf_internal("%s: ", flags, NULL, NULL, prefix);
+	kprintf_internal("autoconfiguration error: ", TOLOG, NULL, NULL);
 	kprintf(fmt, flags, NULL, NULL, ap);
 
 	kprintf_unlock();



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

2023-02-24 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Feb 24 14:17:18 UTC 2023

Modified Files:
src/sys/kern [netbsd-8]: subr_prf.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1804):

sys/kern/subr_prf.c: revision 1.171

Make identification of accounted aprint_error()s possible by putting a
big ugly "autoconfiguration error: " in the log when they occur.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.160.8.1 src/sys/kern/subr_prf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2022-09-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Sep 10 08:21:49 UTC 2022

Modified Files:
src/sys/kern [netbsd-8]: kern_core.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1761):

sys/kern/kern_core.c: revision 1.37

avoid a GCC warning (happens on -current, -9, and -8.)


To generate a diff of this commit:
cvs rdiff -u -r1.24.10.1 -r1.24.10.2 src/sys/kern/kern_core.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_core.c
diff -u src/sys/kern/kern_core.c:1.24.10.1 src/sys/kern/kern_core.c:1.24.10.2
--- src/sys/kern/kern_core.c:1.24.10.1	Fri Sep  9 18:24:20 2022
+++ src/sys/kern/kern_core.c	Sat Sep 10 08:21:49 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_core.c,v 1.24.10.1 2022/09/09 18:24:20 martin Exp $	*/
+/*	$NetBSD: kern_core.c,v 1.24.10.2 2022/09/10 08:21:49 martin Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.24.10.1 2022/09/09 18:24:20 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.24.10.2 2022/09/10 08:21:49 martin Exp $");
 
 #include 
 #include 
@@ -102,7 +102,7 @@ coredump(struct lwp *l, const char *patt
 	struct coredump_iostate	io;
 	struct plimit		*lim;
 	int			error, error1;
-	char			*name, *lastslash;
+	char			*name, *lastslash = NULL /* XXXgcc */;
 
 	name = PNBUF_GET();
 



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

2022-09-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Sep 10 08:21:49 UTC 2022

Modified Files:
src/sys/kern [netbsd-8]: kern_core.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1761):

sys/kern/kern_core.c: revision 1.37

avoid a GCC warning (happens on -current, -9, and -8.)


To generate a diff of this commit:
cvs rdiff -u -r1.24.10.1 -r1.24.10.2 src/sys/kern/kern_core.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2022-09-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Sep  9 18:24:20 UTC 2022

Modified Files:
src/sys/kern [netbsd-8]: kern_core.c

Log Message:
Pull up following revision(s) (requested by christos in ticket #1760):

sys/kern/kern_core.c: revision 1.36

Don't forget to free the cred we just held.
Thanks to Chris J-D (chris at accessvector dot net)

While here, de-duplicate the mutex exit sequence.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.24.10.1 src/sys/kern/kern_core.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_core.c
diff -u src/sys/kern/kern_core.c:1.24 src/sys/kern/kern_core.c:1.24.10.1
--- src/sys/kern/kern_core.c:1.24	Thu Jul  7 06:55:43 2016
+++ src/sys/kern/kern_core.c	Fri Sep  9 18:24:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_core.c,v 1.24 2016/07/07 06:55:43 msaitoh Exp $	*/
+/*	$NetBSD: kern_core.c,v 1.24.10.1 2022/09/09 18:24:20 martin Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.24 2016/07/07 06:55:43 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.24.10.1 2022/09/09 18:24:20 martin Exp $");
 
 #include 
 #include 
@@ -95,7 +95,7 @@ coredump(struct lwp *l, const char *patt
 	struct vnode		*vp;
 	struct proc		*p;
 	struct vmspace		*vm;
-	kauth_cred_t		cred;
+	kauth_cred_t		cred = NULL;
 	struct pathbuf		*pb;
 	struct nameidata	nd;
 	struct vattr		vattr;
@@ -120,9 +120,7 @@ coredump(struct lwp *l, const char *patt
 	if (USPACE + ctob(vm->vm_dsize + vm->vm_ssize) >=
 	p->p_rlimit[RLIMIT_CORE].rlim_cur) {
 		error = EFBIG;		/* better error code? */
-		mutex_exit(p->p_lock);
-		mutex_exit(proc_lock);
-		goto done;
+		goto release;
 	}
 
 	/*
@@ -139,9 +137,7 @@ coredump(struct lwp *l, const char *patt
 	if (p->p_flag & PK_SUGID) {
 		if (!security_setidcore_dump) {
 			error = EPERM;
-			mutex_exit(p->p_lock);
-			mutex_exit(proc_lock);
-			goto done;
+			goto release;
 		}
 		pattern = security_setidcore_path;
 	}
@@ -155,11 +151,8 @@ coredump(struct lwp *l, const char *patt
 	error = coredump_buildname(p, name, pattern, MAXPATHLEN);
 	mutex_exit(&lim->pl_lock);
 
-	if (error) {
-		mutex_exit(p->p_lock);
-		mutex_exit(proc_lock);
-		goto done;
-	}
+	if (error)
+		goto release;
 
 	/*
 	 * On a simple filename, see if the filesystem allow us to write
@@ -173,6 +166,7 @@ coredump(struct lwp *l, const char *patt
 			error = EPERM;
 	}
 
+release:
 	mutex_exit(p->p_lock);
 	mutex_exit(proc_lock);
 	if (error)
@@ -260,6 +254,8 @@ coredump(struct lwp *l, const char *patt
 	if (error == 0)
 		error = error1;
 done:
+	if (cred != NULL)
+		kauth_cred_free(cred);
 	if (name != NULL)
 		PNBUF_PUT(name);
 	return error;



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

2022-09-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Sep  9 18:24:20 UTC 2022

Modified Files:
src/sys/kern [netbsd-8]: kern_core.c

Log Message:
Pull up following revision(s) (requested by christos in ticket #1760):

sys/kern/kern_core.c: revision 1.36

Don't forget to free the cred we just held.
Thanks to Chris J-D (chris at accessvector dot net)

While here, de-duplicate the mutex exit sequence.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.24.10.1 src/sys/kern/kern_core.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2021-10-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Oct  8 14:59:59 UTC 2021

Modified Files:
src/sys/kern [netbsd-8]: sys_pipe.c

Log Message:
Pull up following revision(s) (requested by hannken in ticket #1698):

sys/kern/sys_pipe.c: revision 1.157

Fix a deadlock where one thread writes to a pipe, has more data
and no space in the pipe and waits on "pipe_wcv" while the reader
is closing the pipe and waits on "pipe_draincv".

Swap the test for "PIPE_EOF" and the "cv_wait_sig()" in "pipe_write()".

PR bin/56422 "zgrep -l sometimes hangs"


To generate a diff of this commit:
cvs rdiff -u -r1.140.12.1 -r1.140.12.2 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.140.12.1 src/sys/kern/sys_pipe.c:1.140.12.2
--- src/sys/kern/sys_pipe.c:1.140.12.1	Wed May  1 14:51:17 2019
+++ src/sys/kern/sys_pipe.c	Fri Oct  8 14:59:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_pipe.c,v 1.140.12.1 2019/05/01 14:51:17 martin Exp $	*/
+/*	$NetBSD: sys_pipe.c,v 1.140.12.2 2021/10/08 14:59:59 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.140.12.1 2019/05/01 14:51:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.140.12.2 2021/10/08 14:59:59 martin Exp $");
 
 #include 
 #include 
@@ -1017,11 +1017,6 @@ pipe_write(file_t *fp, off_t *offset, st
 break;
 			}
 
-			pipeunlock(wpipe);
-			error = cv_wait_sig(&wpipe->pipe_wcv, lock);
-			(void)pipelock(wpipe, false);
-			if (error != 0)
-break;
 			/*
 			 * If read side wants to go away, we just issue a signal
 			 * to ourselves.
@@ -1030,6 +1025,12 @@ pipe_write(file_t *fp, off_t *offset, st
 error = EPIPE;
 break;
 			}
+
+			pipeunlock(wpipe);
+			error = cv_wait_sig(&wpipe->pipe_wcv, lock);
+			(void)pipelock(wpipe, false);
+			if (error != 0)
+break;
 			wakeup_state = wpipe->pipe_state;
 		}
 	}



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

2021-10-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Oct  8 14:59:59 UTC 2021

Modified Files:
src/sys/kern [netbsd-8]: sys_pipe.c

Log Message:
Pull up following revision(s) (requested by hannken in ticket #1698):

sys/kern/sys_pipe.c: revision 1.157

Fix a deadlock where one thread writes to a pipe, has more data
and no space in the pipe and waits on "pipe_wcv" while the reader
is closing the pipe and waits on "pipe_draincv".

Swap the test for "PIPE_EOF" and the "cv_wait_sig()" in "pipe_write()".

PR bin/56422 "zgrep -l sometimes hangs"


To generate a diff of this commit:
cvs rdiff -u -r1.140.12.1 -r1.140.12.2 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-8] src/sys/kern

2019-11-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 25 16:03:08 UTC 2019

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

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

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.27.10.1 -r1.27.10.2 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.27.10.1 src/sys/kern/subr_cprng.c:1.27.10.2
--- src/sys/kern/subr_cprng.c:1.27.10.1	Tue Sep  3 12:08:22 2019
+++ src/sys/kern/subr_cprng.c	Mon Nov 25 16:03:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_cprng.c,v 1.27.10.1 2019/09/03 12:08:22 martin Exp $ */
+/*	$NetBSD: subr_cprng.c,v 1.27.10.2 2019/11/25 16:03:08 martin Exp $ */
 
 /*-
  * Copyright (c) 2011-2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.27.10.1 2019/09/03 12:08:22 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.27.10.2 2019/11/25 16:03:08 martin Exp $");
 
 #include 
 #include 
@@ -507,6 +507,7 @@ cprng_strong_rndsink_callback(void *cont
 	mutex_exit(&cprng->cs_lock);
 }
 
+static ONCE_DECL(sysctl_prng_once);
 static cprng_strong_t *sysctl_prng;
 
 static int
@@ -526,10 +527,9 @@ makeprng(void)
 static int
 sysctl_kern_urnd(SYSCTLFN_ARGS)
 {
-	static ONCE_DECL(control);
 	int v, rv;
 
-	RUN_ONCE(&control, makeprng);
+	RUN_ONCE(&sysctl_prng_once, makeprng);
 	rv = cprng_strong(sysctl_prng, &v, sizeof(v), 0);
 	if (rv == sizeof(v)) {
 		struct sysctlnode node = *rnode;
@@ -558,6 +558,7 @@ sysctl_kern_arnd(SYSCTLFN_ARGS)
 	int error;
 	void *v;
 	struct sysctlnode node = *rnode;
+	size_t n __diagused;
 
 	switch (*oldlenp) {
 	case 0:
@@ -566,8 +567,10 @@ sysctl_kern_arnd(SYSCTLFN_ARGS)
 		if (*oldlenp > 256) {
 			return E2BIG;
 		}
+		RUN_ONCE(&sysctl_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(&node));



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

2019-11-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 25 16:03:08 UTC 2019

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

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

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.27.10.1 -r1.27.10.2 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.



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

2019-11-24 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Nov 24 08:15:17 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #1456):

sys/kern/sys_ptrace_common.c: revision 1.73

Fix regression introduced to ptrace_regs() in rev 1.27:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/sys_ptrace_common.c#rev1.27

Size of registers should be determined from tracer, NOT tracee.

Now, 64-bit tracer can manipulate registers of 32-bit tracee again.
gdb for amd64 works for i386 binaries to some extent.

XXX
pullup to netbsd-9 and -8.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.7 -r1.22.2.8 src/sys/kern/sys_ptrace_common.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_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.22.2.7 src/sys/kern/sys_ptrace_common.c:1.22.2.8
--- src/sys/kern/sys_ptrace_common.c:1.22.2.7	Tue Nov 19 10:50:25 2019
+++ src/sys/kern/sys_ptrace_common.c	Sun Nov 24 08:15:17 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.7 2019/11/19 10:50:25 martin Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.8 2019/11/24 08:15:17 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.7 2019/11/19 10:50:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.8 2019/11/24 08:15:17 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -775,9 +775,12 @@ ptrace_regs(struct lwp *l, struct lwp **
 void *addr, size_t data)
 {
 	int error;
-	struct proc *t = (*lt)->l_proc;
+	struct proc *p, *t;
 	struct vmspace *vm;
 
+	p = l->l_proc;		/* tracer */
+	t = (*lt)->l_proc;	/* traced */
+
 	if ((error = ptrace_update_lwp(t, lt, data)) != 0)
 		return error;
 
@@ -791,7 +794,7 @@ ptrace_regs(struct lwp *l, struct lwp **
 	case_PT_SETREGS
 		if (!process_validregs(*lt))
 			return EINVAL;
-		size = PROC_REGSZ(t);
+		size = PROC_REGSZ(p);
 		func = ptm->ptm_doregs;
 		break;
 #endif
@@ -800,7 +803,7 @@ ptrace_regs(struct lwp *l, struct lwp **
 	case_PT_SETFPREGS
 		if (!process_validfpregs(*lt))
 			return EINVAL;
-		size = PROC_FPREGSZ(t);
+		size = PROC_FPREGSZ(p);
 		func = ptm->ptm_dofpregs;
 		break;
 #endif
@@ -809,7 +812,7 @@ ptrace_regs(struct lwp *l, struct lwp **
 	case_PT_SETDBREGS
 		if (!process_validdbregs(*lt))
 			return EINVAL;
-		size = PROC_DBREGSZ(t);
+		size = PROC_DBREGSZ(p);
 		func = ptm->ptm_dodbregs;
 		break;
 #endif



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

2019-11-24 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Nov 24 08:15:17 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #1456):

sys/kern/sys_ptrace_common.c: revision 1.73

Fix regression introduced to ptrace_regs() in rev 1.27:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/sys_ptrace_common.c#rev1.27

Size of registers should be determined from tracer, NOT tracee.

Now, 64-bit tracer can manipulate registers of 32-bit tracee again.
gdb for amd64 works for i386 binaries to some extent.

XXX
pullup to netbsd-9 and -8.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.7 -r1.22.2.8 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-11-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Nov 19 10:50:26 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #1452):

sys/kern/sys_ptrace_common.c: revision 1.72

Fix pointer arithmetic for 32-bit process on LP64 kernel in
process_auxv_offset().

Now, PIOD_READ_AUXV works fine with COMPAT_NETBSD32.

XXX
pullup to netbsd-9 and netbsd-8


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.6 -r1.22.2.7 src/sys/kern/sys_ptrace_common.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_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.22.2.6 src/sys/kern/sys_ptrace_common.c:1.22.2.7
--- src/sys/kern/sys_ptrace_common.c:1.22.2.6	Sun Aug  4 11:05:29 2019
+++ src/sys/kern/sys_ptrace_common.c	Tue Nov 19 10:50:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.6 2019/08/04 11:05:29 martin Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.7 2019/11/19 10:50:25 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.6 2019/08/04 11:05:29 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.7 2019/11/19 10:50:25 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -1506,7 +1506,15 @@ process_auxv_offset(struct proc *p, stru
 	if (pss.ps_envstr == NULL)
 		return EIO;
 
-	uio->uio_offset += (off_t)(vaddr_t)(pss.ps_envstr + pss.ps_nenvstr + 1);
+#ifdef COMPAT_NETBSD32
+	if (p->p_flag & PK_32)
+		uio->uio_offset += (off_t)((vaddr_t)pss.ps_envstr +
+		sizeof(uint32_t) * (pss.ps_nenvstr + 1));
+	else
+#endif
+		uio->uio_offset += (off_t)(vaddr_t)(pss.ps_envstr +
+		pss.ps_nenvstr + 1);
+
 #ifdef __MACHINE_STACK_GROWS_UP
 	if (uio->uio_offset < off)
 		return EIO;



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

2019-11-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Nov 19 10:50:26 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #1452):

sys/kern/sys_ptrace_common.c: revision 1.72

Fix pointer arithmetic for 32-bit process on LP64 kernel in
process_auxv_offset().

Now, PIOD_READ_AUXV works fine with COMPAT_NETBSD32.

XXX
pullup to netbsd-9 and netbsd-8


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.6 -r1.22.2.7 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-11-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Nov  1 09:29:25 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: subr_disk.c

Log Message:
Pull up following revision(s) (requested by cnst in ticket #1397):

sys/kern/subr_disk.c: revision 1.129

kern/subr_disk: bounds_check_with_label: really protect against div by zero

Solves kernel panic in NetBSD 8.1 amd64 on VirtualBox 6.0.12 r133076.

Triggered with an NVMe controller without any actual discs behind it:

nvme0 at pci0 dev 14 function 0: vendor 80ee product 4e56 (rev. 0x00)
nvme0: NVMe 1.2
nvme0: interrupting at ioapic0 pin 22
nvme0: ORCL-VBOX-NVME-VER12, firmware 1.0, serial VB1234-56789
ld0 at nvme0 nsid 1
ld0: 0, 0 cyl, 16 head, 63 sec, 1 bytes/sect x 0 sectors

Code path is reached 4 times during normal boot, each time after wd0a
is already mounted; this patch avoids a crash with a dirty filesystem.


To generate a diff of this commit:
cvs rdiff -u -r1.119.2.1 -r1.119.2.2 src/sys/kern/subr_disk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-11-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Nov  1 09:29:25 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: subr_disk.c

Log Message:
Pull up following revision(s) (requested by cnst in ticket #1397):

sys/kern/subr_disk.c: revision 1.129

kern/subr_disk: bounds_check_with_label: really protect against div by zero

Solves kernel panic in NetBSD 8.1 amd64 on VirtualBox 6.0.12 r133076.

Triggered with an NVMe controller without any actual discs behind it:

nvme0 at pci0 dev 14 function 0: vendor 80ee product 4e56 (rev. 0x00)
nvme0: NVMe 1.2
nvme0: interrupting at ioapic0 pin 22
nvme0: ORCL-VBOX-NVME-VER12, firmware 1.0, serial VB1234-56789
ld0 at nvme0 nsid 1
ld0: 0, 0 cyl, 16 head, 63 sec, 1 bytes/sect x 0 sectors

Code path is reached 4 times during normal boot, each time after wd0a
is already mounted; this patch avoids a crash with a dirty filesystem.


To generate a diff of this commit:
cvs rdiff -u -r1.119.2.1 -r1.119.2.2 src/sys/kern/subr_disk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_disk.c
diff -u src/sys/kern/subr_disk.c:1.119.2.1 src/sys/kern/subr_disk.c:1.119.2.2
--- src/sys/kern/subr_disk.c:1.119.2.1	Fri Apr  5 08:40:19 2019
+++ src/sys/kern/subr_disk.c	Fri Nov  1 09:29:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_disk.c,v 1.119.2.1 2019/04/05 08:40:19 msaitoh Exp $	*/
+/*	$NetBSD: subr_disk.c,v 1.119.2.2 2019/11/01 09:29:25 martin Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.119.2.1 2019/04/05 08:40:19 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.119.2.2 2019/11/01 09:29:25 martin Exp $");
 
 #include 
 #include 
@@ -374,7 +374,7 @@ bounds_check_with_label(struct disk *dk,
 	}
 
 	/* Protect against division by zero. XXX: Should never happen?!?! */
-	if (lp->d_secpercyl == 0) {
+	if ((lp->d_secsize / DEV_BSIZE) == 0 || lp->d_secpercyl == 0) {
 		bp->b_error = EINVAL;
 		return -1;
 	}



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

2019-10-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Oct 14 19:20:14 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: vnode_if.c

Log Message:
regen (for ticket #1405)


To generate a diff of this commit:
cvs rdiff -u -r1.104.2.2 -r1.104.2.3 src/sys/kern/vnode_if.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/vnode_if.c
diff -u src/sys/kern/vnode_if.c:1.104.2.2 src/sys/kern/vnode_if.c:1.104.2.3
--- src/sys/kern/vnode_if.c:1.104.2.2	Tue Jul 25 01:29:56 2017
+++ src/sys/kern/vnode_if.c	Mon Oct 14 19:20:14 2019
@@ -1,13 +1,13 @@
-/*	$NetBSD: vnode_if.c,v 1.104.2.2 2017/07/25 01:29:56 snj Exp $	*/
+/*	$NetBSD: vnode_if.c,v 1.104.2.3 2019/10/14 19:20:14 martin Exp $	*/
 
 /*
  * Warning: DO NOT EDIT! This file is automatically generated!
  * (Modifications made here may easily be lost!)
  *
  * Created from the file:
- *	NetBSD: vnode_if.src,v 1.75.2.2 2017/07/25 01:29:23 snj Exp
+ *	NetBSD: vnode_if.src,v 1.75.2.3 2019/10/14 17:43:58 martin Exp
  * by the script:
- *	NetBSD: vnode_if.sh,v 1.64.4.1 2017/06/04 20:35:01 bouyer Exp
+ *	NetBSD: vnode_if.sh,v 1.64.4.2 2019/10/14 17:43:58 martin Exp
  */
 
 /*
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.104.2.2 2017/07/25 01:29:56 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.104.2.3 2019/10/14 19:20:14 martin Exp $");
 
 #include 
 #include 
@@ -49,7 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v
 #include 
 #include 
 
-enum fst_op { FST_NO, FST_YES, FST_TRY };
+enum fst_op { FST_NO, FST_YES, FST_LAZY, FST_TRY };
 
 static inline int
 vop_pre(vnode_t *vp, struct mount **mp, bool *mpsafe, enum fst_op op)
@@ -62,7 +62,7 @@ vop_pre(vnode_t *vp, struct mount **mp, 
 		KERNEL_LOCK(1, curlwp);
 	}
 
-	if (op == FST_YES || op == FST_TRY) {
+	if (op == FST_YES || op == FST_LAZY || op == FST_TRY) {
 		for (;;) {
 			*mp = vp->v_mount;
 			if (op == FST_TRY) {
@@ -73,6 +73,8 @@ vop_pre(vnode_t *vp, struct mount **mp, 
 	}
 	return error;
 }
+			} else if (op == FST_LAZY) {
+fstrans_start_lazy(*mp);
 			} else {
 fstrans_start(*mp);
 			}
@@ -91,7 +93,7 @@ static inline void
 vop_post(vnode_t *vp, struct mount *mp, bool mpsafe, enum fst_op op)
 {
 
-	if (op == FST_YES) {
+	if (op == FST_YES || op == FST_LAZY) {
 		fstrans_done(mp);
 	}
 
@@ -1378,11 +1380,11 @@ VOP_STRATEGY(struct vnode *vp,
 	a.a_desc = VDESC(vop_strategy);
 	a.a_vp = vp;
 	a.a_bp = bp;
-	error = vop_pre(vp, &mp, &mpsafe, FST_YES);
+	error = vop_pre(vp, &mp, &mpsafe, FST_LAZY);
 	if (error)
 		return error;
 	error = (VCALL(vp, VOFFSET(vop_strategy), &a));
-	vop_post(vp, mp, mpsafe, FST_YES);
+	vop_post(vp, mp, mpsafe, FST_LAZY);
 	return error;
 }
 



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

2019-10-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Oct 14 19:20:14 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: vnode_if.c

Log Message:
regen (for ticket #1405)


To generate a diff of this commit:
cvs rdiff -u -r1.104.2.2 -r1.104.2.3 src/sys/kern/vnode_if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-10-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Oct 14 17:43:58 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: vnode_if.sh vnode_if.src

Log Message:
Pull up following revision(s) (requested by hannken in ticket #1405):

sys/kern/vnode_if.sh: revision 1.67
sys/kern/vnode_if.src: revision 1.78

As VOP_STRATEGY() usually calls itself on the file system holding "/dev"
it may deadlock on suspension of this file system.

Add fstrans type LAZY and use it for VOP_STRATEGY().

Adress PR kern/53624 (dom0 freeze on domU exit) is still there


To generate a diff of this commit:
cvs rdiff -u -r1.64.4.1 -r1.64.4.2 src/sys/kern/vnode_if.sh
cvs rdiff -u -r1.75.2.2 -r1.75.2.3 src/sys/kern/vnode_if.src

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/vnode_if.sh
diff -u src/sys/kern/vnode_if.sh:1.64.4.1 src/sys/kern/vnode_if.sh:1.64.4.2
--- src/sys/kern/vnode_if.sh:1.64.4.1	Sun Jun  4 20:35:01 2017
+++ src/sys/kern/vnode_if.sh	Mon Oct 14 17:43:58 2019
@@ -29,7 +29,7 @@ copyright="\
  * SUCH DAMAGE.
  */
 "
-SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.64.4.1 2017/06/04 20:35:01 bouyer Exp $'
+SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.64.4.2 2019/10/14 17:43:58 martin Exp $'
 
 # Script to produce VFS front-end sugar.
 #
@@ -318,7 +318,7 @@ echo '
 
 if [ -z "${rump}" ] ; then
 	echo "
-enum fst_op { FST_NO, FST_YES, FST_TRY };
+enum fst_op { FST_NO, FST_YES, FST_LAZY, FST_TRY };
 
 static inline int
 vop_pre(vnode_t *vp, struct mount **mp, bool *mpsafe, enum fst_op op)
@@ -331,7 +331,7 @@ vop_pre(vnode_t *vp, struct mount **mp, 
 		KERNEL_LOCK(1, curlwp);
 	}
 
-	if (op == FST_YES || op == FST_TRY) {
+	if (op == FST_YES || op == FST_LAZY || op == FST_TRY) {
 		for (;;) {
 			*mp = vp->v_mount;
 			if (op == FST_TRY) {
@@ -342,6 +342,8 @@ vop_pre(vnode_t *vp, struct mount **mp, 
 	}
 	return error;
 }
+			} else if (op == FST_LAZY) {
+fstrans_start_lazy(*mp);
 			} else {
 fstrans_start(*mp);
 			}
@@ -360,7 +362,7 @@ static inline void
 vop_post(vnode_t *vp, struct mount *mp, bool mpsafe, enum fst_op op)
 {
 
-	if (op == FST_YES) {
+	if (op == FST_YES || op == FST_LAZY) {
 		fstrans_done(mp);
 	}
 

Index: src/sys/kern/vnode_if.src
diff -u src/sys/kern/vnode_if.src:1.75.2.2 src/sys/kern/vnode_if.src:1.75.2.3
--- src/sys/kern/vnode_if.src:1.75.2.2	Tue Jul 25 01:29:23 2017
+++ src/sys/kern/vnode_if.src	Mon Oct 14 17:43:58 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: vnode_if.src,v 1.75.2.2 2017/07/25 01:29:23 snj Exp $
+#	$NetBSD: vnode_if.src,v 1.75.2.3 2019/10/14 17:43:58 martin Exp $
 #
 # Copyright (c) 1992, 1993
 #	The Regents of the University of California.  All rights reserved.
@@ -436,6 +436,7 @@ vop_bmap {
 #% strategy   vp  = = =
 #
 vop_strategy {
+	FSTRANS=LAZY
 	IN struct vnode *vp;
 	IN struct buf *bp;
 };



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

2019-10-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Oct 14 17:43:58 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: vnode_if.sh vnode_if.src

Log Message:
Pull up following revision(s) (requested by hannken in ticket #1405):

sys/kern/vnode_if.sh: revision 1.67
sys/kern/vnode_if.src: revision 1.78

As VOP_STRATEGY() usually calls itself on the file system holding "/dev"
it may deadlock on suspension of this file system.

Add fstrans type LAZY and use it for VOP_STRATEGY().

Adress PR kern/53624 (dom0 freeze on domU exit) is still there


To generate a diff of this commit:
cvs rdiff -u -r1.64.4.1 -r1.64.4.2 src/sys/kern/vnode_if.sh
cvs rdiff -u -r1.75.2.2 -r1.75.2.3 src/sys/kern/vnode_if.src

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-08-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug 11 10:04:03 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_lwp.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1333):

sys/kern/sys_lwp.c: revision 1.69 (patch)

Fix info leak: instead of using SS_INIT as a literal compound, use a global
variable from rodata. The compound gets pushed on the stack, the padding
of the structure was therefore not initialized, and was getting leaked to
userland in sys___sigaltstack14().


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.61.2.1 src/sys/kern/sys_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-08-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug 11 10:04:03 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_lwp.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1333):

sys/kern/sys_lwp.c: revision 1.69 (patch)

Fix info leak: instead of using SS_INIT as a literal compound, use a global
variable from rodata. The compound gets pushed on the stack, the padding
of the structure was therefore not initialized, and was getting leaked to
userland in sys___sigaltstack14().


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.61.2.1 src/sys/kern/sys_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_lwp.c
diff -u src/sys/kern/sys_lwp.c:1.61 src/sys/kern/sys_lwp.c:1.61.2.1
--- src/sys/kern/sys_lwp.c:1.61	Thu Jun  1 02:45:13 2017
+++ src/sys/kern/sys_lwp.c	Sun Aug 11 10:04:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_lwp.c,v 1.61 2017/06/01 02:45:13 chs Exp $	*/
+/*	$NetBSD: sys_lwp.c,v 1.61.2.1 2019/08/11 10:04:03 martin Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.61 2017/06/01 02:45:13 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.61.2.1 2019/08/11 10:04:03 martin Exp $");
 
 #include 
 #include 
@@ -53,6 +53,8 @@ __KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 
 
 #define	LWP_UNPARK_MAX		1024
 
+static const stack_t lwp_ss_init = SS_INIT;
+
 static syncobj_t lwp_park_sobj = {
 	SOBJ_SLEEPQ_LIFO,
 	sleepq_unsleep,
@@ -86,7 +88,7 @@ do_lwp_create(lwp_t *l, void *arg, u_lon
 		return ENOMEM;
 
 	error = lwp_create(l, p, uaddr, flags & LWP_DETACHED, NULL, 0,
-	p->p_emul->e_startlwp, arg, &l2, l->l_class, sigmask, &SS_INIT);
+	p->p_emul->e_startlwp, arg, &l2, l->l_class, sigmask, &lwp_ss_init);
 	if (__predict_false(error)) {
 		uvm_uarea_free(uaddr);
 		return error;



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

2019-08-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  7 08:21:55 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: uipc_socket2.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1330):

sys/kern/uipc_socket2.c: revision 1.134

Fix info leaks: the alignment of the structures causes uninitialized heap
memory to be copied to userland in sys_recvmsg().


To generate a diff of this commit:
cvs rdiff -u -r1.124.8.3 -r1.124.8.4 src/sys/kern/uipc_socket2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-08-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  7 08:21:55 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: uipc_socket2.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1330):

sys/kern/uipc_socket2.c: revision 1.134

Fix info leaks: the alignment of the structures causes uninitialized heap
memory to be copied to userland in sys_recvmsg().


To generate a diff of this commit:
cvs rdiff -u -r1.124.8.3 -r1.124.8.4 src/sys/kern/uipc_socket2.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_socket2.c
diff -u src/sys/kern/uipc_socket2.c:1.124.8.3 src/sys/kern/uipc_socket2.c:1.124.8.4
--- src/sys/kern/uipc_socket2.c:1.124.8.3	Tue Jul 31 17:01:20 2018
+++ src/sys/kern/uipc_socket2.c	Wed Aug  7 08:21:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_socket2.c,v 1.124.8.3 2018/07/31 17:01:20 martin Exp $	*/
+/*	$NetBSD: uipc_socket2.c,v 1.124.8.4 2019/08/07 08:21:55 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.124.8.3 2018/07/31 17:01:20 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.124.8.4 2019/08/07 08:21:55 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1419,6 +1419,10 @@ sbcreatecontrol1(void **p, int size, int
 	cp->cmsg_len = CMSG_LEN(size);
 	cp->cmsg_level = level;
 	cp->cmsg_type = type;
+
+	memset(cp + 1, 0, CMSG_LEN(0) - sizeof(*cp));
+	memset((uint8_t *)*p + size, 0, CMSG_ALIGN(size) - size);
+
 	return m;
 }
 



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

2019-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Aug  5 14:47:49 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: kern_exec.c

Log Message:
Fix editor mistake in previous


To generate a diff of this commit:
cvs rdiff -u -r1.442.4.6 -r1.442.4.7 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.442.4.6 src/sys/kern/kern_exec.c:1.442.4.7
--- src/sys/kern/kern_exec.c:1.442.4.6	Mon Aug  5 14:43:54 2019
+++ src/sys/kern/kern_exec.c	Mon Aug  5 14:47:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.442.4.6 2019/08/05 14:43:54 martin Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.442.4.7 2019/08/05 14:47:49 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.442.4.6 2019/08/05 14:43:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.442.4.7 2019/08/05 14:47:49 martin Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -677,7 +677,7 @@ execve_loadvm(struct lwp *l, const char 
 	struct proc		*p;
 	char			*dp;
 	u_int			modgen;
-	size_t			offss = 0;	// XXX: GCC
+	size_t			offs = 0;	// XXX: GCC
 
 	KASSERT(data != NULL);
 



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

2019-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Aug  5 14:47:49 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: kern_exec.c

Log Message:
Fix editor mistake in previous


To generate a diff of this commit:
cvs rdiff -u -r1.442.4.6 -r1.442.4.7 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-8] src/sys/kern

2019-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Aug  5 14:43:54 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: kern_exec.c

Log Message:
Backout the pullup of r1.476:

remove offs initialization and XXX gcc comment.

While actually the "offs" variable is always initialized when used, the
gcc version on this branch is not smart enough to recognize that.


To generate a diff of this commit:
cvs rdiff -u -r1.442.4.5 -r1.442.4.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.442.4.5 src/sys/kern/kern_exec.c:1.442.4.6
--- src/sys/kern/kern_exec.c:1.442.4.5	Sun Aug  4 11:25:43 2019
+++ src/sys/kern/kern_exec.c	Mon Aug  5 14:43:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.442.4.5 2019/08/04 11:25:43 martin Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.442.4.6 2019/08/05 14:43:54 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.442.4.5 2019/08/04 11:25:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.442.4.6 2019/08/05 14:43:54 martin Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -677,7 +677,7 @@ execve_loadvm(struct lwp *l, const char 
 	struct proc		*p;
 	char			*dp;
 	u_int			modgen;
-	size_t			offs;
+	size_t			offss = 0;	// XXX: GCC
 
 	KASSERT(data != NULL);
 



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

2019-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Aug  5 14:43:54 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: kern_exec.c

Log Message:
Backout the pullup of r1.476:

remove offs initialization and XXX gcc comment.

While actually the "offs" variable is always initialized when used, the
gcc version on this branch is not smart enough to recognize that.


To generate a diff of this commit:
cvs rdiff -u -r1.442.4.5 -r1.442.4.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-8] src/sys/kern

2019-08-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug  4 11:25:44 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: kern_exec.c

Log Message:
Pull up the following revisions, requested by maxv in ticket #1324:

sys/kern/kern_exec.c1.469-1.478 (via patch)

Fix off-by-one and info leak.


To generate a diff of this commit:
cvs rdiff -u -r1.442.4.4 -r1.442.4.5 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-8] src/sys/kern

2019-08-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug  4 11:25:44 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: kern_exec.c

Log Message:
Pull up the following revisions, requested by maxv in ticket #1324:

sys/kern/kern_exec.c1.469-1.478 (via patch)

Fix off-by-one and info leak.


To generate a diff of this commit:
cvs rdiff -u -r1.442.4.4 -r1.442.4.5 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.442.4.4 src/sys/kern/kern_exec.c:1.442.4.5
--- src/sys/kern/kern_exec.c:1.442.4.4	Wed Nov 21 11:58:32 2018
+++ src/sys/kern/kern_exec.c	Sun Aug  4 11:25:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.442.4.4 2018/11/21 11:58:32 martin Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.442.4.5 2019/08/04 11:25:43 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.442.4.4 2018/11/21 11:58:32 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.442.4.5 2019/08/04 11:25:43 martin Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -541,6 +541,12 @@ sys_execve(struct lwp *l, const struct s
 	SCARG(uap, envp), execve_fetch_element);
 }
 
+/*
+ * Copy the user or kernel supplied upath to the allocated pathbuffer pbp
+ * making it absolute in the process, by prepending the current working
+ * directory if it is not. If offs is supplied it will contain the offset
+ * where the original supplied copy of upath starts.
+ */
 int
 sys_fexecve(struct lwp *l, const struct sys_fexecve_args *uap,
 register_t *retval)
@@ -610,11 +616,8 @@ makepathbuf(struct lwp *l, const char *u
 
 	path = PNBUF_GET();
 	error = copyinstr(upath, path, MAXPATHLEN, &len);
-	if (error) {
-		PNBUF_PUT(path);
-		DPRINTF(("%s: copyin path @%p %d\n", __func__, upath, error));
-		return error;
-	}
+	if (error)
+		goto err;
 
 	if (path[0] == '/') {
 		*offs = 0;
@@ -622,8 +625,10 @@ makepathbuf(struct lwp *l, const char *u
 	}
 
 	len++;
-	if (len + 1 >= MAXPATHLEN)
-		goto out;
+	if (len + 1 >= MAXPATHLEN) {
+		error = ENAMETOOLONG;
+		goto err;
+	}
 	bp = path + MAXPATHLEN - len;
 	memmove(bp, path, len);
 	*(--bp) = '/';
@@ -634,19 +639,19 @@ makepathbuf(struct lwp *l, const char *u
 	GETCWD_CHECK_ACCESS, l);
 	rw_exit(&cwdi->cwdi_lock);
 
-	if (error) {
-		DPRINTF(("%s: getcwd_common path %s %d\n", __func__, path,
-		error));
-		goto out;
-	}
+	if (error)
+		goto err;
 	tlen = path + MAXPATHLEN - bp;
 
 	memmove(path, bp, tlen);
-	path[tlen] = '\0';
+	path[tlen - 1] = '\0';
 	*offs = tlen - len;
 out:
 	*pbp = pathbuf_assimilate(path);
 	return 0;
+err:
+	PNBUF_PUT(path);
+	return error;
 }
 
 vaddr_t
@@ -672,7 +677,7 @@ execve_loadvm(struct lwp *l, const char 
 	struct proc		*p;
 	char			*dp;
 	u_int			modgen;
-	size_t			offs = 0;	// XXX: GCC
+	size_t			offs;
 
 	KASSERT(data != NULL);
 
@@ -2088,6 +2093,7 @@ spawn_return(void *arg)
 	/* handle posix_spawnattr */
 	if (spawn_data->sed_attrs != NULL) {
 		struct sigaction sigact;
+		memset(&sigact, 0, sizeof(sigact));
 		sigact._sa_u._sa_handler = SIG_DFL;
 		sigact.sa_flags = 0;
 



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

2019-08-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug  4 11:05:29 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1319):

sys/kern/sys_ptrace_common.c: revision 1.57

Fix bug, don't release the reflock if we didn't take it in the first place.
Looks like there are other locking issues in here.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.5 -r1.22.2.6 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-08-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug  4 11:05:29 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1319):

sys/kern/sys_ptrace_common.c: revision 1.57

Fix bug, don't release the reflock if we didn't take it in the first place.
Looks like there are other locking issues in here.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.5 -r1.22.2.6 src/sys/kern/sys_ptrace_common.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_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.22.2.5 src/sys/kern/sys_ptrace_common.c:1.22.2.6
--- src/sys/kern/sys_ptrace_common.c:1.22.2.5	Mon Jul 22 18:02:09 2019
+++ src/sys/kern/sys_ptrace_common.c	Sun Aug  4 11:05:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.5 2019/07/22 18:02:09 martin Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.6 2019/08/04 11:05:29 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.5 2019/07/22 18:02:09 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.6 2019/08/04 11:05:29 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -365,8 +365,11 @@ ptrace_find(struct lwp *l, int req, pid_
 }
 
 static int
-ptrace_allowed(struct lwp *l, int req, struct proc *t, struct proc *p)
+ptrace_allowed(struct lwp *l, int req, struct proc *t, struct proc *p,
+bool *locked)
 {
+	*locked = false;
+
 	/*
 	 * Grab a reference on the process to prevent it from execing or
 	 * exiting.
@@ -374,6 +377,8 @@ ptrace_allowed(struct lwp *l, int req, s
 	if (!rw_tryenter(&t->p_reflock, RW_READER))
 		return EBUSY;
 
+	*locked = true;
+
 	/* Make sure we can operate on it. */
 	switch (req) {
 	case PT_TRACE_ME:
@@ -978,6 +983,7 @@ do_ptrace(struct ptrace_methods *ptm, st
 	int error, write, tmp, pheld;
 	int signo = 0;
 	int resume_all;
+	bool locked;
 	error = 0;
 
 	/*
@@ -993,7 +999,7 @@ do_ptrace(struct ptrace_methods *ptm, st
 	}
 
 	pheld = 1;
-	if ((error = ptrace_allowed(l, req, t, p)) != 0)
+	if ((error = ptrace_allowed(l, req, t, p, &locked)) != 0)
 		goto out;
 
 	if ((error = kauth_authorize_process(l->l_cred,
@@ -1318,7 +1324,8 @@ out:
 	}
 	if (lt != NULL)
 		lwp_delref(lt);
-	rw_exit(&t->p_reflock);
+	if (locked)
+		rw_exit(&t->p_reflock);
 
 	return error;
 }



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

2019-07-22 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 22 18:02:09 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by kamil in ticket #1302):

sys/kern/sys_ptrace_common.c: revision 1.58

Enhance locking of ptrace_update_lwp

Replace lwp_delref() + mutex_enter() with: mutex_enter() + lwp_delref2().=

This avoids extra taking and exiting from a mutex.

Add missing mutex_exit() for LW_SYSTEM.

Do not switch lwp for PT_SET_SIGINFO. This operation is not needed and
avoids panic for >2 LWPs as p_lock is attempted to be entered again in a
critical section.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.4 -r1.22.2.5 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



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

2019-07-22 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 22 18:02:09 UTC 2019

Modified Files:
src/sys/kern [netbsd-8]: sys_ptrace_common.c

Log Message:
Pull up following revision(s) (requested by kamil in ticket #1302):

sys/kern/sys_ptrace_common.c: revision 1.58

Enhance locking of ptrace_update_lwp

Replace lwp_delref() + mutex_enter() with: mutex_enter() + lwp_delref2().=

This avoids extra taking and exiting from a mutex.

Add missing mutex_exit() for LW_SYSTEM.

Do not switch lwp for PT_SET_SIGINFO. This operation is not needed and
avoids panic for >2 LWPs as p_lock is attempted to be entered again in a
critical section.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.4 -r1.22.2.5 src/sys/kern/sys_ptrace_common.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_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.22.2.4 src/sys/kern/sys_ptrace_common.c:1.22.2.5
--- src/sys/kern/sys_ptrace_common.c:1.22.2.4	Thu Nov 29 14:58:25 2018
+++ src/sys/kern/sys_ptrace_common.c	Mon Jul 22 18:02:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.4 2018/11/29 14:58:25 martin Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.22.2.5 2019/07/22 18:02:09 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.4 2018/11/29 14:58:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.22.2.5 2019/07/22 18:02:09 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -527,9 +527,9 @@ ptrace_update_lwp(struct proc *t, struct
 	if (lid == 0 || lid == (*lt)->l_lid || t->p_nlwps == 1)
 		return 0;
 
-	lwp_delref(*lt);
-
 	mutex_enter(t->p_lock);
+	lwp_delref2(*lt);
+
 	*lt = lwp_find(t, lid);
 	if (*lt == NULL) {
 		mutex_exit(t->p_lock);
@@ -537,6 +537,7 @@ ptrace_update_lwp(struct proc *t, struct
 	}
 
 	if ((*lt)->l_flag & LW_SYSTEM) {
+		mutex_exit(t->p_lock);
 		*lt = NULL;
 		return EINVAL;
 	}
@@ -574,9 +575,6 @@ ptrace_set_siginfo(struct proc *t, struc
 	if (psi.psi_siginfo.si_signo < 0 || psi.psi_siginfo.si_signo >= NSIG)
 		return EINVAL;
 
-	if ((error = ptrace_update_lwp(t, lt, psi.psi_lwpid)) != 0)
-		return error;
-
 	t->p_sigctx.ps_faked = true;
 	t->p_sigctx.ps_info = psi.psi_siginfo._info;
 	t->p_sigctx.ps_lwp = psi.psi_lwpid;



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

2017-06-21 Thread Soren Jacobsen
On 06/21 18:25, m...@netbsd.org wrote:
> On Wed, Jun 21, 2017 at 06:12:40PM +, Soren Jacobsen wrote:
> > Module Name:src
> > Committed By:   snj
> > Date:   Wed Jun 21 18:12:40 UTC 2017
> > 
> > Modified Files:
> > src/sys/kern [netbsd-8]: exec_subr.c
> > 
> > Log Message:
> > Pull up following revision(s) (requested by joerg in ticket #50):
> > sys/kern/exec_subr.c: revision 1.79
> > Always include a 1MB guard area beyond the end of stack. While ASLR will
> > normally create a guard area as well, this provides a deterministic area
> > for all binaries.
> > Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
> > Qualys.
> > 
> > 
> > To generate a diff of this commit:
> > cvs rdiff -u -r1.78 -r1.78.2.1 src/sys/kern/exec_subr.c
> 
> joerg reverted this one, stating it breaks i386
> 
> http://mail-index.netbsd.org/source-changes/2017/06/19/msg085502.html

Reverted on netbsd-8 as well.

Soren


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

2017-06-21 Thread maya
On Wed, Jun 21, 2017 at 06:12:40PM +, Soren Jacobsen wrote:
> Module Name:  src
> Committed By: snj
> Date: Wed Jun 21 18:12:40 UTC 2017
> 
> Modified Files:
>   src/sys/kern [netbsd-8]: exec_subr.c
> 
> Log Message:
> Pull up following revision(s) (requested by joerg in ticket #50):
>   sys/kern/exec_subr.c: revision 1.79
> Always include a 1MB guard area beyond the end of stack. While ASLR will
> normally create a guard area as well, this provides a deterministic area
> for all binaries.
> Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
> Qualys.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.78 -r1.78.2.1 src/sys/kern/exec_subr.c

joerg reverted this one, stating it breaks i386

http://mail-index.netbsd.org/source-changes/2017/06/19/msg085502.html