Debian Codegraph @

capability/enum.go

raw symbols SCIP
1 // Copyright 2024 The Capability Authors.
2 // Copyright 2013 Suryandaru Triandana <[email protected]>
3 // All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
7
8 package capability
9
10 import "slices"
11
12 type CapType uint
13
14 func (c CapType) String() string {
15 switch c {
16 case EFFECTIVE:
17 return "effective"
18 case PERMITTED:
19 return "permitted"
20 case INHERITABLE:
21 return "inheritable"
22 case BOUNDING:
23 return "bounding"
24 case CAPS:
25 return "caps"
26 case AMBIENT:
27 return "ambient"
28 }
29 return "unknown"
30 }
31
32 const (
33 EFFECTIVE CapType = 1 << iota
34 PERMITTED
35 INHERITABLE
36 BOUNDING
37 AMBIENT
38
39 CAPS = EFFECTIVE | PERMITTED | INHERITABLE
40 BOUNDS = BOUNDING
41 AMBS = AMBIENT
42 )
43
44 //go:generate go run enumgen/gen.go
45 type Cap int
46
47 // POSIX-draft defined capabilities and Linux extensions.
48 //
49 // Defined in https://github.com/torvalds/linux/blob/master/include/uapi/linux/capability.h
50 const (
51 // In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
52 // overrides the restriction of changing file ownership and group
53 // ownership.
54 CAP_CHOWN = Cap(0)
55
56 // Override all DAC access, including ACL execute access if
57 // [_POSIX_ACL] is defined. Excluding DAC access covered by
58 // CAP_LINUX_IMMUTABLE.
59 CAP_DAC_OVERRIDE = Cap(1)
60
61 // Overrides all DAC restrictions regarding read and search on files
62 // and directories, including ACL restrictions if [_POSIX_ACL] is
63 // defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE.
64 CAP_DAC_READ_SEARCH = Cap(2)
65
66 // Overrides all restrictions about allowed operations on files, where
67 // file owner ID must be equal to the user ID, except where CAP_FSETID
68 // is applicable. It doesn't override MAC and DAC restrictions.
69 CAP_FOWNER = Cap(3)
70
71 // Overrides the following restrictions that the effective user ID
72 // shall match the file owner ID when setting the S_ISUID and S_ISGID
73 // bits on that file; that the effective group ID (or one of the
74 // supplementary group IDs) shall match the file owner ID when setting
75 // the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
76 // cleared on successful return from chown(2) (not implemented).
77 CAP_FSETID = Cap(4)
78
79 // Overrides the restriction that the real or effective user ID of a
80 // process sending a signal must match the real or effective user ID
81 // of the process receiving the signal.
82 CAP_KILL = Cap(5)
83
84 // Allows setgid(2) manipulation
85 // Allows setgroups(2)
86 // Allows forged gids on socket credentials passing.
87 CAP_SETGID = Cap(6)
88
89 // Allows set*uid(2) manipulation (including fsuid).
90 // Allows forged pids on socket credentials passing.
91 CAP_SETUID = Cap(7)
92
93 // Linux-specific capabilities
94
95 // Without VFS support for capabilities:
96 // Transfer any capability in your permitted set to any pid,
97 // remove any capability in your permitted set from any pid
98 // With VFS support for capabilities (neither of above, but)
99 // Add any capability from current's capability bounding set
100 // to the current process' inheritable set
101 // Allow taking bits out of capability bounding set
102 // Allow modification of the securebits for a process
103 CAP_SETPCAP = Cap(8)
104
105 // Allow modification of S_IMMUTABLE and S_APPEND file attributes
106 CAP_LINUX_IMMUTABLE = Cap(9)
107
108 // Allows binding to TCP/UDP sockets below 1024
109 // Allows binding to ATM VCIs below 32
110 CAP_NET_BIND_SERVICE = Cap(10)
111
112 // Allow broadcasting, listen to multicast
113 CAP_NET_BROADCAST = Cap(11)
114
115 // Allow interface configuration
116 // Allow administration of IP firewall, masquerading and accounting
117 // Allow setting debug option on sockets
118 // Allow modification of routing tables
119 // Allow setting arbitrary process / process group ownership on
120 // sockets
121 // Allow binding to any address for transparent proxying (also via NET_RAW)
122 // Allow setting TOS (type of service)
123 // Allow setting promiscuous mode
124 // Allow clearing driver statistics
125 // Allow multicasting
126 // Allow read/write of device-specific registers
127 // Allow activation of ATM control sockets
128 CAP_NET_ADMIN = Cap(12)
129
130 // Allow use of RAW sockets
131 // Allow use of PACKET sockets
132 // Allow binding to any address for transparent proxying (also via NET_ADMIN)
133 CAP_NET_RAW = Cap(13)
134
135 // Allow locking of shared memory segments
136 // Allow mlock and mlockall (which doesn't really have anything to do
137 // with IPC)
138 CAP_IPC_LOCK = Cap(14)
139
140 // Override IPC ownership checks
141 CAP_IPC_OWNER = Cap(15)
142
143 // Insert and remove kernel modules - modify kernel without limit
144 CAP_SYS_MODULE = Cap(16)
145
146 // Allow ioperm/iopl access
147 // Allow sending USB messages to any device via /proc/bus/usb
148 CAP_SYS_RAWIO = Cap(17)
149
150 // Allow use of chroot()
151 CAP_SYS_CHROOT = Cap(18)
152
153 // Allow ptrace() of any process
154 CAP_SYS_PTRACE = Cap(19)
155
156 // Allow configuration of process accounting
157 CAP_SYS_PACCT = Cap(20)
158
159 // Allow configuration of the secure attention key
160 // Allow administration of the random device
161 // Allow examination and configuration of disk quotas
162 // Allow setting the domainname
163 // Allow setting the hostname
164 // Allow calling bdflush()
165 // Allow mount() and umount(), setting up new smb connection
166 // Allow some autofs root ioctls
167 // Allow nfsservctl
168 // Allow VM86_REQUEST_IRQ
169 // Allow to read/write pci config on alpha
170 // Allow irix_prctl on mips (setstacksize)
171 // Allow flushing all cache on m68k (sys_cacheflush)
172 // Allow removing semaphores
173 // Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
174 // and shared memory
175 // Allow locking/unlocking of shared memory segment
176 // Allow turning swap on/off
177 // Allow forged pids on socket credentials passing
178 // Allow setting readahead and flushing buffers on block devices
179 // Allow setting geometry in floppy driver
180 // Allow turning DMA on/off in xd driver
181 // Allow administration of md devices (mostly the above, but some
182 // extra ioctls)
183 // Allow tuning the ide driver
184 // Allow access to the nvram device
185 // Allow administration of apm_bios, serial and bttv (TV) device
186 // Allow manufacturer commands in isdn CAPI support driver
187 // Allow reading non-standardized portions of pci configuration space
188 // Allow DDI debug ioctl on sbpcd driver
189 // Allow setting up serial ports
190 // Allow sending raw qic-117 commands
191 // Allow enabling/disabling tagged queuing on SCSI controllers and sending
192 // arbitrary SCSI commands
193 // Allow setting encryption key on loopback filesystem
194 // Allow setting zone reclaim policy
195 // Allow everything under CAP_BPF and CAP_PERFMON for backward compatibility
196 CAP_SYS_ADMIN = Cap(21)
197
198 // Allow use of reboot()
199 CAP_SYS_BOOT = Cap(22)
200
201 // Allow raising priority and setting priority on other (different
202 // UID) processes
203 // Allow use of FIFO and round-robin (realtime) scheduling on own
204 // processes and setting the scheduling algorithm used by another
205 // process.
206 // Allow setting cpu affinity on other processes
207 CAP_SYS_NICE = Cap(23)
208
209 // Override resource limits. Set resource limits.
210 // Override quota limits.
211 // Override reserved space on ext2 filesystem
212 // Modify data journaling mode on ext3 filesystem (uses journaling
213 // resources)
214 // NOTE: ext2 honors fsuid when checking for resource overrides, so
215 // you can override using fsuid too
216 // Override size restrictions on IPC message queues
217 // Allow more than 64hz interrupts from the real-time clock
218 // Override max number of consoles on console allocation
219 // Override max number of keymaps
220 // Control memory reclaim behavior
221 CAP_SYS_RESOURCE = Cap(24)
222
223 // Allow manipulation of system clock
224 // Allow irix_stime on mips
225 // Allow setting the real-time clock
226 CAP_SYS_TIME = Cap(25)
227
228 // Allow configuration of tty devices
229 // Allow vhangup() of tty
230 CAP_SYS_TTY_CONFIG = Cap(26)
231
232 // Allow the privileged aspects of mknod()
233 CAP_MKNOD = Cap(27)
234
235 // Allow taking of leases on files
236 CAP_LEASE = Cap(28)
237
238 CAP_AUDIT_WRITE = Cap(29)
239 CAP_AUDIT_CONTROL = Cap(30)
240 CAP_SETFCAP = Cap(31)
241
242 // Override MAC access.
243 // The base kernel enforces no MAC policy.
244 // An LSM may enforce a MAC policy, and if it does and it chooses
245 // to implement capability based overrides of that policy, this is
246 // the capability it should use to do so.
247 CAP_MAC_OVERRIDE = Cap(32)
248
249 // Allow MAC configuration or state changes.
250 // The base kernel requires no MAC configuration.
251 // An LSM may enforce a MAC policy, and if it does and it chooses
252 // to implement capability based checks on modifications to that
253 // policy or the data required to maintain it, this is the
254 // capability it should use to do so.
255 CAP_MAC_ADMIN = Cap(33)
256
257 // Allow configuring the kernel's syslog (printk behaviour)
258 CAP_SYSLOG = Cap(34)
259
260 // Allow triggering something that will wake the system
261 CAP_WAKE_ALARM = Cap(35)
262
263 // Allow preventing system suspends
264 CAP_BLOCK_SUSPEND = Cap(36)
265
266 // Allow reading the audit log via multicast netlink socket
267 CAP_AUDIT_READ = Cap(37)
268
269 // Allow system performance and observability privileged operations
270 // using perf_events, i915_perf and other kernel subsystems
271 CAP_PERFMON = Cap(38)
272
273 // CAP_BPF allows the following BPF operations:
274 // - Creating all types of BPF maps
275 // - Advanced verifier features
276 // - Indirect variable access
277 // - Bounded loops
278 // - BPF to BPF function calls
279 // - Scalar precision tracking
280 // - Larger complexity limits
281 // - Dead code elimination
282 // - And potentially other features
283 // - Loading BPF Type Format (BTF) data
284 // - Retrieve xlated and JITed code of BPF programs
285 // - Use bpf_spin_lock() helper
286 //
287 // CAP_PERFMON relaxes the verifier checks further:
288 // - BPF progs can use of pointer-to-integer conversions
289 // - speculation attack hardening measures are bypassed
290 // - bpf_probe_read to read arbitrary kernel memory is allowed
291 // - bpf_trace_printk to print kernel memory is allowed
292 //
293 // CAP_SYS_ADMIN is required to use bpf_probe_write_user.
294 //
295 // CAP_SYS_ADMIN is required to iterate system wide loaded
296 // programs, maps, links, BTFs and convert their IDs to file descriptors.
297 //
298 // CAP_PERFMON and CAP_BPF are required to load tracing programs.
299 // CAP_NET_ADMIN and CAP_BPF are required to load networking programs.
300 CAP_BPF = Cap(39)
301
302 // Allow checkpoint/restore related operations.
303 // Introduced in kernel 5.9
304 CAP_CHECKPOINT_RESTORE = Cap(40)
305 )
306
307 // List returns the list of all capabilities known to the package.
308 //
309 // Deprecated: use [ListKnown] or [ListSupported] instead.
310 func List() []Cap {
311 return ListKnown()
312 }
313
314 // ListKnown returns the list of all capabilities known to the package.
315 func ListKnown() []Cap {
316 return list()
317 }
318
319 // ListSupported returns the list of all capabilities known to the package,
320 // except those that are not supported by the currently running Linux kernel.
321 func ListSupported() ([]Cap, error) {
322 last, err := LastCap()
323 if err != nil {
324 return nil, err
325 }
326 return slices.DeleteFunc(list(), func(c Cap) bool {
327 // Remove caps not supported by the kernel.
328 return c > last
329 }), nil
330 }