openbsd
9 years agoindent the builtin text a little, for naddy;
jmc [Mon, 12 Oct 2015 12:34:42 +0000 (12:34 +0000)]
indent the builtin text a little, for naddy;

9 years agotwo leftovers string missed in tame->pledge conversion
semarie [Mon, 12 Oct 2015 12:17:36 +0000 (12:17 +0000)]
two leftovers string missed in tame->pledge conversion

ok jsg@

9 years agoUnify link state change notification.
mpi [Mon, 12 Oct 2015 11:32:39 +0000 (11:32 +0000)]
Unify link state change notification.

ok mikeb@

9 years agodont need to do suser checks in ioctl paths cos if.c does them for us.
dlg [Mon, 12 Oct 2015 10:51:49 +0000 (10:51 +0000)]
dont need to do suser checks in ioctl paths cos if.c does them for us.

ok mikeb@ mpi@

9 years agoprotect SIOCSLIFPHYTTL, SIOCSVNETID so only root can call them, and
dlg [Mon, 12 Oct 2015 10:49:40 +0000 (10:49 +0000)]
protect SIOCSLIFPHYTTL, SIOCSVNETID so only root can call them, and
return EPNOTSUPP for SIOCGLIFPHYTTL and SIOCGVNETID. all so drivers
dont have to do these checks themselves.

ok mikeb@ mpi@

9 years agofix case of PACkAGE_REPOSITORY; remco at dpub nl
sthen [Mon, 12 Oct 2015 10:27:22 +0000 (10:27 +0000)]
fix case of PACkAGE_REPOSITORY; remco at dpub nl
               ^

9 years agoIntroduce bridge_ifinput() to handle some repeated logic before
reyk [Mon, 12 Oct 2015 10:03:25 +0000 (10:03 +0000)]
Introduce bridge_ifinput() to handle some repeated logic before
if_input() and to have a counterpart for bridge_ifenqueue() that helps
to understand the traffic/code flow in bridge better.  The bridge
currently only puts a single packet on the input mbuf list, and
changing will need to undo part of this commit, but it still makes
sense to have a well-defined call for the ports receive path.
No functional change.

OK mpi@

9 years agoAlways initialise the index into iwm's tx queue array, fixing a
stsp [Mon, 12 Oct 2015 10:01:27 +0000 (10:01 +0000)]
Always initialise the index into iwm's tx queue array, fixing a
potential crash. This must have somehow been working by magic.
Fruther cleanup of QoS support in this driver is very much needed.
ok mpi@

9 years agoRevert the pledge() call on pax/ar_io.c for now.
semarie [Mon, 12 Oct 2015 09:28:54 +0000 (09:28 +0000)]
Revert the pledge() call on pax/ar_io.c for now.

A pledged program is not allowed to change user/group for others.

"I think that makes the most sense" @sthen

9 years agodo not umask() [with the wrong umask] around mkstemp() calls, no matter
deraadt [Mon, 12 Oct 2015 07:58:19 +0000 (07:58 +0000)]
do not umask() [with the wrong umask] around mkstemp() calls, no matter
how broken other systems are.
ok guenther gilles

9 years agoCorrectly mark-up some recent additions. ok jmc@
lum [Mon, 12 Oct 2015 07:55:52 +0000 (07:55 +0000)]
Correctly mark-up some recent additions. ok jmc@

9 years agopledge "stdio" after opening files, code is very similar to mkuboot
deraadt [Mon, 12 Oct 2015 07:45:48 +0000 (07:45 +0000)]
pledge "stdio" after opening files, code is very similar to mkuboot

9 years agoMove execution of the constraints from the ntp to the parent process.
reyk [Mon, 12 Oct 2015 06:50:08 +0000 (06:50 +0000)]
Move execution of the constraints from the ntp to the parent process.
This helps the ntp process to a) give a better pledge(2) and to b)
keep the promise of "saving the world again... on time" by removing
the delays that have been introduced by expensive constraint forks.
The new design offers better privsep but introduces a few more imsgs
and runs a little bit more code in the privileged parent.  The
privileged code is minimal, carefully checked, and does not attempt to
"parse" any contents; the forked constraints instantly drop all
privileges and pledge to "stdio inet".

