summaryrefslogtreecommitdiff
path: root/share/man/man4/systrace.4
blob: 5dbb4f5499278a96524c9bdbeb753cb95f2a6602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
.\"	$OpenBSD: systrace.4,v 1.7 2003/06/06 10:29:41 jmc Exp $
.\"
.\" Copyright (c) 2002, 2003 CubeSoft Communications, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd May 26, 2002
.Dt SYSTRACE 4
.Os
.Sh NAME
.Nm systrace
.Nd enforce and generate policies for system calls
.Sh SYNOPSIS
.Cd "pseudo-device systrace 1"
.Sh DESCRIPTION
.Nm
attaches to processes and enforces policies for system calls.
A pseudo-device,
.Pa /dev/systrace ,
allows userland processes to control the behavior of
.Nm
through an
.Xr ioctl 2
interface.
.Sh SYSTEM CALL POLICIES
.Nm
can assign the following policies to system calls:
.Bl -tag -enum -width SYSTR_POLICY_XXXXXX
.It SYSTR_POLICY_ASK
Send a message of the type
.Dv SYSTR_MSG_ASK ,
and put the process to sleep until a
.Dv STRIOCANSWER
.Xr ioctl 2
is made.
.It SYSTR_POLICY_PERMIT
Immediately allow the system call.
.It SYSTR_POLICY_NEVER
Immediately return an error code.
.El
.Sh SYSTRACE MESSAGES
A
.Xr read 2
operation on the
.Nm
pseudo-device will block if there are no pending messages, or
return the following structure:
.Bd -literal
struct str_message {
	int msg_type;
#define SYSTR_MSG_ASK	1
#define SYSTR_MSG_RES	2
#define SYSTR_MSG_EMUL	3
#define SYSTR_MSG_CHILD	4
	pid_t msg_pid;
	short msg_policy;
	union {
		struct str_msg_emul msg_emul;
		struct str_msg_ask msg_ask;
		struct str_msg_child msg_child;
	} msg_data;
};

struct str_msg_emul {
	char emul[SYSTR_EMULEN];
};

struct str_msg_ask {
	int code;
	int argsize;
	register_t args[SYSTR_MAXARGS];
	register_t rval[2];
	int result;
};

struct str_msg_child {
	pid_t new_pid;
};
.Ed
.Sh IOCTL INTERFACE
.Nm
supports the following
.Xr ioctl 2
commands:
.Bl -tag -width "xxxxxx"
.It Dv SYSTR_CLONE Fa "int"
Return a
.Nm
file descriptor for
further
.Xr ioctl 2
operations.
.El
.Bl -tag -width STRIOCXXXXXXXX
.It Dv STRIOCATTACH Fa "pid_t"
Attach to a process, unless:
.Bl -enum -compact -width 2n
.It
It's the process that's doing the attaching.
.It
It's a system process.
.It
It's being traced already.
.It
You do not own the process and you're not root.
.It
It's
.Xr init 8 ,
and the
kernel was not compiled with
.Cd option INSECURE .
.El
.It Dv STRIOCDETACH Fa "pid_t"
Wake up a process if it is waiting for an answer, and detach from it.
.It Dv STRIOCANSWER Fa "struct systrace_answer"
Tell
.Nm
what to do with a system call that was assigned a policy of
.Dv SYSTR_POLICY_ASK .
.Bd -literal
struct systrace_answer {
	pid_t stra_pid;     /* PID of process being traced */
	int stra_policy;    /* Policy to assign */
	int stra_error;     /* Return value of denied syscall
	                       (will return EPERM if zero) */
	int stra_flags;
#define	SYSTR_FLAGS_RESULT 0x0001    /* Report syscall result */
};
.Ed
.It Dv STRIOCREPORT Fa "pid_t"
Report the current emulation a process is using inside the
.Va msg_emul
structure.
.It Dv STRIOCREPLACE Fa "struct systrace_replace"
Arrange for system call arguments to be replaced by arguments
supplied by the monitoring process.
.Bd -literal
struct systrace_replace {
	pid_t strr_pid;
	int strr_nrepl;		/* # of arguments to replace */
	caddr_t	strr_base;		/* Base user memory */
	size_t strr_len;		/* Length of memory */
	int strr_argind[SYSTR_MAXARGS];	/* Argument indexes */
	size_t strr_off[SYSTR_MAXARGS];	/* Argument offsets */
	size_t strr_offlen[SYSTR_MAXARGS]; /* Argument sizes */
};
.Ed
.It Dv STRIOCIO Fa "struct systrace_io"
Copy data in/out of the process being traced.
.Bd -literal
struct systrace_io {
	pid_t strio_pid;    /* PID of process being traced */
	int strio_ops;
#define	SYSTR_READ	1
#define	SYSTR_WRITE	2
	void *strio_offs;
	void *strio_addr;
	size_t strio_len;
};
.Ed
.It Dv STRIOCPOLICY Fa "struct systrace_policy"
Manipulate the set of policies.
.Bd -literal
struct systrace_policy {
	int strp_op;
#define	SYSTR_POLICY_NEW	1    /* Allocate a new policy */
#define	SYSTR_POLICY_ASSIGN	2    /* Assign policy to process */
#define	SYSTR_POLICY_MODIFY	3    /* Modify an entry */
	int strp_num;
	union {
		struct {
			short code;
#define SYSTR_POLICY_ASK	0
#define SYSTR_POLICY_PERMIT	1
#define SYSTR_POLICY_NEVER	2
			short policy;
		} assign;
		pid_t pid;
		int maxents;
	} strp_data;
#define strp_pid	strp_data.pid
#define strp_maxents	strp_data.maxents
#define strp_code	strp_data.assign.code
#define strp_policy	strp_data.assign.policy
};
.Ed
.Pp
The
.Dv SYSTR_POLICY_NEW
operation allocates a new policy with all entries initialized to
.Dv SYSTR_POLICY_ASK ,
and returns the new policy number into
.Va strp_num .
The
.Dv SYSTR_POLICY_ASSIGN
operation attaches the policy identified by
.Va strp_num
to
.Va strp_pid ,
with a maximum of
.Va strp_maxents
entries.
The
.Dv SYSTR_POLICY_MODIFY
operation changes the entry indexed by
.Va strp_code
to
.Va strp_policy .
.It Dv STRIOCGETCWD Fa "pid_t"
Set the working directory of the current process to that of the
named process.
.It Dv STRIOCRESCWD
Restore the working directory of the current process.
.El
.Sh FILES
.Bl -tag -width "/dev/systrace" -compact
.It Pa /dev/systrace
system call tracing facility
.El
.Sh SEE ALSO
.Xr ioctl 2 ,
.Xr read 2 ,
.Xr options 4 ,
.Xr securelevel 7
.Sh HISTORY
The
.Nm
facility first appeared in
.Ox 3.2 .
.\" .Sh BUGS
.\" .Sh CAVEATS