landlock.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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: December 2022
  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. Design choices
  41. ==============
  42. Inode access rights
  43. -------------------
  44. All access rights are tied to an inode and what can be accessed through it.
  45. Reading the content of a directory does not imply to be allowed to read the
  46. content of a listed inode. Indeed, a file name is local to its parent
  47. directory, and an inode can be referenced by multiple file names thanks to
  48. (hard) links. Being able to unlink a file only has a direct impact on the
  49. directory, not the unlinked inode. This is the reason why
  50. ``LANDLOCK_ACCESS_FS_REMOVE_FILE`` or ``LANDLOCK_ACCESS_FS_REFER`` are not
  51. allowed to be tied to files but only to directories.
  52. File descriptor access rights
  53. -----------------------------
  54. Access rights are checked and tied to file descriptors at open time. The
  55. underlying principle is that equivalent sequences of operations should lead to
  56. the same results, when they are executed under the same Landlock domain.
  57. Taking the ``LANDLOCK_ACCESS_FS_TRUNCATE`` right as an example, it may be
  58. allowed to open a file for writing without being allowed to
  59. :manpage:`ftruncate` the resulting file descriptor if the related file
  60. hierarchy doesn't grant that access right. The following sequences of
  61. operations have the same semantic and should then have the same result:
  62. * ``truncate(path);``
  63. * ``int fd = open(path, O_WRONLY); ftruncate(fd); close(fd);``
  64. Similarly to file access modes (e.g. ``O_RDWR``), Landlock access rights
  65. attached to file descriptors are retained even if they are passed between
  66. processes (e.g. through a Unix domain socket). Such access rights will then be
  67. enforced even if the receiving process is not sandboxed by Landlock. Indeed,
  68. this is required to keep access controls consistent over the whole system, and
  69. this avoids unattended bypasses through file descriptor passing (i.e. confused
  70. deputy attack).
  71. Tests
  72. =====
  73. Userspace tests for backward compatibility, ptrace restrictions and filesystem
  74. support can be found here: `tools/testing/selftests/landlock/`_.
  75. Kernel structures
  76. =================
  77. Object
  78. ------
  79. .. kernel-doc:: security/landlock/object.h
  80. :identifiers:
  81. Filesystem
  82. ----------
  83. .. kernel-doc:: security/landlock/fs.h
  84. :identifiers:
  85. Ruleset and domain
  86. ------------------
  87. A domain is a read-only ruleset tied to a set of subjects (i.e. tasks'
  88. credentials). Each time a ruleset is enforced on a task, the current domain is
  89. duplicated and the ruleset is imported as a new layer of rules in the new
  90. domain. Indeed, once in a domain, each rule is tied to a layer level. To
  91. grant access to an object, at least one rule of each layer must allow the
  92. requested action on the object. A task can then only transit to a new domain
  93. that is the intersection of the constraints from the current domain and those
  94. of a ruleset provided by the task.
  95. The definition of a subject is implicit for a task sandboxing itself, which
  96. makes the reasoning much easier and helps avoid pitfalls.
  97. .. kernel-doc:: security/landlock/ruleset.h
  98. :identifiers:
  99. .. Links
  100. .. _tools/testing/selftests/landlock/:
  101. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/testing/selftests/landlock/