OK beck@ deraadt@

9 years agoGahamas -> Bahamas;
jmc [Mon, 12 Oct 2015 06:33:21 +0000 (06:33 +0000)]
Gahamas -> Bahamas;
from pgoyette (netbsd -r1.26)

9 years agopledge "stdio" after opening up the input & output files.
deraadt [Mon, 12 Oct 2015 06:24:28 +0000 (06:24 +0000)]
pledge "stdio" after opening up the input & output files.
ok jsg

9 years agounifdef EVP_CHECK_DES_KEY: Ben Kaduk noticed it has a syntax error; that
guenther [Mon, 12 Oct 2015 06:05:52 +0000 (06:05 +0000)]
unifdef EVP_CHECK_DES_KEY: Ben Kaduk noticed it has a syntax error; that
error was present in the original 2004 commit, so it hasn't been used in
over 11 years, thus exceeding our deprecation requirements by over a decade.
OpenSSL has chosen to *fix it*; we'll gladly watch it burn

ok jsing@

9 years agosame thing as biff, pledge "stdio rpath fattr tty"
deraadt [Mon, 12 Oct 2015 06:00:57 +0000 (06:00 +0000)]
same thing as biff, pledge "stdio rpath fattr tty"

9 years agobiff pledges to only do "stdio rpath fattr tty". (very small program..
deraadt [Mon, 12 Oct 2015 05:59:43 +0000 (05:59 +0000)]
biff pledges to only do "stdio rpath fattr tty".  (very small program..
the actual order of use is tty, rpath, stdio or fattr)

9 years agofstat() of opened fd, rather than stat(), to avoid TOCTOU
deraadt [Mon, 12 Oct 2015 05:54:18 +0000 (05:54 +0000)]
fstat() of opened fd, rather than stat(), to avoid TOCTOU
ok jsg

9 years agopreservation modes can adjust setugid bits, so no pledge is possible.
deraadt [Mon, 12 Oct 2015 05:05:24 +0000 (05:05 +0000)]
preservation modes can adjust setugid bits, so no pledge is possible.
Otherwise, lay the groundwork for whether a gzip program may be run or not.
After such a gzip program is started, pledge the program will not exec
again.  Took a few iterations to get this going... it is looking good.
with guenther.

9 years agodoes not need ioctl.h
deraadt [Mon, 12 Oct 2015 04:43:30 +0000 (04:43 +0000)]
does not need ioctl.h

9 years agowith the RPATH enforcement, acpidump(1) don't work anymore...
semarie [Mon, 12 Oct 2015 04:02:57 +0000 (04:02 +0000)]
with the RPATH enforcement, acpidump(1) don't work anymore...

it needs rpath for reading /dev/mem (at least):
  kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL)

ok doug@
fix the regression deraadt@

9 years agopledge to only use "stdio rpath"; rpath is for readig the wtmp files.
deraadt [Mon, 12 Oct 2015 02:02:00 +0000 (02:02 +0000)]
pledge to only use "stdio rpath"; rpath is for readig the wtmp files.
ok doug

9 years agotunefs can pledge to only use "stdio", after it has opened the device.
deraadt [Mon, 12 Oct 2015 02:01:15 +0000 (02:01 +0000)]
tunefs can pledge to only use "stdio", after it has opened the device.
ok doug

9 years agopledge "stdio" right after opening the device. The remainder is
deraadt [Mon, 12 Oct 2015 01:43:52 +0000 (01:43 +0000)]
pledge "stdio" right after opening the device.  The remainder is
is just read, write, fsync, and close.
ok doug

