diff options
author | Damien Miller <djm@mindrot.org> | 2011-06-27 07:18:18 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2011-06-27 07:18:18 +1000 |
commit | cd5e52ee784f0ff67b60ffeeab335ed64df688a4 (patch) | |
tree | 26405057dba53c82c603b3bb360faf81d6ff9e33 | |
parent | dcbd41e7aff4c7ef10dd13d8833a8cba82f9a794 (diff) |
- (djm) [configure.ac Makefile.in sandbox-darwin.c] Add a sandbox for
Darwin/OS X using sandbox_init() + setrlimit(); feedback and testing
markus@
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | configure.ac | 11 | ||||
-rw-r--r-- | sandbox-darwin.c | 98 |
4 files changed, 114 insertions, 4 deletions
@@ -1,3 +1,8 @@ | |||
1 | 20110624 | ||
2 | - (djm) [configure.ac Makefile.in sandbox-darwin.c] Add a sandbox for | ||
3 | Darwin/OS X using sandbox_init() + setrlimit(); feedback and testing | ||
4 | markus@ | ||
5 | |||
1 | 20110623 | 6 | 20110623 |
2 | - OpenBSD CVS Sync | 7 | - OpenBSD CVS Sync |
3 | - djm@cvs.openbsd.org 2011/06/22 21:47:28 | 8 | - djm@cvs.openbsd.org 2011/06/22 21:47:28 |
diff --git a/Makefile.in b/Makefile.in index f64aaac94..aeb67e1d8 100644 --- a/Makefile.in +++ b/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.323 2011/06/22 22:30:03 djm Exp $ | 1 | # $Id: Makefile.in,v 1.324 2011/06/26 21:18:20 djm Exp $ |
2 | 2 | ||
3 | # uncomment if you run a non bourne compatable shell. Ie. csh | 3 | # uncomment if you run a non bourne compatable shell. Ie. csh |
4 | #SHELL = @SH@ | 4 | #SHELL = @SH@ |
@@ -90,7 +90,7 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \ | |||
90 | loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \ | 90 | loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \ |
91 | sftp-server.o sftp-common.o \ | 91 | sftp-server.o sftp-common.o \ |
92 | roaming_common.o roaming_serv.o \ | 92 | roaming_common.o roaming_serv.o \ |
93 | sandbox-null.o sandbox-rlimit.o sandbox-systrace.o | 93 | sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o |
94 | 94 | ||
95 | MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out | 95 | MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out |
96 | MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5 | 96 | MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5 |
diff --git a/configure.ac b/configure.ac index 380a8b949..74d5263a4 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: configure.ac,v 1.477 2011/06/22 22:30:03 djm Exp $ | 1 | # $Id: configure.ac,v 1.478 2011/06/26 21:18:20 djm Exp $ |
2 | # | 2 | # |
3 | # Copyright (c) 1999-2004 Damien Miller | 3 | # Copyright (c) 1999-2004 Damien Miller |
4 | # | 4 | # |
@@ -15,7 +15,7 @@ | |||
15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | 16 | ||
17 | AC_INIT([OpenSSH], [Portable], [openssh-unix-dev@mindrot.org]) | 17 | AC_INIT([OpenSSH], [Portable], [openssh-unix-dev@mindrot.org]) |
18 | AC_REVISION($Revision: 1.477 $) | 18 | AC_REVISION($Revision: 1.478 $) |
19 | AC_CONFIG_SRCDIR([ssh.c]) | 19 | AC_CONFIG_SRCDIR([ssh.c]) |
20 | AC_LANG([C]) | 20 | AC_LANG([C]) |
21 | 21 | ||
@@ -525,6 +525,8 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16)) | |||
525 | AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV], | 525 | AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV], |
526 | [Define to a Set Process Title type if your system is | 526 | [Define to a Set Process Title type if your system is |
527 | supported by bsd-setproctitle.c]) | 527 | supported by bsd-setproctitle.c]) |
528 | AC_CHECK_FUNCS([sandbox_init]) | ||
529 | AC_CHECK_HEADERS([sandbox.h]) | ||
528 | ;; | 530 | ;; |
529 | *-*-dragonfly*) | 531 | *-*-dragonfly*) |
530 | SSHDLIBS="$SSHDLIBS -lcrypt" | 532 | SSHDLIBS="$SSHDLIBS -lcrypt" |
@@ -2487,6 +2489,11 @@ if test "x$sandbox_arg" = "xsystrace" || \ | |||
2487 | ( test -z "$sandbox_arg" && test "x$have_systr_policy_kill" = "x1" ) ; then | 2489 | ( test -z "$sandbox_arg" && test "x$have_systr_policy_kill" = "x1" ) ; then |
2488 | SANDBOX_STYLE="systrace" | 2490 | SANDBOX_STYLE="systrace" |
2489 | AC_DEFINE([SANDBOX_SYSTRACE], [1], [Sandbox using systrace(4)]) | 2491 | AC_DEFINE([SANDBOX_SYSTRACE], [1], [Sandbox using systrace(4)]) |
2492 | elif test "x$sandbox_arg" = "xdarwin" || \ | ||
2493 | ( test -z "$sandbox_arg" && test "x$ac_cv_func_sandbox_init" = "xyes" && \ | ||
2494 | test "x$ac_cv_header_sandbox_h" = "xyes") ; then | ||
2495 | SANDBOX_STYLE="darwin" | ||
2496 | AC_DEFINE([SANDBOX_DARWIN], [1], [Sandbox using Darwin sandbox_init(3)]) | ||
2490 | elif test "x$sandbox_arg" = "xrlimit" || \ | 2497 | elif test "x$sandbox_arg" = "xrlimit" || \ |
2491 | ( test -z "$sandbox_arg" && test "x$ac_cv_func_setrlimit" = "xyes" ) ; then | 2498 | ( test -z "$sandbox_arg" && test "x$ac_cv_func_setrlimit" = "xyes" ) ; then |
2492 | SANDBOX_STYLE="rlimit" | 2499 | SANDBOX_STYLE="rlimit" |
diff --git a/sandbox-darwin.c b/sandbox-darwin.c new file mode 100644 index 000000000..69901ef14 --- /dev/null +++ b/sandbox-darwin.c | |||
@@ -0,0 +1,98 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "includes.h" | ||
18 | |||
19 | #ifdef SANDBOX_DARWIN | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | |||
23 | #include <sandbox.h> | ||
24 | |||
25 | #include <errno.h> | ||
26 | #include <stdarg.h> | ||
27 | #include <stdio.h> | ||
28 | #include <stdlib.h> | ||
29 | #include <string.h> | ||
30 | #include <unistd.h> | ||
31 | |||
32 | #include "log.h" | ||
33 | #include "sandbox.h" | ||
34 | #include "xmalloc.h" | ||
35 | |||
36 | /* Darwin/OS X sandbox */ | ||
37 | |||
38 | struct ssh_sandbox { | ||
39 | pid_t child_pid; | ||
40 | }; | ||
41 | |||
42 | struct ssh_sandbox * | ||
43 | ssh_sandbox_init(void) | ||
44 | { | ||
45 | struct ssh_sandbox *box; | ||
46 | |||
47 | /* | ||
48 | * Strictly, we don't need to maintain any state here but we need | ||
49 | * to return non-NULL to satisfy the API. | ||
50 | */ | ||
51 | debug3("%s: preparing Darwin sandbox", __func__); | ||
52 | box = xcalloc(1, sizeof(*box)); | ||
53 | box->child_pid = 0; | ||
54 | |||
55 | return box; | ||
56 | } | ||
57 | |||
58 | void | ||
59 | ssh_sandbox_child(struct ssh_sandbox *box) | ||
60 | { | ||
61 | char *errmsg; | ||
62 | struct rlimit rl_zero; | ||
63 | |||
64 | debug3("%s: starting Darwin sandbox", __func__); | ||
65 | if (sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, | ||
66 | &errmsg) == -1) | ||
67 | fatal("%s: sandbox_init: %s", __func__, errmsg); | ||
68 | |||
69 | /* | ||
70 | * The kSBXProfilePureComputation still allows sockets, so | ||
71 | * we must disable these using rlimit. | ||
72 | */ | ||
73 | rl_zero.rlim_cur = rl_zero.rlim_max = 0; | ||
74 | if (setrlimit(RLIMIT_FSIZE, &rl_zero) == -1) | ||
75 | fatal("%s: setrlimit(RLIMIT_FSIZE, { 0, 0 }): %s", | ||
76 | __func__, strerror(errno)); | ||
77 | if (setrlimit(RLIMIT_NOFILE, &rl_zero) == -1) | ||
78 | fatal("%s: setrlimit(RLIMIT_NOFILE, { 0, 0 }): %s", | ||
79 | __func__, strerror(errno)); | ||
80 | if (setrlimit(RLIMIT_NPROC, &rl_zero) == -1) | ||
81 | fatal("%s: setrlimit(RLIMIT_NPROC, { 0, 0 }): %s", | ||
82 | __func__, strerror(errno)); | ||
83 | } | ||
84 | |||
85 | void | ||
86 | ssh_sandbox_parent_finish(struct ssh_sandbox *box) | ||
87 | { | ||
88 | free(box); | ||
89 | debug3("%s: finished", __func__); | ||
90 | } | ||
91 | |||
92 | void | ||
93 | ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid) | ||
94 | { | ||
95 | box->child_pid = child_pid; | ||
96 | } | ||
97 | |||
98 | #endif /* SANDBOX_DARWIN */ | ||