RIGHTS(4)
π RIGHTS(4) β Capability rights, bestie π
πΈ NAME πΈ
Capability rights β the Capsicum capability rights situation for file descriptors, and yes bestie this is the whole vibe.
β¨ DESCRIPTION β¨
Okay so when a file descriptor gets created by a function like fhopen(2), kqueue(2), mq_open(2), open(2), pdfork(2), pipe(2), shm_open(2), socket(2) or socketpair(2), it starts out with all the capability rights. And for accept(2), accept4(2) or openat(2), it inherits capability rights from the βparentβ file descriptor. Iconic inheritance behavior, honestly.
Those rights can be reduced β but never expanded, no cap β by using the cap_rights_limit(2), cap_fcntls_limit(2) and cap_ioctls_limit(2) system calls. Once the capability rights are reduced, operations on the file descriptor are limited to those permitted by rights. Thatβs the whole point, periodt.
The complete list of capability rights is below. The cap_rights_t type stores the list of capability rights. The cap_rights_init(3) family of functions should be used to manage the structure. Use the right tools for the job, babes.
π¦ RIGHTS π¦
Heads up: rights are not simple bitmasks, and they cannot be bitwise-ORed together. Not me warning you again. See cap_rights_init(3) for the details.
The following rights are available:
CAP_ACCEPTβ Letsaccept(2)andaccept4(2)happen.CAP_ACL_CHECKβ Letsacl_valid_fd_np(3)happen.CAP_ACL_DELETEβ Letsacl_delete_fd_np(3)happen.CAP_ACL_GETβ Letsacl_get_fd(3)andacl_get_fd_np(3)happen.CAP_ACL_SETβ Letsacl_set_fd(3)andacl_set_fd_np(3)happen.CAP_BINDβ When youβre not in capabilities mode, letsbind(2)andbindat(2)work with the special valueAT_FDCWDin thefdparameter. Also note that sockets can become bound implicitly as a result ofconnect(2)orsend(2), and socket options set withsetsockopt(2)may also affect binding behavior. Sneaky little binding behavior, but okay.CAP_BINDATβ Letsbindat(2)happen. This right has to be present on the directory descriptor. This right includes theCAP_LOOKUPright.CAP_CHFLAGSATβ An alias toCAP_FCHFLAGSandCAP_LOOKUP.CAP_CONNECTβ When youβre not in capabilities mode, letsconnect(2)andconnectat(2)work with the special valueAT_FDCWDin thefdparameter. This right is also required forsendto(2)with a non-NULL destination address. Very βyou need me for that tooβ energy.CAP_CONNECTATβ Letsconnectat(2)happen. This right has to be present on the directory descriptor. This right includes theCAP_LOOKUPright.CAP_CREATEβ Letsopenat(2)use theO_CREATflag.CAP_EVENTβ Letsselect(2),poll(2), andkevent(2)be used to monitor the file descriptor for events. Event-watching rights, slay.CAP_EXTATTR_DELETEβ Letsextattr_delete_fd(2)happen.CAP_EXTATTR_GETβ Letsextattr_get_fd(2)happen.CAP_EXTATTR_LISTβ Letsextattr_list_fd(2)happen.CAP_EXTATTR_SETβ Letsextattr_set_fd(2)happen.CAP_FCHDIRβ Letsfchdir(2)happen.CAP_FCHFLAGSβ Letsfchflags(2)andchflagsat(2)happen if theCAP_LOOKUPright is also present.CAP_FCHMODβ Letsfchmod(2)andfchmodat(2)happen if theCAP_LOOKUPright is also present.CAP_FCHMODATβ An alias toCAP_FCHMODandCAP_LOOKUP.CAP_FCHOWNβ Letsfchown(2)andfchownat(2)happen if theCAP_LOOKUPright is also present.CAP_FCHOWNATβ An alias toCAP_FCHOWNandCAP_LOOKUP.CAP_FCHROOTβ Letsfchroot(2)happen.CAP_FCNTLβ Letsfcntl(2)happen. Note that only theF_GETFL,F_SETFL,F_GETOWNandF_SETOWNcommands require this capability right. Also note that the list of permitted commands can be further limited with thecap_fcntls_limit(2)system call.CAP_FEXECVEβ Letsfexecve(2)andopenat(2)use theO_EXECflag;CAP_READis also required. Teamwork makes the dream work.CAP_FLOCKβ Letsflock(2),fcntl(2)(withF_GETLK,F_SETLK,F_SETLKWorF_SETLK_REMOTEflag) andopenat(2)(withO_EXLOCKorO_SHLOCKflag) happen.CAP_FPATHCONFβ Letsfpathconf(2)happen.CAP_FSCKβ Lets UFS background-fsck operations happen on the descriptor.CAP_FSTATβ Letsfstat(2)andfstatat(2)happen if theCAP_LOOKUPright is also present.CAP_FSTATATβ An alias toCAP_FSTATandCAP_LOOKUP.CAP_FSTATFSβ Letsfstatfs(2)happen.CAP_FSYNCβ Letsaio_fsync(2),fdatasync(2),fsync(2)andopenat(2)with theO_DSYNC,O_FSYNC, orO_SYNCflag happen.CAP_FTRUNCATEβ Letsftruncate(2)andopenat(2)with theO_TRUNCflag happen.CAP_FUTIMESβ Letsfutimens(2)andfutimes(2)happen, and letsfutimesat(2)andutimensat(2)happen if theCAP_LOOKUPright is also present.CAP_FUTIMESATβ An alias toCAP_FUTIMESandCAP_LOOKUP.CAP_GETPEERNAMEβ Letsgetpeername(2)happen.CAP_GETSOCKNAMEβ Letsgetsockname(2)happen.CAP_GETSOCKOPTβ Letsgetsockopt(2)happen.CAP_INOTIFY_ADDβ Letsinotify_add_watch(2)andinotify_add_watch_at(2)happen.CAP_INOTIFY_RMβ Letsinotify_rm_watch(2)happen.CAP_IOCTLβ Letsioctl(2)happen. Be aware that this system call has enormous scope, including potentially global scope for some objects. The list of permitted ioctl commands can be further limited with thecap_ioctls_limit(2)system call. Huge scope, handle with care, bestie.CAP_KQUEUEβ An alias toCAP_KQUEUE_CHANGEandCAP_KQUEUE_EVENT.CAP_KQUEUE_CHANGEβ Letskevent(2)happen on akqueue(2)descriptor that modifies the list of monitored events (thechangelistargument is non-NULL).CAP_KQUEUE_EVENTβ Letskevent(2)happen on akqueue(2)descriptor that monitors events (theeventlistargument is non-NULL).CAP_EVENTis also required on file descriptors that will be monitored usingkevent(2). Yes, both. Itβs giving teamwork.CAP_LINKAT_SOURCEβ Letslinkat(2)happen on the source directory descriptor. This right includes theCAP_LOOKUPright.
Warning:CAP_LINKAT_SOURCEmakes it possible to link files in a directory for which file descriptors exist that have additional rights. For example, a file stored in a directory that does not allowCAP_READmay be linked in another directory that does allowCAP_READ, thereby granting read access to a file that is otherwise unreadable. Thatβs not a cute little loophole, thatβs a real warning.
CAP_LINKAT_TARGETβ Letslinkat(2)happen on the target directory descriptor. This right includes theCAP_LOOKUPright.CAP_LISTENβ Letslisten(2)happen; not much use (generally) withoutCAP_BIND.CAP_LOOKUPβ Lets the file descriptor be used as a starting directory for calls such aslinkat(2),openat(2), andunlinkat(2).CAP_MAC_GETβ Letsmac_get_fd(3)happen.CAP_MAC_SETβ Letsmac_set_fd(3)happen.CAP_MKDIRATβ Letsmkdirat(2)happen. This right includes theCAP_LOOKUPright.CAP_MKFIFOATβ Letsmkfifoat(2)happen. This right includes theCAP_LOOKUPright.CAP_MKNODATβ Letsmknodat(2)happen. This right includes theCAP_LOOKUPright.CAP_MMAPβ Letsmmap(2)happen with thePROT_NONEprotection.CAP_MMAP_Rβ Letsmmap(2)happen with thePROT_READprotection. This right includes theCAP_READandCAP_SEEKrights.CAP_MMAP_RWβ An alias toCAP_MMAP_RandCAP_MMAP_W.CAP_MMAP_RWXβ An alias toCAP_MMAP_R,CAP_MMAP_WandCAP_MMAP_X.CAP_MMAP_RXβ An alias toCAP_MMAP_RandCAP_MMAP_X.CAP_MMAP_Wβ Letsmmap(2)happen with thePROT_WRITEprotection. This right includes theCAP_WRITEandCAP_SEEKrights.CAP_MMAP_WXβ An alias toCAP_MMAP_WandCAP_MMAP_X.CAP_MMAP_Xβ Letsmmap(2)happen with thePROT_EXECprotection. This right includes theCAP_SEEKright.CAP_PDGETPIDβ Letspdgetpid(2)happen.CAP_PDKILLβ Letspdkill(2)happen.CAP_PDWAITβ Letspdwait(2)happen.CAP_PEELOFFβ Letssctp_peeloff(2)happen.CAP_PREADβ An alias toCAP_READandCAP_SEEK.CAP_PWRITEβ An alias toCAP_SEEKandCAP_WRITE.CAP_READβ Letsaio_read(2)happen (CAP_SEEKis also required), letsopenat(2)use theO_RDONLYflag, and letsread(2),readv(2),recv(2),recvfrom(2),recvmsg(2),pread(2)(CAP_SEEKis also required),preadv(2)(CAP_SEEKis also required),getdents(2),getdirentries(2), and related system calls happen. A whole little read squad.CAP_RECVβ An alias toCAP_READ.CAP_RENAMEAT_SOURCEβ Letsrenameat(2)happen on the source directory descriptor. This right includes theCAP_LOOKUPright.
Warning:CAP_RENAMEAT_SOURCEmakes it possible to move files to a directory for which file descriptors exist that have additional rights. For example, a file stored in a directory that does not allowCAP_READmay be moved to another directory that does allowCAP_READ, thereby granting read access to a file that is otherwise unreadable. Again: real warning, not just drama.
CAP_RENAMEAT_TARGETβ Letsrenameat(2)happen on the target directory descriptor. This right includes theCAP_LOOKUPright.CAP_SEEKβ Lets operations that seek on the file descriptor happen, such aslseek(2), but itβs also required for I/O system calls that can read or write at any position in the file, such aspread(2)andpwrite(2).CAP_SEM_GETVALUEβ Letssem_getvalue(3)happen.CAP_SEM_POSTβ Letssem_post(3)happen.CAP_SEM_WAITβ Letssem_wait(3)andsem_trywait(3)happen.CAP_SENDβ An alias toCAP_WRITE.CAP_SETSOCKOPTβ Letssetsockopt(2)happen; this controls various aspects of socket behavior and may affect binding, connecting, and other behaviors with global scope.CAP_SHUTDOWNβ Lets explicitshutdown(2)happen; closing the socket will also generally shut down any connections on it.CAP_SYMLINKATβ the green light forsymlinkat(2)πβ¨ and ngl it comes bundled with theCAP_LOOKUPright, so you get lookups too. package deal, bestie πCAP_TTYHOOKβ lets you configure TTY hooks on that file descriptor, likesnp(4)π which is very much a "with great power" situation, so use it responsibly πCAP_UNLINKATβ permission slip forunlinkat(2)andrenameat(2)ποΈ but here's the nuance: you only need this right forrenameat(2)on the destination directory descriptor if the destination object already exists and is gonna get removed by the rename. tiny detail, huge difference, iykyk. aaaand it includes theCAP_LOOKUPright too π«ΆCAP_WRITEβ the big one, the main character π this lets throughaio_write(2),openat(2)with theO_WRONLYandO_APPENDflags set,send(2),sendmsg(2),sendto(2),write(2),writev(2),pwrite(2),pwritev(2)and all their related system calls π₯ but bestie, the fine print is fine:- for
sendto(2)with a non-NULL connection address, you also needCAP_CONNECTπ‘ - for
openat(2)with theO_WRONLYflag but without theO_APPENDorO_TRUNCflag, you also needCAP_SEEKπ― - for
aio_write(2),pwrite(2)andpwritev(2),CAP_SEEKis also required π
- for
β¨ SEE ALSO β¨
okay so this is the friend group π like, the whole extended roster, no cap:
accept(2), accept4(2), aio_fsync(2), aio_read(2), aio_write(2), bind(2), bindat(2), cap_enter(2), cap_fcntls_limit(2), cap_ioctls_limit(2), cap_rights_limit(2), chflagsat(2), connect(2), connectat(2), extattr_delete_fd(2), extattr_get_fd(2), extattr_list_fd(2), extattr_set_fd(2), fchflags(2), fchmod(2), fchmodat(2), fchown(2), fchownat(2), fcntl(2), fexecve(2), fhopen(2), flock(2), fpathconf(2), fstat(2), fstatat(2), fstatfs(2), fsync(2), ftruncate(2), futimes(2), getdents(2), getdirentries(2), getpeername(2), getsockname(2), getsockopt(2), ioctl(2), kevent(2), kqueue(2), linkat(2), listen(2), mmap(2), mq_open(2), open(2), openat(2),
pdfork(2), pdgetpid(2), pdkill(2), pdwait4(2), pipe(2), poll(2), pread(2), preadv(2), pwrite(2), pwritev(2), read(2), readv(2), recv(2), recvfrom(2), recvmsg(2), renameat(2), sctp_peeloff(2), select(2), send(2), sendmsg(2), sendto(2), setsockopt(2), shm_open(2), shutdown(2), socket(2), socketpair(2), symlinkat(2), unlinkat(2), write(2), writev(2),
acl_delete_fd_np(3), acl_get_fd(3), acl_get_fd_np(3), acl_set_fd(3), acl_set_fd_np(3), acl_valid_fd_np(3), mac_get_fd(3), mac_set_fd(3), sem_getvalue(3), sem_post(3), sem_trywait(3), sem_wait(3), capsicum(4), snp(4)
like, that's the whole group chat, go say hi π¦
πΈ HISTORY πΈ
so basically, support for capabilities and capabilities mode was developed as part of the TrustedBSD Project π§ a little origin story, we love to see it β¨
π AUTHORS π
this manual page was created by Pawel Jakub Dawidek <pawel@dawidek.net> π«Ά under sponsorship from the FreeBSD Foundation, based on the cap_new(2) manual page by Robert Watson <rwatson@FreeBSD.org> β collaborative queen behavior, honestly π
and that's a wrap on rights(4), bestie!! π this lil beauty comes to you from Debian, dated May 22, 2025 β go forth and gate those file descriptors responsibly, mwah ππ
β¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 2008-2010 Robert N. M. Watson
- Copyright (c) 2012-2013 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms