xref: /freebsd/lib/libsys/cap_ioctls_limit.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\"
2*8269e767SBrooks Davis.\" Copyright (c) 2012 The FreeBSD Foundation
3*8269e767SBrooks Davis.\"
4*8269e767SBrooks Davis.\" This documentation was written by Pawel Jakub Dawidek under sponsorship
5*8269e767SBrooks Davis.\" the FreeBSD Foundation.
6*8269e767SBrooks Davis.\"
7*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
8*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
9*8269e767SBrooks Davis.\" are met:
10*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
11*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
12*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
13*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
14*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
15*8269e767SBrooks Davis.\"
16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8269e767SBrooks Davis.\" SUCH DAMAGE.
27*8269e767SBrooks Davis.\"
28*8269e767SBrooks Davis.Dd March 9, 2023
29*8269e767SBrooks Davis.Dt CAP_IOCTLS_LIMIT 2
30*8269e767SBrooks Davis.Os
31*8269e767SBrooks Davis.Sh NAME
32*8269e767SBrooks Davis.Nm cap_ioctls_limit ,
33*8269e767SBrooks Davis.Nm cap_ioctls_get
34*8269e767SBrooks Davis.Nd manage allowed ioctl commands
35*8269e767SBrooks Davis.Sh LIBRARY
36*8269e767SBrooks Davis.Lb libc
37*8269e767SBrooks Davis.Sh SYNOPSIS
38*8269e767SBrooks Davis.In sys/capsicum.h
39*8269e767SBrooks Davis.Ft int
40*8269e767SBrooks Davis.Fn cap_ioctls_limit "int fd" "const unsigned long *cmds" "size_t ncmds"
41*8269e767SBrooks Davis.Ft ssize_t
42*8269e767SBrooks Davis.Fn cap_ioctls_get "int fd" "unsigned long *cmds" "size_t maxcmds"
43*8269e767SBrooks Davis.Sh DESCRIPTION
44*8269e767SBrooks DavisIf a file descriptor is granted the
45*8269e767SBrooks Davis.Dv CAP_IOCTL
46*8269e767SBrooks Daviscapability right, the list of allowed
47*8269e767SBrooks Davis.Xr ioctl 2
48*8269e767SBrooks Daviscommands can be selectively reduced (but never expanded) with the
49*8269e767SBrooks Davis.Fn cap_ioctls_limit
50*8269e767SBrooks Davissystem call.
51*8269e767SBrooks DavisThe
52*8269e767SBrooks Davis.Fa cmds
53*8269e767SBrooks Davisargument is an array of
54*8269e767SBrooks Davis.Xr ioctl 2
55*8269e767SBrooks Daviscommands and the
56*8269e767SBrooks Davis.Fa ncmds
57*8269e767SBrooks Davisargument specifies the number of elements in the array.
58*8269e767SBrooks DavisThere can be up to
59*8269e767SBrooks Davis.Va 256
60*8269e767SBrooks Daviselements in the array.
61*8269e767SBrooks DavisIncluding an element that has been previously revoked will generate an error.
62*8269e767SBrooks DavisAfter a successful call only those listed in the array may be used.
63*8269e767SBrooks Davis.Pp
64*8269e767SBrooks DavisThe list of allowed ioctl commands for a given file descriptor can be obtained
65*8269e767SBrooks Daviswith the
66*8269e767SBrooks Davis.Fn cap_ioctls_get
67*8269e767SBrooks Davissystem call.
68*8269e767SBrooks DavisThe
69*8269e767SBrooks Davis.Fa cmds
70*8269e767SBrooks Davisargument points at memory that can hold up to
71*8269e767SBrooks Davis.Fa maxcmds
72*8269e767SBrooks Davisvalues.
73*8269e767SBrooks DavisThe function populates the provided buffer with up to
74*8269e767SBrooks Davis.Fa maxcmds
75*8269e767SBrooks Daviselements, but always returns the total number of ioctl commands allowed for the
76*8269e767SBrooks Davisgiven file descriptor.
77*8269e767SBrooks DavisThe total number of ioctls commands for the given file descriptor can be
78*8269e767SBrooks Davisobtained by passing
79*8269e767SBrooks Davis.Dv NULL as the
80*8269e767SBrooks Davis.Fa cmds
81*8269e767SBrooks Davisargument and
82*8269e767SBrooks Davis.Va 0
83*8269e767SBrooks Davisas the
84*8269e767SBrooks Davis.Fa maxcmds
85*8269e767SBrooks Davisargument.
86*8269e767SBrooks DavisIf all ioctl commands are allowed
87*8269e767SBrooks Davis.Dv ( CAP_IOCTL
88*8269e767SBrooks Daviscapability right is assigned to the file descriptor and the
89*8269e767SBrooks Davis.Fn cap_ioctls_limit
90*8269e767SBrooks Davissystem call was never called for this file descriptor), the
91*8269e767SBrooks Davis.Fn cap_ioctls_get
92*8269e767SBrooks Davissystem call will return
93*8269e767SBrooks Davis.Dv CAP_IOCTLS_ALL
94*8269e767SBrooks Davisand will not modify the buffer pointed to by the
95*8269e767SBrooks Davis.Fa cmds
96*8269e767SBrooks Davisargument.
97*8269e767SBrooks Davis.Sh RETURN VALUES
98*8269e767SBrooks Davis.Rv -std cap_ioctls_limit
99*8269e767SBrooks Davis.Pp
100*8269e767SBrooks DavisThe
101*8269e767SBrooks Davis.Fn cap_ioctls_get
102*8269e767SBrooks Davisfunction, if successful, returns the total number of allowed ioctl commands or
103*8269e767SBrooks Davisthe value
104*8269e767SBrooks Davis.Dv CAP_IOCTLS_ALL
105*8269e767SBrooks Davisif all ioctls commands are allowed.
106*8269e767SBrooks DavisOn failure the value
107*8269e767SBrooks Davis.Va -1
108*8269e767SBrooks Davisis returned and the global variable errno is set to indicate the error.
109*8269e767SBrooks Davis.Sh ERRORS
110*8269e767SBrooks DavisThe
111*8269e767SBrooks Davis.Fn cap_ioctls_limit
112*8269e767SBrooks Davisand
113*8269e767SBrooks Davis.Fn cap_ioctls_get
114*8269e767SBrooks Davissystem calls will fail if:
115*8269e767SBrooks Davis.Bl -tag -width Er
116*8269e767SBrooks Davis.It Bq Er EBADF
117*8269e767SBrooks DavisThe
118*8269e767SBrooks Davis.Fa fd
119*8269e767SBrooks Davisargument is not a valid descriptor.
120*8269e767SBrooks Davis.It Bq Er EFAULT
121*8269e767SBrooks DavisThe
122*8269e767SBrooks Davis.Fa cmds
123*8269e767SBrooks Davisargument points at an invalid address.
124*8269e767SBrooks Davis.It Bq Er ENOSYS
125*8269e767SBrooks DavisThe running kernel was compiled without
126*8269e767SBrooks Davis.Cd "options CAPABILITY_MODE" .
127*8269e767SBrooks Davis.El
128*8269e767SBrooks Davis.Pp
129*8269e767SBrooks DavisThe
130*8269e767SBrooks Davis.Fn cap_ioctls_limit
131*8269e767SBrooks Davissystem call may also return the following errors:
132*8269e767SBrooks Davis.Bl -tag -width Er
133*8269e767SBrooks Davis.It Bq Er EINVAL
134*8269e767SBrooks DavisThe
135*8269e767SBrooks Davis.Fa ncmds
136*8269e767SBrooks Davisargument is greater than
137*8269e767SBrooks Davis.Va 256 .
138*8269e767SBrooks Davis.It Bq Er ENOTCAPABLE
139*8269e767SBrooks Davis.Fa cmds
140*8269e767SBrooks Daviswould expand the list of allowed
141*8269e767SBrooks Davis.Xr ioctl 2
142*8269e767SBrooks Daviscommands.
143*8269e767SBrooks Davis.El
144*8269e767SBrooks Davis.Sh SEE ALSO
145*8269e767SBrooks Davis.Xr cap_fcntls_limit 2 ,
146*8269e767SBrooks Davis.Xr cap_rights_limit 2 ,
147*8269e767SBrooks Davis.Xr ioctl 2
148*8269e767SBrooks Davis.Sh HISTORY
149*8269e767SBrooks DavisThe
150*8269e767SBrooks Davis.Fn cap_ioctls_get
151*8269e767SBrooks Davisand
152*8269e767SBrooks Davis.Fn cap_ioctls_limit
153*8269e767SBrooks Davissystem calls first appeared in
154*8269e767SBrooks Davis.Fx 8.3 .
155*8269e767SBrooks DavisSupport for capabilities and capabilities mode was developed as part of the
156*8269e767SBrooks Davis.Tn TrustedBSD
157*8269e767SBrooks DavisProject.
158*8269e767SBrooks Davis.Sh AUTHORS
159*8269e767SBrooks DavisThis function was created by
160*8269e767SBrooks Davis.An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
161*8269e767SBrooks Davisunder sponsorship of the FreeBSD Foundation.
162