Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/pmap Disallow printing of kernel mappings if we are ...



details:   https://anonhg.NetBSD.org/src/rev/dc5d22953eb3
branches:  trunk
changeset: 770482:dc5d22953eb3
user:      jym <jym%NetBSD.org@localhost>
date:      Tue Oct 18 20:54:56 2011 +0000

description:
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.

diffstat:

 usr.bin/pmap/main.c |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diffs (47 lines):

diff -r f5c5a4b3f38d -r dc5d22953eb3 usr.bin/pmap/main.c
--- a/usr.bin/pmap/main.c       Tue Oct 18 20:20:29 2011 +0000
+++ b/usr.bin/pmap/main.c       Tue Oct 18 20:54:56 2011 +0000
@@ -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 @@
                        }
                }
 
+               /*
+                * 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) {



Home | Main Index | Thread Index | Old Index