securebits.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI_LINUX_SECUREBITS_H
  3. #define _UAPI_LINUX_SECUREBITS_H
  4. /* Each securesetting is implemented using two bits. One bit specifies
  5. whether the setting is on or off. The other bit specify whether the
  6. setting is locked or not. A setting which is locked cannot be
  7. changed from user-level. */
  8. #define issecure_mask(X) (1 << (X))
  9. #define SECUREBITS_DEFAULT 0x00000000
  10. /* When set UID 0 has no special privileges. When unset, we support
  11. inheritance of root-permissions and suid-root executable under
  12. compatibility mode. We raise the effective and inheritable bitmasks
  13. *of the executable file* if the effective uid of the new process is
  14. 0. If the real uid is 0, we raise the effective (legacy) bit of the
  15. executable file. */
  16. #define SECURE_NOROOT 0
  17. #define SECURE_NOROOT_LOCKED 1 /* make bit-0 immutable */
  18. #define SECBIT_NOROOT (issecure_mask(SECURE_NOROOT))
  19. #define SECBIT_NOROOT_LOCKED (issecure_mask(SECURE_NOROOT_LOCKED))
  20. /* When set, setuid to/from uid 0 does not trigger capability-"fixup".
  21. When unset, to provide compatiblility with old programs relying on
  22. set*uid to gain/lose privilege, transitions to/from uid 0 cause
  23. capabilities to be gained/lost. */
  24. #define SECURE_NO_SETUID_FIXUP 2
  25. #define SECURE_NO_SETUID_FIXUP_LOCKED 3 /* make bit-2 immutable */
  26. #define SECBIT_NO_SETUID_FIXUP (issecure_mask(SECURE_NO_SETUID_FIXUP))
  27. #define SECBIT_NO_SETUID_FIXUP_LOCKED \
  28. (issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED))
  29. /* When set, a process can retain its capabilities even after
  30. transitioning to a non-root user (the set-uid fixup suppressed by
  31. bit 2). Bit-4 is cleared when a process calls exec(); setting both
  32. bit 4 and 5 will create a barrier through exec that no exec()'d
  33. child can use this feature again. */
  34. #define SECURE_KEEP_CAPS 4
  35. #define SECURE_KEEP_CAPS_LOCKED 5 /* make bit-4 immutable */
  36. #define SECBIT_KEEP_CAPS (issecure_mask(SECURE_KEEP_CAPS))
  37. #define SECBIT_KEEP_CAPS_LOCKED (issecure_mask(SECURE_KEEP_CAPS_LOCKED))
  38. /* When set, a process cannot add new capabilities to its ambient set. */
  39. #define SECURE_NO_CAP_AMBIENT_RAISE 6
  40. #define SECURE_NO_CAP_AMBIENT_RAISE_LOCKED 7 /* make bit-6 immutable */
  41. #define SECBIT_NO_CAP_AMBIENT_RAISE (issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE))
  42. #define SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED \
  43. (issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED))
  44. #define SECURE_ALL_BITS (issecure_mask(SECURE_NOROOT) | \
  45. issecure_mask(SECURE_NO_SETUID_FIXUP) | \
  46. issecure_mask(SECURE_KEEP_CAPS) | \
  47. issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE))
  48. #define SECURE_ALL_LOCKS (SECURE_ALL_BITS << 1)
  49. #endif /* _UAPI_LINUX_SECUREBITS_H */