Skip to content

Commit 058518c

Browse files
committed
landlock: Align partial refer access checks with final ones
Fix a logical issue that could have been visible if the source or the destination of a rename/link action was allowed for either the source or the destination but not both. However, this logical bug is unreachable because either: - the rename/link action is allowed by the access rights tied to the same mount point (without relying on access rights in a parent mount point) and the access request is allowed (i.e. allow_parent1 and allow_parent2 are true in current_check_refer_path), - or a common rule in a parent mount point updates the access check for the source and the destination (cf. is_access_to_paths_allowed). See the following layout1.refer_part_mount_tree_is_allowed test that work with and without this fix. This fix does not impact current code but it is required for the audit support. Cc: Günther Noack <gnoack@google.com> Link: https://lore.kernel.org/r/20250108154338.1129069-12-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent d6c7cf8 commit 058518c

File tree

1 file changed

+13
-1
lines changed
  • security/landlock

1 file changed

+13
-1
lines changed

security/landlock/fs.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ static void test_no_more_access(struct kunit *const test)
565565
#undef NMA_TRUE
566566
#undef NMA_FALSE
567567

568+
static bool is_layer_masks_allowed(
569+
layer_mask_t (*const layer_masks)[LANDLOCK_NUM_ACCESS_FS])
570+
{
571+
return !memchr_inv(layer_masks, 0, sizeof(*layer_masks));
572+
}
573+
568574
/*
569575
* Removes @layer_masks accesses that are not requested.
570576
*
@@ -582,7 +588,8 @@ scope_to_request(const access_mask_t access_request,
582588

583589
for_each_clear_bit(access_bit, &access_req, ARRAY_SIZE(*layer_masks))
584590
(*layer_masks)[access_bit] = 0;
585-
return !memchr_inv(layer_masks, 0, sizeof(*layer_masks));
591+
592+
return is_layer_masks_allowed(layer_masks);
586593
}
587594

588595
#ifdef CONFIG_SECURITY_LANDLOCK_KUNIT_TEST
@@ -771,9 +778,14 @@ static bool is_access_to_paths_allowed(
771778
if (WARN_ON_ONCE(domain->num_layers < 1 || !layer_masks_parent1))
772779
return false;
773780

781+
allowed_parent1 = is_layer_masks_allowed(layer_masks_parent1);
782+
774783
if (unlikely(layer_masks_parent2)) {
775784
if (WARN_ON_ONCE(!dentry_child1))
776785
return false;
786+
787+
allowed_parent2 = is_layer_masks_allowed(layer_masks_parent2);
788+
777789
/*
778790
* For a double request, first check for potential privilege
779791
* escalation by looking at domain handled accesses (which are

0 commit comments

Comments
 (0)