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