xref: /linux-6.15/include/uapi/linux/securebits.h (revision a0623b2a)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _UAPI_LINUX_SECUREBITS_H
3607ca46eSDavid Howells #define _UAPI_LINUX_SECUREBITS_H
4607ca46eSDavid Howells 
5607ca46eSDavid Howells /* Each securesetting is implemented using two bits. One bit specifies
6607ca46eSDavid Howells    whether the setting is on or off. The other bit specify whether the
7607ca46eSDavid Howells    setting is locked or not. A setting which is locked cannot be
8607ca46eSDavid Howells    changed from user-level. */
9607ca46eSDavid Howells #define issecure_mask(X)	(1 << (X))
10607ca46eSDavid Howells 
11607ca46eSDavid Howells #define SECUREBITS_DEFAULT 0x00000000
12607ca46eSDavid Howells 
13607ca46eSDavid Howells /* When set UID 0 has no special privileges. When unset, we support
14607ca46eSDavid Howells    inheritance of root-permissions and suid-root executable under
15607ca46eSDavid Howells    compatibility mode. We raise the effective and inheritable bitmasks
16607ca46eSDavid Howells    *of the executable file* if the effective uid of the new process is
17607ca46eSDavid Howells    0. If the real uid is 0, we raise the effective (legacy) bit of the
18607ca46eSDavid Howells    executable file. */
19607ca46eSDavid Howells #define SECURE_NOROOT			0
20607ca46eSDavid Howells #define SECURE_NOROOT_LOCKED		1  /* make bit-0 immutable */
21607ca46eSDavid Howells 
22607ca46eSDavid Howells #define SECBIT_NOROOT		(issecure_mask(SECURE_NOROOT))
23607ca46eSDavid Howells #define SECBIT_NOROOT_LOCKED	(issecure_mask(SECURE_NOROOT_LOCKED))
24607ca46eSDavid Howells 
25607ca46eSDavid Howells /* When set, setuid to/from uid 0 does not trigger capability-"fixup".
26607ca46eSDavid Howells    When unset, to provide compatiblility with old programs relying on
27607ca46eSDavid Howells    set*uid to gain/lose privilege, transitions to/from uid 0 cause
28607ca46eSDavid Howells    capabilities to be gained/lost. */
29607ca46eSDavid Howells #define SECURE_NO_SETUID_FIXUP		2
30607ca46eSDavid Howells #define SECURE_NO_SETUID_FIXUP_LOCKED	3  /* make bit-2 immutable */
31607ca46eSDavid Howells 
32607ca46eSDavid Howells #define SECBIT_NO_SETUID_FIXUP	(issecure_mask(SECURE_NO_SETUID_FIXUP))
33607ca46eSDavid Howells #define SECBIT_NO_SETUID_FIXUP_LOCKED \
34607ca46eSDavid Howells 			(issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED))
35607ca46eSDavid Howells 
36607ca46eSDavid Howells /* When set, a process can retain its capabilities even after
37607ca46eSDavid Howells    transitioning to a non-root user (the set-uid fixup suppressed by
38607ca46eSDavid Howells    bit 2). Bit-4 is cleared when a process calls exec(); setting both
39607ca46eSDavid Howells    bit 4 and 5 will create a barrier through exec that no exec()'d
40607ca46eSDavid Howells    child can use this feature again. */
41607ca46eSDavid Howells #define SECURE_KEEP_CAPS		4
42607ca46eSDavid Howells #define SECURE_KEEP_CAPS_LOCKED		5  /* make bit-4 immutable */
43607ca46eSDavid Howells 
44607ca46eSDavid Howells #define SECBIT_KEEP_CAPS	(issecure_mask(SECURE_KEEP_CAPS))
45607ca46eSDavid Howells #define SECBIT_KEEP_CAPS_LOCKED (issecure_mask(SECURE_KEEP_CAPS_LOCKED))
46607ca46eSDavid Howells 
47746bf6d6SAndy Lutomirski /* When set, a process cannot add new capabilities to its ambient set. */
48746bf6d6SAndy Lutomirski #define SECURE_NO_CAP_AMBIENT_RAISE		6
49746bf6d6SAndy Lutomirski #define SECURE_NO_CAP_AMBIENT_RAISE_LOCKED	7  /* make bit-6 immutable */
50746bf6d6SAndy Lutomirski 
51746bf6d6SAndy Lutomirski #define SECBIT_NO_CAP_AMBIENT_RAISE (issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE))
52746bf6d6SAndy Lutomirski #define SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED \
53746bf6d6SAndy Lutomirski 			(issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED))
54746bf6d6SAndy Lutomirski 
55*a0623b2aSMickaël Salaün /* See Documentation/userspace-api/check_exec.rst */
56*a0623b2aSMickaël Salaün #define SECURE_EXEC_RESTRICT_FILE		8
57*a0623b2aSMickaël Salaün #define SECURE_EXEC_RESTRICT_FILE_LOCKED	9  /* make bit-8 immutable */
58*a0623b2aSMickaël Salaün 
59*a0623b2aSMickaël Salaün #define SECBIT_EXEC_RESTRICT_FILE (issecure_mask(SECURE_EXEC_RESTRICT_FILE))
60*a0623b2aSMickaël Salaün #define SECBIT_EXEC_RESTRICT_FILE_LOCKED \
61*a0623b2aSMickaël Salaün 			(issecure_mask(SECURE_EXEC_RESTRICT_FILE_LOCKED))
62*a0623b2aSMickaël Salaün 
63*a0623b2aSMickaël Salaün /* See Documentation/userspace-api/check_exec.rst */
64*a0623b2aSMickaël Salaün #define SECURE_EXEC_DENY_INTERACTIVE		10
65*a0623b2aSMickaël Salaün #define SECURE_EXEC_DENY_INTERACTIVE_LOCKED	11  /* make bit-10 immutable */
66*a0623b2aSMickaël Salaün 
67*a0623b2aSMickaël Salaün #define SECBIT_EXEC_DENY_INTERACTIVE \
68*a0623b2aSMickaël Salaün 			(issecure_mask(SECURE_EXEC_DENY_INTERACTIVE))
69*a0623b2aSMickaël Salaün #define SECBIT_EXEC_DENY_INTERACTIVE_LOCKED \
70*a0623b2aSMickaël Salaün 			(issecure_mask(SECURE_EXEC_DENY_INTERACTIVE_LOCKED))
71*a0623b2aSMickaël Salaün 
72607ca46eSDavid Howells #define SECURE_ALL_BITS		(issecure_mask(SECURE_NOROOT) | \
73607ca46eSDavid Howells 				 issecure_mask(SECURE_NO_SETUID_FIXUP) | \
74746bf6d6SAndy Lutomirski 				 issecure_mask(SECURE_KEEP_CAPS) | \
75*a0623b2aSMickaël Salaün 				 issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE) | \
76*a0623b2aSMickaël Salaün 				 issecure_mask(SECURE_EXEC_RESTRICT_FILE) | \
77*a0623b2aSMickaël Salaün 				 issecure_mask(SECURE_EXEC_DENY_INTERACTIVE))
78607ca46eSDavid Howells #define SECURE_ALL_LOCKS	(SECURE_ALL_BITS << 1)
79607ca46eSDavid Howells 
80*a0623b2aSMickaël Salaün #define SECURE_ALL_UNPRIVILEGED (issecure_mask(SECURE_EXEC_RESTRICT_FILE) | \
81*a0623b2aSMickaël Salaün 				 issecure_mask(SECURE_EXEC_DENY_INTERACTIVE))
82*a0623b2aSMickaël Salaün 
83607ca46eSDavid Howells #endif /* _UAPI_LINUX_SECUREBITS_H */
84