History log of /openbsd-current/usr.sbin/procmap/procmap.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.72 29-Mar-2024 deraadt

Stop printing the "syscall" bit related to msyscall(2), since the subsystem
is being deleted.


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.71 10-Nov-2022 deraadt

change default output to -a format; ok tb


# 1.70 07-Oct-2022 deraadt

Show the entry immutable bit in the various output formats.


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.69 22-Feb-2022 deraadt

MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert


# 1.68 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.67 29-Nov-2019 deraadt

correct order of region bits for -a case: rwxSepc


# 1.66 29-Nov-2019 deraadt

Repurpose the "syscalls must be on a writeable page" mechanism to
enforce a new policy: system calls must be in pre-registered regions.
We have discussed more strict checks than this, but none satisfy the
cost/benefit based upon our understanding of attack methods, anyways
let's see what the next iteration looks like.

This is intended to harden (translation: attackers must put extra
effort into attacking) against a mixture of W^X failures and JIT bugs
which allow syscall misinterpretation, especially in environments with
polymorphic-instruction/variable-sized instructions. It fits in a bit
with libc/libcrypto/ld.so random relink on boot and no-restart-at-crash
behaviour, particularily for remote problems. Less effective once on-host
since someone the libraries can be read.

For static-executables the kernel registers the main program's
PIE-mapped exec section valid, as well as the randomly-placed sigtramp
page. For dynamic executables ELF ld.so's exec segment is also
labelled valid; ld.so then has enough information to register libc's
exec section as valid via call-once msyscall(2)

For dynamic binaries, we continue to to permit the main program exec
segment because "go" (and potentially a few other applications) have
embedded system calls in the main program. Hopefully at least go gets
fixed soon.

We declare the concept of embedded syscalls a bad idea for numerous
reasons, as we notice the ecosystem has many of
static-syscall-in-base-binary which are dynamically linked against
libraries which in turn use libc, which contains another set of
syscall stubs. We've been concerned about adding even one additional
syscall entry point... but go's approach tends to double the entry-point
attack surface.

This was started at a nano-hackathon in Bob Beck's basement 2 weeks
ago during a long discussion with mortimer trying to hide from the SSL
scream-conversations, and finished in more comfortable circumstances
next to a wood-stove at Elk Lakes cabin with UVM scream-conversations.

ok guenther kettenis mortimer, lots of feedback from others
conversations about go with jsing tb sthen


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.65 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


# 1.71 10-Nov-2022 deraadt

change default output to -a format; ok tb


# 1.70 07-Oct-2022 deraadt

Show the entry immutable bit in the various output formats.


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.69 22-Feb-2022 deraadt

MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert


# 1.68 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.67 29-Nov-2019 deraadt

correct order of region bits for -a case: rwxSepc


# 1.66 29-Nov-2019 deraadt

Repurpose the "syscalls must be on a writeable page" mechanism to
enforce a new policy: system calls must be in pre-registered regions.
We have discussed more strict checks than this, but none satisfy the
cost/benefit based upon our understanding of attack methods, anyways
let's see what the next iteration looks like.

This is intended to harden (translation: attackers must put extra
effort into attacking) against a mixture of W^X failures and JIT bugs
which allow syscall misinterpretation, especially in environments with
polymorphic-instruction/variable-sized instructions. It fits in a bit
with libc/libcrypto/ld.so random relink on boot and no-restart-at-crash
behaviour, particularily for remote problems. Less effective once on-host
since someone the libraries can be read.

For static-executables the kernel registers the main program's
PIE-mapped exec section valid, as well as the randomly-placed sigtramp
page. For dynamic executables ELF ld.so's exec segment is also
labelled valid; ld.so then has enough information to register libc's
exec section as valid via call-once msyscall(2)

For dynamic binaries, we continue to to permit the main program exec
segment because "go" (and potentially a few other applications) have
embedded system calls in the main program. Hopefully at least go gets
fixed soon.

We declare the concept of embedded syscalls a bad idea for numerous
reasons, as we notice the ecosystem has many of
static-syscall-in-base-binary which are dynamically linked against
libraries which in turn use libc, which contains another set of
syscall stubs. We've been concerned about adding even one additional
syscall entry point... but go's approach tends to double the entry-point
attack surface.

This was started at a nano-hackathon in Bob Beck's basement 2 weeks
ago during a long discussion with mortimer trying to hide from the SSL
scream-conversations, and finished in more comfortable circumstances
next to a wood-stove at Elk Lakes cabin with UVM scream-conversations.

ok guenther kettenis mortimer, lots of feedback from others
conversations about go with jsing tb sthen


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.65 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


# 1.70 07-Oct-2022 deraadt

Show the entry immutable bit in the various output formats.


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.69 22-Feb-2022 deraadt

MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert


# 1.68 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.67 29-Nov-2019 deraadt

correct order of region bits for -a case: rwxSepc


# 1.66 29-Nov-2019 deraadt

Repurpose the "syscalls must be on a writeable page" mechanism to
enforce a new policy: system calls must be in pre-registered regions.
We have discussed more strict checks than this, but none satisfy the
cost/benefit based upon our understanding of attack methods, anyways
let's see what the next iteration looks like.

This is intended to harden (translation: attackers must put extra
effort into attacking) against a mixture of W^X failures and JIT bugs
which allow syscall misinterpretation, especially in environments with
polymorphic-instruction/variable-sized instructions. It fits in a bit
with libc/libcrypto/ld.so random relink on boot and no-restart-at-crash
behaviour, particularily for remote problems. Less effective once on-host
since someone the libraries can be read.

For static-executables the kernel registers the main program's
PIE-mapped exec section valid, as well as the randomly-placed sigtramp
page. For dynamic executables ELF ld.so's exec segment is also
labelled valid; ld.so then has enough information to register libc's
exec section as valid via call-once msyscall(2)

For dynamic binaries, we continue to to permit the main program exec
segment because "go" (and potentially a few other applications) have
embedded system calls in the main program. Hopefully at least go gets
fixed soon.

We declare the concept of embedded syscalls a bad idea for numerous
reasons, as we notice the ecosystem has many of
static-syscall-in-base-binary which are dynamically linked against
libraries which in turn use libc, which contains another set of
syscall stubs. We've been concerned about adding even one additional
syscall entry point... but go's approach tends to double the entry-point
attack surface.

This was started at a nano-hackathon in Bob Beck's basement 2 weeks
ago during a long discussion with mortimer trying to hide from the SSL
scream-conversations, and finished in more comfortable circumstances
next to a wood-stove at Elk Lakes cabin with UVM scream-conversations.

ok guenther kettenis mortimer, lots of feedback from others
conversations about go with jsing tb sthen


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.65 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


# 1.69 22-Feb-2022 deraadt

MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert


# 1.68 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.67 29-Nov-2019 deraadt

correct order of region bits for -a case: rwxSepc


# 1.66 29-Nov-2019 deraadt

Repurpose the "syscalls must be on a writeable page" mechanism to
enforce a new policy: system calls must be in pre-registered regions.
We have discussed more strict checks than this, but none satisfy the
cost/benefit based upon our understanding of attack methods, anyways
let's see what the next iteration looks like.

This is intended to harden (translation: attackers must put extra
effort into attacking) against a mixture of W^X failures and JIT bugs
which allow syscall misinterpretation, especially in environments with
polymorphic-instruction/variable-sized instructions. It fits in a bit
with libc/libcrypto/ld.so random relink on boot and no-restart-at-crash
behaviour, particularily for remote problems. Less effective once on-host
since someone the libraries can be read.

For static-executables the kernel registers the main program's
PIE-mapped exec section valid, as well as the randomly-placed sigtramp
page. For dynamic executables ELF ld.so's exec segment is also
labelled valid; ld.so then has enough information to register libc's
exec section as valid via call-once msyscall(2)

For dynamic binaries, we continue to to permit the main program exec
segment because "go" (and potentially a few other applications) have
embedded system calls in the main program. Hopefully at least go gets
fixed soon.

We declare the concept of embedded syscalls a bad idea for numerous
reasons, as we notice the ecosystem has many of
static-syscall-in-base-binary which are dynamically linked against
libraries which in turn use libc, which contains another set of
syscall stubs. We've been concerned about adding even one additional
syscall entry point... but go's approach tends to double the entry-point
attack surface.

This was started at a nano-hackathon in Bob Beck's basement 2 weeks
ago during a long discussion with mortimer trying to hide from the SSL
scream-conversations, and finished in more comfortable circumstances
next to a wood-stove at Elk Lakes cabin with UVM scream-conversations.

ok guenther kettenis mortimer, lots of feedback from others
conversations about go with jsing tb sthen


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.65 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


# 1.68 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.67 29-Nov-2019 deraadt

correct order of region bits for -a case: rwxSepc


# 1.66 29-Nov-2019 deraadt

Repurpose the "syscalls must be on a writeable page" mechanism to
enforce a new policy: system calls must be in pre-registered regions.
We have discussed more strict checks than this, but none satisfy the
cost/benefit based upon our understanding of attack methods, anyways
let's see what the next iteration looks like.

This is intended to harden (translation: attackers must put extra
effort into attacking) against a mixture of W^X failures and JIT bugs
which allow syscall misinterpretation, especially in environments with
polymorphic-instruction/variable-sized instructions. It fits in a bit
with libc/libcrypto/ld.so random relink on boot and no-restart-at-crash
behaviour, particularily for remote problems. Less effective once on-host
since someone the libraries can be read.

For static-executables the kernel registers the main program's
PIE-mapped exec section valid, as well as the randomly-placed sigtramp
page. For dynamic executables ELF ld.so's exec segment is also
labelled valid; ld.so then has enough information to register libc's
exec section as valid via call-once msyscall(2)

For dynamic binaries, we continue to to permit the main program exec
segment because "go" (and potentially a few other applications) have
embedded system calls in the main program. Hopefully at least go gets
fixed soon.

We declare the concept of embedded syscalls a bad idea for numerous
reasons, as we notice the ecosystem has many of
static-syscall-in-base-binary which are dynamically linked against
libraries which in turn use libc, which contains another set of
syscall stubs. We've been concerned about adding even one additional
syscall entry point... but go's approach tends to double the entry-point
attack surface.

This was started at a nano-hackathon in Bob Beck's basement 2 weeks
ago during a long discussion with mortimer trying to hide from the SSL
scream-conversations, and finished in more comfortable circumstances
next to a wood-stove at Elk Lakes cabin with UVM scream-conversations.

ok guenther kettenis mortimer, lots of feedback from others
conversations about go with jsing tb sthen


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.65 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


# 1.67 29-Nov-2019 deraadt

correct order of region bits for -a case: rwxSepc


# 1.66 29-Nov-2019 deraadt

Repurpose the "syscalls must be on a writeable page" mechanism to
enforce a new policy: system calls must be in pre-registered regions.
We have discussed more strict checks than this, but none satisfy the
cost/benefit based upon our understanding of attack methods, anyways
let's see what the next iteration looks like.

This is intended to harden (translation: attackers must put extra
effort into attacking) against a mixture of W^X failures and JIT bugs
which allow syscall misinterpretation, especially in environments with
polymorphic-instruction/variable-sized instructions. It fits in a bit
with libc/libcrypto/ld.so random relink on boot and no-restart-at-crash
behaviour, particularily for remote problems. Less effective once on-host
since someone the libraries can be read.

For static-executables the kernel registers the main program's
PIE-mapped exec section valid, as well as the randomly-placed sigtramp
page. For dynamic executables ELF ld.so's exec segment is also
labelled valid; ld.so then has enough information to register libc's
exec section as valid via call-once msyscall(2)

For dynamic binaries, we continue to to permit the main program exec
segment because "go" (and potentially a few other applications) have
embedded system calls in the main program. Hopefully at least go gets
fixed soon.

We declare the concept of embedded syscalls a bad idea for numerous
reasons, as we notice the ecosystem has many of
static-syscall-in-base-binary which are dynamically linked against
libraries which in turn use libc, which contains another set of
syscall stubs. We've been concerned about adding even one additional
syscall entry point... but go's approach tends to double the entry-point
attack surface.

