summaryrefslogtreecommitdiff
path: root/lib/libc/sys/unveil.2
blob: 4be65d187da468184190800d81b8ecb7b52cc6cb (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
.\" $OpenBSD: unveil.2,v 1.3 2018/07/16 12:02:45 espie 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: July 16 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 *flags"
.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 .
Subsequent calls to
.Nm
expose additional views of the filesystem.
.Pp
The
.Nm
call is treated specially and can continue to see the filesystem for
subsequent calls.
.Nm
can be locked,
preventing further filesytem exposure by calling
.Nm
with two
.Ar NULL
arguments.
.Xr pledge 2
may alternatively be used
to remove the "unveil" permission.
.Pp
The
.Fa flags
argument points to a string consisting of the following characters.
.Pp
.Bl -tag -width c -offset indent -compact
.It Dv r
.Ar path
should be made available for read operations corresponding to
.Xr pledge 2
promise
.Ar rpath .
.It Dv w
.Ar path
should be available for write operations corresponding to
.Xr pledge 2
promise
.Ar wpath .
.It Dv x
.Ar path
should be available for execute operations corresponding to
.Xr pledge 2
promise
.Ar exec .
.It Dv c
.Ar path
should be allowed to be created and removed, corresponding to
.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 flags
if and only if no more specific matching
.Fn unveil
exists at a lower level.
.Pp
Attempts to access paths not allowed by
.Nm
will result in an error of
.Ar EACCES
when the
.Ar flags
argument does not match the attempted operation.
.Ar ENOENT
is returned for paths for which no
.Nm
flags are present.
.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.
It is important to consider that directory results 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.
Non directories 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.
.Sh RETURN VALUES
.Fn unveil
returns 0 on success or -1 on failure.
.Sh ERRORS
.Bl -tag -width Er
.It E2BIG
The addition of
.Ar path
would exceed the per-process limit for pledged paths.
.It ENOENT
A directory in
.Ar path
did not exist.
.It EINVAL
An invalid value of
.Ar flags
was used.
.It EPERM
An attempt to add permission to
.Ar flags
was made, or
.Ar path
was not accessible, or
.Nm
was called after it was locked
.El
.Sh HISTORY
The
.Fn unveil
system call first appeared in
.Ox 6.4 .