Subject: kern/699: uninialized variable in procfs causes ptrace to fail
To: None <gnats-admin@NetBSD.ORG>
From: David Jones <dej@qpoint.torfree.net>
List: netbsd-bugs
Date: 01/04/1995 18:20:05
>Number:         699
>Category:       kern
>Synopsis:       uninialized variable in procfs causes ptrace to fail
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan  4 18:20:03 1995
>Originator:     David Jones
>Organization:
"	"
>Release:        
>Environment:
	
System: NetBSD qpoint 1.0A NetBSD 1.0A (QPOINT) #7: Wed Jan 4 20:50:05 EST 1995 dej@qpoint:/local/src/sys.941230/arch/amiga/compile/QPOINT amiga


>Description:
GDB cannot read/write the process address space when tracing a process.
It gets "no such process".  This error is intermittent.
GDB will refuse to single-step the process further.
	
>How-To-Repeat:
	
Simply use GDB to single-step a process.  If your system is susceptible to
the bug, then you will get a "no such process" error message.
>Fix:
	
GDB uses ptrace to read the process address space.  ptrace uses procfs to
do its work.  procfs_rwmem() uses the VM system to map the desired page
into kernel space, from which uiomove() can fetch the required data.
However, the kva variable is uninitialized.  Depending on what's on
the stack, vm_map_find() may fail.

The problem can be fixed by applying the following patch:

*** procfs_mem.c	Wed Jan  4 20:54:05 1995
--- /local/src/sys.941204/miscfs/procfs/procfs_mem.c	Wed Jun 29 06:29:57 1994
***************
*** 158,168 ****
  		}
  
  		/* Find space in kernel_map for the page we're interested in */
! 		if (!error) {
! 			kva = 0;
  			error = vm_map_find(kernel_map, object, off, &kva,
  					PAGE_SIZE, 1);
- 		}
  
  		if (!error) {
  			/*
--- 158,166 ----
  		}
  
  		/* Find space in kernel_map for the page we're interested in */
! 		if (!error)
  			error = vm_map_find(kernel_map, object, off, &kva,
  					PAGE_SIZE, 1);
  
  		if (!error) {
  			/*
>Audit-Trail:
>Unformatted: