| 1 | |
| 2 | * This is <linux/capability.h>
|
| 3 | *
|
| 4 | * Andrew G. Morgan <[email protected]>
|
| 5 | * Alexander Kjeldaas <[email protected]>
|
| 6 | * with help from Aleph1, Roland Buresund and Andrew Main.
|
| 7 | *
|
| 8 | * See here for the libcap library ("POSIX draft" compliance):
|
| 9 | *
|
| 10 | * ftp://linux.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.2/
|
| 11 |
|
| 12 |
|
| 13 | #ifndef _LINUX_CAPABILITY_H
|
| 14 | #define _LINUX_CAPABILITY_H
|
| 15 |
|
| 16 | #include <linux/types.h>
|
| 17 | #include <linux/compiler.h>
|
| 18 |
|
| 19 | |
| 20 | capabilities based on the version tag given by the kernel. The
|
| 21 | kernel might be somewhat backwards compatible, but don't bet on
|
| 22 | it.
|
| 23 |
|
| 24 | |
| 25 | a set of three capability sets. The transposition of 3*the
|
| 26 | following structure to such a composite is better handled in a user
|
| 27 | library since the draft standard requires the use of malloc/free
|
| 28 | etc..
|
| 29 |
|
| 30 | #define _LINUX_CAPABILITY_VERSION 0x19980330
|
| 31 |
|
| 32 | typedef struct __user_cap_header_struct {
|
| 33 | __u32 version;
|
| 34 | int pid;
|
| 35 | } __user *cap_user_header_t;
|
| 36 |
|
| 37 | typedef struct __user_cap_data_struct {
|
| 38 | __u32 effective;
|
| 39 | __u32 permitted;
|
| 40 | __u32 inheritable;
|
| 41 | } __user *cap_user_data_t;
|
| 42 |
|
| 43 | #ifdef __KERNEL__
|
| 44 |
|
| 45 | #include <linux/spinlock.h>
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 | #ifdef STRICT_CAP_T_TYPECHECKS
|
| 50 |
|
| 51 | typedef struct kernel_cap_struct {
|
| 52 | __u32 cap;
|
| 53 | } kernel_cap_t;
|
| 54 |
|
| 55 | #else
|
| 56 |
|
| 57 | typedef __u32 kernel_cap_t;
|
| 58 |
|
| 59 | #endif
|
| 60 |
|
| 61 | #define _USER_CAP_HEADER_SIZE (2*sizeof(__u32))
|
| 62 | #define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t))
|
| 63 |
|
| 64 | #endif
|
| 65 |
|
| 66 |
|
| 67 | |
| 68 | ** POSIX-draft defined capabilities.
|
| 69 | *
|
| 70 |
|
| 71 | |
| 72 | overrides the restriction of changing file ownership and group
|
| 73 | ownership.
|
| 74 |
|
| 75 | #define CAP_CHOWN 0
|
| 76 |
|
| 77 | |
| 78 | [_POSIX_ACL] is defined. Excluding DAC access covered by
|
| 79 | CAP_LINUX_IMMUTABLE.
|
| 80 |
|
| 81 | #define CAP_DAC_OVERRIDE 1
|
| 82 |
|
| 83 | |
| 84 | and directories, including ACL restrictions if [_POSIX_ACL] is
|
| 85 | defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE.
|
| 86 |
|
| 87 | #define CAP_DAC_READ_SEARCH 2
|
| 88 |
|
| 89 | |
| 90 | file owner ID must be equal to the user ID, except where CAP_FSETID
|
| 91 | is applicable. It doesn't override MAC and DAC restrictions.
|
| 92 |
|
| 93 | #define CAP_FOWNER 3
|
| 94 |
|
| 95 | |
| 96 | shall match the file owner ID when setting the S_ISUID and S_ISGID
|
| 97 | bits on that file; that the effective group ID (or one of the
|
| 98 | supplementary group IDs) shall match the file owner ID when setting
|
| 99 | the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
|
| 100 | cleared on successful return from chown(2) (not implemented).
|
| 101 |
|
| 102 | #define CAP_FSETID 4
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 | #define CAP_FS_MASK 0x1f
|
| 107 |
|
| 108 | |
| 109 | process sending a signal must match the real or effective user ID
|
| 110 | of the process receiving the signal.
|
| 111 |
|
| 112 | #define CAP_KILL 5
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 | #define CAP_SETGID 6
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 | #define CAP_SETUID 7
|
| 124 |
|
| 125 |
|
| 126 | |
| 127 | ** Linux-specific capabilities
|
| 128 | *
|
| 129 |
|
| 130 | |
| 131 | remove any capability in your permitted set from any pid
|
| 132 |
|
| 133 | #define CAP_SETPCAP 8
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 | #define CAP_LINUX_IMMUTABLE 9
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 | #define CAP_NET_BIND_SERVICE 10
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 | #define CAP_NET_BROADCAST 11
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 | |
| 153 | sockets
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 | #define CAP_NET_ADMIN 12
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 | #define CAP_NET_RAW 13
|
| 168 |
|
| 169 |
|
| 170 | |
| 171 | with IPC)
|
| 172 |
|
| 173 | #define CAP_IPC_LOCK 14
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 | #define CAP_IPC_OWNER 15
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 | #define CAP_SYS_MODULE 16
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 | #define CAP_SYS_RAWIO 17
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 | #define CAP_SYS_CHROOT 18
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 | #define CAP_SYS_PTRACE 19
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 | #define CAP_SYS_PACCT 20
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 | |
| 216 | and shared memory
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 | |
| 224 | extra ioctls)
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 | |
| 234 | arbitrary SCSI commands
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 | #define CAP_SYS_ADMIN 21
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 | #define CAP_SYS_BOOT 22
|
| 243 |
|
| 244 | |
| 245 | UID) processes
|
| 246 | |
| 247 | processes and setting the scheduling algorithm used by another
|
| 248 | process.
|
| 249 |
|
| 250 |
|
| 251 | #define CAP_SYS_NICE 23
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 | |
| 257 | resources)
|
| 258 | |
| 259 | you can override using fsuid too
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 | #define CAP_SYS_RESOURCE 24
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 | #define CAP_SYS_TIME 25
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 | #define CAP_SYS_TTY_CONFIG 26
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 | #define CAP_MKNOD 27
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 | #define CAP_LEASE 28
|
| 285 |
|
| 286 | #define CAP_AUDIT_WRITE 29
|
| 287 |
|
| 288 | #define CAP_AUDIT_CONTROL 30
|
| 289 |
|
| 290 | #ifdef __KERNEL__
|
| 291 | |
| 292 | * Bounding set
|
| 293 |
|
| 294 | extern kernel_cap_t cap_bset;
|
| 295 |
|
| 296 | |
| 297 | * Internal kernel functions only
|
| 298 |
|
| 299 |
|
| 300 | #ifdef STRICT_CAP_T_TYPECHECKS
|
| 301 |
|
| 302 | #define to_cap_t(x) { x }
|
| 303 | #define cap_t(x) (x).cap
|
| 304 |
|
| 305 | #else
|
| 306 |
|
| 307 | #define to_cap_t(x) (x)
|
| 308 | #define cap_t(x) (x)
|
| 309 |
|
| 310 | #endif
|
| 311 |
|
| 312 | #define CAP_EMPTY_SET to_cap_t(0)
|
| 313 | #define CAP_FULL_SET to_cap_t(~0)
|
| 314 | #define CAP_INIT_EFF_SET to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
|
| 315 | #define CAP_INIT_INH_SET to_cap_t(0)
|
| 316 |
|
| 317 | #define CAP_TO_MASK(x) (1 << (x))
|
| 318 | #define cap_raise(c, flag) (cap_t(c) |= CAP_TO_MASK(flag))
|
| 319 | #define cap_lower(c, flag) (cap_t(c) &= ~CAP_TO_MASK(flag))
|
| 320 | #define cap_raised(c, flag) (cap_t(c) & CAP_TO_MASK(flag))
|
| 321 |
|
| 322 | static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b)
|
| 323 | {
|
| 324 | kernel_cap_t dest;
|
| 325 | cap_t(dest) = cap_t(a) | cap_t(b);
|
| 326 | return dest;
|
| 327 | }
|
| 328 |
|
| 329 | static inline kernel_cap_t cap_intersect(kernel_cap_t a, kernel_cap_t b)
|
| 330 | {
|
| 331 | kernel_cap_t dest;
|
| 332 | cap_t(dest) = cap_t(a) & cap_t(b);
|
| 333 | return dest;
|
| 334 | }
|
| 335 |
|
| 336 | static inline kernel_cap_t cap_drop(kernel_cap_t a, kernel_cap_t drop)
|
| 337 | {
|
| 338 | kernel_cap_t dest;
|
| 339 | cap_t(dest) = cap_t(a) & ~cap_t(drop);
|
| 340 | return dest;
|
| 341 | }
|
| 342 |
|
| 343 | static inline kernel_cap_t cap_invert(kernel_cap_t c)
|
| 344 | {
|
| 345 | kernel_cap_t dest;
|
| 346 | cap_t(dest) = ~cap_t(c);
|
| 347 | return dest;
|
| 348 | }
|
| 349 |
|
| 350 | #define cap_isclear(c) (!cap_t(c))
|
| 351 | #define cap_issubset(a,set) (!(cap_t(a) & ~cap_t(set)))
|
| 352 |
|
| 353 | #define cap_clear(c) do { cap_t(c) = 0; } while(0)
|
| 354 | #define cap_set_full(c) do { cap_t(c) = ~0; } while(0)
|
| 355 | #define cap_mask(c,mask) do { cap_t(c) &= cap_t(mask); } while(0)
|
| 356 |
|
| 357 | #define cap_is_fs_cap(c) (CAP_TO_MASK(c) & CAP_FS_MASK)
|
| 358 |
|
| 359 | #endif
|
| 360 |
|
| 361 | #endif
|