Skip to content

Commit b91c3e4

Browse files
committed
landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER
Add a new LANDLOCK_ACCESS_FS_REFER access right to enable policy writers to allow sandboxed processes to link and rename files from and to a specific set of file hierarchies. This access right should be composed with LANDLOCK_ACCESS_FS_MAKE_* for the destination of a link or rename, and with LANDLOCK_ACCESS_FS_REMOVE_* for a source of a rename. This lift a Landlock limitation that always denied changing the parent of an inode. Renaming or linking to the same directory is still always allowed, whatever LANDLOCK_ACCESS_FS_REFER is used or not, because it is not considered a threat to user data. However, creating multiple links or renaming to a different parent directory may lead to privilege escalations if not handled properly. Indeed, we must be sure that the source doesn't gain more privileges by being accessible from the destination. This is handled by making sure that the source hierarchy (including the referenced file or directory itself) restricts at least as much the destination hierarchy. If it is not the case, an EXDEV error is returned, making it potentially possible for user space to copy the file hierarchy instead of moving or linking it. Instead of creating different access rights for the source and the destination, we choose to make it simple and consistent for users. Indeed, considering the previous constraint, it would be weird to require such destination access right to be also granted to the source (to make it a superset). Moreover, RENAME_EXCHANGE would also add to the confusion because of paths being both a source and a destination. See the provided documentation for additional details. New tests are provided with a following commit. Reviewed-by: Paul Moore <[email protected]> Signed-off-by: Mickaël Salaün <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 100f59d commit b91c3e4

File tree

6 files changed

+556
-80
lines changed

6 files changed

+556
-80
lines changed

include/uapi/linux/landlock.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ struct landlock_ruleset_attr {
2121
/**
2222
* @handled_access_fs: Bitmask of actions (cf. `Filesystem flags`_)
2323
* that is handled by this ruleset and should then be forbidden if no
24-
* rule explicitly allow them. This is needed for backward
25-
* compatibility reasons.
24+
* rule explicitly allow them: it is a deny-by-default list that should
25+
* contain as much Landlock access rights as possible. Indeed, all
26+
* Landlock filesystem access rights that are not part of
27+
* handled_access_fs are allowed. This is needed for backward
28+
* compatibility reasons. One exception is the
29+
* LANDLOCK_ACCESS_FS_REFER access right, which is always implicitly
30+
* handled, but must still be explicitly handled to add new rules with
31+
* this access right.
2632
*/
2733
__u64 handled_access_fs;
2834
};
@@ -112,6 +118,22 @@ struct landlock_path_beneath_attr {
112118
* - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe.
113119
* - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (or rename or link) a block device.
114120
* - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or rename or link) a symbolic link.
121+
* - %LANDLOCK_ACCESS_FS_REFER: Link or rename a file from or to a different
122+
* directory (i.e. reparent a file hierarchy). This access right is
123+
* available since the second version of the Landlock ABI. This is also the
124+
* only access right which is always considered handled by any ruleset in
125+
* such a way that reparenting a file hierarchy is always denied by default.
126+
* To avoid privilege escalation, it is not enough to add a rule with this
127+
* access right. When linking or renaming a file, the destination directory
128+
* hierarchy must also always have the same or a superset of restrictions of
129+
* the source hierarchy. If it is not the case, or if the domain doesn't
130+
* handle this access right, such actions are denied by default with errno
131+
* set to EXDEV. Linking also requires a LANDLOCK_ACCESS_FS_MAKE_* access
132+
* right on the destination directory, and renaming also requires a
133+
* LANDLOCK_ACCESS_FS_REMOVE_* access right on the source's (file or
134+
* directory) parent. Otherwise, such actions are denied with errno set to
135+
* EACCES. The EACCES errno prevails over EXDEV to let user space
136+
* efficiently deal with an unrecoverable error.
115137
*
116138
* .. warning::
117139
*
@@ -137,6 +159,7 @@ struct landlock_path_beneath_attr {
137159
#define LANDLOCK_ACCESS_FS_MAKE_FIFO (1ULL << 10)
138160
#define LANDLOCK_ACCESS_FS_MAKE_BLOCK (1ULL << 11)
139161
#define LANDLOCK_ACCESS_FS_MAKE_SYM (1ULL << 12)
162+
#define LANDLOCK_ACCESS_FS_REFER (1ULL << 13)
140163
/* clang-format on */
141164

142165
#endif /* _UAPI_LINUX_LANDLOCK_H */

0 commit comments

Comments
 (0)