summaryrefslogtreecommitdiff
path: root/lib/libc/sys/unveil.2
blob: cc5e91d10bf0210e24920609bfd8c03e3830ad5c (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
.\" $OpenBSD: unveil.2,v 1.10 2018/09/26 02:54:34 miko 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 26 2018 $
.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
.Nm
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
.Ar path
and
.Ar permission .
Subsequent calls to
.Nm
can expose additional paths with specified permissions in the filesystem.
.Pp
The
.Nm
call itself is treated specially and can continue to see the
filesystem for subsequent calls.
.Pp
Future calls to
.Nm
can be blocked by passing two
.Ar NULL
arguments.
If the veil is not yet active, this does not activate it.
Alternatively,
.Xr pledge 2
may be used to remove the
.Va unveil
promise.
.Pp
The
.Fa permissions
argument points to a string consisting of the following characters:
.Pp
.Bl -tag -width "XXXX" -offset indent -compact
.It Dv r
Make
.Ar path
available for read operations, corresponding to the
.Xr pledge 2
promise
.Ar rpath .
.It Dv w
Make
.Ar path
available for write operations, corresponding to the
.Xr pledge 2
promise
.Ar wpath .
.It Dv x
Make
.Ar path
available for execute operations, corresponding to the
.Xr pledge 2
promise
.Ar exec .
.It Dv c
Allow
.Ar path
to be created and removed, corresponding to the
.Xr pledge 2
promise
.Ar cpath .
.El
.Pp
A
.Ar path
that is a directory will enable all filesystem access underneath
.Ar path
using
.Ar 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-directories 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
.Nm
will result in an error of
.Ar EACCES
when the
.Ar permissions
argument does not match the attempted operation.
.Ar ENOENT
is returned for paths for which no
.Nm
permissions qualify.
.Pp
As with
.Xr pledge 2 ,
the use of
.Fn unveil
in an application will require lots of study and understanding
of the interfaces called.
In most cases it is best practice to unveil the directories
in which an application makes use of files.
.Sh RETURN VALUES
.Rv -std
.Sh ERRORS
.Bl -tag -width Er
.It E2BIG
The addition of
.Ar path
would exceed the per-process limit for unveiled paths.
.It ENOENT
A directory in
.Ar path
did not exist.
.It EINVAL
An invalid value of
.Ar permissions
was used.
.It EPERM
An attempt to increase permissions was made, or the
.Ar path
was not accessible, or
.Nm
was called after locking.
.El
.Sh HISTORY
The
.Fn unveil
system call first appeared in
.Ox 6.4 .
.Sh BUGS
Filesystem lookups work today when they cross an
.Fn unveil
during
.Xr namei 9
lookup in the kernel.
A program that does relative operations below a higher
.Fn unveil
may currently not see the parts of the filesystem
underneath the high level unveil.
This is actively being worked on.