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