CVS commit: src/usr.bin/pmap

2022-08-21 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Aug 21 07:46:52 UTC 2022

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

Log Message:
Add -t option to print pmap as underlying RB tree.
Report gap/maxgap fields when dumping vm_map structure.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/pmap/main.h
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/pmap/pmap.1
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/pmap/pmap.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/pmap/pmap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2022-08-21 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Aug 21 07:46:52 UTC 2022

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

Log Message:
Add -t option to print pmap as underlying RB tree.
Report gap/maxgap fields when dumping vm_map structure.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/pmap/main.h
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/pmap/pmap.1
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/pmap/pmap.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/pmap/pmap.h

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.29 src/usr.bin/pmap/main.c:1.30
--- src/usr.bin/pmap/main.c:1.29	Wed Nov  4 01:37:55 2020
+++ src/usr.bin/pmap/main.c	Sun Aug 21 07:46:52 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.29 2020/11/04 01:37:55 chs Exp $ */
+/*	$NetBSD: main.c,v 1.30 2022/08/21 07:46:52 mlelstv Exp $ */
 
 /*
  * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.29 2020/11/04 01:37:55 chs Exp $");
+__RCSID("$NetBSD: main.c,v 1.30 2022/08/21 07:46:52 mlelstv Exp $");
 #endif
 
 #include 
@@ -60,6 +60,7 @@ struct vm_map *st_map, *pt_map, *module_
 u_long kernel_map_addr;
 int debug, verbose, recurse, page_size;
 int print_all, print_map, print_maps, print_solaris, print_ddb;
+int tree;
 rlim_t maxssiz;
 
 struct nlist ksyms[] = {
@@ -133,12 +134,13 @@ main(int argc, char *argv[])
 	pid = -1;
 	which = verbose = debug = 0;
 	print_all = print_map = print_maps = print_solaris = print_ddb = 0;
+	tree = 0;
 	recurse = 0;
 	kmem = kernel = NULL;
 	address = 0;
 	vmspace = 
 
-	while ((ch = getopt(argc, argv, "A:aD:dE:lM:mN:Pp:RrS:sV:vx")) != -1) {
+	while ((ch = getopt(argc, argv, "A:aD:dE:lM:mN:Pp:RrS:stV:vx")) != -1) {
 		switch (ch) {
 		case 'A':
 		case 'E':
@@ -204,6 +206,9 @@ main(int argc, char *argv[])
 		case 's':
 			print_solaris = 1;
 			break;
+		case 't':
+			tree = 1;
+			break;
 		case 'v':
 			verbose++;
 			break;
@@ -213,7 +218,7 @@ main(int argc, char *argv[])
 			/*NOTREACHED*/
 		case '?':
 		default:
