Skip to content

Commit 92dda32

Browse files
committed
Merge tag 'landlock-6.12-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/mic/linux
Pull landlock fixes from Mickaël Salaün: "This fixes issues in the Landlock's sandboxer sample and documentation, slightly refactors helpers (required for ongoing patch series), and improve/fix a feature merged in v6.12 (signal and abstract UNIX socket scoping)" * tag 'landlock-6.12-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/mic/linux: landlock: Optimize scope enforcement landlock: Refactor network access mask management landlock: Refactor filesystem access mask management samples/landlock: Clarify option parsing behaviour samples/landlock: Refactor help message samples/landlock: Fix port parsing in sandboxer landlock: Fix grammar issues in documentation landlock: Improve documentation of previous limitations
2 parents 3022e9d + 03197e4 commit 92dda32

File tree

8 files changed

+217
-152
lines changed

8 files changed

+217
-152
lines changed

Documentation/security/landlock.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ Landlock LSM: kernel documentation
1111

1212
Landlock's goal is to create scoped access-control (i.e. sandboxing). To
1313
harden a whole system, this feature should be available to any process,
14-
including unprivileged ones. Because such process may be compromised or
14+
including unprivileged ones. Because such a process may be compromised or
1515
backdoored (i.e. untrusted), Landlock's features must be safe to use from the
1616
kernel and other processes point of view. Landlock's interface must therefore
1717
expose a minimal attack surface.
1818

1919
Landlock is designed to be usable by unprivileged processes while following the
2020
system security policy enforced by other access control mechanisms (e.g. DAC,
21-
LSM). Indeed, a Landlock rule shall not interfere with other access-controls
22-
enforced on the system, only add more restrictions.
21+
LSM). A Landlock rule shall not interfere with other access-controls enforced
22+
on the system, only add more restrictions.
2323

2424
Any user can enforce Landlock rulesets on their processes. They are merged and
25-
evaluated according to the inherited ones in a way that ensures that only more
25+
evaluated against inherited rulesets in a way that ensures that only more
2626
constraints can be added.
2727

2828
User space documentation can be found here:
@@ -43,7 +43,7 @@ Guiding principles for safe access controls
4343
only impact the processes requesting them.
4444
* Resources (e.g. file descriptors) directly obtained from the kernel by a
4545
sandboxed process shall retain their scoped accesses (at the time of resource
46-
acquisition) whatever process use them.
46+
acquisition) whatever process uses them.
4747
Cf. `File descriptor access rights`_.
4848

4949
Design choices
@@ -71,7 +71,7 @@ the same results, when they are executed under the same Landlock domain.
7171
Taking the ``LANDLOCK_ACCESS_FS_TRUNCATE`` right as an example, it may be
7272
allowed to open a file for writing without being allowed to
7373
:manpage:`ftruncate` the resulting file descriptor if the related file
74-
hierarchy doesn't grant such access right. The following sequences of
74+
hierarchy doesn't grant that access right. The following sequences of
7575
operations have the same semantic and should then have the same result:
7676

7777
* ``truncate(path);``
@@ -81,7 +81,7 @@ Similarly to file access modes (e.g. ``O_RDWR``), Landlock access rights
8181
attached to file descriptors are retained even if they are passed between
8282
processes (e.g. through a Unix domain socket). Such access rights will then be
8383
enforced even if the receiving process is not sandboxed by Landlock. Indeed,
84-
this is required to keep a consistent access control over the whole system, and
84+
this is required to keep access controls consistent over the whole system, and
8585
this avoids unattended bypasses through file descriptor passing (i.e. confused
8686
deputy attack).
8787

Documentation/userspace-api/landlock.rst

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Landlock: unprivileged access control
88
=====================================
99

1010
:Author: Mickaël Salaün
11-
:Date: September 2024
11+
:Date: October 2024
1212

