Skip to content

Commit f490693

Browse files
l0kodgregkh
authored andcommitted
landlock: Fix asymmetric private inodes referring
commit d9818b3 upstream. When linking or renaming a file, if only one of the source or destination directory is backed by an S_PRIVATE inode, then the related set of layer masks would be used as uninitialized by is_access_to_paths_allowed(). This would result to indeterministic access for one side instead of always being allowed. This bug could only be triggered with a mounted filesystem containing both S_PRIVATE and !S_PRIVATE inodes, which doesn't seem possible. The collect_domain_accesses() calls return early if is_nouser_or_private() returns false, which means that the directory's superblock has SB_NOUSER or its inode has S_PRIVATE. Because rename or link actions are only allowed on the same mounted filesystem, the superblock is always the same for both source and destination directories. However, it might be possible in theory to have an S_PRIVATE parent source inode with an !S_PRIVATE parent destination inode, or vice versa. To make sure this case is not an issue, explicitly initialized both set of layer masks to 0, which means to allow all actions on the related side. If at least on side has !S_PRIVATE, then collect_domain_accesses() and is_access_to_paths_allowed() check for the required access rights. Cc: Arnd Bergmann <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Günther Noack <[email protected]> Cc: Jann Horn <[email protected]> Cc: Shervin Oloumi <[email protected]> Cc: [email protected] Fixes: b91c3e4 ("landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0be289b commit f490693

File tree

1 file changed

+2
-2
lines changed
  • security/landlock

1 file changed

+2
-2
lines changed

security/landlock/fs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ static int current_check_refer_path(struct dentry *const old_dentry,
820820
bool allow_parent1, allow_parent2;
821821
access_mask_t access_request_parent1, access_request_parent2;
822822
struct path mnt_dir;
823-
layer_mask_t layer_masks_parent1[LANDLOCK_NUM_ACCESS_FS],
824-
layer_masks_parent2[LANDLOCK_NUM_ACCESS_FS];
823+
layer_mask_t layer_masks_parent1[LANDLOCK_NUM_ACCESS_FS] = {},
824+
layer_masks_parent2[LANDLOCK_NUM_ACCESS_FS] = {};
825825

826826
if (!dom)
827827
return 0;

0 commit comments

Comments
 (0)