landlock: Explain file descriptor access rights
Subsystems (3)
Mickaël Salaün
maintainerPATCH v2 1/1 landlock: Explain file descriptor access rights
Starting with LANDLOCK_ACCESS_FS_TRUNCATE, it is worth explaining why we choose to restrict access checks at open time. This new "File descriptor access rights" section is complementary to the existing "Inode access rights" section. Add a new guiding principle related to this section.
---
Changes since v1:
https://lore.kernel.org/r/[email protected]
* Reworded the new section based on Günther suggestions.
* Added a new guiding principle.
* Update date.
--- Documentation/security/landlock.rst | 33 ++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
Documentation/security/landlock.rst +30 -3
@@ -7,7 +7,7 @@ Landlock LSM: kernel documentation ================================== :Author: Mickaël Salaün -:Date: September 2022 +:Date: December 2022 Landlock's goal is to create scoped access-control (i.e. sandboxing). To harden a whole system, this feature should be available to any process,
@@ -41,12 +41,15 @@ Guiding principles for safe access controls processes. * Computation related to Landlock operations (e.g. enforcing a ruleset) shall only impact the processes requesting them. +* Resources (e.g. file descriptors) directly obtained from the kernel by a + sandboxed process shall retain their scoped accesses whatever process use + them. Cf. `File descriptor access rights`_. Design choices ============== -Filesystem access rights ------------------------- +Inode access rights +------------------- All access rights are tied to an inode and what can be accessed through it. Reading the content of a directory does not imply to be allowed to read the
@@ -57,6 +60,30 @@ directory, not the unlinked inode. This is the reason why ``LANDLOCK_ACCESS_FS_REMOVE_FILE`` or ``LANDLOCK_ACCESS_FS_REFER`` are not allowed to be tied to files but only to directories. +File descriptor access rights +----------------------------- + +Access rights are checked and tied to file descriptors at open time. The +underlying principle is that equivalent sequences of operations should lead to +the same results, when they are executed under the same Landlock domain. + +Taking the ``LANDLOCK_ACCESS_FS_TRUNCATE`` right as an example, it may be +allowed to open a file for writing without being allowed to +:manpage:`ftruncate` the resulting file descriptor if the related file +hierarchy doesn't grant such access right. The following sequences of +operations have the same semantic and should then have the same result: + +* ``truncate(path);`` +* ``int fd = open(path, O_WRONLY); ftruncate(fd); close(fd);`` + +Similarly to file access modes (e.g. ``O_RDWR``), Landlock access rights +attached to file descriptors are retained even if they are passed between +processes (e.g. through a Unix domain socket). Such access rights will then be +enforced even if the receiving process is not sandboxed by Landlock. Indeed, +this is required to keep a consistent access control over the whole system, and +avoid unattended bypasses through file descriptor passing (i.e. confused deputy +attack). + Tests =====
base-commit: 0b4ab8cd635e8b21e42c14b9e4810ca701babd11
Signature · 1 line
2.38.1
Quoted 34 lines · Mickaël Salaün
Starting with
LANDLOCK_ACCESS_FS_TRUNCATE, it is worth explaining why we choose to restrict access checks at open time. This new "File descriptor access rights" section is complementary to the existing "Inode access rights" section. Add a new guiding principle related to this section.Cc Günther Noack <[email protected]>Signed-off-by Mickaël Salaün <[email protected]>---
Changes since v1:
https://lore.kernel.org/r/[email protected]
* Reworded the new section based on Günther suggestions.
* Added a new guiding principle.
* Update date.--- Documentation/security/landlock.rst | 33 ++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)Documentation/security/landlock.rst +1
-1@@ -7,7 +7,7 @@ Landlock LSM: kernel documentation ================================== :Author: Mickaël Salaün -:Date: September 2022 +:Date: December 2022 Landlock's goal is to create scoped access-control (i.e. sandboxing). To harden a whole system, this feature should be available to any process,
Documentation/security/landlock.rst Guiding principles for safe access controls · line 45
Quoted 5 lines
Documentation/security/landlock.rst +2
-0@@ -41,12 +41,15 @@ Guiding principles for safe access controls processes. * Computation related to Landlock operations (e.g. enforcing a ruleset) shall only impact the processes requesting them. +* Resources (e.g. file descriptors) directly obtained from the kernel by a + sandboxed process shall retain their scoped accesses whatever process use
Optional nit: Maybe add "at the time of resource acquisition" to stress that part?
Quoted 44 lines
Documentation/security/landlock.rst +27
-2+ them. Cf. `File descriptor access rights`_. Design choices ============== -Filesystem access rights ------------------------- +Inode access rights +------------------- All access rights are tied to an inode and what can be accessed through it. Reading the content of a directory does not imply to be allowed to read the@@ -57,6 +60,30 @@ directory, not the unlinked inode. This is the reason why ``LANDLOCK_ACCESS_FS_REMOVE_FILE`` or ``LANDLOCK_ACCESS_FS_REFER`` are not allowed to be tied to files but only to directories. +File descriptor access rights +----------------------------- + +Access rights are checked and tied to file descriptors at open time. The +underlying principle is that equivalent sequences of operations should lead to +the same results, when they are executed under the same Landlock domain. + +Taking the ``LANDLOCK_ACCESS_FS_TRUNCATE`` right as an example, it may be +allowed to open a file for writing without being allowed to +:manpage:`ftruncate` the resulting file descriptor if the related file +hierarchy doesn't grant such access right. The following sequences of +operations have the same semantic and should then have the same result: + +* ``truncate(path);`` +* ``int fd = open(path, O_WRONLY); ftruncate(fd); close(fd);`` + +Similarly to file access modes (e.g. ``O_RDWR``), Landlock access rights +attached to file descriptors are retained even if they are passed between +processes (e.g. through a Unix domain socket). Such access rights will then be +enforced even if the receiving process is not sandboxed by Landlock. Indeed, +this is required to keep a consistent access control over the whole system, and +avoid unattended bypasses through file descriptor passing (i.e. confused deputy +attack). + Tests =====
Quoted 4 lines
base-commit:
0b4ab8cd635e8b21e42c14b9e4810ca701babd11Signature · 1 line
2.38.1
Thank you!
Mickaël Salaün
maintainerQuoted 32 lines · Günther Noack
Quoted 31 lines · Mickaël Salaün
Starting with
LANDLOCK_ACCESS_FS_TRUNCATE, it is worth explaining why we choose to restrict access checks at open time. This new "File descriptor access rights" section is complementary to the existing "Inode access rights" section. Add a new guiding principle related to this section.Cc Günther Noack <[email protected]>Signed-off-by Mickaël Salaün <[email protected]>---
Changes since v1:
https://lore.kernel.org/r/[email protected]
* Reworded the new section based on Günther suggestions.
* Added a new guiding principle.
* Update date.--- Documentation/security/landlock.rst | 33 ++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)Documentation/security/landlock.rst +1
-1@@ -7,7 +7,7 @@ Landlock LSM: kernel documentation ================================== :Author: Mickaël Salaün -:Date: September 2022 +:Date: December 2022
Quoted 10 lines
Documentation/security/landlock.rst Guiding principles for safe access controls · line 45
Quoted 8 lines
Documentation/security/landlock.rst +2
-0Landlock's goal is to create scoped access-control (i.e. sandboxing). To harden a whole system, this feature should be available to any process,@@ -41,12 +41,15 @@ Guiding principles for safe access controls processes. * Computation related to Landlock operations (e.g. enforcing a ruleset) shall only impact the processes requesting them. +* Resources (e.g. file descriptors) directly obtained from the kernel by a + sandboxed process shall retain their scoped accesses whatever process useOptional nit: Maybe add "at the time of resource acquisition" to stress that part?
I included this suggestion in -next: https://git.kernel.org/mic/c/4dd6da345ac2
Thanks!
Quoted 54 lines
Quoted 45 lines
Documentation/security/landlock.rst +27
-2+ them. Cf. `File descriptor access rights`_. Design choices ============== -Filesystem access rights ------------------------- +Inode access rights +------------------- All access rights are tied to an inode and what can be accessed through it. Reading the content of a directory does not imply to be allowed to read the@@ -57,6 +60,30 @@ directory, not the unlinked inode. This is the reason why ``LANDLOCK_ACCESS_FS_REMOVE_FILE`` or ``LANDLOCK_ACCESS_FS_REFER`` are not allowed to be tied to files but only to directories. +File descriptor access rights +----------------------------- + +Access rights are checked and tied to file descriptors at open time. The +underlying principle is that equivalent sequences of operations should lead to +the same results, when they are executed under the same Landlock domain. + +Taking the ``LANDLOCK_ACCESS_FS_TRUNCATE`` right as an example, it may be +allowed to open a file for writing without being allowed to +:manpage:`ftruncate` the resulting file descriptor if the related file +hierarchy doesn't grant such access right. The following sequences of +operations have the same semantic and should then have the same result: + +* ``truncate(path);`` +* ``int fd = open(path, O_WRONLY); ftruncate(fd); close(fd);`` + +Similarly to file access modes (e.g. ``O_RDWR``), Landlock access rights +attached to file descriptors are retained even if they are passed between +processes (e.g. through a Unix domain socket). Such access rights will then be +enforced even if the receiving process is not sandboxed by Landlock. Indeed, +this is required to keep a consistent access control over the whole system, and +avoid unattended bypasses through file descriptor passing (i.e. confused deputy +attack). + Tests =====Quoted 4 lines
base-commit:
0b4ab8cd635e8b21e42c14b9e4810ca701babd11Signature · 1 line
2.38.1Reviewed-by Günther Noack <[email protected]>Thank you!