9 years agopledge() "stdio" includes trusting open&read of the root-owned timezone
deraadt [Mon, 12 Oct 2015 01:40:09 +0000 (01:40 +0000)]
pledge() "stdio" includes trusting open&read of the root-owned timezone
databases located at system paths (a reasonable bar had to be chosen; in
the future we can replace the interfaces, since this effort is identifying
them and placing their paths in a visble place), so this program only
needs "stdio"
ok doug

9 years agomake description of ERRORS more complete;
schwarze [Mon, 12 Oct 2015 01:17:08 +0000 (01:17 +0000)]
make description of ERRORS more complete;
diff from Benny Lofgren <bl dash lists at lofgren dot biz>;
ok nicm@

9 years agoremove useless quoting from .Fo arguments; forgotten diff found in my tree
schwarze [Mon, 12 Oct 2015 00:49:34 +0000 (00:49 +0000)]
remove useless quoting from .Fo arguments; forgotten diff found in my tree

9 years agoClear dform and dsec when exiting a first-level directory in treescan().
schwarze [Mon, 12 Oct 2015 00:32:37 +0000 (00:32 +0000)]
Clear dform and dsec when exiting a first-level directory in treescan().
Fixes a segfault reported by bentley@.
While here, do some style cleanup in the same function.

9 years agoFix an obvious bug found during the /* FALLTHROUGH */ cleanup:
schwarze [Mon, 12 Oct 2015 00:14:41 +0000 (00:14 +0000)]
Fix an obvious bug found during the /* FALLTHROUGH */ cleanup:
ASCII_NBRSP has to be rendered as "&nbsp;", not "-".

9 years agoTo make the code more readable, delete 283 /* FALLTHROUGH */ comments
schwarze [Mon, 12 Oct 2015 00:07:27 +0000 (00:07 +0000)]
To make the code more readable, delete 283 /* FALLTHROUGH */ comments
that were right between two adjacent case statement.  Keep only
those 24 where the first case actually executes some code before
falling through to the next case.

9 years agoPass unsigned char to isdigit(3).
bluhm [Sun, 11 Oct 2015 23:51:26 +0000 (23:51 +0000)]
Pass unsigned char to isdigit(3).
From Michael McConville; OK guenther@

9 years agofix regression: ttyname() failure not handled right
deraadt [Sun, 11 Oct 2015 23:29:56 +0000 (23:29 +0000)]
fix regression: ttyname() failure not handled right

9 years agopledge_ioctl_check() will do the killing if neccessary; if it returns,
deraadt [Sun, 11 Oct 2015 23:13:02 +0000 (23:13 +0000)]
pledge_ioctl_check() will do the killing if neccessary; if it returns,
that is an errno to pass up to the calling system call instead. test
case is "who < /dev/null", via ttyname().

9 years agonow that tsort has a clean structure, do more specific pledge() calls.
espie [Sun, 11 Oct 2015 23:01:32 +0000 (23:01 +0000)]
now that tsort has a clean structure, do more specific pledge() calls.
okay deraadt@

9 years agoDrop tags containing a blank character:
schwarze [Sun, 11 Oct 2015 21:59:48 +0000 (21:59 +0000)]
Drop tags containing a blank character:
They don't work, they break other tags in weird ways, and even
if they could be made to work, they would be mostly useless.
Issue reported by naddy@, thanks.

9 years agoDo not insert whitespace into syntax displays, it's just confusing,
schwarze [Sun, 11 Oct 2015 21:30:02 +0000 (21:30 +0000)]
Do not insert whitespace into syntax displays, it's just confusing,
except at the one place where it is indeed helpful.
Add some missing .Cm macros.
Remove some useless escaping, one needless .Xo, and an empty .No.
Triggered by a much smaller patch from guenther@.
OK jmc@ guenther@

9 years agoFix empty .No macros, use .Pf to prefix delimiters to macros.
schwarze [Sun, 11 Oct 2015 21:23:24 +0000 (21:23 +0000)]
Fix empty .No macros, use .Pf to prefix delimiters to macros.
Based on a patch from guenther@, tweaked by me.
OK jmc@ guenther@