This was started at a nano-hackathon in Bob Beck's basement 2 weeks
ago during a long discussion with mortimer trying to hide from the SSL
scream-conversations, and finished in more comfortable circumstances
next to a wood-stove at Elk Lakes cabin with UVM scream-conversations.

ok guenther kettenis mortimer, lots of feedback from others
conversations about go with jsing tb sthen


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.65 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


# 1.66 29-Nov-2019 deraadt

Repurpose the "syscalls must be on a writeable page" mechanism to
enforce a new policy: system calls must be in pre-registered regions.
We have discussed more strict checks than this, but none satisfy the
cost/benefit based upon our understanding of attack methods, anyways
let's see what the next iteration looks like.

This is intended to harden (translation: attackers must put extra
effort into attacking) against a mixture of W^X failures and JIT bugs
which allow syscall misinterpretation, especially in environments with
polymorphic-instruction/variable-sized instructions. It fits in a bit
with libc/libcrypto/ld.so random relink on boot and no-restart-at-crash
behaviour, particularily for remote problems. Less effective once on-host
since someone the libraries can be read.

For static-executables the kernel registers the main program's
PIE-mapped exec section valid, as well as the randomly-placed sigtramp
page. For dynamic executables ELF ld.so's exec segment is also
labelled valid; ld.so then has enough information to register libc's
exec section as valid via call-once msyscall(2)

For dynamic binaries, we continue to to permit the main program exec
segment because "go" (and potentially a few other applications) have
embedded system calls in the main program. Hopefully at least go gets
fixed soon.

We declare the concept of embedded syscalls a bad idea for numerous
reasons, as we notice the ecosystem has many of
static-syscall-in-base-binary which are dynamically linked against
libraries which in turn use libc, which contains another set of
syscall stubs. We've been concerned about adding even one additional
syscall entry point... but go's approach tends to double the entry-point
attack surface.

This was started at a nano-hackathon in Bob Beck's basement 2 weeks
ago during a long discussion with mortimer trying to hide from the SSL
scream-conversations, and finished in more comfortable circumstances
next to a wood-stove at Elk Lakes cabin with UVM scream-conversations.

ok guenther kettenis mortimer, lots of feedback from others
conversations about go with jsing tb sthen


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.65 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


# 1.65 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


# 1.64 31-Mar-2018 otto

Fix description of -v and implement -v for -a showing holes; ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.63 16-Sep-2016 dlg

procmap fumbles with uvm_map_addr structures, which are now in RBTs

it also does proper traversal of the tree (ie, it does FOREACH)
which in turn uses MIN and NEXT operations to iterate over the whole
tree. theyre complicated and need code.

so for now this pulls in subr_tree.c from the kernel and builds it
as part of procmap. that allows for traversal of the RBT using the
same code that the kernel uses.

it is a bit ugly though because procmap updates the pointers between
items in the tree so they point at local copies instead of kernel
addresses. its made worse because RBT code has pointers between
rb_entry structs, not between the nodes.

im putting this in now to unbreak the tree. it can be polished after
coffee/naps.


Revision tags: OPENBSD_6_0_BASE
# 1.62 26-May-2016 stefan

Re-introduce vnode-to-filename mapping

The name cache walking code got adapted to the new name cache layout.
Along with the previous commit, procmap is now able to map a vnode
to a filename as long as it is in the name cache.

"nice stuff" deraadt@


# 1.61 25-May-2016 stefan

Must extract uvm_vnode from uvm_object first before reading the vnode

Otherwise procmap interprets the uvm_vnode contents as a vnode,
yielding bogus values. This should cure the
"procmap: invalid address (ffffffffffffffff) == -1 vs. 656 @ ffffffffffffffff"
error messages that appear sporadically.

ok deraadt@


# 1.60 16-Apr-2016 stefan

Remove am_maxslot from amap.

am_maxslot represents the total number of slots an amap can be extended
to. Since we do not extend amaps, this field as well as rounding the
number of slots to the next malloc bucket is not useful.

This also removes the corresponding output from procmap(1).

ok kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.59 19-Jan-2015 kettenis

Also print the fspace member of map entries when PRINT_VM_MAP_ENTRY is
requested.

