Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

landlock: Document good practices about filesystem policies

Explain how to set access rights per hierarchy in an efficient and safe
way, especially with the LANDLOCK_ACCESS_FS_REFER side effect (i.e.
partial ordering and constraints for access rights per hierarchy).

Reviewed-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Link: https://lore.kernel.org/r/20220506161102.525323-12-mic@digikod.net

+21
+21
Documentation/userspace-api/landlock.rst
··· 156 156 157 157 Full working code can be found in `samples/landlock/sandboxer.c`_. 158 158 159 + Good practices 160 + -------------- 161 + 162 + It is recommended setting access rights to file hierarchy leaves as much as 163 + possible. For instance, it is better to be able to have ``~/doc/`` as a 164 + read-only hierarchy and ``~/tmp/`` as a read-write hierarchy, compared to 165 + ``~/`` as a read-only hierarchy and ``~/tmp/`` as a read-write hierarchy. 166 + Following this good practice leads to self-sufficient hierarchies that don't 167 + depend on their location (i.e. parent directories). This is particularly 168 + relevant when we want to allow linking or renaming. Indeed, having consistent 169 + access rights per directory enables to change the location of such directory 170 + without relying on the destination directory access rights (except those that 171 + are required for this operation, see `LANDLOCK_ACCESS_FS_REFER` documentation). 172 + Having self-sufficient hierarchies also helps to tighten the required access 173 + rights to the minimal set of data. This also helps avoid sinkhole directories, 174 + i.e. directories where data can be linked to but not linked from. However, 175 + this depends on data organization, which might not be controlled by developers. 176 + In this case, granting read-write access to ``~/tmp/``, instead of write-only 177 + access, would potentially allow to move ``~/tmp/`` to a non-readable directory 178 + and still keep the ability to list the content of ``~/tmp/``. 179 + 159 180 Layers of file path access rights 160 181 --------------------------------- 161 182