-			fprintf(stderr, "usage: %s [-adlmPRsv] [-A address] "
+			fprintf(stderr, "usage: %s [-adlmPRstv] [-A address] "
 "[-D number] [-E address] [-M core]\n"
 "\t[-N system] [-p pid] [-S address] "
 "[-V address] [pid ...]\n",

Index: src/usr.bin/pmap/main.h
diff -u src/usr.bin/pmap/main.h:1.6 src/usr.bin/pmap/main.h:1.7
--- src/usr.bin/pmap/main.h:1.6	Mon Apr 28 20:24:14 2008
+++ src/usr.bin/pmap/main.h	Sun Aug 21 07:46:52 2022
@@ -1,4 +1,4 @@
-/*  $NetBSD: main.h,v 1.6 2008/04/28 20:24:14 martin Exp $ */
+/*  $NetBSD: main.h,v 1.7 2022/08/21 07:46:52 mlelstv Exp $ */
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,6 +31,7 @@
 
 extern int debug, verbose, recurse, page_size;
 extern int print_all, print_map, print_maps, print_solaris, print_ddb;
+extern int tree;
 extern u_long kernel_map_addr;
 extern void *uvm_vnodeops, *uvm_deviceops, *aobj_pager, *ubc_pager;
 extern rlim_t maxssiz;

Index: src/usr.bin/pmap/pmap.1
diff -u src/usr.bin/pmap/pmap.1:1.19 src/usr.bin/pmap/pmap.1:1.20
--- src/usr.bin/pmap/pmap.1:1.19	Mon Jul  3 21:34:20 2017
+++ src/usr.bin/pmap/pmap.1	Sun Aug 21 07:46:52 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pmap.1,v 1.19 2017/07/03 21:34:20 wiz Exp $
+.\"	$NetBSD: pmap.1,v 1.20 2022/08/21 07:46:52 mlelstv Exp $
 .\"
 .\" Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -35,7 +35,7 @@
 .Nd display process memory map
 .Sh SYNOPSIS
 .Nm
-.Op Fl adlmPRsv
+.Op Fl adlmPRstv
 .Op Fl A Ar address
 .Op Fl D Ar number
 .Op Fl E Ar address
@@ -170,6 +170,9 @@ Dumps the vmspace structure found at
 The Solaris style output format, modeled after the Solaris command of
 the same name.
 This is the default output style.
+.It Fl t
+Print entries to the underlying RB tree, root first, followed by lower
+and higher subtree, indented similar to submaps.
 .It Fl V Ar address
 Dumps the vm_map structure found at
 .Ar address .

Index: src/usr.bin/pmap/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.56 src/usr.bin/pmap/pmap.c:1.57
--- src/usr.bin/pmap/pmap.c:1.56	Wed Nov  4 01:37:55 2020
+++ src/usr.bin/pmap/pmap.c	Sun Aug 21 07:46:52 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.56 2020/11/04 01:37:55 chs Exp $ */
+/*	$NetBSD: pmap.c,v 1.57 2022/08/21 07:46:52 mlelstv Exp $ */
 
 /*
  * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: pmap.c,v 1.56 2020/11/04 01:37:55 chs Exp $");
+__RCSID("$NetBSD: pmap.c,v 1.57 2022/08/21 07:46:52 mlelstv Exp $");
 #endif
 
 #include 
@@ -45,9 +45,10 @@ static char *findname(kvm_t *, struct kb
 	struct kbit *, struct kbit *);
 static int search_cache(kvm_t *, struct vnode *, char **, char *, size_t);
 
-/* when 

CVS commit: src/usr.bin/pmap

2020-11-03 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Nov  4 01:37:55 UTC 2020

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

Log Message:
Restrict to root any command option that prints kernel addresses.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/pmap/pmap.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/pmap/pmap.h

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.28 src/usr.bin/pmap/main.c:1.29
--- src/usr.bin/pmap/main.c:1.28	Sun Mar 22 14:41:32 2020
+++ src/usr.bin/pmap/main.c	Wed Nov  4 01:37:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.28 2020/03/22 14:41:32 ad Exp $ */
+/*	$NetBSD: main.c,v 1.29 2020/11/04 01:37:55 chs Exp $ */
 
 /*
  * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.28 2020/03/22 14:41:32 ad Exp $");
+__RCSID("$NetBSD: main.c,v 1.29 2020/11/04 01:37:55 chs Exp $");
 #endif
 
 #include 
@@ -121,6 +121,7 @@ main(int argc, char *argv[])
 	struct kbit kbit, *vmspace;
 	u_long address;
 
+	uid = getuid();
 	egid = getegid();
 	if (setegid(getgid()) == -1)
 		err(1, "failed to reset privileges");
@@ -231,11 +232,12 @@ main(int argc, char *argv[])
 	print_ddb == 0)
 		print_solaris = 1;
 
-	/* get privs back if it appears to be safe, otherwise toss them */
-	if (kernel == NULL && kmem == NULL && address == 0)
-		rc = setegid(egid);
-	else
-		rc = setgid(getgid());
+	if ((kernel != NULL || kmem != NULL || address != 0 ||
+	 print_ddb || debug) && uid != 0)
+		errx(1, "one or more options specified is restricted to root");
+
+	/* get privs back since it appears to be safe. */
+	rc = setegid(egid);
 	if (rc == -1)
 		err(1, "failed to reset privileges");
 
@@ -283,8 +285,6 @@ main(int argc, char *argv[])
 		exit(0);
 	}
 
-	uid = getuid();
-
 	do {
 		if (pid == -1) {
 			if (argc == 0)

Index: src/usr.bin/pmap/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.55 src/usr.bin/pmap/pmap.c:1.56
--- src/usr.bin/pmap/pmap.c:1.55	Sun Mar 22 14:41:32 2020
+++ src/usr.bin/pmap/pmap.c	Wed Nov  4 01:37:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.55 2020/03/22 14:41:32 ad Exp $ */
+/*	$NetBSD: pmap.c,v 1.56 2020/11/04 01:37:55 chs Exp $ */
 
 /*
  * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: pmap.c,v 1.55 2020/03/22 14:41:32 ad Exp $");
+__RCSID("$NetBSD: pmap.c,v 1.56 2020/11/04 01:37:55 chs Exp $");
 #endif
 
 #include 
@@ -483,9 +483,7 @@ dump_vm_map_entry(kvm_t *kd, struct kinf
 
 	if (print_all) {
 		sz = (size_t)((vme->end - vme->start) / 1024);
-		printf(A(vp) ?
-		   "%*s%0*"PRIxVADDR"-%0*"PRIxVADDR" %7luk %0*" PRIx64 " %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s [%p]\n" :
-		   "%*s%0*"PRIxVADDR"-%0*"PRIxVADDR" %7luk %0*" PRIx64 " %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s\n",
+		printf("%*s%0*"PRIxVADDR"-%0*"PRIxVADDR" %7luk %0*" PRIx64 " %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s\n",
 		   indent(2), "",
 		   (int)sizeof(void *) * 2,
 		   vme->start,
@@ -508,7 +506,7 @@ dump_vm_map_entry(kvm_t *kd, struct kinf
 		   (unsigned long long)major(dev),
 		   (unsigned long long)minor(dev),
 		   (unsigned long long)inode,
-		   name, P(vp));
+		   name);
 	}
 
 	/* no access allowed, don't count space */

Index: src/usr.bin/pmap/pmap.h
diff -u src/usr.bin/pmap/pmap.h:1.12 src/usr.bin/pmap/pmap.h:1.13
--- src/usr.bin/pmap/pmap.h:1.12	Sun Mar 22 14:41:32 2020
+++ src/usr.bin/pmap/pmap.h	Wed Nov  4 01:37:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.12 2020/03/22 14:41:32 ad Exp $ */
+/*	$NetBSD: pmap.h,v 1.13 2020/11/04 01:37:55 chs Exp $ */
 
 /*
  * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
@@ -98,8 +98,7 @@
 	((size_t)kvm_read((kd), (addr), (dst), (sz)) == (size_t)(sz))
 #define _KDEREF(kd, addr, dst, sz) do { \
 	if (!_KDEREFOK((kd), (addr), (dst), (sz))) \
-		errx(1, "trying to read %lu (%s) bytes from %lx: %s", \
-		(unsigned long)(sz), #sz, (addr), kvm_geterr(kd)); \
+		errx(1, "reading from kmem failed: %s", kvm_geterr(kd)); \
 } while (0/*CONSTCOND*/)
 
 /* suck the data using the structure */



CVS commit: src/usr.bin/pmap

2020-11-03 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Nov  4 01:37:55 UTC 2020

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

Log Message:
Restrict to root any command option that prints kernel addresses.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/pmap/pmap.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/pmap/pmap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2020-03-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Mar 22 14:41:32 UTC 2020

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

Log Message:
- Don't copy the entire namecache only to look up a few names.  Walk the
  data structures like cache_revlookup().

- nchash and mb_map are gone.  module_map replaced lkm_map.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/pmap/pmap.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/pmap/pmap.h

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.27 src/usr.bin/pmap/main.c:1.28
--- src/usr.bin/pmap/main.c:1.27	Fri Sep 13 13:55:24 2019
+++ src/usr.bin/pmap/main.c	Sun Mar 22 14:41:32 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: main.c,v 1.27 2019/09/13 13:55:24 christos Exp $ */
+/*	$NetBSD: main.c,v 1.28 2020/03/22 14:41:32 ad Exp $ */
 
 /*
- * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.27 2019/09/13 13:55:24 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.28 2020/03/22 14:41:32 ad Exp $");
 #endif
 
 #include 
@@ -54,11 +54,10 @@ __RCSID("$NetBSD: main.c,v 1.27 2019/09/
 #include "main.h"
 
 struct cache_head lcache;
-struct nchashhead *nchashtbl;
 void *uvm_vnodeops, *uvm_deviceops, *aobj_pager, *ubc_pager;
-struct vm_map *kmem_map, *mb_map, *phys_map, *exec_map, *pager_map;
-struct vm_map *st_map, *pt_map, *lkm_map, *buf_map;
-u_long nchash_addr, nchashtbl_addr, kernel_map_addr;
+struct vm_map *kmem_map, *phys_map, *exec_map, *pager_map;
+struct vm_map *st_map, *pt_map, *module_map, *buf_map;
+u_long kernel_map_addr;
 int debug, verbose, recurse, page_size;
 int print_all, print_map, print_maps, print_solaris, print_ddb;
 rlim_t maxssiz;
@@ -76,32 +75,26 @@ struct nlist ksyms[] = {
 #define NL_UBC_PAGER		4
 	{ "_kernel_map", 0, 0, 0, 0 },
 #define NL_KERNEL_MAP		5
-	{ "_nchashtbl", 0, 0, 0, 0 },
-#define NL_NCHASHTBL		6
-	{ "_nchash", 0, 0, 0, 0 },
-#define NL_NCHASH		7
 	{ NULL, 0, 0, 0, 0 }
 };
 
 struct nlist kmaps[] = {
 	{ "_kmem_map", 0, 0, 0, 0 },
 #define NL_kmem_map		0
-	{ "_mb_map", 0, 0, 0, 0 },
-#define NL_mb_map		1
 	{ "_phys_map", 0, 0, 0, 0 },
-#define NL_phys_map		2
+#define NL_phys_map		1
 	{ "_exec_map", 0, 0, 0, 0 },
-#define NL_exec_map		3
+#define NL_exec_map		2
 	{ "_pager_map", 0, 0, 0, 0 },
-#define NL_pager_map		4
+#define NL_pager_map		3
 	{ "_st_map", 0, 0, 0, 0 },
-#define NL_st_map		5
+#define NL_st_map		4
 	{ "_pt_map", 0, 0, 0, 0 },
-#define NL_pt_map		6
-	{ "_lkm_map", 0, 0, 0, 0 },
-#define NL_lkm_map		7
+#define NL_pt_map		5
+	{ "_module_map", 0, 0, 0, 0 },
+#define NL_module_map		6
 	{ "_buf_map", 0, 0, 0, 0 },
-#define NL_buf_map		8
+#define NL_buf_map		7
 	{ NULL, 0, 0, 0, 0 },
 };
 
@@ -398,12 +391,8 @@ load_symbols(kvm_t *kd)
 	aobj_pager =	(void*)ksyms[NL_AOBJ_PAGER].n_value;
 	ubc_pager =	(void*)ksyms[NL_UBC_PAGER].n_value;
 
-	nchash_addr =	ksyms[NL_NCHASH].n_value;
-
 	_KDEREF(kd, ksyms[NL_MAXSSIZ].n_value, ,
 		sizeof(maxssiz));
-	_KDEREF(kd, ksyms[NL_NCHASHTBL].n_value, _addr,
-	   sizeof(nchashtbl_addr));
 	_KDEREF(kd, ksyms[NL_KERNEL_MAP].n_value, _map_addr,
 		sizeof(kernel_map_addr));
 
@@ -420,13 +409,12 @@ load_symbols(kvm_t *kd)
 	} while (0/*CONSTCOND*/)
 
 	get_map_address(kmem_map);
-	get_map_address(mb_map);
 	get_map_address(phys_map);
 	get_map_address(exec_map);
 	get_map_address(pager_map);
 	get_map_address(st_map);
 	get_map_address(pt_map);
-	get_map_address(lkm_map);
+	get_map_address(module_map);
 	get_map_address(buf_map);
 
 	mib[0] = CTL_HW;
@@ -444,8 +432,6 @@ mapname(void *addr)
 		return ("kernel_map");
 	else if (addr == kmem_map)
 		return ("kmem_map");
-	else if (addr == mb_map)
-		return ("mb_map");
 	else if (addr == phys_map)
 		return ("phys_map");
 	else if (addr == exec_map)
@@ -456,83 +442,10 @@ mapname(void *addr)
 		return ("st_map");
 	else if (addr == pt_map)
 		return ("pt_map");
-	else if (addr == lkm_map)
-		return ("lkm_map");
+	else if (addr == module_map)
+		return ("module_map");
 	else if (addr == buf_map)
 		return ("buf_map");
 	else
 		return (NULL);
 }