ok deraadt@


# 1.58 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.57 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.56 08-Sep-2014 guenther

Delete procfs; it's always had races and is now unused: no one noticed for
months that I broke it before the 5.5 release.

confirmed as not being required by ports by sthen@, ajacoutot@, dcoppa@


Revision tags: OPENBSD_5_6_BASE
# 1.55 08-Jul-2014 deraadt

decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.h
don't need to be married.
ok guenther miod beck jsing kettenis


# 1.54 08-Jul-2014 deraadt

There really isn't a strict "heap" anymore, so just call everything like
that an anon. Useful change since BRKSIZ will soon leave the namespace.
ok kettenis


# 1.53 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.52 13-Feb-2014 tedu

remove tendrils of namei dumping code


# 1.51 13-Feb-2014 tedu

use strtonum


# 1.50 12-Aug-2013 otto

get ready for big ino_t; ok gunther@


Revision tags: OPENBSD_5_4_BASE
# 1.49 14-May-2013 miod

Don't bother printing vm_swrss of a process, the current uvm accounting
logic never sets this value.


# 1.48 24-Apr-2013 deraadt

pretty-print bigger ino_t variables


# 1.47 21-Apr-2013 tedu

revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner


# 1.46 26-Mar-2013 tedu

for the sake of argument, let's pretend this #if 0 code isn't wanted


# 1.45 23-Mar-2013 tedu

rework the main loop so we can drop kmem privs a little later,
prepping for a coming kernel change. we need to call sysctl for
all the procs to get their vmspace pointer, then we drop, then
we go grovelling. ok deraadt


# 1.44 20-Mar-2013 tedu

revert, that restriction is already enforced the right way


# 1.43 20-Mar-2013 deraadt

Only root can look at the kernel address space.


Revision tags: OPENBSD_5_3_BASE
# 1.42 16-Jan-2013 deraadt

document a safe cast, which should be (unsigned int) instead of simply
(unsigned)


Revision tags: OPENBSD_5_2_BASE
# 1.41 09-Mar-2012 ariane

Userspace counterpart of new vmmap.

Allows memory walks to function.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.40 06-Jun-2011 ariane

Userland counterpart of the vmmap backout; cranks major version of libkvm.


# 1.39 24-May-2011 ariane

Reimplement uvm/uvm_map.

vmmap is designed to perform address space randomized allocations,
without letting fragmentation of the address space go through the roof.

Some highlights:
- kernel address space randomization
- proper implementation of guardpages
- roughly 10% system time reduction during kernel build

Tested by alot of people on tech@ and developers.
Theo's machines are still happy.


# 1.38 23-Apr-2011 tedu

BRKSIZ is the right constant now, so I don't get lots of teeny tiny heaps
mixed up in my address space.


# 1.37 10-Apr-2011 guenther

Switch back from KERN_PROC2/kinfo_proc2 to KERN_PROC/kinfo_proc now
that we've got name we want for the API we want

"ZAP!" deraadt@


# 1.36 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.35 05-Apr-2011 thib

Remove portalfs.

While it is a terribly cool idea, it's just awful and since noone has stepped
up to the plate to keep it up with the current vop state, retire it to the
attic.

ok krw@, deraadt@, guenther@, miod@.
comments from jmc@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 12-Aug-2009 miod

Update nlist array and uncomment a few things to pave the way for upcoming
new name cache information gathering code.


# 1.33 12-Aug-2009 beck

Namecache revamp.

This eliminates the large single namecache hash table, and implements
the name cache as a global lru of entires, and a redblack tree in each
vnode. It makes cache_purge actually purge the namecache entries associated
with a vnode when a vnode is recycled (very important for later on actually being
able to resize the vnode pool)

This commit does #if 0 out a bunch of procmap code that was
already broken before this change, but needs to be redone completely.

Tested by many, including in thib's nfs test setup.

ok oga@,art@,thib@,miod@


Revision tags: OPENBSD_4_6_BASE
# 1.32 04-Jun-2009 miod

No longer consider kernel pointers invalid if pointing under the kernel
load address (hello, PMAP_DIRECT architectures). Makes procmap walk the
kernel name cache correctly.
ok art@


