From feae6f7556348ff718cc01407f9dbd9f3d29143a Mon Sep 17 00:00:00 2001 From: semarie Date: Mon, 26 Oct 2015 18:52:19 +0000 Subject: [PATCH] update regress suite for pledge --- regress/sys/kern/pledge/generic/Makefile | 4 +- regress/sys/kern/pledge/generic/main.c | 78 ++++---------------- regress/sys/kern/pledge/generic/test_stdio.c | 58 +++++++++++++++ regress/sys/kern/pledge/generic/test_tty.c | 6 +- regress/sys/kern/pledge/generic/tests.out | 33 +++------ 5 files changed, 88 insertions(+), 91 deletions(-) create mode 100644 regress/sys/kern/pledge/generic/test_stdio.c diff --git a/regress/sys/kern/pledge/generic/Makefile b/regress/sys/kern/pledge/generic/Makefile index 2c764df0fb1..0b373b2c5ef 100644 --- a/regress/sys/kern/pledge/generic/Makefile +++ b/regress/sys/kern/pledge/generic/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.3 2015/10/09 11:38:39 semarie Exp $ +# $OpenBSD: Makefile,v 1.4 2015/10/26 18:52:19 semarie Exp $ PROG= generic -SRCS+= main.c manager.c test_tty.c +SRCS+= main.c manager.c test_stdio.c test_tty.c NOMAN= yes CFLAGS+= -Wall -Werror diff --git a/regress/sys/kern/pledge/generic/main.c b/regress/sys/kern/pledge/generic/main.c index 906fc997fc1..04437f23b11 100644 --- a/regress/sys/kern/pledge/generic/main.c +++ b/regress/sys/kern/pledge/generic/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.5 2015/10/18 13:01:40 semarie Exp $ */ +/* $OpenBSD: main.c,v 1.6 2015/10/26 18:52:19 semarie Exp $ */ /* * Copyright (c) 2015 Sebastien Marie * @@ -37,6 +37,7 @@ #include "manager.h" +void test_request_stdio(void); void test_request_tty(void); static void @@ -60,39 +61,6 @@ test_kill() kill(0, SIGINT); } -static void -test_allowed_syscalls() -{ - clock_getres(CLOCK_MONOTONIC, NULL); - clock_gettime(CLOCK_MONOTONIC, NULL); - /* fchdir(); */ - getdtablecount(); - getegid(); - geteuid(); - getgid(); - getgroups(0, NULL); - getitimer(ITIMER_REAL, NULL); - getlogin(); - getpgid(0); - getpgrp(); - getpid(); - getppid(); - /* getresgid(); */ - /* getresuid(); */ - { struct rlimit rl; getrlimit(RLIMIT_CORE, &rl); } - getsid(0); - getthrid(); - { struct timeval tp; gettimeofday(&tp, NULL); } - getuid(); - geteuid(); - issetugid(); - /* nanosleep(); */ - /* sigreturn(); */ - umask(0000); - /* wait4(); */ -} - - static void open_close(const char *filename) { @@ -263,37 +231,20 @@ main(int argc, char *argv[]) /* test coredump */ start_test(&ret, "abort", NULL, test_inet); - /* inet under inet is ok */ + /* inet under inet is ok (stdio is needed of close(2)) */ + start_test(&ret, "stdio", NULL, test_inet); start_test(&ret, "inet", NULL, test_inet); + start_test(&ret, "stdio inet", NULL, test_inet); - /* kill under fattr is forbidden (don't have PLEDGE_SELF) */ + /* kill under fattr is forbidden */ start_test(&ret, "fattr", NULL, test_kill); /* kill under proc is allowed */ start_test(&ret, "proc", NULL, test_kill); - /* tests PLEDGE_SELF for permitted syscalls */ - start_test(&ret, "malloc", NULL, test_allowed_syscalls); - start_test(&ret, "rw", NULL, test_allowed_syscalls); - start_test(&ret, "stdio", NULL, test_allowed_syscalls); - start_test(&ret, "rpath", NULL, test_allowed_syscalls); - start_test(&ret, "wpath", NULL, test_allowed_syscalls); - start_test(&ret, "tmppath", NULL, test_allowed_syscalls); - start_test(&ret, "inet", NULL, test_allowed_syscalls); - start_test(&ret, "unix", NULL, test_allowed_syscalls); - start_test(&ret, "dns", NULL, test_allowed_syscalls); - start_test(&ret, "getpw", NULL, test_allowed_syscalls); - - /* tests req without PLEDGE_SELF for "permitted syscalls" */ - // XXX it is a documentation bug - start_test(&ret, "ioctl", NULL, test_allowed_syscalls); - start_test(&ret, "proc", NULL, test_allowed_syscalls); - start_test(&ret, "cpath", NULL, test_allowed_syscalls); - start_test(&ret, "abort", NULL, test_allowed_syscalls); - start_test(&ret, "fattr", NULL, test_allowed_syscalls); - - start_test(&ret, "rpath", NULL, test_rpath); - start_test(&ret, "wpath", NULL, test_wpath); + /* stdio for open(2) */ + start_test(&ret, "stdio rpath", NULL, test_rpath); + start_test(&ret, "stdio wpath", NULL, test_wpath); start_test(&ret, "rpath cpath", NULL, test_cpath); /* @@ -316,8 +267,6 @@ main(int argc, char *argv[]) */ /* same request */ start_test(&ret, "stdio rpath", NULL, test_pledge); - /* same request (stdio = malloc rw) */ - start_test(&ret, "malloc rw rpath", NULL, test_pledge); /* reduce request */ start_test(&ret, "stdio rpath wpath", NULL, test_pledge); /* reduce request (with same/other wpaths) */ @@ -326,14 +275,17 @@ main(int argc, char *argv[]) /* add request */ start_test(&ret, "stdio", NULL, test_pledge); /* change request */ - start_test(&ret, "unix", NULL, test_pledge); + start_test(&ret, "stdio unix", NULL, test_pledge); /* test stat(2) */ start_test1(&ret, "stdio rpath", "/usr/share/man", test_stat); /* mmap */ - start_test1(&ret, "rpath malloc prot_exec", "/dev/zero", test_mmap); - start_test1(&ret, "rpath malloc", "/dev/zero", test_mmap); + start_test1(&ret, "stdio rpath prot_exec", "/dev/zero", test_mmap); + start_test1(&ret, "stdio rpath", "/dev/zero", test_mmap); + + /* stdio */ + start_test(&ret, NULL, NULL, test_request_stdio); /* tty */ start_test(&ret, NULL, NULL, test_request_tty); diff --git a/regress/sys/kern/pledge/generic/test_stdio.c b/regress/sys/kern/pledge/generic/test_stdio.c new file mode 100644 index 00000000000..ec6546226be --- /dev/null +++ b/regress/sys/kern/pledge/generic/test_stdio.c @@ -0,0 +1,58 @@ +/* $OpenBSD: test_stdio.c,v 1.1 2015/10/26 18:52:19 semarie Exp $ */ +/* + * Copyright (c) 2015 Sebastien Marie + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include +#include + +void +test_request_stdio() +{ + if (pledge("stdio", NULL) == -1) + _exit(errno); + + clock_getres(CLOCK_MONOTONIC, NULL); + clock_gettime(CLOCK_MONOTONIC, NULL); + /* fchdir(); */ + getdtablecount(); + getegid(); + geteuid(); + getgid(); + getgroups(0, NULL); + getitimer(ITIMER_REAL, NULL); + getlogin(); + getpgid(0); + getpgrp(); + getpid(); + getppid(); + /* getresgid(); */ + /* getresuid(); */ + { struct rlimit rl; getrlimit(RLIMIT_CORE, &rl); } + getsid(0); + getthrid(); + { struct timeval tp; gettimeofday(&tp, NULL); } + getuid(); + geteuid(); + issetugid(); + /* nanosleep(); */ + /* sigreturn(); */ + umask(0000); + /* wait4(); */ +} diff --git a/regress/sys/kern/pledge/generic/test_tty.c b/regress/sys/kern/pledge/generic/test_tty.c index 320d6ba34fb..faabc7961fd 100644 --- a/regress/sys/kern/pledge/generic/test_tty.c +++ b/regress/sys/kern/pledge/generic/test_tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_tty.c,v 1.2 2015/10/09 11:42:54 semarie Exp $ */ +/* $OpenBSD: test_tty.c,v 1.3 2015/10/26 18:52:19 semarie Exp $ */ /* * Copyright (c) 2015 Sebastien Marie * @@ -35,8 +35,8 @@ test_request_tty() /* TODO: get a tty */ - /* tests that need tty+proc (malloc for self) */ - if (pledge("tty proc malloc", NULL) == -1) + /* tests that need tty+proc (stdio for pledge(2) */ + if (pledge("stdio tty proc", NULL) == -1) _exit(errno); /* TIOCSPGRP (tty+proc) */ diff --git a/regress/sys/kern/pledge/generic/tests.out b/regress/sys/kern/pledge/generic/tests.out index 9fe7dec45b8..1dff6955690 100644 --- a/regress/sys/kern/pledge/generic/tests.out +++ b/regress/sys/kern/pledge/generic/tests.out @@ -1,27 +1,14 @@ -# $OpenBSD: tests.out,v 1.7 2015/10/20 06:44:51 semarie Exp $ +# $OpenBSD: tests.out,v 1.8 2015/10/26 18:52:19 semarie Exp $ test(test_nop): pledge=("",NULL) status=0 exit=0 test(test_inet): pledge=("",NULL) status=9 signal=9 pledged_syscall=97 test(test_inet): pledge=("abort",NULL) status=134 signal=6 coredump=present pledged_syscall=97 -test(test_inet): pledge=("inet",NULL) status=0 exit=0 +test(test_inet): pledge=("stdio",NULL) status=9 signal=9 pledged_syscall=97 +test(test_inet): pledge=("inet",NULL) status=9 signal=9 pledged_syscall=6 +test(test_inet): pledge=("stdio inet",NULL) status=0 exit=0 test(test_kill): pledge=("fattr",NULL) status=9 signal=9 pledged_syscall=37 test(test_kill): pledge=("proc",NULL) status=2 signal=2 pledged_syscall=not_found -test(test_allowed_syscalls): pledge=("malloc",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("rw",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("stdio",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("rpath",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("wpath",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("tmppath",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("inet",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("unix",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("dns",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("getpw",NULL) status=0 exit=0 -test(test_allowed_syscalls): pledge=("ioctl",NULL) status=9 signal=9 pledged_syscall=89 -test(test_allowed_syscalls): pledge=("proc",NULL) status=9 signal=9 pledged_syscall=89 -test(test_allowed_syscalls): pledge=("cpath",NULL) status=9 signal=9 pledged_syscall=89 -test(test_allowed_syscalls): pledge=("abort",NULL) status=134 signal=6 coredump=present pledged_syscall=89 -test(test_allowed_syscalls): pledge=("fattr",NULL) status=9 signal=9 pledged_syscall=89 -test(test_rpath): pledge=("rpath",NULL) status=0 exit=0 -test(test_wpath): pledge=("wpath",NULL) status=0 exit=0 +test(test_rpath): pledge=("stdio rpath",NULL) status=0 exit=0 +test(test_wpath): pledge=("stdio wpath",NULL) status=0 exit=0 test(test_cpath): pledge=("rpath cpath",NULL) status=0 exit=0 test(test_wpaths): pledge=("stdio rpath",NULL) open_close("/etc/passwd") fd=3 errno=0 @@ -84,12 +71,11 @@ test(test_wpaths): pledge=("stdio rpath",{".",NULL}) open_close("/nonexistent") fd=-1 errno=2 status=0 exit=0 test(test_pledge): pledge=("stdio rpath",NULL) status=0 exit=0 -test(test_pledge): pledge=("malloc rw rpath",NULL) status=0 exit=0 test(test_pledge): pledge=("stdio rpath wpath",NULL) status=0 exit=0 test(test_pledge): pledge=("stdio rpath wpath",{"/sbin",NULL}) status=256 exit=1 (errno: "Operation not permitted") test(test_pledge): pledge=("stdio rpath wpath",{"/",NULL}) status=256 exit=1 (errno: "Operation not permitted") test(test_pledge): pledge=("stdio",NULL) status=256 exit=1 (errno: "Operation not permitted") -test(test_pledge): pledge=("unix",NULL) status=256 exit=1 (errno: "Operation not permitted") +test(test_pledge): pledge=("stdio unix",NULL) status=256 exit=1 (errno: "Operation not permitted") test(test_stat): pledge=("stdio rpath",{"/usr/share/man",NULL}) stat("/usr/share/man/man8/afterboot.8"): realpath="/usr/share/man/man8/afterboot.8" uid=0 gid=7 mode=100444 stat("/usr/share/man/man8/"): realpath="/usr/share/man/man8" uid=0 gid=0 mode=40755 @@ -99,6 +85,7 @@ test(test_stat): pledge=("stdio rpath",{"/usr/share/man",NULL}) stat("/"): realpath="/" uid=0 gid=0 mode=40111 stat("/usr/bin/gzip"): realpath=failed(2) errno=2 status=0 exit=0 -test(test_mmap): pledge=("rpath malloc prot_exec",{"/dev/zero",NULL}) status=0 exit=0 -test(test_mmap): pledge=("rpath malloc",{"/dev/zero",NULL}) status=9 signal=9 pledged_syscall=197 +test(test_mmap): pledge=("stdio rpath prot_exec",{"/dev/zero",NULL}) status=0 exit=0 +test(test_mmap): pledge=("stdio rpath",{"/dev/zero",NULL}) status=9 signal=9 pledged_syscall=197 +test(test_request_stdio): pledge=skip status=0 exit=0 test(test_request_tty): pledge=skip status=0 exit=0 -- 2.20.1