9 years ago-version options on commands like this make no sense; the version number
deraadt [Sun, 11 Oct 2015 21:23:15 +0000 (21:23 +0000)]
-version options on commands like this make no sense; the version number
makes no promises about compatibility nor the lack of compatibility.
suggestion & diff from micheal reed

9 years agoFinally use __progname, err(3) and warn(3).
schwarze [Sun, 11 Oct 2015 21:06:59 +0000 (21:06 +0000)]
Finally use __progname, err(3) and warn(3).
That's more readable and less error-prone than fumbling around
with argv[0], fprintf(3), strerror(3), perror(3), and exit(3).
It also shortens the code by 50 lines.

It's a bad idea to boycott good interfaces merely because standards
committees ignore them.  Instead, it's the job of the portable
distribution to provide compatibility modules for archaic systems
(like commercial Solaris) that still don't have them.  Actually,
the compat code for the portable distribution already exists and
will be committed right after this.

9 years agoUserspace doesn't need to use SUN_LEN(): connect() and bind() must accept
guenther [Sun, 11 Oct 2015 20:23:49 +0000 (20:23 +0000)]
Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing.
Also convert some strncpy() to strlcpy()

ok deraadt@

9 years agoDon't return errno from main()
guenther [Sun, 11 Oct 2015 20:17:49 +0000 (20:17 +0000)]
Don't return errno from main()

ok beck@ doug@ deraadt@ tedu@