13-
The goal of Landlock is to enable to restrict ambient rights (e.g. global
13+
The goal of Landlock is to enable restriction of ambient rights (e.g. global
1414
filesystem or network access) for a set of processes. Because Landlock
15-
is a stackable LSM, it makes possible to create safe security sandboxes as new
16-
security layers in addition to the existing system-wide access-controls. This
17-
kind of sandbox is expected to help mitigate the security impact of bugs or
15+
is a stackable LSM, it makes it possible to create safe security sandboxes as
16+
new security layers in addition to the existing system-wide access-controls.
17+
This kind of sandbox is expected to help mitigate the security impact of bugs or
1818
unexpected/malicious behaviors in user space applications. Landlock empowers
1919
any process, including unprivileged ones, to securely restrict themselves.
2020

@@ -86,8 +86,8 @@ to be explicit about the denied-by-default access rights.
8686
LANDLOCK_SCOPE_SIGNAL,
8787
};
8888
89-
Because we may not know on which kernel version an application will be
90-
executed, it is safer to follow a best-effort security approach. Indeed, we
89+
Because we may not know which kernel version an application will be executed
90+
on, it is safer to follow a best-effort security approach. Indeed, we
9191
should try to protect users as much as possible whatever the kernel they are
9292
using.
9393

@@ -129,7 +129,7 @@ version, and only use the available subset of access rights:
129129
LANDLOCK_SCOPE_SIGNAL);
130130
}
131131
132-
This enables to create an inclusive ruleset that will contain our rules.
132+
This enables the creation of an inclusive ruleset that will contain our rules.
133133

134134
.. code-block:: c
135135
@@ -219,42 +219,41 @@ If the ``landlock_restrict_self`` system call succeeds, the current thread is
219219
now restricted and this policy will be enforced on all its subsequently created
220220
children as well. Once a thread is landlocked, there is no way to remove its
221221
security policy; only adding more restrictions is allowed. These threads are
222-
now in a new Landlock domain, merge of their parent one (if any) with the new
223-
ruleset.
222+
now in a new Landlock domain, which is a merger of their parent one (if any)
223+
with the new ruleset.
224224

225225
Full working code can be found in `samples/landlock/sandboxer.c`_.
226226

227227
Good practices
228228
--------------
229229

230-
It is recommended setting access rights to file hierarchy leaves as much as
230+
It is recommended to set access rights to file hierarchy leaves as much as
231231
possible. For instance, it is better to be able to have ``~/doc/`` as a
232232
read-only hierarchy and ``~/tmp/`` as a read-write hierarchy, compared to
233233
``~/`` as a read-only hierarchy and ``~/tmp/`` as a read-write hierarchy.
234234
Following this good practice leads to self-sufficient hierarchies that do not
235235
depend on their location (i.e. parent directories). This is particularly
236236
relevant when we want to allow linking or renaming. Indeed, having consistent
237-
access rights per directory enables to change the location of such directory
237+
access rights per directory enables changing the location of such directories
238238
without relying on the destination directory access rights (except those that
239239
are required for this operation, see ``LANDLOCK_ACCESS_FS_REFER``
240240
documentation).
241241

242242
Having self-sufficient hierarchies also helps to tighten the required access
243243
rights to the minimal set of data. This also helps avoid sinkhole directories,
244-
i.e. directories where data can be linked to but not linked from. However,
244+
i.e. directories where data can be linked to but not linked from. However,
245245
this depends on data organization, which might not be controlled by developers.
246246
In this case, granting read-write access to ``~/tmp/``, instead of write-only
247-
access, would potentially allow to move ``~/tmp/`` to a non-readable directory
247+
access, would potentially allow moving ``~/tmp/`` to a non-readable directory
248248
and still keep the ability to list the content of ``~/tmp/``.
249249

250250
Layers of file path access rights
251251
---------------------------------
252252

253253
Each time a thread enforces a ruleset on itself, it updates its Landlock domain
254-
with a new layer of policy. Indeed, this complementary policy is stacked with
255-
the potentially other rulesets already restricting this thread. A sandboxed
256-
thread can then safely add more constraints to itself with a new enforced
257-
ruleset.
254+
with a new layer of policy. This complementary policy is stacked with any
255+
other rulesets potentially already restricting this thread. A sandboxed thread
256+
can then safely add more constraints to itself with a new enforced ruleset.
258257

259258
One policy layer grants access to a file path if at least one of its rules
260259
encountered on the path grants the access. A sandboxed thread can only access
@@ -265,7 +264,7 @@ etc.).
265264
Bind mounts and OverlayFS
266265
-------------------------
267266

268-
Landlock enables to restrict access to file hierarchies, which means that these
267+
Landlock enables restricting access to file hierarchies, which means that these
269268
access rights can be propagated with bind mounts (cf.
270269
Documentation/filesystems/sharedsubtree.rst) but not with
271270
Documentation/filesystems/overlayfs.rst.
@@ -278,21 +277,21 @@ access to multiple file hierarchies at the same time, whether these hierarchies
278277
are the result of bind mounts or not.
279278

280279
An OverlayFS mount point consists of upper and lower layers. These layers are
281-
combined in a merge directory, result of the mount point. This merge hierarchy
282-
may include files from the upper and lower layers, but modifications performed
283-
on the merge hierarchy only reflects on the upper layer. From a Landlock
284-
policy point of view, each OverlayFS layers and merge hierarchies are
285-
standalone and contains their own set of files and directories, which is
286-
different from bind mounts. A policy restricting an OverlayFS layer will not
287-
restrict the resulted merged hierarchy, and vice versa. Landlock users should
288-
then only think about file hierarchies they want to allow access to, regardless
289-
of the underlying filesystem.
280+
combined in a merge directory, and that merged directory becomes available at
281+
the mount point. This merge hierarchy may include files from the upper and
282+
lower layers, but modifications performed on the merge hierarchy only reflect
283+
on the upper layer. From a Landlock policy point of view, all OverlayFS layers
284+
and merge hierarchies are standalone and each contains their own set of files
285+
and directories, which is different from bind mounts. A policy restricting an
286+
OverlayFS layer will not restrict the resulted merged hierarchy, and vice versa.
287+
Landlock users should then only think about file hierarchies they want to allow
288+
access to, regardless of the underlying filesystem.
290289

291290
Inheritance
292291
-----------
293292

294293
Every new thread resulting from a :manpage:`clone(2)` inherits Landlock domain
295-
restrictions from its parent. This is similar to the seccomp inheritance (cf.
294+
restrictions from its parent. This is similar to seccomp inheritance (cf.
296295
Documentation/userspace-api/seccomp_filter.rst) or any other LSM dealing with
297296
task's :manpage:`credentials(7)`. For instance, one process's thread may apply
298297
Landlock rules to itself, but they will not be automatically applied to other
@@ -311,8 +310,8 @@ Ptrace restrictions
311310
A sandboxed process has less privileges than a non-sandboxed process and must
312311
then be subject to additional restrictions when manipulating another process.
313312
To be allowed to use :manpage:`ptrace(2)` and related syscalls on a target
314-
process, a sandboxed process should have a subset of the target process rules,
315-
which means the tracee must be in a sub-domain of the tracer.
313+
process, a sandboxed process should have a superset of the target process's
314+
access rights, which means the tracee must be in a sub-domain of the tracer.
316315

317316
IPC scoping
318317
-----------
@@ -322,7 +321,7 @@ interactions between sandboxes. Each Landlock domain can be explicitly scoped
322321
for a set of actions by specifying it on a ruleset. For example, if a
323322
sandboxed process should not be able to :manpage:`connect(2)` to a
324323
non-sandboxed process through abstract :manpage:`unix(7)` sockets, we can
325-
specify such restriction with ``LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET``.
324+
specify such a restriction with ``LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET``.
326325
Moreover, if a sandboxed process should not be able to send a signal to a
327326
non-sandboxed process, we can specify this restriction with
328327
``LANDLOCK_SCOPE_SIGNAL``.
@@ -394,7 +393,7 @@ Backward and forward compatibility
394393
Landlock is designed to be compatible with past and future versions of the
395394
kernel. This is achieved thanks to the system call attributes and the
396395
associated bitflags, particularly the ruleset's ``handled_access_fs``. Making
397-
handled access right explicit enables the kernel and user space to have a clear
396+
handled access rights explicit enables the kernel and user space to have a clear
398397
contract with each other. This is required to make sure sandboxing will not
399398
get stricter with a system update, which could break applications.
400399

@@ -563,33 +562,34 @@ always allowed when using a kernel that only supports the first or second ABI.
563562
Starting with the Landlock ABI version 3, it is now possible to securely control
564563
truncation thanks to the new ``LANDLOCK_ACCESS_FS_TRUNCATE`` access right.
565564

566-
Network support (ABI < 4)
567-
-------------------------
565+
TCP bind and connect (ABI < 4)
566+
------------------------------
568567

569568
Starting with the Landlock ABI version 4, it is now possible to restrict TCP
570569
bind and connect actions to only a set of allowed ports thanks to the new
571570
``LANDLOCK_ACCESS_NET_BIND_TCP`` and ``LANDLOCK_ACCESS_NET_CONNECT_TCP``
572571
access rights.
573572

574-
IOCTL (ABI < 5)
575-
---------------
573+
Device IOCTL (ABI < 5)
574+
----------------------
576575

577576
IOCTL operations could not be denied before the fifth Landlock ABI, so
578577
:manpage:`ioctl(2)` is always allowed when using a kernel that only supports an
579578
earlier ABI.
580579

581580
Starting with the Landlock ABI version 5, it is possible to restrict the use of
582-
:manpage:`ioctl(2)` using the new ``LANDLOCK_ACCESS_FS_IOCTL_DEV`` right.
581+
:manpage:`ioctl(2)` on character and block devices using the new
582+
``LANDLOCK_ACCESS_FS_IOCTL_DEV`` right.
583583

584-
Abstract UNIX socket scoping (ABI < 6)
585-
--------------------------------------
584+
Abstract UNIX socket (ABI < 6)
585+
------------------------------
586586

587587
Starting with the Landlock ABI version 6, it is possible to restrict
588588
connections to an abstract :manpage:`unix(7)` socket by setting
589589
``LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET`` to the ``scoped`` ruleset attribute.
590590

591-
Signal scoping (ABI < 6)
592-
------------------------
591+
Signal (ABI < 6)
592+
----------------
593593

594594
Starting with the Landlock ABI version 6, it is possible to restrict
595595
:manpage:`signal(7)` sending by setting ``LANDLOCK_SCOPE_SIGNAL`` to the
@@ -605,9 +605,9 @@ Build time configuration
605605

606606
Landlock was first introduced in Linux 5.13 but it must be configured at build
607607
time with ``CONFIG_SECURITY_LANDLOCK=y``. Landlock must also be enabled at boot
608-
time as the other security modules. The list of security modules enabled by
608+
time like other security modules. The list of security modules enabled by
609609
default is set with ``CONFIG_LSM``. The kernel configuration should then
610-
contains ``CONFIG_LSM=landlock,[...]`` with ``[...]`` as the list of other
610+
contain ``CONFIG_LSM=landlock,[...]`` with ``[...]`` as the list of other
611611
potentially useful security modules for the running system (see the
612612
``CONFIG_LSM`` help).
613613

@@ -669,7 +669,7 @@ Questions and answers
669669
What about user space sandbox managers?
670670
---------------------------------------
671671

672-
Using user space process to enforce restrictions on kernel resources can lead
672+
Using user space processes to enforce restrictions on kernel resources can lead
673673
to race conditions or inconsistent evaluations (i.e. `Incorrect mirroring of
674674
the OS code and state
675675
<https://www.ndss-symposium.org/ndss2003/traps-and-pitfalls-practical-problems-system-call-interposition-based-security-tools/>`_).

0 commit comments

Comments
 (0)