Revision tags: OPENBSD_4_5_BASE
# 1.31 18-Sep-2008 otto

document -A and include in usage


# 1.30 18-Sep-2008 art

Add a flag to print amap usage.
otto@ ok


Revision tags: OPENBSD_4_4_BASE
# 1.29 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.28 09-Jun-2008 miod

Define a new flag, UVM_FLAG_HOLE, for uvm_map to create a vm_map_entry of
a new etype, UVM_ET_HOLE, meaning it has no backend.

UVM_ET_HOLE entries (which should be created as UVM_PROT_NONE and with
UVM_FLAG_NOMERGE and UVM_FLAG_HOLE) are skipped in uvm_unmap_remove(), so
that pmap_{k,}remove() is not called on the entry.

This is intended to save time, and behave better, on pmaps with MMU holes
at process exit time.

ok art@, kettenis@ provided feedback as well.


Revision tags: OPENBSD_4_3_BASE
# 1.27 02-Oct-2007 kettenis

Use kinfo_proc2 instead of kinfo_proc.

ok art@


# 1.26 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.25 31-May-2007 thib

Zap a bunch of unused VT_* tags.

ok tedu@,pedro@


# 1.24 26-Apr-2007 deraadt

kill some commented "struct proc *", and knf while there; ok ray


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 01-Jul-2006 miod

Don't warn for kernel_text being zero on (some) m68k systems.


Revision tags: OPENBSD_3_9_BASE
# 1.22 06-Dec-2005 pedro

Remove fdescfs


# 1.21 24-Nov-2005 pedro

Remove kernfs, okay deraadt@.


Revision tags: OPENBSD_3_8_BASE
# 1.20 26-May-2005 pedro

kill stackable filesystems ghosts


# 1.19 03-May-2005 djm

setresgid; ok deraadt@


# 1.18 25-Mar-2005 jaredy

Use the return value from getopt() instead of optopt in non-error
cases since optopt is not set in these cases, and it is not required
by POSIX that it should be.

ok millert otto


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.17 09-Jul-2004 tdeval

[From: Joris Vink]
Use strtonum(3) instead of strtol(3). ok deraadt@ & me


# 1.16 01-Apr-2004 tdeval

Off by 1 ! OK millert@, tedu@


Revision tags: OPENBSD_3_5_BASE
# 1.15 15-Mar-2004 tedu

more accurate msg, pr3713 from Andre Lucas


# 1.14 23-Feb-2004 tedu

make sure we don't backwards before buffer


# 1.13 23-Feb-2004 tedu

buffer len paranoia


# 1.12 23-Feb-2004 tedu

if the heap is non-exec, it makes it hard to find by looking for an exec
mapping. much better heuristic.


# 1.11 23-Feb-2004 tedu

unknown is less ugly than ??, and not a trigraph. requested by deraadt


# 1.10 23-Feb-2004 tedu

no peeking at kernel or other processes for normal users. ok deraadt@


# 1.9 19-Feb-2004 tedu

pedro martelletto tells me stroul returns an unsigned long which
may be bigger than a pid_t


# 1.8 18-Feb-2004 tedu

strtoul for getting pid. ok and numerous hints from deraadt@
also correct errbuf size


# 1.7 18-Feb-2004 deraadt

revoke privs asap; tedu ok


# 1.6 18-Feb-2004 deraadt

a pinch of knf


# 1.5 18-Feb-2004 tedu

little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@


# 1.4 18-Feb-2004 tedu

printing (null) is not so useful. instead print names of missing symbols
with a useful message.


# 1.3 17-Feb-2004 tedu

malloc checks, strlcpy. based on patch from Vink Joris <nimadeus@pandora.be>


# 1.2 16-Feb-2004 tedu

catch all vnode types


# 1.1 16-Feb-2004 tedu

rough cut of netbsd's pmap process memory map inspector.
initially from drahn@, renamed to procmap to avoid conflict with
unrelated pmap(9).
works more or less as advertised, could definitely use some work though.
would be really nice if somebody made it use sysctl and not kmem.
more or less ok deraadt@ drahn@