1.\" $OpenBSD: unveil.2,v 1.21 2020/04/25 13:23:01 beck Exp $ 2.\" 3.\" Copyright (c) 2018 Bob Beck <beck@openbsd.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: April 25 2020 $ 18.Dt UNVEIL 2 19.Os 20.Sh NAME 21.Nm unveil 22.Nd unveil parts of a restricted filesystem view 23.Sh SYNOPSIS 24.In unistd.h 25.Ft int 26.Fn unveil "const char *path" "const char *permissions" 27.Sh DESCRIPTION 28The first call to 29.Fn unveil 30that specifies a 31.Fa path 32removes visibility of the entire filesystem from all other 33filesystem-related system calls (such as 34.Xr open 2 , 35.Xr chmod 2 36and 37.Xr rename 2 ) , 38except for the specified 39.Fa path 40and 41.Fa permissions . 42.Pp 43The 44.Fn unveil 45system call remains capable of traversing to any 46.Fa path 47in the filesystem, so additional calls can set permissions at other 48points in the filesystem hierarchy. 49.Pp 50After establishing a collection of 51.Fa path 52and 53.Fa permissions 54rules, future calls to 55.Fn unveil 56can be disabled by passing two 57.Dv NULL 58arguments. 59Alternatively, 60.Xr pledge 2 61may be used to remove the 62.Qq unveil 63promise. 64.Pp 65The 66.Fa permissions 67argument points to a string consisting of zero or more of the following 68characters: 69.Pp 70.Bl -tag -width "XXXX" -offset indent -compact 71.It Cm r 72Make 73.Fa path 74available for read operations, corresponding to the 75.Xr pledge 2 76promise 77.Qq rpath . 78.It Cm w 79Make 80.Fa path 81available for write operations, corresponding to the 82.Xr pledge 2 83promise 84.Qq wpath . 85.It Cm x 86Make 87.Fa path 88available for execute operations, corresponding to the 89.Xr pledge 2 90promise 91.Qq exec . 92.It Cm c 93Allow 94.Fa path 95to be created and removed, corresponding to the 96.Xr pledge 2 97promise 98.Qq cpath . 99.El 100.Pp 101A 102.Fa path 103that is a directory will enable all filesystem access underneath 104.Fa path 105using 106.Fa permissions 107if and only if no more specific matching 108.Fn unveil 109exists at a lower level. 110Directories are remembered at the time of a call to 111.Fn unveil . 112This means that a directory that is removed and recreated after a call to 113.Fn unveil 114will appear to not exist. 115.Pp 116Non-directory paths are remembered by name within their containing 117directory, and so may be created, removed, or re-created after a call to 118.Fn unveil 119and still appear to exist. 120.Pp 121Attempts to access paths not allowed by 122.Fn unveil 123will result in an error of 124.Er EACCES 125when the 126.Fa permissions 127argument does not match the attempted operation. 128.Er ENOENT 129is returned for paths for which no 130.Fn unveil 131permissions qualify. 132After a process has terminated, 133.Xr lastcomm 1 134will mark it with the 135.Sq U 136flag if file access was prevented by 137.Fn unveil . 138.Pp 139.Fn unveil 140use can be tricky because programs misbehave badly when their files 141unexpectedly disappear. 142In many cases it is easier to unveil the directories in which an 143application makes use of files. 144.Sh RETURN VALUES 145.Rv -std 146.Sh ERRORS 147.Bl -tag -width Er 148.It Er E2BIG 149The addition of 150.Fa path 151would exceed the per-process limit for unveiled paths. 152.It Er ENOENT 153A directory in 154.Fa path 155did not exist. 156.It Er EINVAL 157An invalid value of 158.Fa permissions 159was used. 160.It Er EPERM 161An attempt to increase permissions was made, or the 162.Fa path 163was not accessible, or 164.Fn unveil 165was called after locking. 166.El 167.Sh HISTORY 168The 169.Fn unveil 170system call first appeared in 171.Ox 6.4 . 172