9 years agoHandle the blackhole well-known community in bgpctl as well (print it
sthen [Sun, 11 Oct 2015 19:53:57 +0000 (19:53 +0000)]
Handle the blackhole well-known community in bgpctl as well (print it
symbolically, and don't deny its use in 'bgpctl sh rib comm 65535:6666').
ok phessler@

9 years agostandardize a community that has been independently created by nearly
phessler [Sun, 11 Oct 2015 19:30:12 +0000 (19:30 +0000)]
standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@

9 years agosome peers are following an expired draft RFC and are sending "unknown"
phessler [Sun, 11 Oct 2015 19:25:06 +0000 (19:25 +0000)]
some peers are following an expired draft RFC and are sending "unknown"
error codes to OPEN messages.  make them "known", and show them.

OK benno@, claudio@, sthen@

9 years agoadd "best" as an alias for "selected"
phessler [Sun, 11 Oct 2015 19:21:44 +0000 (19:21 +0000)]
add "best" as an alias for "selected"
Helps finger memory for people used to Junipers

OK benno@, claudio@

9 years agoPledge that ncheck_ffs only uses "stdio" after opening the device.
doug [Sun, 11 Oct 2015 19:00:40 +0000 (19:00 +0000)]
Pledge that ncheck_ffs only uses "stdio" after opening the device.

ok deraadt@

9 years agoMention that the first argument of .Pf does not need escaping.
schwarze [Sun, 11 Oct 2015 18:56:08 +0000 (18:56 +0000)]
Mention that the first argument of .Pf does not need escaping.
While here, make the first sentence regarding .Pf more concise.
OK jmc@

9 years agowith the RPATH enforcement, csplit(1) don't work anymore on stdin...
semarie [Sun, 11 Oct 2015 17:43:03 +0000 (17:43 +0000)]
with the RPATH enforcement, csplit(1) don't work anymore on stdin...

the newfile() function used for create files open files in "w+"
(O_RDWR), and may occasionally do reading on the file (function
toomuch()).

ok deraadt@

9 years agoreorg code to have an array with all the files used apparent.
espie [Sun, 11 Oct 2015 17:39:50 +0000 (17:39 +0000)]
reorg code to have an array with all the files used apparent.
okay millert@

9 years agoadd a missed check for PLEDGE_RPATH when reading a file.
semarie [Sun, 11 Oct 2015 16:19:48 +0000 (16:19 +0000)]
add a missed check for PLEDGE_RPATH when reading a file.

ok deraadt@

9 years agosigaltstack is directly used by setjmp on some architectures. it only
deraadt [Sun, 11 Oct 2015 16:01:06 +0000 (16:01 +0000)]
sigaltstack is directly used by setjmp on some architectures. it only
refers to the process itself.  pledge should allow it.

9 years agoput TIOCSWINSZ in the right block "tty", not in "ioctl". this happened
deraadt [Sun, 11 Oct 2015 15:40:48 +0000 (15:40 +0000)]
put TIOCSWINSZ in the right block "tty", not in "ioctl".  this happened
because the "route' tests were placed between the two, creating
confusion.  fix that while here.

9 years agoneeds at least some include love; choosing <stdlib.h>
deraadt [Sun, 11 Oct 2015 15:36:58 +0000 (15:36 +0000)]
needs at least some include love; choosing <stdlib.h>

9 years agopledge "stdio tty" works once the kernel allows TIOCGWINSZ. Do the pledge
deraadt [Sun, 11 Oct 2015 15:27:19 +0000 (15:27 +0000)]
pledge "stdio tty" works once the kernel allows TIOCGWINSZ.  Do the pledge
after TIOCGETD, which the kernel is unlikely to support (does not feel like
a good idea for a program to switch line disc, and therefor not worth allowing
the program to ask either)

9 years agoIn pledge "tty", allow TIOCSWINSZ. stty(1) is the obvious silly use.
deraadt [Sun, 11 Oct 2015 15:25:39 +0000 (15:25 +0000)]
In pledge "tty", allow TIOCSWINSZ.  stty(1) is the obvious silly use.
The more important use will be tmux(1) and other active window size
controlling programs. There seems little risk in exposing this small
tty setting alongside the tcsetattr() family.
ok millert

9 years agoConvert some fgetln to getline.
sunil [Sun, 11 Oct 2015 12:50:00 +0000 (12:50 +0000)]
Convert some fgetln to getline.

Ok gilles@, giovanni@, millert@

9 years agoConvert some fgetln to getline.
sunil [Sun, 11 Oct 2015 12:09:06 +0000 (12:09 +0000)]
Convert some fgetln to getline.

Suggestion and ok millert@, ok gilles@, eric@

9 years agohandle comma separated list of arguments, i.e. pkg-config --exists gcr-3,gcr-base-3
jasper [Sun, 11 Oct 2015 11:48:46 +0000 (11:48 +0000)]
handle comma separated list of arguments, i.e. pkg-config --exists gcr-3,gcr-base-3

9 years agoadd variation on existing --exists tests; separated by spaces
jasper [Sun, 11 Oct 2015 11:47:21 +0000 (11:47 +0000)]
add variation on existing --exists tests; separated by spaces

9 years agoAdd a symbolic name for the special '-1' value of iwm's sc_wantresp.
stsp [Sun, 11 Oct 2015 10:22:28 +0000 (10:22 +0000)]
Add a symbolic name for the special '-1' value of iwm's sc_wantresp.
ok phessler

9 years agoDocument that execve(2) resets SIGCHLD to SIG_DFL
guenther [Sun, 11 Oct 2015 09:51:26 +0000 (09:51 +0000)]
Document that execve(2) resets SIGCHLD to SIG_DFL

wordsmithing and ok jmc@

9 years agoPrefer .Fa over .Em for struct members
guenther [Sun, 11 Oct 2015 07:53:49 +0000 (07:53 +0000)]
Prefer .Fa over .Em for struct members

ok jmc@

9 years agoSimplify and lock down priv_open():
guenther [Sun, 11 Oct 2015 07:32:06 +0000 (07:32 +0000)]
Simplify and lock down priv_open():
 * kill the 'mode' argument
 * fail if passed any flags other than O_ACCMODE OR O_NONBLOCK
 * paranoia: mask O_CREAT when calling open() with only two arguments
 * instead of using ioctl(FIONBIO) after the fact, pass O_NONBLOCK to
   priv_open()

"good start" deraadt@
ok yasuoka@

9 years agoDocument that bind(2) and connect(2) ignore the incoming sa_len
guenther [Sun, 11 Oct 2015 07:25:11 +0000 (07:25 +0000)]
Document that bind(2) and connect(2) ignore the incoming sa_len

suggest by and ok deraadt@
wordsmithing jmc@

9 years agoYYSTYPE.number is int64_t, so format with <inttypes.h>'s PRId64
guenther [Sun, 11 Oct 2015 07:16:01 +0000 (07:16 +0000)]
YYSTYPE.number is int64_t, so format with <inttypes.h>'s PRId64

ok yasuoka@

9 years agoAfter the filesystem is opened, pledge "stdio"
deraadt [Sun, 11 Oct 2015 04:37:23 +0000 (04:37 +0000)]
After the filesystem is opened, pledge "stdio"
ok doug

9 years agoIf only displaying the disklabel (the normal thing to do against potentially
deraadt [Sun, 11 Oct 2015 04:36:22 +0000 (04:36 +0000)]
If only displaying the disklabel (the normal thing to do against potentially
unknown disks...), after opening & reading the disklabel, pledge "stdio"
ok doug

9 years agoAfter the disk is opened, this can pledge "stdio".
deraadt [Sun, 11 Oct 2015 04:33:17 +0000 (04:33 +0000)]
After the disk is opened, this can pledge "stdio".
ok doug

9 years agoThe <ctype.h> is*() interfaces expect EOF or an unsigned char; cast to
guenther [Sun, 11 Oct 2015 03:23:28 +0000 (03:23 +0000)]
The <ctype.h> is*() interfaces expect EOF or an unsigned char; cast to
(unsigned char) as required

found by Michael McConville (mmcconv1 (at) sccs.swarthmore.edu) w/Coccinelle

9 years agoDon't allow "rm -rf /"
daniel [Sun, 11 Oct 2015 03:08:46 +0000 (03:08 +0000)]
Don't allow "rm -rf /"

Patch from Theo Buehler who was inspired by watching Bryan Cantrill
in BSD Now 103.

Minor tweak from me to turn the complained variables into flags instead
of counters.

"i think it's ok" tedu@
"this isn't 1980 anymore" deraadt@
ok millert@

9 years agofix a regression spotted by chris@. the -f and -I arguments fetch process
deraadt [Sun, 11 Oct 2015 03:08:20 +0000 (03:08 +0000)]
fix a regression spotted by chris@.  the -f and -I arguments fetch process
arguments using kvm_getargs, after the pledge() has been made.  someone
brave should refactor this, hoisting the argument fetching to between
kvm_getprocs() and pledge() - storing the argument data as neccessary.
the current situation is also a race -- it fetches the data twice.

9 years ago__get_tcb() is needed for errno access in threaded programs on some archs.
guenther [Sun, 11 Oct 2015 01:56:56 +0000 (01:56 +0000)]
__get_tcb() is needed for errno access in threaded programs on some archs.
Make it always available.

ok deraadt@

9 years agoAlways set the timeout at least one tick in the future for EVFILT_TIMER
guenther [Sun, 11 Oct 2015 01:53:39 +0000 (01:53 +0000)]
Always set the timeout at least one tick in the future for EVFILT_TIMER
to avoid looping in softclock()

based on diff by sthen@
ok sthen@

9 years agoUserspace doesn't need to use SUN_LEN(): connect() and bind() must accept
guenther [Sun, 11 Oct 2015 00:26:23 +0000 (00:26 +0000)]
Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@

9 years agoPrefer dprintf() over snprintf()+write()
guenther [Sun, 11 Oct 2015 00:20:29 +0000 (00:20 +0000)]
Prefer dprintf() over snprintf()+write()

ok beck@ deraadt@

9 years agoUse correct terminology
guenther [Sun, 11 Oct 2015 00:13:39 +0000 (00:13 +0000)]
Use correct terminology

9 years agoDocument support for CPU power states
guenther [Sun, 11 Oct 2015 00:12:38 +0000 (00:12 +0000)]
Document support for CPU power states

9 years agoConvert FIONBIO to SOCK_NONBLOCK
guenther [Sat, 10 Oct 2015 23:06:32 +0000 (23:06 +0000)]
Convert FIONBIO to SOCK_NONBLOCK

ok dlg@

9 years agoPledge that ln only needs "stdio rpath cpath".
doug [Sat, 10 Oct 2015 22:36:46 +0000 (22:36 +0000)]
Pledge that ln only needs "stdio rpath cpath".

ok deraadt@

9 years agopflogd contained the same "privsep error" as tcpdump -- assuming that
deraadt [Sat, 10 Oct 2015 22:36:06 +0000 (22:36 +0000)]
pflogd contained the same "privsep error" as tcpdump -- assuming that
it can ioctl()'s against a bpf device node.  Privsep that operation
via a message to the parent process.  Unfortunately "rpath wpath cpath"
is still needed due to SIGHUP handling, but I have asked canacar the
expert to look into this.

9 years agoPledge that arithmetic only takes "stdio".
doug [Sat, 10 Oct 2015 22:32:55 +0000 (22:32 +0000)]
Pledge that arithmetic only takes "stdio".

9 years agoInitial support for pledges in openssl(1) commands.
doug [Sat, 10 Oct 2015 22:28:51 +0000 (22:28 +0000)]
Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using.  However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions.  Most
commands only need "stdio rpath wpath cpath".  The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.

9 years agopledge "stdio rpath wpath cpath fattr inet" after chroot and such
deraadt [Sat, 10 Oct 2015 22:21:39 +0000 (22:21 +0000)]
pledge "stdio rpath wpath cpath fattr inet" after chroot and such
appears to be good enough for the main loop processing.

9 years agopledge "stdio route"; untested. this has the if_nametoindex() problem as
deraadt [Sat, 10 Oct 2015 22:11:37 +0000 (22:11 +0000)]
pledge "stdio route"; untested.  this has the if_nametoindex() problem as
other *ctl programs using their daemon's log.c, and thus requires "route"
for now.  we hope to solve that issue soon.

9 years agoAdd a define for the invalid state, from mksh via Michael McConville.
nicm [Sat, 10 Oct 2015 22:09:23 +0000 (22:09 +0000)]
Add a define for the invalid state, from mksh via Michael McConville.

ok millert

9 years agoanother pledge argument reorder for sake of re-audit
deraadt [Sat, 10 Oct 2015 22:06:41 +0000 (22:06 +0000)]
another pledge argument reorder for sake of re-audit

9 years agoFix YP user and group support in getent(1).
doug [Sat, 10 Oct 2015 21:50:05 +0000 (21:50 +0000)]
Fix YP user and group support in getent(1).

These should have been "stdio getpw" before, but they worked for non-YP
environments.  With YP, it won't work without "getpw".

Reported by semarie@ and confirmed as a problem by miod@.

ok deraadt@

9 years agopledge "stdio rpath wpath cpath"
deraadt [Sat, 10 Oct 2015 21:29:59 +0000 (21:29 +0000)]
pledge "stdio rpath wpath cpath"
ok doug

9 years agoenv(1) is obviously a program falling into pledge "stdio exec". It
deraadt [Sat, 10 Oct 2015 21:19:14 +0000 (21:19 +0000)]
env(1) is obviously a program falling into pledge "stdio exec".  It
does stdio, and it does a raw execve().  It is so obvious.  It gets
only _exit(2), kbind(2), and 46 system calls -- over half of which
are deeply gutted in their functionality to only serve narrow libc
needs for "stdio (includes malloc)".  the other 161 system calls kill it.

9 years agoKill pledges to only use "stdio proc".
doug [Sat, 10 Oct 2015 21:15:25 +0000 (21:15 +0000)]
Kill pledges to only use "stdio proc".

deraadt@ notes that kill now works because of improved kernel semantics.
For full kill(1) functionality, you need the new kern_sig functionality.
Make sure you have an updated kernel.

ok deraadt@

9 years agopledge "stdio inet rpath" seems to be enough for a YP environment.
deraadt [Sat, 10 Oct 2015 21:08:09 +0000 (21:08 +0000)]
pledge "stdio inet rpath" seems to be enough for a YP environment.
rpath is to access /etc/rpc, and inet to talk to portmap & local world.
ok beck

9 years agopledge "stdio rpath wpath cpath proc exec"; this spawns cpp.
deraadt [Sat, 10 Oct 2015 20:57:00 +0000 (20:57 +0000)]
pledge "stdio rpath wpath cpath proc exec"; this spawns cpp.
ok doug

9 years agoAdded missing curly bracket into LIST_EMPTY example.
tobias [Sat, 10 Oct 2015 20:36:20 +0000 (20:36 +0000)]
Added missing curly bracket into LIST_EMPTY example.

ok deraadt@, otto@

9 years agonormalize a few more tame request orderings, to help review
deraadt [Sat, 10 Oct 2015 20:35:00 +0000 (20:35 +0000)]
normalize a few more tame request orderings, to help review

9 years agonormalize the ordering of tame requests (particularily, "rpath wpath cpath",
deraadt [Sat, 10 Oct 2015 20:18:30 +0000 (20:18 +0000)]
normalize the ordering of tame requests (particularily, "rpath wpath cpath",
which i have put in that order). this is not important, but helps look
for outliers which might be strange.  it hints that "ioctl" should be
reassessed in a few places, to see if "tty" is better; that "unix" may
be used in some places where "route" could now work.

9 years agopledge "dns rw" is not a reliable pattern. This means malloc() and other
deraadt [Sat, 10 Oct 2015 20:10:14 +0000 (20:10 +0000)]
pledge "dns rw" is not a reliable pattern.  This means malloc() and other
types of functions (perhaps required by 'stdio' or 'libevent' will not
become available unless DNS suceeds.  Replace it with "stdio dns".

9 years agoAdd pledge support in awk and make awk -safe actually safe.
doug [Sat, 10 Oct 2015 20:04:28 +0000 (20:04 +0000)]
Add pledge support in awk and make awk -safe actually safe.

awk -safe was introduced back in 1997 to stop awk from doing file output,
execute commands or access the environment.  The lexer rejected programs
when it saw awk commands that would write, exec or env.  Beyond that,
it wasn't safe from write/exec/env during program execution.

With pledge "stdio rpath", the kernel is now enforcing the awk -safe
mode restrictions at runtime (other than env).

Based on a diff by deraadt@

ok deraadt@ beck@

9 years agoRather than invoking fork/execve of dc(1) on a pipe, compile in the dc(1)
deraadt [Sat, 10 Oct 2015 19:28:54 +0000 (19:28 +0000)]
Rather than invoking fork/execve of dc(1) on a pipe, compile in the dc(1)
code directly and use it as a subfunction.  This refactoring allows use of
pledge "stdio rpath proc tty" in the main bc(1) process before fork, pledge
"stdio rpath tty" after fork, and fully reduced to "stdio" in the dc(1)
child.

This requires two recent to the kernel code (allowing sigsuspend(),
and kill() self as pid 0).
ok otto

9 years agosince kdump may getprotobynumber() late, do not drop "rpath". We could
deraadt [Sat, 10 Oct 2015 19:19:46 +0000 (19:19 +0000)]
since kdump may getprotobynumber() late, do not drop "rpath".  We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need?  At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch