Debian Codegraph @

upstream/fedora-44/man2/landlock_restrict_self.2

raw
1 .\" Copyright © 2017-2020 Mickaël Salaün <[email protected]>
2 .\" Copyright © 2019-2020 ANSSI
3 .\" Copyright © 2021 Microsoft Corporation
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH landlock_restrict_self 2 2024-07-23 "Linux man-pages 6.13"
8 .SH NAME
9 landlock_restrict_self \- enforce a Landlock ruleset
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .BR "#include <linux/landlock.h>" " /* Definition of " LANDLOCK_* " constants */"
16 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
17 .P
18 .BI "int syscall(SYS_landlock_restrict_self, int " ruleset_fd ,
19 .BI " uint32_t " flags );
20 .SH DESCRIPTION
21 Once a Landlock ruleset is populated with the desired rules, the
22 .BR landlock_restrict_self ()
23 system call enforces this ruleset on the calling thread.
24 See
25 .BR landlock (7)
26 for a global overview.
27 .P
28 A thread can be restricted with multiple rulesets that are then
29 composed together to form the thread's Landlock domain.
30 This can be seen as a stack of rulesets but
31 it is implemented in a more efficient way.
32 A domain can only be updated in such a way that
33 the constraints of each past and future composed rulesets
34 will restrict the thread and its future children for their entire life.
35 It is then possible to gradually enforce tailored access control policies
36 with multiple independent rulesets coming from different sources
37 (e.g., init system configuration, user session policy,
38 built-in application policy).
39 However, most applications should only need one call to
40 .BR landlock_restrict_self ()
41 and they should avoid arbitrary numbers of such calls
42 because of the composed rulesets limit.
43 Instead,
44 developers are encouraged to build a single tailored ruleset
45 with multiple calls to
46 .BR landlock_add_rule (2).
47 .P
48 In order to enforce a ruleset, either the caller must have the
49 .B CAP_SYS_ADMIN
50 capability in its user namespace, or the thread must already have the
51 .I no_new_privs
52 bit set.
53 As for
54 .BR seccomp (2),
55 this avoids scenarios where unprivileged processes can affect
56 the behavior of privileged children (e.g., because of set-user-ID binaries).
57 If that bit was not already set by an ancestor of this thread,
58 the thread must make the following call:
59 .IP
60 .EX
61 prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
62 .EE
63 .P
64 .I ruleset_fd
65 is a Landlock ruleset file descriptor obtained with
66 .BR landlock_create_ruleset (2)
67 and fully populated with a set of calls to
68 .BR landlock_add_rule (2).
69 .P
70 .I flags
71 must be 0.
72 .SH RETURN VALUE
73 On success,
74 .BR landlock_restrict_self ()
75 returns 0.
76 On error,
77 \-1 is returned and
78 .I errno
79 is set to indicate the error.
80 .SH ERRORS
81 .BR landlock_restrict_self ()
82 can fail for the following reasons:
83 .TP
84 .B EOPNOTSUPP
85 Landlock is supported by the kernel but disabled at boot time.
86 .TP
87 .B EINVAL
88 .I flags
89 is not 0.
90 .TP
91 .B EBADF
92 .I ruleset_fd
93 is not a file descriptor for the current thread.
94 .TP
95 .B EBADFD
96 .I ruleset_fd
97 is not a ruleset file descriptor.
98 .TP
99 .B EPERM
100 .I ruleset_fd
101 has no read access to the underlying ruleset,
102 or the calling thread is not running with
103 .IR no_new_privs ,
104 or it doesn't have the
105 .B CAP_SYS_ADMIN
106 in its user namespace.
107 .TP
108 .B E2BIG
109 The maximum number of composed rulesets is reached for the calling thread.
110 This limit is currently 64.
111 .SH STANDARDS
112 Linux.
113 .SH HISTORY
114 Linux 5.13.
115 .SH EXAMPLES
116 See
117 .BR landlock (7).
118 .SH SEE ALSO
119 .BR landlock_create_ruleset (2),
120 .BR landlock_add_rule (2),
121 .BR landlock (7)