Module Name:    src
Committed By:   kamil
Date:           Fri Jan  3 00:37:30 UTC 2020

Modified Files:
        src/sys/kern: sys_ptrace_common.c

Log Message:
Correct the rule to iterate over LWPs with PT_LWPNEXT and PT_LWPINFO

Correctly exclude dead/dying/zombie and system threads.

Fixes kern/54802 (gdb -p kills the kernel) by <martin>


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 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.76 src/sys/kern/sys_ptrace_common.c:1.77
--- src/sys/kern/sys_ptrace_common.c:1.76	Thu Dec 26 08:52:38 2019
+++ src/sys/kern/sys_ptrace_common.c	Fri Jan  3 00:37:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.76 2019/12/26 08:52:38 kamil Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.77 2020/01/03 00:37:29 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.76 2019/12/26 08:52:38 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.77 2020/01/03 00:37:29 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -757,7 +757,8 @@ ptrace_lwpinfo(struct proc *t, struct lw
 		*lt = LIST_NEXT(*lt, l_sibling);
 	}
 
-	while (*lt != NULL && !lwp_alive(*lt))
+	while (*lt != NULL && (!lwp_alive(*lt) ||
+	       ((*lt)->l_flag & LW_SYSTEM) != 0))
 		*lt = LIST_NEXT(*lt, l_sibling);
 
 	pl.pl_lwpid = 0;
@@ -822,8 +823,8 @@ ptrace_lwpstatus(struct proc *t, struct 
 			*lt = LIST_NEXT(*lt, l_sibling);
 		}
 
-		while (*lt != NULL && !lwp_alive(*lt) &&
-		       ((*lt)->l_flag & LW_SYSTEM) != 0)
+		while (*lt != NULL && (!lwp_alive(*lt) ||
+		       ((*lt)->l_flag & LW_SYSTEM) != 0))
 			*lt = LIST_NEXT(*lt, l_sibling);
 
 		if (*lt == NULL) {

Reply via email to