-
-void
-load_name_cache(kvm_t *kd)
-{
-	struct namecache *ncp, *oncp;
-	union {
-		struct namecache ncp;
-		char buf[sizeof(*ncp) + USHRT_MAX];
-	} _n;
-#define _ncp _n.ncp
-	struct nchashhead _ncpp, *ncpp; 
-	u_long lnchash;
-	size_t nchash, i;
-
-	LIST_INIT();
-
-	_KDEREF(kd, nchash_addr, , sizeof(lnchash));
-	nchash = (size_t)lnchash + 1;
-	nchashtbl = ecalloc(nchash, sizeof(*nchashtbl));
-	_KDEREF(kd, nchashtbl_addr, nchashtbl, sizeof(*nchashtbl) * nchash);
-
-	ncpp = &_ncpp;
-
-	for (i = 0; i < nchash; i++) {
-		ncpp = [i];
-		oncp = NULL;
-		

CVS commit: src/usr.bin/pmap

2020-03-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Mar 22 14:41:32 UTC 2020

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

Log Message:
- Don't copy the entire namecache only to look up a few names.  Walk the
  data structures like cache_revlookup().

- nchash and mb_map are gone.  module_map replaced lkm_map.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/pmap/pmap.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/pmap/pmap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2019-09-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Sep 13 13:55:24 UTC 2019

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

Log Message:
deal with variable length namecache entries.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 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.26 src/usr.bin/pmap/main.c:1.27
--- src/usr.bin/pmap/main.c:1.26	Sun Dec 13 22:15:10 2015
+++ src/usr.bin/pmap/main.c	Fri Sep 13 09:55:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.26 2015/12/14 03:15:10 christos Exp $ */
+/*	$NetBSD: main.c,v 1.27 2019/09/13 13:55:24 christos Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.26 2015/12/14 03:15:10 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.27 2019/09/13 13:55:24 christos Exp $");
 #endif
 
 #include 
@@ -467,7 +467,12 @@ mapname(void *addr)
 void
 load_name_cache(kvm_t *kd)
 {
-	struct namecache _ncp, *ncp, *oncp;
+	struct namecache *ncp, *oncp;
+	union {
+		struct namecache ncp;
+		char buf[sizeof(*ncp) + USHRT_MAX];
+	} _n;
+#define _ncp _n.ncp
 	struct nchashhead _ncpp, *ncpp; 
 	u_long lnchash;
 	size_t nchash, i;
@@ -485,11 +490,19 @@ load_name_cache(kvm_t *kd)
 		ncpp = [i];
 		oncp = NULL;
 		LIST_FOREACH(ncp, ncpp, nc_hash) {
+			size_t len;
+
 			if (ncp == oncp ||
 			ncp == (void*)0xdeadbeef)
 break;
 			oncp = ncp;
-			_KDEREF(kd, (u_long)ncp, &_ncp, sizeof(*ncp));
+			len = NCHNAMLEN;
+again:
+			_KDEREF(kd, (u_long)ncp, &_ncp, (len + sizeof(*ncp)));
+			if (_ncp.nc_nlen > len && _ncp.nc_nlen < 1024) {
+len = _ncp.nc_nlen;
+goto again;
+			}
 			ncp = &_ncp;
 			if (ncp->nc_nlen > 0) {
 if (ncp->nc_nlen > 2 ||



CVS commit: src/usr.bin/pmap

2019-09-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Sep 13 13:55:24 UTC 2019

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

Log Message:
deal with variable length namecache entries.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 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.



CVS commit: src/usr.bin/pmap

2018-05-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May  9 01:04:01 UTC 2018

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

Log Message:
handle field rename.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/pmap/pmap.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/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.53 src/usr.bin/pmap/pmap.c:1.54
--- src/usr.bin/pmap/pmap.c:1.53	Wed Oct  4 07:33:01 2017
+++ src/usr.bin/pmap/pmap.c	Tue May  8 21:04:01 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.53 2017/10/04 11:33:01 kamil Exp $ */
+/*	$NetBSD: pmap.c,v 1.54 2018/05/09 01:04:01 christos Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: pmap.c,v 1.53 2017/10/04 11:33:01 kamil Exp $");
+__RCSID("$NetBSD: pmap.c,v 1.54 2018/05/09 01:04:01 christos Exp $");
 #endif
 
 #include 
@@ -119,7 +119,7 @@ dump_vm_map(kvm_t *kd, struct kinfo_proc
 		printf(" vm_refcnt = %d,", D(vmspace, vmspace)->vm_refcnt);
 		printf(" vm_shm = %p,\n", D(vmspace, vmspace)->vm_shm);
 		printf("vm_rssize = %d,", D(vmspace, vmspace)->vm_rssize);
-		printf(" vm_swrss = %d,", D(vmspace, vmspace)->vm_swrss);
+		printf(" vm_rssmax = %d,", D(vmspace, vmspace)->vm_rssmax);
 		printf(" vm_tsize = %d,", D(vmspace, vmspace)->vm_tsize);
 		printf(" vm_dsize = %d,\n", D(vmspace, vmspace)->vm_dsize);
 		printf("vm_ssize = %d,", D(vmspace, vmspace)->vm_ssize);



CVS commit: src/usr.bin/pmap

2018-05-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May  9 01:04:01 UTC 2018

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

Log Message:
handle field rename.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2017-10-04 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Oct  4 11:33:01 UTC 2017

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

Log Message:
pmap: Refresh debugging facilities

Print vm_aslr_delta_mmap from 'struct vmspace'.
Print the WANTVA bit of 'flags' from 'struct vm_map'.
Replace %x with %#x, this improves readability of hex vs dec numbers.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2017-10-04 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Oct  4 11:33:01 UTC 2017

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

Log Message:
pmap: Refresh debugging facilities

Print vm_aslr_delta_mmap from 'struct vmspace'.
Print the WANTVA bit of 'flags' from 'struct vm_map'.
Replace %x with %#x, this improves readability of hex vs dec numbers.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/pmap/pmap.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/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.52 src/usr.bin/pmap/pmap.c:1.53
--- src/usr.bin/pmap/pmap.c:1.52	Mon Dec 14 03:15:10 2015
+++ src/usr.bin/pmap/pmap.c	Wed Oct  4 11:33:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.52 2015/12/14 03:15:10 christos Exp $ */
+/*	$NetBSD: pmap.c,v 1.53 2017/10/04 11:33:01 kamil Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: pmap.c,v 1.52 2015/12/14 03:15:10 christos Exp $");
+__RCSID("$NetBSD: pmap.c,v 1.53 2017/10/04 11:33:01 kamil Exp $");
 #endif
 
 #include 
@@ -127,8 +127,10 @@ dump_vm_map(kvm_t *kd, struct kinfo_proc
 		printf(" vm_daddr = %p,\n", D(vmspace, vmspace)->vm_daddr);
 		printf("vm_maxsaddr = %p,",
 		   D(vmspace, vmspace)->vm_maxsaddr);
-		printf(" vm_minsaddr = %p }\n",
+		printf(" vm_minsaddr = %p,\n",
 		   D(vmspace, vmspace)->vm_minsaddr);
+		printf("vm_aslr_delta_mmap = %#zx }\n",
+		   D(vmspace, vmspace)->vm_aslr_delta_mmap);
 	}
 
 	if (debug & PRINT_VM_MAP) {
@@ -144,7 +146,7 @@ dump_vm_map(kvm_t *kd, struct kinfo_proc
 		   D(vm_map, vm_map)->hint);
 		printf("%*sfirst_free = %p,", indent(2), "",
 		   D(vm_map, vm_map)->first_free);
-		printf(" flags = %x <%s%s%s%s >,\n", D(vm_map, vm_map)->flags,
+		printf(" flags = %#x <%s%s%s%s%s >,\n", D(vm_map, vm_map)->flags,
 		   D(vm_map, vm_map)->flags & VM_MAP_PAGEABLE ? " PAGEABLE" : "",
 		   D(vm_map, vm_map)->flags & VM_MAP_WIREFUTURE ? " WIREFUTURE" : "",
 #ifdef VM_MAP_DYING
@@ -154,6 +156,10 @@ dump_vm_map(kvm_t *kd, struct kinfo_proc
 #ifdef VM_MAP_TOPDOWN
 		   D(vm_map, vm_map)->flags & VM_MAP_TOPDOWN ? " TOPDOWN" :
 #endif
+		   "",
+#ifdef VM_MAP_WANTVA
+		   D(vm_map, vm_map)->flags & VM_MAP_WANTVA ? " WANTVA" :
+#endif
 		   "");
 		printf("%*stimestamp = %u }\n", indent(2), "",
 		 D(vm_map, vm_map)->timestamp);
@@ -165,7 +171,7 @@ dump_vm_map(kvm_t *kd, struct kinfo_proc
 		   recurse < 2 ? "MAP" : "SUBMAP", P(vm_map),
 		   vm_map_min(D(vm_map, vm_map)),
 		   vm_map_max(D(vm_map, vm_map)));
-		printf("\t%*s#ent=%d, sz=%"PRIxVSIZE", ref=%d, version=%d, flags=0x%x\n",
+		printf("\t%*s#ent=%d, sz=%"PRIxVSIZE", ref=%d, version=%d, flags=%#x\n",
 		   indent(2), "", D(vm_map, vm_map)->nentries,
 		   D(vm_map, vm_map)->size, D(vm_map, vm_map)->ref_count,
 		   D(vm_map, vm_map)->timestamp, D(vm_map, vm_map)->flags);
@@ -289,20 +295,20 @@ dump_vm_map_entry(kvm_t *kd, struct kinf
 		printf(" object.uvm_obj/sub_map = %p,\n", vme->object.uvm_obj);
 		printf("%*soffset = %" PRIx64 ",", indent(2), "",
 		   vme->offset);
-		printf(" etype = %x <%s%s%s%s >,", vme->etype,
+		printf(" etype = %#x <%s%s%s%s >,", vme->etype,
 		   UVM_ET_ISOBJ(vme) ? " OBJ" : "",
 		   UVM_ET_ISSUBMAP(vme) ? " SUBMAP" : "",
 		   UVM_ET_ISCOPYONWRITE(vme) ? " COW" : "",
 		   UVM_ET_ISNEEDSCOPY(vme) ? " NEEDSCOPY" : "");
-		printf(" protection = %x,\n", vme->protection);
-		printf("%*smax_protection = %x,", indent(2), "",
+		printf(" protection = %#x,\n", vme->protection);
+		printf("%*smax_protection = %#x,", indent(2), "",
 		   vme->max_protection);
 		printf(" inheritance = %d,", vme->inheritance);
 		printf(" wired_count = %d,\n", vme->wired_count);
-		printf("%*saref = { ar_pageoff = %x, ar_amap = %p },",
+		printf("%*saref = { ar_pageoff = %#x, ar_amap = %p },",
 		   indent(2), "", vme->aref.ar_pageoff, vme->aref.ar_amap);
 		printf(" advice = %d,\n", vme->advice);
-		printf("%*sflags = %x <%s%s%s > }\n", indent(2), "",
+		printf("%*sflags = %#x <%s%s%s > }\n", indent(2), "",
 		   vme->flags,
 		   vme->flags & UVM_MAP_KERNEL ? " KERNEL" : "",
 		   vme->flags & UVM_MAP_STATIC ? " STATIC" : "",
@@ -425,7 +431,7 @@ dump_vm_map_entry(kvm_t *kd, struct kinf
 	}
 
 	if (print_ddb) {
-		printf("%*s - %p: %#"PRIxVADDR"->%#"PRIxVADDR": obj=%p/0x%" PRIx64 ", amap=%p/%d\n",
+		printf("%*s - %p: %#"PRIxVADDR"->%#"PRIxVADDR": obj=%p/%#" PRIx64 ", amap=%p/%d\n",
 		   indent(2), "",
 		   P(vm_map_entry), vme->start, vme->end,
 		   vme->object.uvm_obj, vme->offset,
@@ -541,7 +547,7 @@ dump_amap(kvm_t *kd, struct kbit *amap)
 	}
 
 	printf("%*s  amap %p = { am_ref = %d, "
-	   "am_flags = %x,\n"
+	   "am_flags = %#x,\n"
 	   "%*s  

CVS commit: src/usr.bin/pmap

2016-12-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Dec 22 22:41:02 UTC 2016

Modified Files:
src/usr.bin/pmap: pmap.h

Log Message:
add the member name to an error string so we know what object failed
while being requested.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/pmap/pmap.h

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/pmap.h
diff -u src/usr.bin/pmap/pmap.h:1.8 src/usr.bin/pmap/pmap.h:1.9
--- src/usr.bin/pmap/pmap.h:1.8	Mon Apr 13 00:27:38 2009
+++ src/usr.bin/pmap/pmap.h	Thu Dec 22 22:41:02 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.8 2009/04/13 00:27:38 lukem Exp $ */
+/*	$NetBSD: pmap.h,v 1.9 2016/12/22 22:41:02 mrg Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -95,8 +95,8 @@
 	((size_t)kvm_read((kd), (addr), (dst), (sz)) == (size_t)(sz))
 #define _KDEREF(kd, addr, dst, sz) do { \
 	if (!_KDEREFOK((kd), (addr), (dst), (sz))) \
-		errx(1, "trying to read %lu bytes from %lx: %s", \
-		(unsigned long)(sz), (addr), kvm_geterr(kd)); \
+		errx(1, "trying to read %lu (%s) bytes from %lx: %s", \
+		(unsigned long)(sz), #sz, (addr), kvm_geterr(kd)); \
 } while (0/*CONSTCOND*/)
 
 /* suck the data using the structure */



CVS commit: src/usr.bin/pmap

2016-12-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Dec 22 22:41:02 UTC 2016

Modified Files:
src/usr.bin/pmap: pmap.h

Log Message:
add the member name to an error string so we know what object failed
while being requested.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/pmap/pmap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2015-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 14 03:15:10 UTC 2015

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

Log Message:
use ecalloc


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/pmap/Makefile
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/pmap/pmap.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/Makefile
diff -u src/usr.bin/pmap/Makefile:1.5 src/usr.bin/pmap/Makefile:1.6
--- src/usr.bin/pmap/Makefile:1.5	Thu May 26 08:56:33 2011
+++ src/usr.bin/pmap/Makefile	Sun Dec 13 22:15:10 2015
@@ -1,12 +1,12 @@
-#	$NetBSD: Makefile,v 1.5 2011/05/26 12:56:33 joerg Exp $
+#	$NetBSD: Makefile,v 1.6 2015/12/14 03:15:10 christos Exp $
 
 USE_FORT?=	yes	# setgid
 PROG=		pmap
 SRCS=		main.c pmap.c
 BINGRP=		kmem
 BINMODE=	2555
-LDADD=		-lkvm
-DPADD=		${LIBKVM}
+LDADD=		-lutil -lkvm
+DPADD=		${LIBUTIL} ${LIBKVM}
 
 CWARNFLAGS.clang+=	-Wno-format-extra-args
 

Index: src/usr.bin/pmap/main.c
diff -u src/usr.bin/pmap/main.c:1.25 src/usr.bin/pmap/main.c:1.26
--- src/usr.bin/pmap/main.c:1.25	Sun Dec 13 13:09:00 2015
+++ src/usr.bin/pmap/main.c	Sun Dec 13 22:15:10 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.25 2015/12/13 18:09:00 christos Exp $ */
+/*	$NetBSD: main.c,v 1.26 2015/12/14 03:15:10 christos Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.25 2015/12/13 18:09:00 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.26 2015/12/14 03:15:10 christos Exp $");
 #endif
 
 #include 
@@ -48,6 +48,7 @@ __RCSID("$NetBSD: main.c,v 1.25 2015/12/
 #include 
 #include 
 #include 
+#include 
 
 #include "pmap.h"
 #include "main.h"
@@ -475,7 +476,7 @@ load_name_cache(kvm_t *kd)
 
 	_KDEREF(kd, nchash_addr, , sizeof(lnchash));
 	nchash = (size_t)lnchash + 1;
-	nchashtbl = malloc(nchash * sizeof(*nchashtbl));
+	nchashtbl = ecalloc(nchash, sizeof(*nchashtbl));
 	_KDEREF(kd, nchashtbl_addr, nchashtbl, sizeof(*nchashtbl) * nchash);
 
 	ncpp = &_ncpp;
@@ -512,7 +513,7 @@ cache_enter(u_long i, struct namecache *
 		   i, ncp->nc_vp, ncp->nc_dvp,
 		   ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
 
-	ce = malloc(sizeof(struct cache_entry));
+	ce = emalloc(sizeof(struct cache_entry));
 	
 	ce->ce_vp = ncp->nc_vp;
 	ce->ce_pvp = ncp->nc_dvp;

Index: src/usr.bin/pmap/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.51 src/usr.bin/pmap/pmap.c:1.52
--- src/usr.bin/pmap/pmap.c:1.51	Mon Oct 29 12:25:25 2012
+++ src/usr.bin/pmap/pmap.c	Sun Dec 13 22:15:10 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.51 2012/10/29 16:25:25 para Exp $ */
+/*	$NetBSD: pmap.c,v 1.52 2015/12/14 03:15:10 christos Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,10 +31,11 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: pmap.c,v 1.51 2012/10/29 16:25:25 para Exp $");
+__RCSID("$NetBSD: pmap.c,v 1.52 2015/12/14 03:15:10 christos Exp $");
 #endif
 
 #include 
+#include 
 
 #include "pmap.h"
 #include "main.h"
@@ -565,22 +566,23 @@ dump_amap(kvm_t *kd, struct kbit *amap)
 	 * Assume that sizeof(struct vm_anon *) >= sizeof(size_t) and
 	 * allocate that amount of space.
 	 */
-	l = sizeof(struct vm_anon *) * D(amap, amap)->am_maxslot;
-	am_anon = malloc(l);
+	am_anon = ecalloc(D(amap, amap)->am_maxslot, sizeof(*am_anon));
+	l = D(amap, amap)->am_maxslot * sizeof(*am_anon);
 	_KDEREF(kd, (u_long)D(amap, amap)->am_anon, am_anon, l);
 
-	l = sizeof(int) * D(amap, amap)->am_maxslot;
-	am_bckptr = malloc(l);
+	l = D(amap, amap)->am_maxslot * sizeof(*am_bckptr);
+	am_bckptr = ecalloc(D(amap, amap)->am_maxslot, sizeof(*am_bckptr));
 	_KDEREF(kd, (u_long)D(amap, amap)->am_bckptr, am_bckptr, l);
 
-	l = sizeof(int) * D(amap, amap)->am_maxslot;
-	am_slots = malloc(l);
+	l = D(amap, amap)->am_maxslot * sizeof(*am_slots);
+	am_slots = ecalloc(D(amap, amap)->am_maxslot, sizeof(*am_slots));
 	_KDEREF(kd, (u_long)D(amap, amap)->am_slots, am_slots, l);
 
 	if (D(amap, amap)->am_ppref != NULL &&
 	D(amap, amap)->am_ppref != PPREF_NONE) {
-		l = sizeof(int) * D(amap, amap)->am_maxslot;
-		am_ppref = malloc(l);
+		am_ppref = ecalloc(
+		D(amap, amap)->am_maxslot, sizeof(*am_ppref));
+		l = D(amap, amap)->am_maxslot * sizeof(*am_ppref);
 		_KDEREF(kd, (u_long)D(amap, amap)->am_ppref, am_ppref, l);
 	} else {
 		am_ppref = NULL;



CVS commit: src/usr.bin/pmap

2015-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 13 18:09:00 UTC 2015

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

Log Message:
PR/50546: David Binderman: Fix bad sizeof


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 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.24 src/usr.bin/pmap/main.c:1.25
--- src/usr.bin/pmap/main.c:1.24	Tue Oct 25 19:45:19 2011
+++ src/usr.bin/pmap/main.c	Sun Dec 13 13:09:00 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.24 2011/10/25 23:45:19 jym Exp $ */
+/*	$NetBSD: main.c,v 1.25 2015/12/13 18:09:00 christos Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.24 2011/10/25 23:45:19 jym Exp $");
+__RCSID("$NetBSD: main.c,v 1.25 2015/12/13 18:09:00 christos Exp $");
 #endif
 
 #include 
@@ -468,18 +468,19 @@ load_name_cache(kvm_t *kd)
 {
 	struct namecache _ncp, *ncp, *oncp;
 	struct nchashhead _ncpp, *ncpp; 
-	u_long nchash, i;
+	u_long lnchash;
+	size_t nchash, i;
 
 	LIST_INIT();
 
-	_KDEREF(kd, nchash_addr, , sizeof(nchash));
-	nchashtbl = malloc(sizeof(nchashtbl) * (int)(nchash + 1));
-	_KDEREF(kd, nchashtbl_addr, nchashtbl,
-		sizeof(nchashtbl) * (int)(nchash + 1));
+	_KDEREF(kd, nchash_addr, , sizeof(lnchash));
+	nchash = (size_t)lnchash + 1;
+	nchashtbl = malloc(nchash * sizeof(*nchashtbl));
+	_KDEREF(kd, nchashtbl_addr, nchashtbl, sizeof(*nchashtbl) * nchash);
 
 	ncpp = &_ncpp;
 
-	for (i = 0; i <= nchash; i++) {
+	for (i = 0; i < nchash; i++) {
 		ncpp = [i];
 		oncp = NULL;
 		LIST_FOREACH(ncp, ncpp, nc_hash) {



CVS commit: src/usr.bin/pmap

2015-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 13 18:09:00 UTC 2015

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

Log Message:
PR/50546: David Binderman: Fix bad sizeof


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 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.



CVS commit: src/usr.bin/pmap

2015-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 14 03:15:10 UTC 2015

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

Log Message:
use ecalloc


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/pmap/Makefile
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2012-10-29 Thread Lars Heidieker
Module Name:src
Committed By:   para
Date:   Mon Oct 29 16:25:27 UTC 2012

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

Log Message:
fix format string


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/pmap/pmap.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/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.50 src/usr.bin/pmap/pmap.c:1.51
--- src/usr.bin/pmap/pmap.c:1.50	Mon Oct 29 16:00:05 2012
+++ src/usr.bin/pmap/pmap.c	Mon Oct 29 16:25:25 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.50 2012/10/29 16:00:05 para Exp $ */
+/*	$NetBSD: pmap.c,v 1.51 2012/10/29 16:25:25 para Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pmap.c,v 1.50 2012/10/29 16:00:05 para Exp $);
+__RCSID($NetBSD: pmap.c,v 1.51 2012/10/29 16:25:25 para Exp $);
 #endif
 
 #include string.h
@@ -301,7 +301,7 @@ dump_vm_map_entry(kvm_t *kd, struct kinf
 		printf(%*saref = { ar_pageoff = %x, ar_amap = %p },,
 		   indent(2), , vme-aref.ar_pageoff, vme-aref.ar_amap);
 		printf( advice = %d,\n, vme-advice);
-		printf(%*sflags = %x %s%s%s%s  }\n, indent(2), ,
+		printf(%*sflags = %x %s%s%s  }\n, indent(2), ,
 		   vme-flags,
 		   vme-flags  UVM_MAP_KERNEL ?  KERNEL : ,
 		   vme-flags  UVM_MAP_STATIC ?  STATIC : ,



CVS commit: src/usr.bin/pmap

2012-10-29 Thread Lars Heidieker
Module Name:src
Committed By:   para
Date:   Mon Oct 29 16:25:27 UTC 2012

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

Log Message:
fix format string


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2012-02-18 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun Feb 19 02:47:53 UTC 2012

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

Log Message:
G/C VM_MAP_INTRSAFE flag


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/pmap/pmap.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/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.48 src/usr.bin/pmap/pmap.c:1.49
--- src/usr.bin/pmap/pmap.c:1.48	Fri Jan 27 19:48:42 2012
+++ src/usr.bin/pmap/pmap.c	Sun Feb 19 02:47:53 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.48 2012/01/27 19:48:42 para Exp $ */
+/*	$NetBSD: pmap.c,v 1.49 2012/02/19 02:47:53 rmind Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pmap.c,v 1.48 2012/01/27 19:48:42 para Exp $);
+__RCSID($NetBSD: pmap.c,v 1.49 2012/02/19 02:47:53 rmind Exp $);
 #endif
 
 #include string.h
@@ -143,9 +143,8 @@ dump_vm_map(kvm_t *kd, struct kinfo_proc
 		   D(vm_map, vm_map)-hint);
 		printf(%*sfirst_free = %p,, indent(2), ,
 		   D(vm_map, vm_map)-first_free);
-		printf( flags = %x %s%s%s%s%s ,\n, D(vm_map, vm_map)-flags,
+		printf( flags = %x %s%s%s%s ,\n, D(vm_map, vm_map)-flags,
 		   D(vm_map, vm_map)-flags  VM_MAP_PAGEABLE ?  PAGEABLE : ,
-		   D(vm_map, vm_map)-flags  VM_MAP_INTRSAFE ?  INTRSAFE : ,
 		   D(vm_map, vm_map)-flags  VM_MAP_WIREFUTURE ?  WIREFUTURE : ,
 #ifdef VM_MAP_DYING
 		   D(vm_map, vm_map)-flags  VM_MAP_DYING ?  DYING :



CVS commit: src/usr.bin/pmap

2012-02-18 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun Feb 19 02:47:53 UTC 2012

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

Log Message:
G/C VM_MAP_INTRSAFE flag


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2011-10-25 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Tue Oct 25 22:13:22 UTC 2011

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

Log Message:
kill(2) might not be a good test after all, users can send signals
to setuid binaries (like SIGINT for ping(8)). So apply the exact same
rights as procfs, and test uid against proc p_uid (real owner of process).

Bail out if we are not root and we attempt to print mappings of a process
that the user does not really own.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 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.22 src/usr.bin/pmap/main.c:1.23
--- src/usr.bin/pmap/main.c:1.22	Tue Oct 18 20:54:56 2011
+++ src/usr.bin/pmap/main.c	Tue Oct 25 22:13:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.22 2011/10/18 20:54:56 jym Exp $ */
+/*	$NetBSD: main.c,v 1.23 2011/10/25 22:13:22 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.22 2011/10/18 20:54:56 jym Exp $);
+__RCSID($NetBSD: main.c,v 1.23 2011/10/25 22:13:22 jym Exp $);
 #endif
 
 #include sys/param.h
@@ -118,6 +118,7 @@ main(int argc, char *argv[])
 {
 	kvm_t *kd;
 	pid_t pid;
+	uid_t uid;
 	int which, many, ch, rc;
 	char errbuf[_POSIX2_LINE_MAX + 1];
 	struct kinfo_proc2 *kproc;
@@ -308,33 +309,36 @@ 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;
-
-		}
+		uid = getuid();
 
+		errno = 0;
 		/* find the process id */
-		if (pid == 0)
+		if (pid == 0) {
 			kproc = NULL;
-		else {
+			if (uid != 0) {
+/* only root can print kernel mappings */
+errno = EPERM;
+			}
+		} else {
 			kproc = kvm_getproc2(kd, KERN_PROC_PID, pid,
-	 sizeof(struct kinfo_proc2), rc);
+sizeof(struct kinfo_proc2), rc);
 			if (kproc == NULL || rc == 0) {
 errno = ESRCH;
-warn(%d, pid);
-pid = -1;
-continue;
+			} else if (uid != 0  uid != kproc-p_uid) {
+/*
+ * only the real owner of the process and
+ * root can print process mappings
+ */
+errno = EPERM;
 			}
 		}
 
+		if (errno != 0) {
+			warn(%d, pid);
+			pid = -1;
+			continue;
+		}
+
 		/* dump it */
 		if (many) {
 			if (kproc)



CVS commit: src/usr.bin/pmap

2011-10-25 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Tue Oct 25 23:45:19 UTC 2011

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

Log Message:
Move getuid() out of the loop, uid should not change behind our back. KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 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.23 src/usr.bin/pmap/main.c:1.24
--- src/usr.bin/pmap/main.c:1.23	Tue Oct 25 22:13:22 2011
+++ src/usr.bin/pmap/main.c	Tue Oct 25 23:45:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.23 2011/10/25 22:13:22 jym Exp $ */
+/*	$NetBSD: main.c,v 1.24 2011/10/25 23:45:19 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.23 2011/10/25 22:13:22 jym Exp $);
+__RCSID($NetBSD: main.c,v 1.24 2011/10/25 23:45:19 jym Exp $);
 #endif
 
 #include sys/param.h
@@ -289,6 +289,8 @@ main(int argc, char *argv[])
 		exit(0);
 	}
 
+	uid = getuid();
+
 	do {
 		if (pid == -1) {
 			if (argc == 0)
@@ -309,8 +311,6 @@ main(int argc, char *argv[])
 			}
 		}
 
-		uid = getuid();
-
 		errno = 0;
 		/* find the process id */
 		if (pid == 0) {
@@ -321,7 +321,7 @@ main(int argc, char *argv[])
 			}
 		} else {
 			kproc = kvm_getproc2(kd, KERN_PROC_PID, pid,
-sizeof(struct kinfo_proc2), rc);
+			sizeof(struct kinfo_proc2), rc);
 			if (kproc == NULL || rc == 0) {
 errno = ESRCH;
 			} else if (uid != 0  uid != kproc-p_uid) {
@@ -341,7 +341,7 @@ main(int argc, char *argv[])
 
 		/* dump it */
 		if (many) {
-			if (kproc)
+			if (kproc != NULL)
 printf(process %d:\n, kproc-p_pid);
 			else
 printf(kernel:\n);



CVS commit: src/usr.bin/pmap

2011-10-25 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Tue Oct 25 22:13:22 UTC 2011

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

Log Message:
kill(2) might not be a good test after all, users can send signals
to setuid binaries (like SIGINT for ping(8)). So apply the exact same
rights as procfs, and test uid against proc p_uid (real owner of process).

Bail out if we are not root and we attempt to print mappings of a process
that the user does not really own.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 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.



CVS commit: src/usr.bin/pmap

2011-10-25 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Tue Oct 25 23:45:19 UTC 2011

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

Log Message:
Move getuid() out of the loop, uid should not change behind our back. KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 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.



CVS commit: src/usr.bin/pmap

2011-10-18 Thread Jean-Yves Migeon
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) {



CVS commit: src/usr.bin/pmap

2011-10-18 Thread Jean-Yves Migeon
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.



CVS commit: src/usr.bin/pmap

2011-10-11 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Tue Oct 11 12:25:56 UTC 2011

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

Log Message:
Consistently use %#PRIxVADDR to print VA, not 0x%#PRIxVADDR
or 0x%PRIxVADDR etc.  Noticed by Y.Sugahara.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/pmap/pmap.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/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.46 src/usr.bin/pmap/pmap.c:1.47
--- src/usr.bin/pmap/pmap.c:1.46	Sun Jun 12 06:34:59 2011
+++ src/usr.bin/pmap/pmap.c	Tue Oct 11 12:25:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.46 2011/06/12 06:34:59 mrg Exp $ */
+/*	$NetBSD: pmap.c,v 1.47 2011/10/11 12:25:56 tsutsui Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pmap.c,v 1.46 2011/06/12 06:34:59 mrg Exp $);
+__RCSID($NetBSD: pmap.c,v 1.47 2011/10/11 12:25:56 tsutsui Exp $);
 #endif
 
 #include string.h
@@ -161,7 +161,7 @@ dump_vm_map(kvm_t *kd, struct kinfo_proc
 	if (print_ddb) {
 		const char *name = mapname(P(vm_map));
 
-		printf(%*s%s %p: [0x%#PRIxVADDR-0x%#PRIxVADDR]\n, indent(2), ,
+		printf(%*s%s %p: [%#PRIxVADDR-%#PRIxVADDR]\n, indent(2), ,
 		   recurse  2 ? MAP : SUBMAP, P(vm_map),
 		   vm_map_min(D(vm_map, vm_map)),
 		   vm_map_max(D(vm_map, vm_map)));
@@ -384,7 +384,7 @@ dump_vm_map_entry(kvm_t *kd, struct kinf
 	name = findname(kd, vmspace, vm_map_entry, vp, vfs, uvm_obj);
 
 	if (print_map) {
-		printf(%*s0x%#PRIxVADDR 0x%#PRIxVADDR %c%c%c %c%c%c %s %s %d %d %d,
+		printf(%*s%#PRIxVADDR %#PRIxVADDR %c%c%c %c%c%c %s %s %d %d %d,
 		   indent(2), ,
 		   vme-start, vme-end,
 		   (vme-protection  VM_PROT_READ) ? 'r' : '-',
@@ -427,7 +427,7 @@ dump_vm_map_entry(kvm_t *kd, struct kinf
 	}
 
 	if (print_ddb) {
-		printf(%*s - %p: 0x%PRIxVADDR-0x%PRIxVADDR: obj=%p/0x% PRIx64 , amap=%p/%d\n,
+		printf(%*s - %p: %#PRIxVADDR-%#PRIxVADDR: obj=%p/0x% PRIx64 , amap=%p/%d\n,
 		   indent(2), ,
 		   P(vm_map_entry), vme-start, vme-end,
 		   vme-object.uvm_obj, vme-offset,



CVS commit: src/usr.bin/pmap

2011-10-11 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Tue Oct 11 12:25:56 UTC 2011

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

Log Message:
Consistently use %#PRIxVADDR to print VA, not 0x%#PRIxVADDR
or 0x%PRIxVADDR etc.  Noticed by Y.Sugahara.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/pmap

2011-06-26 Thread David Holland
On Sun, Jun 26, 2011 at 12:55:33AM +0200, Jean-Yves Migeon wrote:
   Don't give out information about processes we can't control.
  
  Thanks to Aleksey and you for fixing the procfs leak.
  
  I wonder whether pmap's code is the right place to check for
  information access control. It's difficult to modify except by
  patching the source, does not protect from abusing/finding exploits to
  circumvent the check (any executable that has kmem sgid rights is a
  target), and there are other potential tools usable out there (lsof(1),
  maybe?).

It used to e.g. give out the pathnames of all the files everyone on
the system has open, which is definitely not desirable. I remember I
had concerns about it when it first appeared, and I remember
contacting someone about it, but I don't remember who and neither they
nor I followed up at the time. :-/

-- 
David A. Holland
dholl...@netbsd.org


Re: CVS commit: src/usr.bin/pmap

2011-06-25 Thread Jean-Yves Migeon
On 24.06.2011 00:50, Christos Zoulas wrote:
 Module Name:  src
 Committed By: christos
 Date: Thu Jun 23 22:50:54 UTC 2011
 
 Modified Files:
   src/usr.bin/pmap: main.c
 
 Log Message:
 Don't give out information about processes we can't control.

Thanks to Aleksey and you for fixing the procfs leak.

I wonder whether pmap's code is the right place to check for
information access control. It's difficult to modify except by
patching the source, does not protect from abusing/finding exploits to
circumvent the check (any executable that has kmem sgid rights is a
target), and there are other potential tools usable out there (lsof(1),
maybe?).

Isn't it something that rather fits the kauth(9) ACLs?

-- 
Jean-Yves Migeon
jeanyves.mig...@free.fr


Re: CVS commit: src/usr.bin/pmap

2011-06-25 Thread Christos Zoulas
In article 4e066765.6010...@free.fr,
Jean-Yves Migeon  jeanyves.mig...@free.fr wrote:
On 24.06.2011 00:50, Christos Zoulas wrote:
 Module Name: src
 Committed By:christos
 Date:Thu Jun 23 22:50:54 UTC 2011
 
 Modified Files:
  src/usr.bin/pmap: main.c
 
 Log Message:
 Don't give out information about processes we can't control.

Thanks to Aleksey and you for fixing the procfs leak.

I wonder whether pmap's code is the right place to check for
information access control. It's difficult to modify except by
patching the source, does not protect from abusing/finding exploits to
circumvent the check (any executable that has kmem sgid rights is a
target), and there are other potential tools usable out there (lsof(1),
maybe?).

Isn't it something that rather fits the kauth(9) ACLs?

We need to kill all the setgid kmem grovelers and use sysctl/procfs
to get data from the kernel. If one decides to compile and install
setuid or setgid programs that have information leaks, it is not
NetBSD's fault..

christos



CVS commit: src/usr.bin/pmap

2011-06-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 23 22:50:54 UTC 2011

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

Log Message:
Don't give out information about processes we can't control.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 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.



CVS commit: src/usr.bin/pmap

2011-06-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Jun 12 06:35:00 UTC 2011

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

Log Message:
an_ref is now a uintptr_t.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/pmap/pmap.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/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.45 src/usr.bin/pmap/pmap.c:1.46
--- src/usr.bin/pmap/pmap.c:1.45	Mon Dec 14 17:16:12 2009
+++ src/usr.bin/pmap/pmap.c	Sun Jun 12 06:34:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.45 2009/12/14 17:16:12 uebayasi Exp $ */
+/*	$NetBSD: pmap.c,v 1.46 2011/06/12 06:34:59 mrg Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pmap.c,v 1.45 2009/12/14 17:16:12 uebayasi Exp $);
+__RCSID($NetBSD: pmap.c,v 1.46 2011/06/12 06:34:59 mrg Exp $);
 #endif
 
 #include string.h
@@ -659,7 +659,7 @@
 		else
 			KDEREF(kd, anon);
 
-		printf( = { an_ref = %d, an_page = %p, an_swslot = %d },
+		printf( = { an_ref = %PRIuPTR, an_page = %p, an_swslot = %d },
 		D(anon, anon)-an_ref, D(anon, anon)-an_page,
 		D(anon, anon)-an_swslot);
 	}



CVS commit: src/usr.bin/pmap

2011-06-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Jun 12 06:35:00 UTC 2011

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

Log Message:
an_ref is now a uintptr_t.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2010-05-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri May 14 17:31:27 UTC 2010

Modified Files:
src/usr.bin/pmap: pmap.1

Log Message:
Explicitly close quote.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/pmap/pmap.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2010-03-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Mar 22 18:34:14 UTC 2010

Modified Files:
src/usr.bin/pmap: pmap.1

Log Message:
Use .In instead of .Aq Pa for header files.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/pmap/pmap.1

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/pmap.1
diff -u src/usr.bin/pmap/pmap.1:1.15 src/usr.bin/pmap/pmap.1:1.16
--- src/usr.bin/pmap/pmap.1:1.15	Sun Feb 15 22:49:37 2009
+++ src/usr.bin/pmap/pmap.1	Mon Mar 22 18:34:14 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: pmap.1,v 1.15 2009/02/15 22:49:37 wiz Exp $
+.\	$NetBSD: pmap.1,v 1.16 2010/03/22 18:34:14 joerg Exp $
 .\
 .\ Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -240,7 +240,7 @@
 .Pp
 The value of the flags field (in hexadecimal) is taken from
 the include file
-.Aq Pa uvm/uvm_map.h :
+.In uvm/uvm_map.h :
 .Bl -column VM_MAP_WIREFUTURE VM_MAP_WIREFUTURE -offset indent
 .It Dv VM_MAP_PAGEABLE   Ta No 0x01   entries are pageable
 .It Dv VM_MAP_INTRSAFE   Ta No 0x02   interrupt safe map
@@ -263,7 +263,7 @@
 \(or protection) field, along with
 .Dq max
 \(maximum protection allowed) are made up of the following flags from
-.Aq Pa uvm/uvm_extern.h :
+.In uvm/uvm_extern.h :
 .\ this column width specifically chosen so that all the header file
 .\ excerpts appear to line up cleanly
 .Bl -column VM_MAP_WIREFUTURE VM_MAP_WIREFUTURE -offset indent



CVS commit: src/usr.bin/pmap

2010-03-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Mar 22 18:34:14 UTC 2010

Modified Files:
src/usr.bin/pmap: pmap.1

Log Message:
Use .In instead of .Aq Pa for header files.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/pmap/pmap.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/pmap

2009-12-14 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Mon Dec 14 14:29:09 UTC 2009

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

Log Message:
Merge from matt-nb5-mips64; adapt to vaddr_t / vsize_t format specifiers.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/pmap/pmap.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/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.43 src/usr.bin/pmap/pmap.c:1.44
--- src/usr.bin/pmap/pmap.c:1.43	Mon Apr 13 00:27:38 2009
+++ src/usr.bin/pmap/pmap.c	Mon Dec 14 14:29:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.43 2009/04/13 00:27:38 lukem Exp $ */
+/*	$NetBSD: pmap.c,v 1.44 2009/12/14 14:29:09 uebayasi Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pmap.c,v 1.43 2009/04/13 00:27:38 lukem Exp $);
+__RCSID($NetBSD: pmap.c,v 1.44 2009/12/14 14:29:09 uebayasi Exp $);
 #endif
 
 #include string.h
@@ -136,7 +136,7 @@
 		printf(%*slock = struct lock,, indent(2), );
 		printf( header = struct vm_map_entry,);
 		printf( nentries = %d,\n, D(vm_map, vm_map)-nentries);
-		printf(%*ssize = %lx,, indent(2), ,
+		printf(%*ssize = %#PRIxVSIZE,, indent(2), ,
 		   D(vm_map, vm_map)-size);
 		printf( ref_count = %d,, D(vm_map, vm_map)-ref_count);
 		printf(%*shint = %p,, indent(2), ,
@@ -161,11 +161,11 @@
 	if (print_ddb) {
 		const char *name = mapname(P(vm_map));
 
-		printf(%*s%s %p: [0x%lx-0x%lx]\n, indent(2), ,
+		printf(%*s%s %p: [0x%#PRIxVADDR-0x%#PRIxVADDR]\n, indent(2), ,
 		   recurse  2 ? MAP : SUBMAP, P(vm_map),
 		   vm_map_min(D(vm_map, vm_map)),
 		   vm_map_max(D(vm_map, vm_map)));
-		printf(\t%*s#ent=%d, sz=%ld, ref=%d, version=%d, flags=0x%x\n,
+		printf(\t%*s#ent=%d, sz=%PRIdVSIZE, ref=%d, version=%d, flags=0x%x\n,
 		   indent(2), , D(vm_map, vm_map)-nentries,
 		   D(vm_map, vm_map)-size, D(vm_map, vm_map)-ref_count,
 		   D(vm_map, vm_map)-timestamp, D(vm_map, vm_map)-flags);
@@ -284,8 +284,8 @@
 		   P(vm_map_entry));
 		printf( prev = %p,, vme-prev);
 		printf( next = %p,\n, vme-next);
-		printf(%*sstart = %lx,, indent(2), , vme-start);
-		printf( end = %lx,, vme-end);
+		printf(%*sstart = %#PRIxVADDR,, indent(2), , vme-start);
+		printf( end = %#PRIxVADDR,, vme-end);
 		printf( object.uvm_obj/sub_map = %p,\n, vme-object.uvm_obj);
 		printf(%*soffset = % PRIx64 ,, indent(2), ,
 		   vme-offset);
@@ -384,7 +384,7 @@
 	name = findname(kd, vmspace, vm_map_entry, vp, vfs, uvm_obj);
 
 	if (print_map) {
-		printf(%*s0x%lx 0x%lx %c%c%c %c%c%c %s %s %d %d %d,
+		printf(%*s0x%#PRIxVADDR 0x%#PRIxVADDR %c%c%c %c%c%c %s %s %d %d %d,
 		   indent(2), ,
 		   vme-start, vme-end,
 		   (vme-protection  VM_PROT_READ) ? 'r' : '-',
@@ -410,7 +410,7 @@
 	}
 
 	if (print_maps) {
-		printf(%*s%0*lx-%0*lx %c%c%c%c %0* PRIx64  %02llx:%02llx %llu %s\n,
+		printf(%*s%0*PRIxVADDR-%0*PRIxVADDR %c%c%c%c %0* PRIx64  %02llx:%02llx %llu %s\n,
 		   indent(2), ,
 		   (int)sizeof(void *) * 2, vme-start,
 		   (int)sizeof(void *) * 2, vme-end,
@@ -427,7 +427,7 @@
 	}
 
 	if (print_ddb) {
-		printf(%*s - %p: 0x%lx-0x%lx: obj=%p/0x% PRIx64 , amap=%p/%d\n,
+		printf(%*s - %p: 0x%PRIxVADDR-0x%PRIxVADDR: obj=%p/0x% PRIx64 , amap=%p/%d\n,
 		   indent(2), ,
 		   P(vm_map_entry), vme-start, vme-end,
 		   vme-object.uvm_obj, vme-offset,
@@ -480,8 +480,8 @@
 	if (print_all) {
 		sz = (size_t)((vme-end - vme-start) / 1024);
 		printf(A(vp) ?
-		   %*s%0*lx-%0*lx %7luk %0* PRIx64  %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s [%p]\n :
-		   %*s%0*lx-%0*lx %7luk %0* PRIx64  %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s\n,
+		   %*s%0*PRIxVADDR-%0*PRIxVADDR %7luk %0* PRIx64  %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s [%p]\n :
+		   %*s%0*PRIxVADDR-%0*PRIxVADDR %7luk %0* PRIx64  %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s\n,
 		   indent(2), ,
 		   (int)sizeof(void *) * 2,
 		   vme-start,



CVS commit: src/usr.bin/pmap

2009-12-14 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Mon Dec 14 17:16:13 UTC 2009

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

Log Message:
Fix typo in previous.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/pmap/pmap.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/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.44 src/usr.bin/pmap/pmap.c:1.45
--- src/usr.bin/pmap/pmap.c:1.44	Mon Dec 14 14:29:09 2009
+++ src/usr.bin/pmap/pmap.c	Mon Dec 14 17:16:12 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.44 2009/12/14 14:29:09 uebayasi Exp $ */
+/*	$NetBSD: pmap.c,v 1.45 2009/12/14 17:16:12 uebayasi Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pmap.c,v 1.44 2009/12/14 14:29:09 uebayasi Exp $);
+__RCSID($NetBSD: pmap.c,v 1.45 2009/12/14 17:16:12 uebayasi Exp $);
 #endif
 
 #include string.h
@@ -165,7 +165,7 @@
 		   recurse  2 ? MAP : SUBMAP, P(vm_map),
 		   vm_map_min(D(vm_map, vm_map)),
 		   vm_map_max(D(vm_map, vm_map)));
-		printf(\t%*s#ent=%d, sz=%PRIdVSIZE, ref=%d, version=%d, flags=0x%x\n,
+		printf(\t%*s#ent=%d, sz=%PRIxVSIZE, ref=%d, version=%d, flags=0x%x\n,
 		   indent(2), , D(vm_map, vm_map)-nentries,
 		   D(vm_map, vm_map)-size, D(vm_map, vm_map)-ref_count,
 		   D(vm_map, vm_map)-timestamp, D(vm_map, vm_map)-flags);



CVS commit: src/usr.bin/pmap

2009-04-12 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon Apr 13 00:27:38 UTC 2009

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

Log Message:
Fix WARNS=4 issues (-Wcast-qual -Wextra -Wsign-compare)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/pmap/main.c
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/pmap/pmap.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/pmap/pmap.h

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.19 src/usr.bin/pmap/main.c:1.20
--- src/usr.bin/pmap/main.c:1.19	Tue Jun 17 15:54:45 2008
+++ src/usr.bin/pmap/main.c	Mon Apr 13 00:27:38 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.19 2008/06/17 15:54:45 christos Exp $ */
+/*	$NetBSD: main.c,v 1.20 2009/04/13 00:27:38 lukem 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.19 2008/06/17 15:54:45 christos Exp $);
+__RCSID($NetBSD: main.c,v 1.20 2009/04/13 00:27:38 lukem Exp $);
 #endif
 
 #include sys/param.h
@@ -62,45 +62,45 @@
 rlim_t maxssiz;
 
 struct nlist ksyms[] = {
-	{ _maxsmap },
+	{ _maxsmap, 0, 0, 0, 0 },
 #define NL_MAXSSIZ		0
-	{ _uvm_vnodeops },
+	{ _uvm_vnodeops, 0, 0, 0, 0 },
 #define NL_UVM_VNODEOPS		1
-	{ _uvm_deviceops },
+	{ _uvm_deviceops, 0, 0, 0, 0 },
 #define NL_UVM_DEVICEOPS	2
-	{ _aobj_pager },
+	{ _aobj_pager, 0, 0, 0, 0 },
 #define NL_AOBJ_PAGER		3
-	{ _ubc_pager },
+	{ _ubc_pager, 0, 0, 0, 0 },
 #define NL_UBC_PAGER		4
-	{ _kernel_map },
+	{ _kernel_map, 0, 0, 0, 0 },
 #define NL_KERNEL_MAP		5
-	{ _nchashtbl },
+	{ _nchashtbl, 0, 0, 0, 0 },
 #define NL_NCHASHTBL		6
-	{ _nchash },
+	{ _nchash, 0, 0, 0, 0 },
 #define NL_NCHASH		7
-	{ NULL }
+	{ NULL, 0, 0, 0, 0 }
 };
 
 struct nlist kmaps[] = {
-	{ _kmem_map },
+	{ _kmem_map, 0, 0, 0, 0 },
 #define NL_kmem_map		0
-	{ _mb_map },
+	{ _mb_map, 0, 0, 0, 0 },
 #define NL_mb_map		1
-	{ _phys_map },
+	{ _phys_map, 0, 0, 0, 0 },
 #define NL_phys_map		2
-	{ _exec_map },
+	{ _exec_map, 0, 0, 0, 0 },
 #define NL_exec_map		3
-	{ _pager_map },
+	{ _pager_map, 0, 0, 0, 0 },
 #define NL_pager_map		4
-	{ _st_map },
+	{ _st_map, 0, 0, 0, 0 },
 #define NL_st_map		5
-	{ _pt_map },
+	{ _pt_map, 0, 0, 0, 0 },
 #define NL_pt_map		6
-	{ _lkm_map },
+	{ _lkm_map, 0, 0, 0, 0 },
 #define NL_lkm_map		7
-	{ _buf_map },
+	{ _buf_map, 0, 0, 0, 0 },
 #define NL_buf_map		8
-	{ NULL }
+	{ NULL, 0, 0, 0, 0 },
 };
 
 #define VMSPACE_ADDRESS		1
@@ -110,7 +110,7 @@
 
 void check_fd(int);
 void load_symbols(kvm_t *);
-void cache_enter(int, struct namecache *);
+void cache_enter(u_long, struct namecache *);
 
 int
 main(int argc, char *argv[])
@@ -450,8 +450,7 @@
 {
 	struct namecache _ncp, *ncp, *oncp;
 	struct nchashhead _ncpp, *ncpp; 
-	u_long nchash;
-	int i;
+	u_long nchash, i;
 
 	LIST_INIT(lcache);
 
@@ -484,12 +483,12 @@
 }
 
 void
-cache_enter(int i, struct namecache *ncp)
+cache_enter(u_long i, struct namecache *ncp)
 {
 	struct cache_entry *ce;
 
 	if (debug  DUMP_NAMEI_CACHE)
-		printf([%d] ncp-nc_vp %10p, ncp-nc_dvp %10p, 
+		printf([%lu] ncp-nc_vp %10p, ncp-nc_dvp %10p, 
 		   ncp-nc_nlen %3d [%.*s]\n,
 		   i, ncp-nc_vp, ncp-nc_dvp,
 		   ncp-nc_nlen, ncp-nc_nlen, ncp-nc_name);
@@ -500,7 +499,7 @@
 	ce-ce_pvp = ncp-nc_dvp;
 	ce-ce_nlen = ncp-nc_nlen;
 	strncpy(ce-ce_name, ncp-nc_name, sizeof(ce-ce_name));
-	ce-ce_name[MIN(ce-ce_nlen, sizeof(ce-ce_name) - 1)] = '\0';
+	ce-ce_name[MIN(ce-ce_nlen, (int)(sizeof(ce-ce_name) - 1))] = '\0';
 
 	LIST_INSERT_HEAD(lcache, ce, ce_next);
 }

Index: src/usr.bin/pmap/pmap.c
diff -u src/usr.bin/pmap/pmap.c:1.42 src/usr.bin/pmap/pmap.c:1.43
--- src/usr.bin/pmap/pmap.c:1.42	Mon Dec 29 01:40:59 2008
+++ src/usr.bin/pmap/pmap.c	Mon Apr 13 00:27:38 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.42 2008/12/29 01:40:59 christos Exp $ */
+/*	$NetBSD: pmap.c,v 1.43 2009/04/13 00:27:38 lukem Exp $ */
 
 /*
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pmap.c,v 1.42 2008/12/29 01:40:59 christos Exp $);
+__RCSID($NetBSD: pmap.c,v 1.43 2009/04/13 00:27:38 lukem Exp $);
 #endif
 
 #include string.h
@@ -533,7 +533,8 @@
 	int *am_slots;
 	int *am_bckptr;
 	int *am_ppref;
-	size_t i, r, l, e;
+	size_t l;
+	int i, r, e;
 
 	if (S(amap) == (size_t)-1) {
 		heapfound = 1;
@@ -630,7 +631,7 @@
 			l--;
 		}
 
-		dump_vm_anon(kd, am_anon, (int)i);
+		dump_vm_anon(kd, am_anon, i);
 	}
 
 	free(am_anon);
@@ -720,12 +721,18 @@
  (unsigned long long)minor(dev));
 			name = buf;
 		}
-		else if (UVM_OBJ_IS_AOBJ(D(uvm_obj, uvm_object))) 
-			name =   [ uvm_aobj ];
-		else if (UVM_OBJ_IS_UBCPAGER(D(uvm_obj, uvm_object)))
-			name =   [ ubc_pager ];
-		else if (UVM_OBJ_IS_VNODE(D(uvm_obj, uvm_object)))
-			name =   [ ?VNODE? ];
+		else if (UVM_OBJ_IS_AOBJ(D(uvm_obj, uvm_object))) {
+