Debian Codegraph @

upstream/debian-unstable/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 Corp.
4 .\" Copyright, the authors of the Linux man-pages project
5 .\"
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\"
8 .TH landlock_restrict_self 2 2026-04-21 "Linux man-pages 6.18"
9 .SH NAME
10 landlock_restrict_self \- enforce a Landlock ruleset
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ,\~ \-lc )
14 .SH SYNOPSIS
15 .nf
16 .BR "#include <linux/landlock.h>" " /* Definition of " LANDLOCK_* " constants */"
17 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
18 .P
19 .BI "int syscall(SYS_landlock_restrict_self, int " ruleset_fd ,
20 .BI " uint32_t " flags );
21 .SH DESCRIPTION
22 Once a Landlock ruleset is populated with the desired rules, the
23 .BR landlock_restrict_self ()
24 system call enforces this ruleset on the calling thread.
25 See
26 .BR landlock (7)
27 for a global overview.
28 .P
29 A thread can be restricted with multiple rulesets that are then
30 composed together to form the thread's Landlock domain.
31 This can be seen as a stack of rulesets but
32 it is implemented in a more efficient way.
33 A domain can only be updated in such a way that
34 the constraints of each past and future composed rulesets
35 will restrict the thread and its future children for their entire life.
36 It is then possible to gradually enforce tailored access control policies
37 with multiple independent rulesets coming from different sources
38 (e.g., init system configuration, user session policy,
39 built-in application policy).
40 However, most applications should only need one call to
41 .BR landlock_restrict_self ()
42 and they should avoid arbitrary numbers of such calls
43 because of the composed rulesets limit.
44 Instead,
45 developers are encouraged to build a single tailored ruleset
46 with multiple calls to
47 .BR landlock_add_rule (2).
48 .P
49 In order to enforce a ruleset, either the caller must have the
50 .B CAP_SYS_ADMIN
51 capability in its user namespace, or the thread must already have the
52 .I no_new_privs
53 bit set.
54 As for
55 .BR seccomp (2),
56 this avoids scenarios where unprivileged processes can affect
57 the behavior of privileged children (e.g., because of set-user-ID binaries).
58 If that bit was not already set by an ancestor of this thread,
59 the thread must make the following call:
60 .IP
61 .EX
62 prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
63 .EE
64 .P
65 .I ruleset_fd
66 is a Landlock ruleset file descriptor obtained with
67 .BR landlock_create_ruleset (2)
68 and fully populated with a set of calls to
69 .BR landlock_add_rule (2).
70 .P
71 By default,
72 denied accesses originating from programs that sandbox themselves
73 are logged via the audit subsystem.
74 Such events typically indicate unexpected behavior,
75 such as bugs or exploitation attempts.
76 However, to avoid excessive logging,
77 access requests denied by a domain not created by the originating program
78 are not logged by default.
79 The rationale is that programs should know their own behavior,
80 but not necessarily the behavior of other programs.
81 This default configuration is suitable for most programs
82 that sandbox themselves.
83 For specific use cases,
84 the following flags allow programs to modify this default logging behavior.
85 .P
86 The
87 .B LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF
88 and
89 .B LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON
90 flags apply to the newly created Landlock domain.
91 .TP
92 .B LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF
93 Disables logging of denied accesses
94 originating from the thread creating the Landlock domain,
95 as well as its children,
96 as long as they continue running the same executable code
97 (i.e., without an intervening
98 .BR execve (2)
99 call).
100 This is intended for programs that execute unknown code
101 without invoking
102 .BR execve (2),
103 such as script interpreters.
104 Programs that only sandbox themselves should not set this flag,
105 so users can be notified of unauthorized access attempts
106 via system logs.
107 .TP
108 .B LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON
109 Enables logging of denied accesses after an
110 .BR execve (2)
111 call,
112 providing visibility into unauthorized access attempts
113 by newly executed programs within the created Landlock domain.
114 This flag is recommended only when all potential executables
115 in the domain are expected to comply with the access restrictions,
116 as excessive audit log entries could make it more difficult
117 to identify critical events.
118 .TP
119 .B LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF
120 Disables logging of denied accesses
121 originating from nested Landlock domains created by the caller
122 or its descendants.
123 This flag should be set according to runtime configuration,
124 not hardcoded, to avoid suppressing important security events.
125 It is useful for container runtimes or sandboxing tools
126 that may launch programs which themselves create Landlock domains
127 and could otherwise generate excessive logs.
128 Unlike
129 .BR LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF ,
130 this flag only affects future nested domains,
131 not the one being created.
132 It can also be used with a
133 .I ruleset_fd
134 value of \-1 to mute subdomain logs
135 without creating a domain.
136 .P
137 The following flag supports policy enforcement in multithreaded processes:
138 .TP
139 .BR LANDLOCK_RESTRICT_SELF_TSYNC " (since Landlock ABI version 8)"
140 Applies the new Landlock configuration atomically
141 to all threads of the current process,
142 including the Landlock domain and logging configuration.
143 This overrides the Landlock configuration of sibling threads,
144 irrespective of
145 previously established Landlock domains
146 and logging configurations on those threads.
147 .IP
148 If the calling thread is running with
149 .IR no_new_privs ,
150 this operation enables
151 .I no_new_privs
152 on the sibling threads as well.
153 .SH RETURN VALUE
154 On success,
155 .BR landlock_restrict_self ()
156 returns 0.
157 On error,
158 \-1 is returned and
159 .I errno
160 is set to indicate the error.
161 .SH ERRORS
162 .BR landlock_restrict_self ()
163 can fail for the following reasons:
164 .TP
165 .B E2BIG
166 The maximum number of composed rulesets is reached for the calling thread.
167 This limit is currently 64.
168 .TP
169 .B EBADF
170 .I ruleset_fd
171 is not a file descriptor for the current thread.
172 .TP
173 .B EBADFD
174 .I ruleset_fd
175 is not a ruleset file descriptor.
176 .TP
177 .B EINVAL
178 Invalid value in
179 .IR flags .
180 .TP
181 .B EOPNOTSUPP
182 Landlock is supported by the kernel but disabled at boot time.
183 .TP
184 .B EPERM
185 .I ruleset_fd
186 has no read access to the underlying ruleset,
187 or the calling thread is not running with
188 .IR no_new_privs ,
189 or it doesn't have the
190 .B CAP_SYS_ADMIN
191 in its user namespace.
192 .SH STANDARDS
193 Linux.
194 .SH HISTORY
195 Linux 5.13.
196 .SH EXAMPLES
197 See
198 .BR landlock (7).
199 .SH SEE ALSO
200 .BR landlock_create_ruleset (2),
201 .BR landlock_add_rule (2),
202 .BR landlock (7)