caps.bend checks
raw source on the hub · import bend-osdev-caps@0.1.0.0/caps.bend as Caps
bend-osdev-caps: Linux capability sets, as capabilities(7) documents them. This file: capability numbers, sets, and the thread's and file's sets. exec.bend: the transformation during execve(2). adjust.bend: capset(2) and the prctl(2) bounding-set and ambient operations.
A capability set holds bit k for capability k, from CAP_CHOWN (0) to CAP_CHECKPOINT_RESTORE (40): bits 0 to 31 in a native U32, bits 32 to 40 in a Word(9n) (CapSetW, internal). The set operations work bit by bit; the width-n forms (CapBits) are what the laws are proved by induction on, for both parts.
A thread has five sets (CapState): permitted, inheritable, effective, bounding and ambient. A file has a permitted and an inheritable set and an effective bit (CapFileSets). execve, capset, and the prctl(2) bounding-set and ambient operations are modelled on a credential (CapCred): the sets, the real, effective and saved user IDs, and the securebits SECBIT_NOROOT and SECBIT_NO_CAP_AMBIENT_RAISE.
2 imports
import Base import bend-osdev-word64@0.1.0.0/word64.bend as W
Types
type CapSetW source · line 261 · raw
Data
A set is two words: capabilities 0 to 31 are the bits of a native U32 (bit k is capability k), and capabilities 32 to 40 a Word(9n) (bit j is capability 32 + j). Ten machine words, where a Word(41n) cost forty-one (and a CapState of five of them was more than Bend's C backend compiles: bendlang/bend#1069). The high part is exactly nine bits, so every value of the type is a set of capabilities 0 to 40, with one representation each. Internal: use the CapSet defs.
CapSetW@lo:U32 -> @hi:Word(9n) -> CapSetW
type CapState source · line 406 · raw
Data
CapState@permitted:CapSet -> @inheritable:CapSet -> @effective:CapSet -> @bounding:CapSet -> @ambient:CapSet -> CapState
type CapCred source · line 453 · raw
Data
A thread's credentials: real, effective and saved set-user-ID, the securebits SECBIT_NOROOT and SECBIT_NO_CAP_AMBIENT_RAISE, and the sets.
CapCred@ruid:U32 -> @euid:U32 -> @suid:U32 -> @noroot:Bool -> @no_ambient_raise:Bool -> @sets:CapState -> CapCred
type CapFileSets source · line 487 · raw
Data
A file's capabilities (the security.capability attribute)
CapFileSets@permitted:CapSet -> @inheritable:CapSet -> @effective:Bool -> CapFileSets
type CapFile source · line 492 · raw
Data
An executable: its owner, its set-user-ID and set-group-ID bits, and its capabilities, if it has any
CapFile@uid:U32 -> @setuid:Bool -> @setgid:Bool -> @caps:Maybe<&2, CapFileSets> -> CapFile
type CapsKernel source · line 498 · raw
Data
The kernel's choices: the highest capability it supports (/proc/sys/kernel/cap_last_cap; at most 40 here) and whether file capabilities are on (off when booted with no_file_caps)
CapsKernel@last_cap:U32 -> @file_caps:Bool -> CapsKernel
type CapsError source · line 517 · raw
Data
Why a call fails
CapsInvalidCapCapsError
CapsPermittedGrowsCapsError
CapsEffectiveNotPermittedCapsError
CapsInheritableNotBoundedCapsError
CapsInheritableNotPermittedCapsError
CapsNoSetpcapCapsError
CapsAmbientRaiseLockedCapsError
CapsAmbientNotAllowedCapsError
CapsCapabilityDumbCapsError
Definitions
def Cap.chown source · line 23 · raw
U32
def Cap.dac_override source · line 26 · raw
U32
def Cap.dac_read_search source · line 29 · raw
U32
def Cap.fowner source · line 32 · raw
U32
def Cap.fsetid source · line 35 · raw
U32
def Cap.kill source · line 38 · raw
U32
def Cap.setgid source · line 41 · raw
U32
def Cap.setuid source · line 44 · raw
U32
def Cap.setpcap source · line 47 · raw
U32
def Cap.linux_immutable source · line 50 · raw
U32
def Cap.net_bind_service source · line 53 · raw
U32
def Cap.net_broadcast source · line 56 · raw
U32
def Cap.net_admin source · line 59 · raw
U32
def Cap.net_raw source · line 62 · raw
U32
def Cap.ipc_lock source · line 65 · raw
U32
def Cap.ipc_owner source · line 68 · raw
U32
def Cap.sys_module source · line 71 · raw
U32
def Cap.sys_rawio source · line 74 · raw
U32
def Cap.sys_chroot source · line 77 · raw
U32
def Cap.sys_ptrace source · line 80 · raw
U32
def Cap.sys_pacct source · line 83 · raw
U32
def Cap.sys_admin source · line 86 · raw
U32
def Cap.sys_boot source · line 89 · raw
U32
def Cap.sys_nice source · line 92 · raw
U32
def Cap.sys_resource source · line 95 · raw
U32
def Cap.sys_time source · line 98 · raw
U32
def Cap.sys_tty_config source · line 101 · raw
U32
def Cap.mknod source · line 104 · raw
U32
def Cap.lease source · line 107 · raw
U32
def Cap.audit_write source · line 110 · raw
U32
def Cap.audit_control source · line 113 · raw
U32
def Cap.setfcap source · line 116 · raw
U32
def Cap.mac_override source · line 119 · raw
U32
def Cap.mac_admin source · line 122 · raw
U32
def Cap.syslog source · line 125 · raw
U32
def Cap.wake_alarm source · line 128 · raw
U32
def Cap.block_suspend source · line 131 · raw
U32
def Cap.audit_read source · line 134 · raw
U32
def Cap.perfmon source · line 137 · raw
U32
def Cap.bpf source · line 140 · raw
U32
def Cap.checkpoint_restore source · line 143 · raw
U32
def Cap.count source · line 145 · raw
U32
def Cap.names source · line 148 · raw
List<&2, String>
def Cap.valid source · line 152 · raw
@k:U32 -> Bool
whether k names a capability (0 to 40)
def Cap.name.go source · line 155 · raw
@v:Bool -> @k:U32 -> Maybe<&2, String>
def Cap.name source · line 163 · raw
@+k:U32 -> Maybe<&2, String>
the name of capability k, such as "CAP_CHOWN"
def Cap.of_name.hit source · line 166 · raw
@hit:Bool -> @k:U32 -> @rest:Maybe<&2, U32> -> Maybe<&2, U32>
def Cap.of_name.go source · line 173 · raw
@xs:List<&2, String> -> @+s:String -> @+k:U32 -> Maybe<&2, U32>
def Cap.of_name source · line 181 · raw
@s:String -> Maybe<&2, U32>
the number of the capability named s
def CapBits.all source · line 187 · raw
@n:Nat -> Word(n)
the set of every capability below n
def CapBits.sub.bit source · line 195 · raw
@a:Bool -> @b:Bool -> @r:Bool -> Bool
one bit of a subset test: a bit in a must be in b; r is the rest
def CapBits.subset source · line 207 · raw
@n:Nat -> @a:Word(n) -> @b:Word(n) -> Bool
every capability in a is in b
def CapBits.single source · line 217 · raw
@n:Nat -> @k:Nat -> Word(n)
the set holding capability k alone (empty if k >= n)
def CapBits.has source · line 229 · raw
@n:Nat -> @s:Word(n) -> @k:Nat -> Bool
whether capability k is in s
def CapBits.to_list source · line 241 · raw
@n:Nat -> @s:Word(n) -> @+k:U32 -> List<&2, U32>
the capabilities in s, in increasing order, numbered from k
def CapSet source · line 264 · raw
Data
def CapSet.empty source · line 267 · raw
CapSet
def CapSet.full source · line 270 · raw
CapSet
def CapSet.union source · line 273 · raw
@a:CapSet -> @b:CapSet -> CapSet
def CapSet.inter source · line 278 · raw
@a:CapSet -> @b:CapSet -> CapSet
def CapSet.minus source · line 284 · raw
@a:CapSet -> @b:CapSet -> CapSet
the capabilities of a not in b
def CapSet.subset source · line 290 · raw
@a:CapSet -> @b:CapSet -> Bool
a within b: no bit of a outside b (on the low word, a & ~b == 0)
def CapSet.is_eq source · line 295 · raw
@a:CapSet -> @b:CapSet -> Bool
def CapSetW.single.go source · line 300 · raw
@low:Bool -> @+k:U32 -> CapSet
def CapSetW.single source · line 308 · raw
@+k:U32 -> CapSet
the set holding capability k alone (k is 0 to 40)
def CapSet.of.go source · line 311 · raw
@v:Bool -> @k:U32 -> CapSet
def CapSet.of source · line 319 · raw
@+k:U32 -> CapSet
the set holding capability k alone (empty if k is not a capability)
def CapSet.has.go source · line 322 · raw
@v:Bool -> @s:CapSet -> @k:U32 -> Bool
def CapSet.has source · line 330 · raw
@s:CapSet -> @+k:U32 -> Bool
whether capability k is in s
def CapSet.add source · line 333 · raw
@s:CapSet -> @k:U32 -> CapSet
def CapSet.del source · line 336 · raw
@s:CapSet -> @k:U32 -> CapSet
def CapSet.from_list source · line 339 · raw
@xs:List<&2, U32> -> CapSet
def CapSetW.push source · line 346 · raw
@b:Bool -> @k:U32 -> @rest:List<&2, U32> -> List<&2, U32>
def CapSetW.lo_list source · line 354 · raw
@n:Nat -> @+w:U32 -> @+k:U32 -> @rest:List<&2, U32> -> List<&2, U32>
the capabilities among the low n bits of w, numbered from k, then rest
def CapSet.to_list source · line 361 · raw
@s:CapSet -> List<&2, U32>
def CapSetW.bit source · line 366 · raw
@b:Bool -> U32
def CapSetW.word_u32 source · line 374 · raw
@n:Nat -> @w:Word(n) -> U32
the value of the n bits of w, and the n low bits of a, as native words
def CapSetW.u32_word source · line 383 · raw
@n:Nat -> @+a:U32 -> Word(n)
def CapSet.to_w64 source · line 391 · raw
@s:CapSet -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
the 64-bit mask of a set, as capget(2) and /proc/<pid>/status show it
def CapSet.from_w64 source · line 397 · raw
@+v:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> CapSet
the set of the low 41 bits of a 64-bit mask
def CapSet.show source · line 401 · raw
@s:CapSet -> String
16 hex digits, as the CapEff line of /proc/<pid>/status
def CapState.permitted source · line 409 · raw
@s:CapState -> CapSet
def CapState.inheritable source · line 414 · raw
@s:CapState -> CapSet
def CapState.effective source · line 419 · raw
@s:CapState -> CapSet
def CapState.bounding source · line 424 · raw
@s:CapState -> CapSet
def CapState.ambient source · line 429 · raw
@s:CapState -> CapSet
def CapState.with_bounding source · line 434 · raw
@s:CapState -> @b:CapSet -> CapState
def CapState.with_ambient source · line 439 · raw
@s:CapState -> @a:CapSet -> CapState
def CapState.valid source · line 446 · raw
@s:CapState -> Bool
capabilities(7)'s invariants: effective within permitted, and no capability ambient unless it is both permitted and inheritable
def CapCred.ruid source · line 456 · raw
@c:CapCred -> U32
def CapCred.euid source · line 461 · raw
@c:CapCred -> U32
def CapCred.suid source · line 466 · raw
@c:CapCred -> U32
def CapCred.no_ambient_raise source · line 471 · raw
@c:CapCred -> Bool
def CapCred.sets source · line 476 · raw
@c:CapCred -> CapState
def CapCred.with_sets source · line 481 · raw
@c:CapCred -> @st:CapState -> CapCred
def CapsKernel.linux source · line 502 · raw
CapsKernel
Linux since 5.9: capabilities 0 to 40, file capabilities on
def CapsKernel.file_caps source · line 505 · raw
@k:CapsKernel -> Bool
def CapsKernel.valid source · line 511 · raw
@k:CapsKernel -> @+c:U32 -> Bool
whether c names a capability this kernel supports
def CapsError.errno source · line 530 · raw
@e:CapsError -> U32
the errno the kernel answers: EINVAL (22) for a capability it does not support, EPERM (1) otherwise
def Caps.or source · line 552 · raw
@r:Result<&2, &2, CapsError, CapCred> -> @c:CapCred -> CapCred
the credentials after a call: the new ones, or c if it failed
def Caps.sets_or source · line 560 · raw
@r:Result<&2, &2, CapsError, CapCred> -> @s:CapState -> CapState
the sets after a call, or s if it failed