summaryrefslogtreecommitdiff
path: root/lib/libc/sys/unveil.2
blob: 3d0a7e2120f1c0eb2c373ffab13808e2541f82ec (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
.\" $OpenBSD: unveil.2,v 1.22 2021/09/06 08:03:08 deraadt Exp $
.\"
.\" Copyright (c) 2018 Bob Beck <beck@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: September 6 2021 $
.Dt UNVEIL 2
.Os
.Sh NAME
.Nm unveil
.Nd unveil parts of a restricted filesystem view
.Sh SYNOPSIS
.In unistd.h
.Ft int
.Fn unveil "const char *path" "const char *permissions"
.Sh DESCRIPTION
The first call to
.Fn unveil
that specifies a
.Fa path
removes visibility of the entire filesystem from all other
filesystem-related system calls (such as
.Xr open 2 ,
.Xr chmod 2
and
.Xr rename 2 ) ,
except for the specified
.Fa path
and
.Fa permissions .
.Pp
The
.Fn unveil
system call remains capable of traversing to any
.Fa path
in the filesystem, so additional calls can set permissions at other
points in the filesystem hierarchy.
.Pp
After establishing a collection of
.Fa path
and
.Fa permissions
rules, future calls to
.Fn unveil
can be disabled by passing two
.Dv NULL
arguments.
Alternatively,
.Xr pledge 2
may be used to remove the
.Qq unveil
promise.
.Pp
The
.Fa permissions
argument points to a string consisting of zero or more of the following
characters:
.Pp
.Bl -tag -width "XXXX" -offset indent -compact
.It Cm r
Make
.Fa path
available for read operations, corresponding to the
.Xr pledge 2
promise
.Qq rpath .
.It Cm w
Make
.Fa path
available for write operations, corresponding to the
.Xr pledge 2
promise
.Qq wpath .
.It Cm x
Make
.Fa path
available for execute operations, corresponding to the
.Xr pledge 2
promise
.Qq exec .
.It Cm c
Allow
.Fa path
to be created and removed, corresponding to the
.Xr pledge 2
promise
.Qq cpath .
.El
.Pp
A
.Fa path
that is a directory will enable all filesystem access underneath
.Fa path
using
.Fa permissions
if and only if no more specific matching
.Fn unveil
exists at a lower level.
Directories are remembered at the time of a call to
.Fn unveil .
This means that a directory that is removed and recreated after a call to
.Fn unveil
will appear to not exist.
.Pp
Non-directory paths are remembered by name within their containing
directory, and so may be created, removed, or re-created after a call to
.Fn unveil
and still appear to exist.
.Pp
Attempts to access paths not allowed by
.Fn unveil
will result in an error of
.Er EACCES
when the
.Fa permissions
argument does not match the attempted operation.
.Er ENOENT
is returned for paths for which no
.Fn unveil
permissions qualify.
After a process has terminated,
.Xr lastcomm 1
will mark it with the
.Sq U
flag if file access was prevented by
.Fn unveil .
.Pp
.Fn unveil
use can be tricky because programs misbehave badly when their files
unexpectedly disappear.
In many cases it is easier to unveil the directories in which an
application makes use of files.
.Sh RETURN VALUES
.Rv -std
.Sh ERRORS
.Bl -tag -width Er
.It Bq Er E2BIG
The addition of
.Fa path
would exceed the per-process limit for unveiled paths.
.It Bq Er EFAULT
.Fa path
or
.Fa permissions
points outside the process's allocated address space.
.It Bq Er ENOENT
A directory in
.Fa path
did not exist.
.It Bq Er EINVAL
An invalid value of
.Fa permissions
was used.
.It Bq Er EPERM
An attempt to increase permissions was made, or the
.Fa path
was not accessible, or
.Fn unveil
was called after locking.
.El
.Sh HISTORY
The
.Fn unveil
system call first appeared in
.Ox 6.4 .