xref: /dflybsd-src/crypto/openssh/sandbox-pledge.c (revision ba1276acd1c8c22d225b1bcf370a14c878644f44)
1*ba1276acSMatthew Dillon /* $OpenBSD: sandbox-pledge.c,v 1.2 2020/10/18 11:32:01 djm Exp $ */
2*ba1276acSMatthew Dillon /*
3*ba1276acSMatthew Dillon  * Copyright (c) 2015 Theo de Raadt <deraadt@openbsd.org>
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_PLEDGE
21*ba1276acSMatthew Dillon 
22*ba1276acSMatthew Dillon #include <sys/types.h>
23*ba1276acSMatthew Dillon #include <sys/ioctl.h>
24*ba1276acSMatthew Dillon #include <sys/syscall.h>
25*ba1276acSMatthew Dillon #include <sys/socket.h>
26*ba1276acSMatthew Dillon #include <sys/wait.h>
27*ba1276acSMatthew Dillon 
28*ba1276acSMatthew Dillon #include <errno.h>
29*ba1276acSMatthew Dillon #include <limits.h>
30*ba1276acSMatthew Dillon #include <stdarg.h>
31*ba1276acSMatthew Dillon #include <stdio.h>
32*ba1276acSMatthew Dillon #include <stdlib.h>
33*ba1276acSMatthew Dillon #include <unistd.h>
34*ba1276acSMatthew Dillon #include <pwd.h>
35*ba1276acSMatthew Dillon 
36*ba1276acSMatthew Dillon #include "log.h"
37*ba1276acSMatthew Dillon #include "ssh-sandbox.h"
38*ba1276acSMatthew Dillon #include "xmalloc.h"
39*ba1276acSMatthew Dillon 
40*ba1276acSMatthew Dillon struct ssh_sandbox {
41*ba1276acSMatthew Dillon 	pid_t child_pid;
42*ba1276acSMatthew Dillon };
43*ba1276acSMatthew Dillon 
44*ba1276acSMatthew Dillon struct ssh_sandbox *
ssh_sandbox_init(struct monitor * m)45*ba1276acSMatthew Dillon ssh_sandbox_init(struct monitor *m)
46*ba1276acSMatthew Dillon {
47*ba1276acSMatthew Dillon 	struct ssh_sandbox *box;
48*ba1276acSMatthew Dillon 
49*ba1276acSMatthew Dillon 	debug3_f("preparing pledge sandbox");
50*ba1276acSMatthew Dillon 	box = xcalloc(1, sizeof(*box));
51*ba1276acSMatthew Dillon 	box->child_pid = 0;
52*ba1276acSMatthew Dillon 
53*ba1276acSMatthew Dillon 	return box;
54*ba1276acSMatthew Dillon }
55*ba1276acSMatthew Dillon 
56*ba1276acSMatthew Dillon void
ssh_sandbox_child(struct ssh_sandbox * box)57*ba1276acSMatthew Dillon ssh_sandbox_child(struct ssh_sandbox *box)
58*ba1276acSMatthew Dillon {
59*ba1276acSMatthew Dillon 	if (pledge("stdio", NULL) == -1)
60*ba1276acSMatthew Dillon 		fatal_f("pledge()");
61*ba1276acSMatthew Dillon }
62*ba1276acSMatthew Dillon 
63*ba1276acSMatthew Dillon void
ssh_sandbox_parent_finish(struct ssh_sandbox * box)64*ba1276acSMatthew Dillon ssh_sandbox_parent_finish(struct ssh_sandbox *box)
65*ba1276acSMatthew Dillon {
66*ba1276acSMatthew Dillon 	free(box);
67*ba1276acSMatthew Dillon 	debug3_f("finished");
68*ba1276acSMatthew Dillon }
69*ba1276acSMatthew Dillon 
70*ba1276acSMatthew Dillon void
ssh_sandbox_parent_preauth(struct ssh_sandbox * box,pid_t child_pid)71*ba1276acSMatthew Dillon ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
72*ba1276acSMatthew Dillon {
73*ba1276acSMatthew Dillon 	box->child_pid = child_pid;
74*ba1276acSMatthew Dillon 	/* Nothing to do here */
75*ba1276acSMatthew Dillon }
76*ba1276acSMatthew Dillon 
77*ba1276acSMatthew Dillon #endif /* SANDBOX_PLEDGE */
78