NetBSD Problem Report #36649

From gary@duzan.org  Sun Jul 15 14:31:20 2007
Return-Path: <gary@duzan.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id ABE5363B96E
	for <gnats-bugs@gnats.netbsd.org>; Sun, 15 Jul 2007 14:31:20 +0000 (UTC)
Message-Id: <1184506039.779171.4581.nullmailer@capo.xnet.duzan.org>
Date: Sun, 15 Jul 2007 09:27:19 -0400
From: gary@duzan.org
Reply-To: gary@duzan.org
To: gnats-bugs@NetBSD.org
Subject: ps -M causes core in libkvm
X-Send-Pr-Version: 3.95

>Number:         36649
>Category:       lib
>Synopsis:       ps -M causes core in libkvm
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 15 14:35:00 +0000 2007
>Last-Modified:  Sun Jul 15 14:50:00 +0000 2007
>Originator:     Gary Duzan
>Release:        NetBSD 4.99.22
>Organization:
	None
>Environment:
System: NetBSD capo 4.99.22 NetBSD 4.99.22 (CAPO64) #36: Sat Jul 14 18:16:53 EDT 2007 gary@capo:/usr/obj/sys/arch/amd64/compile.amd64/CAPO64 amd64
Architecture: x86_64
Machine: amd64
>Description:
	Running "ps -M /var/crash/netbsd.0.core" causes a segmentation
	fault in kvm_getproc2. The call to kvm_getlwps() returns NULL
	for pid 0 because the read of the back pointer fails.
>How-To-Repeat:
	ps -M /var/crash/netbsd.0.core
>Fix:
	The following allows the ps to complete successfully, though I'm
	not sure it is the correct fix.

Index: lib/libkvm/kvm_proc.c
===================================================================
RCS file: /usr2/netbsd-cvs/src/lib/libkvm/kvm_proc.c,v
retrieving revision 1.73
diff -b -u -p -r1.73 kvm_proc.c
--- lib/libkvm/kvm_proc.c	9 Jul 2007 22:28:13 -0000	1.73
+++ lib/libkvm/kvm_proc.c	15 Jul 2007 13:25:56 -0000
@@ -813,10 +813,15 @@ again:
 			laddr = (u_long)PTRTOUINT64(l.l_runq.tqe_prev);
 			st = kvm_read(kd, laddr, &back, sizeof(back));
 			if (st == -1) {
+#ifdef GDD_NOTDEF_XXX
 				_kvm_syserr(kd, kd->program, "kvm_getlwps");
 				return (NULL);
-			}
+#else
+				kl->l_back = PTRTOUINT64(NULL);
+#endif
+			} else {
 			kl->l_back = PTRTOUINT64(back);
+			}
 			kl->l_addr = PTRTOUINT64(l.l_addr);
 			kl->l_lid = l.l_lid;
 			kl->l_flag = l.l_flag;

>Audit-Trail:
From: Gary Duzan <gary@duzan.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/36649: ps -M causes core in libkvm 
Date: Sun, 15 Jul 2007 10:40:57 -0400

    Since posting my patch, I've realized that PPIDs are mangled
 (all -42899695) in the resulting ps listings. Making the test
 conditional on pid == 0 didn't help.

 					Gary Duzan

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.