CAP_IOCTLS_LIMIT(2)
π
CAP_IOCTLS_LIMIT(2) β the System Calls Manual one, bestie
okay so. you're in the System Calls Manual section of the CAP_IOCTLS_LIMIT(2) page and we're about to talk about cap_ioctls_limit and cap_ioctls_get, which are literally the bouncers for your ioctl commands. no cap. π
β¨ NAME β¨
cap_ioctls_limit, cap_ioctls_get β manage allowed ioctl commands
π LIBRARY π
Standard C Library (libc, -lc) π«Ά
π¦ SYNOPSIS π¦
#include <sys/capsicum.h>
int
cap_ioctls_limit(int fd, const unsigned long *cmds, size_t ncmds);
ssize_t
cap_ioctls_get(int fd, unsigned long *cmds, size_t maxcmds);
πΈ DESCRIPTION πΈ
so here's the tea. if a file descriptor has been granted the CAP_IOCTL capability right, you can selectively reduce the list of allowed ioctl(2) commands with the cap_ioctls_limit() system call. and when I say reduce, I mean reduce β you can never expand it back. that's the whole point, bestie, it's a one-way door. πͺ
- the
cmdsargument? that's an array ofioctl(2)commands. - the
ncmdsargument? that's how many elements are chillin' in that array. - there can be up to 256 elements in the array, periodt.
- and including an element that has been previously revoked will generate an error. do not try it. π
after a successful call, only those commands listed in the array may be used. that's it, that's the list, that's the vibe check. β¨
now, the flip side: the list of allowed ioctl commands for a given file descriptor can be obtained with the cap_ioctls_get() system call. π
cmdspoints at memory that can hold up tomaxcmdsvalues.- the function populates the provided buffer with up to
maxcmdselements, but always returns the total number of ioctl commands allowed for the given file descriptor. the way it gives you the full count even when it can't fit them all?? iconic. - wanna just get the total number of ioctl commands for the given file descriptor? easy. pass
NULLas thecmdsargument and0as themaxcmdsargument. π - and if all ioctl commands are allowed (meaning the
CAP_IOCTLcapability right is assigned to the file descriptor and thecap_ioctls_limit()system call was never called for this file descriptor), thencap_ioctls_get()will returnCAP_IOCTLS_ALLand will not modify the buffer pointed to by thecmdsargument. hands off the buffer, she said. π«Ά
π₯ RETURN VALUES π₯
cap_ioctls_limit() returns the value 0 if successful β slay. otherwise the value -1 is returned and the global variable errno is set to indicate the error. π
cap_ioctls_get(), if successful, returns the total number of allowed ioctl commands, or the value CAP_IOCTLS_ALL if all ioctls commands are allowed. on failure the value -1 is returned and the global variable errno is set to indicate the error. it's giving success or chaos, nothing in between.
π ERRORS π
cap_ioctls_limit() succeeds unless:
[EBADF]β thefdargument is not a valid descriptor.[EFAULT]β thecmdsargument points at an invalid address.[EINVAL]β thencmdsargument is greater than 256.[ENOTCAPABLE]βcmdswould expand the list of allowedioctl(2)commands. (rude of you to even try, honestly.)
cap_ioctls_get() succeeds unless:
[EBADF]β thefdargument is not a valid descriptor.[EFAULT]β thecmdsargument points at invalid address.
π SEE ALSO π
cap_fcntls_limit(2), cap_rights_limit(2), ioctl(2)
π HISTORY π
The cap_ioctls_get() and cap_ioctls_limit() system calls first appeared in FreeBSD 8.3. support for capabilities and capabilities mode was developed as part of the TrustedBSD Project. history really said "let there be sandboxing." π
π AUTHORS π
This function was created by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship of the FreeBSD Foundation. we love a sponsored icon. π
and that's the whole page, bestie!! this one's from the Debian build of the page, dated May 5, 2020, and yes it lives under the name CAP_IOCTLS_LIMIT(2). go forth and limit those ioctls responsibly πβ¨π¦
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2012 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms