@@ -8,7 +8,7 @@ Landlock: unprivileged access control
8
8
=====================================
9
9
10
10
:Author: Mickaël Salaün
11
- :Date: October 2023
11
+ :Date: April 2024
12
12
13
13
The goal of Landlock is to enable to restrict ambient rights (e.g. global
14
14
filesystem or network access) for a set of processes. Because Landlock
@@ -76,7 +76,8 @@ to be explicit about the denied-by-default access rights.
76
76
LANDLOCK_ACCESS_FS_MAKE_BLOCK |
77
77
LANDLOCK_ACCESS_FS_MAKE_SYM |
78
78
LANDLOCK_ACCESS_FS_REFER |
79
- LANDLOCK_ACCESS_FS_TRUNCATE,
79
+ LANDLOCK_ACCESS_FS_TRUNCATE |
80
+ LANDLOCK_ACCESS_FS_IOCTL_DEV,
80
81
.handled_access_net =
81
82
LANDLOCK_ACCESS_NET_BIND_TCP |
82
83
LANDLOCK_ACCESS_NET_CONNECT_TCP,
@@ -85,10 +86,10 @@ to be explicit about the denied-by-default access rights.
85
86
Because we may not know on which kernel version an application will be
86
87
executed, it is safer to follow a best-effort security approach. Indeed, we
87
88
should try to protect users as much as possible whatever the kernel they are
88
- using. To avoid binary enforcement (i.e. either all security features or
89
- none), we can leverage a dedicated Landlock command to get the current version
90
- of the Landlock ABI and adapt the handled accesses. Let's check if we should
91
- remove access rights which are only supported in higher versions of the ABI.
89
+ using.
90
+
91
+ To be compatible with older Linux versions, we detect the available Landlock ABI
92
+ version, and only use the available subset of access rights:
92
93
93
94
.. code-block :: c
94
95
@@ -114,6 +115,10 @@ remove access rights which are only supported in higher versions of the ABI.
114
115
ruleset_attr.handled_access_net &=
115
116
~(LANDLOCK_ACCESS_NET_BIND_TCP |
116
117
LANDLOCK_ACCESS_NET_CONNECT_TCP);
118
+ __attribute__((fallthrough));
119
+ case 4:
120
+ /* Removes LANDLOCK_ACCESS_FS_IOCTL_DEV for ABI < 5 */
121
+ ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_IOCTL_DEV;
117
122
}
118
123
119
124
This enables to create an inclusive ruleset that will contain our rules.
@@ -225,6 +230,7 @@ access rights per directory enables to change the location of such directory
225
230
without relying on the destination directory access rights (except those that
226
231
are required for this operation, see ``LANDLOCK_ACCESS_FS_REFER ``
227
232
documentation).
233
+
228
234
Having self-sufficient hierarchies also helps to tighten the required access
229
235
rights to the minimal set of data. This also helps avoid sinkhole directories,
230
236
i.e. directories where data can be linked to but not linked from. However,
@@ -318,18 +324,26 @@ It should also be noted that truncating files does not require the
318
324
system call, this can also be done through :manpage: `open(2)` with the flags
319
325
``O_RDONLY | O_TRUNC ``.
320
326
321
- When opening a file, the availability of the ``LANDLOCK_ACCESS_FS_TRUNCATE ``
322
- right is associated with the newly created file descriptor and will be used for
323
- subsequent truncation attempts using :manpage: `ftruncate(2)`. The behavior is
324
- similar to opening a file for reading or writing, where permissions are checked
325
- during :manpage: `open(2)`, but not during the subsequent :manpage: `read(2)` and
327
+ The truncate right is associated with the opened file (see below).
328
+
329
+ Rights associated with file descriptors
330
+ ---------------------------------------
331
+
332
+ When opening a file, the availability of the ``LANDLOCK_ACCESS_FS_TRUNCATE `` and
333
+ ``LANDLOCK_ACCESS_FS_IOCTL_DEV `` rights is associated with the newly created
334
+ file descriptor and will be used for subsequent truncation and ioctl attempts
335
+ using :manpage: `ftruncate(2)` and :manpage: `ioctl(2)`. The behavior is similar
336
+ to opening a file for reading or writing, where permissions are checked during
337
+ :manpage: `open(2)`, but not during the subsequent :manpage: `read(2)` and
326
338
:manpage: `write(2)` calls.
327
339
328
- As a consequence, it is possible to have multiple open file descriptors for the
329
- same file, where one grants the right to truncate the file and the other does
330
- not. It is also possible to pass such file descriptors between processes,
331
- keeping their Landlock properties, even when these processes do not have an
332
- enforced Landlock ruleset.
340
+ As a consequence, it is possible that a process has multiple open file
341
+ descriptors referring to the same file, but Landlock enforces different things
342
+ when operating with these file descriptors. This can happen when a Landlock
343
+ ruleset gets enforced and the process keeps file descriptors which were opened
344
+ both before and after the enforcement. It is also possible to pass such file
345
+ descriptors between processes, keeping their Landlock properties, even when some
346
+ of the involved processes do not have an enforced Landlock ruleset.
333
347
334
348
Compatibility
335
349
=============
@@ -458,6 +472,28 @@ Memory usage
458
472
Kernel memory allocated to create rulesets is accounted and can be restricted
459
473
by the Documentation/admin-guide/cgroup-v1/memory.rst.
460
474
475
+ IOCTL support
476
+ -------------
477
+
478
+ The ``LANDLOCK_ACCESS_FS_IOCTL_DEV `` right restricts the use of
479
+ :manpage: `ioctl(2)`, but it only applies to *newly opened * device files. This
480
+ means specifically that pre-existing file descriptors like stdin, stdout and
481
+ stderr are unaffected.
482
+
483
+ Users should be aware that TTY devices have traditionally permitted to control
484
+ other processes on the same TTY through the ``TIOCSTI `` and ``TIOCLINUX `` IOCTL
485
+ commands. Both of these require ``CAP_SYS_ADMIN `` on modern Linux systems, but
486
+ the behavior is configurable for ``TIOCSTI ``.
487
+
488
+ On older systems, it is therefore recommended to close inherited TTY file
489
+ descriptors, or to reopen them from ``/proc/self/fd/* `` without the
490
+ ``LANDLOCK_ACCESS_FS_IOCTL_DEV `` right, if possible.
491
+
492
+ Landlock's IOCTL support is coarse-grained at the moment, but may become more
493
+ fine-grained in the future. Until then, users are advised to establish the
494
+ guarantees that they need through the file hierarchy, by only allowing the
495
+ ``LANDLOCK_ACCESS_FS_IOCTL_DEV `` right on files where it is really required.
496
+
461
497
Previous limitations
462
498
====================
463
499
@@ -495,6 +531,16 @@ bind and connect actions to only a set of allowed ports thanks to the new
495
531
``LANDLOCK_ACCESS_NET_BIND_TCP `` and ``LANDLOCK_ACCESS_NET_CONNECT_TCP ``
496
532
access rights.
497
533
534
+ IOCTL (ABI < 5)
535
+ ---------------
536
+
537
+ IOCTL operations could not be denied before the fifth Landlock ABI, so
538
+ :manpage: `ioctl(2)` is always allowed when using a kernel that only supports an
539
+ earlier ABI.
540
+
541
+ Starting with the Landlock ABI version 5, it is possible to restrict the use of
542
+ :manpage: `ioctl(2)` using the new ``LANDLOCK_ACCESS_FS_IOCTL_DEV `` right.
543
+
498
544
.. _kernel_support :
499
545
500
546
Kernel support
0 commit comments