Subject: kern/34888: kernel panic while trying to access /emul/linux/proc/0/stat
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <njoly@pasteur.fr>
List: netbsd-bugs
Date: 10/23/2006 17:40:01
>Number:         34888
>Category:       kern
>Synopsis:       kernel panic while trying to access /emul/linux/proc/0/stat
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 23 17:40:01 +0000 2006
>Originator:     Nicolas Joly
>Release:        NetBSD 4.99.3
>Organization:
Institut Pasteur, Paris.
>Environment:
System: NetBSD lanfeust.sis.pasteur.fr 4.99.3 NetBSD 4.99.3 (LANFEUST) #6: Mon Oct 23 19:20:32 CEST 2006 njoly@lanfeust.sis.pasteur.fr:/local/src/NetBSD/obj/amd64/sys/arch/amd64/compile/LANFEUST amd64
Architecture: x86_64
Machine: amd64
>Description:
Trying to read `/emul/linux/proc/0/stat' result in a kernel panic. This
is from a process file system mounted with linux option.

Stopped in pid 1591.1 (cat) at  netbsd:procfs_do_pid_stat+0x2ac:        movl    
0x94(%rax),%r8d
db{0}> bt
procfs_do_pid_stat() at netbsd:procfs_do_pid_stat+0x2ac
VOP_READ() at netbsd:VOP_READ+0x2d
vn_read() at netbsd:vn_read+0xc8
dofileread() at netbsd:dofileread+0xd6
sys_read() at netbsd:sys_read+0xc4
syscall_plain() at netbsd:syscall_plain+0x1ff

The problem is that process 0 (kernel) has no parent process. In that case,
`p->p_pptr == NULL' and trying to get `p->p_pptr->p_pid' will crash.
>How-To-Repeat:
mount_procfs -o linux /proc /emul/linux/proc
cat /emul/linux/proc/0/stat
>Fix:
Index: sys/miscfs/procfs/procfs_linux.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_linux.c,v
retrieving revision 1.27
diff -u -r1.27 procfs_linux.c
--- sys/miscfs/procfs/procfs_linux.c	12 Oct 2006 01:32:27 -0000	1.27
+++ sys/miscfs/procfs/procfs_linux.c	23 Oct 2006 17:19:58 -0000
@@ -214,7 +214,7 @@
 	    p->p_pid,
 	    p->p_comm,
 	    "0IR3SZD"[(p->p_stat > 6) ? 0 : (int)p->p_stat],
-	    p->p_pptr->p_pid,
+	    p->p_pptr ? p->p_pptr->p_pid : 0,
 
 	    p->p_pgid,
 	    p->p_session->s_sid,