Module Name:    src
Committed By:   jym
Date:           Tue Oct 18 20:54:57 UTC 2011

Modified Files:
        src/usr.bin/pmap: main.c

Log Message:
Disallow printing of kernel mappings if we are not root.

pid 0 is a special case for kill(pid, 0), and unlikely to be the
correct test there. This follows the procfs "mem" rights changes that
happened some time ago.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/pmap/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/usr.bin/pmap/main.c
diff -u src/usr.bin/pmap/main.c:1.21 src/usr.bin/pmap/main.c:1.22
--- src/usr.bin/pmap/main.c:1.21	Thu Jun 23 22:50:53 2011
+++ src/usr.bin/pmap/main.c	Tue Oct 18 20:54:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.21 2011/06/23 22:50:53 christos Exp $ */
+/*	$NetBSD: main.c,v 1.22 2011/10/18 20:54:56 jym Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.21 2011/06/23 22:50:53 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.22 2011/10/18 20:54:56 jym Exp $");
 #endif
 
 #include <sys/param.h>
@@ -308,15 +308,23 @@ main(int argc, char *argv[])
 			}
 		}
 
+		/*
+		 * Only print mappings for processes we can send a signal(7)
+		 * to, or kernel mappings if we are root
+		 */
+		if (kill(pid, 0) == -1 ||
+		   (pid == 0 && getuid() != 0)) {
+			errno = EPERM;
+			warn("%d", pid);
+			pid = -1;
+			continue;
+
+		}
+
 		/* find the process id */
 		if (pid == 0)
 			kproc = NULL;
 		else {
-			if (kill(pid, 0) == -1) {
-				warn("%d", pid);
-				pid = -1;
-				continue;
-			}
 			kproc = kvm_getproc2(kd, KERN_PROC_PID, pid,
 					     sizeof(struct kinfo_proc2), &rc);
 			if (kproc == NULL || rc == 0) {

Reply via email to