xref: /dflybsd-src/crypto/openssh/sandbox-solaris.c (revision ba1276acd1c8c22d225b1bcf370a14c878644f44)
1*ba1276acSMatthew Dillon /*
2*ba1276acSMatthew Dillon  * Copyright (c) 2015 Joyent, Inc
3*ba1276acSMatthew Dillon  * Author: Alex Wilson <alex.wilson@joyent.com>
4*ba1276acSMatthew Dillon  *
5*ba1276acSMatthew Dillon  * Permission to use, copy, modify, and distribute this software for any
6*ba1276acSMatthew Dillon  * purpose with or without fee is hereby granted, provided that the above
7*ba1276acSMatthew Dillon  * copyright notice and this permission notice appear in all copies.
8*ba1276acSMatthew Dillon  *
9*ba1276acSMatthew Dillon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*ba1276acSMatthew Dillon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*ba1276acSMatthew Dillon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*ba1276acSMatthew Dillon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*ba1276acSMatthew Dillon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*ba1276acSMatthew Dillon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*ba1276acSMatthew Dillon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*ba1276acSMatthew Dillon  */
17*ba1276acSMatthew Dillon 
18*ba1276acSMatthew Dillon #include "includes.h"
19*ba1276acSMatthew Dillon 
20*ba1276acSMatthew Dillon #ifdef SANDBOX_SOLARIS
21*ba1276acSMatthew Dillon #ifndef USE_SOLARIS_PRIVS
22*ba1276acSMatthew Dillon # error "--with-solaris-privs must be used with the Solaris sandbox"
23*ba1276acSMatthew Dillon #endif
24*ba1276acSMatthew Dillon 
25*ba1276acSMatthew Dillon #include <sys/types.h>
26*ba1276acSMatthew Dillon 
27*ba1276acSMatthew Dillon #include <errno.h>
28*ba1276acSMatthew Dillon #include <stdarg.h>
29*ba1276acSMatthew Dillon #include <stdio.h>
30*ba1276acSMatthew Dillon #include <stdlib.h>
31*ba1276acSMatthew Dillon #include <string.h>
32*ba1276acSMatthew Dillon #include <unistd.h>
33*ba1276acSMatthew Dillon #ifdef HAVE_PRIV_H
34*ba1276acSMatthew Dillon # include <priv.h>
35*ba1276acSMatthew Dillon #endif
36*ba1276acSMatthew Dillon 
37*ba1276acSMatthew Dillon #include "log.h"
38*ba1276acSMatthew Dillon #include "ssh-sandbox.h"
39*ba1276acSMatthew Dillon #include "xmalloc.h"
40*ba1276acSMatthew Dillon 
41*ba1276acSMatthew Dillon struct ssh_sandbox {
42*ba1276acSMatthew Dillon 	priv_set_t *pset;
43*ba1276acSMatthew Dillon };
44*ba1276acSMatthew Dillon 
45*ba1276acSMatthew Dillon struct ssh_sandbox *
ssh_sandbox_init(struct monitor * monitor)46*ba1276acSMatthew Dillon ssh_sandbox_init(struct monitor *monitor)
47*ba1276acSMatthew Dillon {
48*ba1276acSMatthew Dillon 	struct ssh_sandbox *box = NULL;
49*ba1276acSMatthew Dillon 
50*ba1276acSMatthew Dillon 	box = xcalloc(1, sizeof(*box));
51*ba1276acSMatthew Dillon 
52*ba1276acSMatthew Dillon 	/* Start with "basic" and drop everything we don't need. */
53*ba1276acSMatthew Dillon 	box->pset = solaris_basic_privset();
54*ba1276acSMatthew Dillon 
55*ba1276acSMatthew Dillon 	if (box->pset == NULL) {
56*ba1276acSMatthew Dillon 		free(box);
57*ba1276acSMatthew Dillon 		return NULL;
58*ba1276acSMatthew Dillon 	}
59*ba1276acSMatthew Dillon 
60*ba1276acSMatthew Dillon 	/* Drop everything except the ability to use already-opened files */
61*ba1276acSMatthew Dillon 	if (priv_delset(box->pset, PRIV_FILE_LINK_ANY) != 0 ||
62*ba1276acSMatthew Dillon #ifdef PRIV_NET_ACCESS
63*ba1276acSMatthew Dillon 	    priv_delset(box->pset, PRIV_NET_ACCESS) != 0 ||
64*ba1276acSMatthew Dillon #endif
65*ba1276acSMatthew Dillon #ifdef PRIV_DAX_ACCESS
66*ba1276acSMatthew Dillon 	    priv_delset(box->pset, PRIV_DAX_ACCESS) != 0 ||
67*ba1276acSMatthew Dillon #endif
68*ba1276acSMatthew Dillon #ifdef PRIV_SYS_IB_INFO
69*ba1276acSMatthew Dillon 	    priv_delset(box->pset, PRIV_SYS_IB_INFO) != 0 ||
70*ba1276acSMatthew Dillon #endif
71*ba1276acSMatthew Dillon 	    priv_delset(box->pset, PRIV_PROC_EXEC) != 0 ||
72*ba1276acSMatthew Dillon 	    priv_delset(box->pset, PRIV_PROC_FORK) != 0 ||
73*ba1276acSMatthew Dillon 	    priv_delset(box->pset, PRIV_PROC_INFO) != 0 ||
74*ba1276acSMatthew Dillon 	    priv_delset(box->pset, PRIV_PROC_SESSION) != 0) {
75*ba1276acSMatthew Dillon 		free(box);
76*ba1276acSMatthew Dillon 		return NULL;
77*ba1276acSMatthew Dillon 	}
78*ba1276acSMatthew Dillon 
79*ba1276acSMatthew Dillon 	/* These may not be available on older Solaris-es */
80*ba1276acSMatthew Dillon # if defined(PRIV_FILE_READ) && defined(PRIV_FILE_WRITE)
81*ba1276acSMatthew Dillon 	if (priv_delset(box->pset, PRIV_FILE_READ) != 0 ||
82*ba1276acSMatthew Dillon 	    priv_delset(box->pset, PRIV_FILE_WRITE) != 0) {
83*ba1276acSMatthew Dillon 		free(box);
84*ba1276acSMatthew Dillon 		return NULL;
85*ba1276acSMatthew Dillon 	}
86*ba1276acSMatthew Dillon # endif
87*ba1276acSMatthew Dillon 
88*ba1276acSMatthew Dillon 	return box;
89*ba1276acSMatthew Dillon }
90*ba1276acSMatthew Dillon 
91*ba1276acSMatthew Dillon void
ssh_sandbox_child(struct ssh_sandbox * box)92*ba1276acSMatthew Dillon ssh_sandbox_child(struct ssh_sandbox *box)
93*ba1276acSMatthew Dillon {
94*ba1276acSMatthew Dillon 	if (setppriv(PRIV_SET, PRIV_PERMITTED, box->pset) != 0 ||
95*ba1276acSMatthew Dillon 	    setppriv(PRIV_SET, PRIV_LIMIT, box->pset) != 0 ||
96*ba1276acSMatthew Dillon 	    setppriv(PRIV_SET, PRIV_INHERITABLE, box->pset) != 0)
97*ba1276acSMatthew Dillon 		fatal("setppriv: %s", strerror(errno));
98*ba1276acSMatthew Dillon }
99*ba1276acSMatthew Dillon 
100*ba1276acSMatthew Dillon void
ssh_sandbox_parent_finish(struct ssh_sandbox * box)101*ba1276acSMatthew Dillon ssh_sandbox_parent_finish(struct ssh_sandbox *box)
102*ba1276acSMatthew Dillon {
103*ba1276acSMatthew Dillon 	priv_freeset(box->pset);
104*ba1276acSMatthew Dillon 	box->pset = NULL;
105*ba1276acSMatthew Dillon 	free(box);
106*ba1276acSMatthew Dillon }
107*ba1276acSMatthew Dillon 
108*ba1276acSMatthew Dillon void
ssh_sandbox_parent_preauth(struct ssh_sandbox * box,pid_t child_pid)109*ba1276acSMatthew Dillon ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
110*ba1276acSMatthew Dillon {
111*ba1276acSMatthew Dillon 	/* Nothing to do here */
112*ba1276acSMatthew Dillon }
113*ba1276acSMatthew Dillon 
114*ba1276acSMatthew Dillon #endif /* SANDBOX_SOLARIS */
115