landlock.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net>
  3. .. Copyright © 2019-2020 ANSSI
  4. ==================================
  5. Landlock LSM: kernel documentation
  6. ==================================
  7. :Author: Mickaël Salaün
  8. :Date: September 2025
  9. Landlock's goal is to create scoped access-control (i.e. sandboxing). To
  10. harden a whole system, this feature should be available to any process,
  11. including unprivileged ones. Because such a process may be compromised or
  12. backdoored (i.e. untrusted), Landlock's features must be safe to use from the
  13. kernel and other processes point of view. Landlock's interface must therefore
  14. expose a minimal attack surface.
  15. Landlock is designed to be usable by unprivileged processes while following the
  16. system security policy enforced by other access control mechanisms (e.g. DAC,
  17. LSM). A Landlock rule shall not interfere with other access-controls enforced
  18. on the system, only add more restrictions.
  19. Any user can enforce Landlock rulesets on their processes. They are merged and
  20. evaluated against inherited rulesets in a way that ensures that only more
  21. constraints can be added.
  22. User space documentation can be found here:
  23. Documentation/userspace-api/landlock.rst.
  24. Guiding principles for safe access controls
  25. ===========================================
  26. * A Landlock rule shall be focused on access control on kernel objects instead
  27. of syscall filtering (i.e. syscall arguments), which is the purpose of
  28. seccomp-bpf.
  29. * To avoid multiple kinds of side-channel attacks (e.g. leak of security
  30. policies, CPU-based attacks), Landlock rules shall not be able to
  31. programmatically communicate with user space.
  32. * Kernel access check shall not slow down access request from unsandboxed
  33. processes.
  34. * Computation related to Landlock operations (e.g. enforcing a ruleset) shall
  35. only impact the processes requesting them.
  36. * Resources (e.g. file descriptors) directly obtained from the kernel by a
  37. sandboxed process shall retain their scoped accesses (at the time of resource
  38. acquisition) whatever process uses them.
  39. Cf. `File descriptor access rights`_.
  40. * Access denials shall be logged according to system and Landlock domain
  41. configurations. Log entries must contain information about the cause of the
  42. denial and the owner of the related security policy. Such log generation
  43. should have a negligible performance and memory impact on allowed requests.
  44. Design choices
  45. ==============
  46. Inode access rights
  47. -------------------
  48. All access rights are tied to an inode and what can be accessed through it.
  49. Reading the content of a directory does not imply to be allowed to read the
  50. content of a listed inode. Indeed, a file name is local to its parent
  51. directory, and an inode can be referenced by multiple file names thanks to
  52. (hard) links. Being able to unlink a file only has a direct impact on the
  53. directory, not the unlinked inode. This is the reason why
  54. ``LANDLOCK_ACCESS_FS_REMOVE_FILE`` or ``LANDLOCK_ACCESS_FS_REFER`` are not
  55. allowed to be tied to files but only to directories.
  56. File descriptor access rights
  57. -----------------------------
  58. Access rights are checked and tied to file descriptors at open time. The
  59. underlying principle is that equivalent sequences of operations should lead to
  60. the same results, when they are executed under the same Landlock domain.
  61. Taking the ``LANDLOCK_ACCESS_FS_TRUNCATE`` right as an example, it may be
  62. allowed to open a file for writing without being allowed to
  63. :manpage:`ftruncate` the resulting file descriptor if the related file
  64. hierarchy doesn't grant that access right. The following sequences of
  65. operations have the same semantic and should then have the same result:
  66. * ``truncate(path);``
  67. * ``int fd = open(path, O_WRONLY); ftruncate(fd); close(fd);``
  68. Similarly to file access modes (e.g. ``O_RDWR``), Landlock access rights
  69. attached to file descriptors are retained even if they are passed between
  70. processes (e.g. through a Unix domain socket). Such access rights will then be
  71. enforced even if the receiving process is not sandboxed by Landlock. Indeed,
  72. this is required to keep access controls consistent over the whole system, and
  73. this avoids unattended bypasses through file descriptor passing (i.e. confused
  74. deputy attack).
  75. Tests
  76. =====
  77. Userspace tests for backward compatibility, ptrace restrictions and filesystem
  78. support can be found here: `tools/testing/selftests/landlock/`_.
  79. Kernel structures
  80. =================
  81. Object
  82. ------
  83. .. kernel-doc:: security/landlock/object.h
  84. :identifiers:
  85. Filesystem
  86. ----------
  87. .. kernel-doc:: security/landlock/fs.h
  88. :identifiers:
  89. Process credential
  90. ------------------
  91. .. kernel-doc:: security/landlock/cred.h
  92. :identifiers:
  93. Ruleset and domain
  94. ------------------
  95. A domain is a read-only ruleset tied to a set of subjects (i.e. tasks'
  96. credentials). Each time a ruleset is enforced on a task, the current domain is
  97. duplicated and the ruleset is imported as a new layer of rules in the new
  98. domain. Indeed, once in a domain, each rule is tied to a layer level. To
  99. grant access to an object, at least one rule of each layer must allow the
  100. requested action on the object. A task can then only transit to a new domain
  101. that is the intersection of the constraints from the current domain and those
  102. of a ruleset provided by the task.
  103. The definition of a subject is implicit for a task sandboxing itself, which
  104. makes the reasoning much easier and helps avoid pitfalls.
  105. .. kernel-doc:: security/landlock/ruleset.h
  106. :identifiers:
  107. .. kernel-doc:: security/landlock/domain.h
  108. :identifiers:
  109. Additional documentation
  110. ========================
  111. * Documentation/userspace-api/landlock.rst
  112. * Documentation/admin-guide/LSM/landlock.rst
  113. * https://landlock.io
  114. .. Links
  115. .. _tools/testing/selftests/landlock/:
  116. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/testing/selftests/landlock/