Debian Codegraph @

upstream/mageia-cauldron/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-02-08 "Linux man-pages 6.17"
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 .I flags
72 must be 0.
73 .SH RETURN VALUE
74 On success,
75 .BR landlock_restrict_self ()
76 returns 0.
77 On error,
78 \-1 is returned and
79 .I errno
80 is set to indicate the error.
81 .SH ERRORS
82 .BR landlock_restrict_self ()
83 can fail for the following reasons:
84 .TP
85 .B EOPNOTSUPP
86 Landlock is supported by the kernel but disabled at boot time.
87 .TP
88 .B EINVAL
89 .I flags
90 is not 0.
91 .TP
92 .B EBADF
93 .I ruleset_fd
94 is not a file descriptor for the current thread.
95 .TP
96 .B EBADFD
97 .I ruleset_fd
98 is not a ruleset file descriptor.
99 .TP
100 .B EPERM
101 .I ruleset_fd
102 has no read access to the underlying ruleset,
103 or the calling thread is not running with
104 .IR no_new_privs ,
105 or it doesn't have the
106 .B CAP_SYS_ADMIN
107 in its user namespace.
108 .TP
109 .B E2BIG
110 The maximum number of composed rulesets is reached for the calling thread.
111 This limit is currently 64.
112 .SH STANDARDS
113 Linux.
114 .SH HISTORY
115 Linux 5.13.
116 .SH EXAMPLES
117 See
118 .BR landlock (7).
119 .SH SEE ALSO
120 .BR landlock_create_ruleset (2),
121 .BR landlock_add_rule (2),
122 .BR landlock (7)