Skip to content

Commit d6c7cf8

Browse files
committed
landlock: Simplify initially denied access rights
Upgrade domain's handled access masks when creating a domain from a ruleset, instead of converting them at runtime. This is more consistent and helps with audit support. Cc: Günther Noack <gnoack@google.com> Link: https://lore.kernel.org/r/20250108154338.1129069-7-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 622e2f5 commit d6c7cf8

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

security/landlock/access.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
/*
2121
* All access rights that are denied by default whether they are handled or not
2222
* by a ruleset/layer. This must be ORed with all ruleset->access_masks[]
23-
* entries when we need to get the absolute handled access masks.
23+
* entries when we need to get the absolute handled access masks, see
24+
* landlock_upgrade_handled_access_masks().
2425
*/
2526
/* clang-format off */
2627
#define _LANDLOCK_ACCESS_FS_INITIALLY_DENIED ( \
@@ -59,4 +60,18 @@ typedef u16 layer_mask_t;
5960
/* Makes sure all layers can be checked. */
6061
static_assert(BITS_PER_TYPE(layer_mask_t) >= LANDLOCK_MAX_NUM_LAYERS);
6162

63+
/* Upgrades with all initially denied by default access rights. */
64+
static inline struct access_masks
65+
landlock_upgrade_handled_access_masks(struct access_masks access_masks)
66+
{
67+
/*
68+
* All access rights that are denied by default whether they are
69+
* explicitly handled or not.
70+
*/
71+
if (access_masks.fs)
72+
access_masks.fs |= _LANDLOCK_ACCESS_FS_INITIALLY_DENIED;
73+
74+
return access_masks;
75+
}
76+
6277
#endif /* _SECURITY_LANDLOCK_ACCESS_H */

security/landlock/fs.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,6 @@ static bool is_nouser_or_private(const struct dentry *dentry)
389389
unlikely(IS_PRIVATE(d_backing_inode(dentry))));
390390
}
391391

392-
static access_mask_t
393-
get_handled_fs_accesses(const struct landlock_ruleset *const domain)
394-
{
395-
/* Handles all initially denied by default access rights. */
396-
return landlock_union_access_masks(domain).fs |
397-
_LANDLOCK_ACCESS_FS_INITIALLY_DENIED;
398-
}
399-
400392
static const struct access_masks any_fs = {
401393
.fs = ~0,
402394
};
@@ -788,7 +780,7 @@ static bool is_access_to_paths_allowed(
788780
* a superset of the meaningful requested accesses).
789781
*/
790782
access_masked_parent1 = access_masked_parent2 =
791-
get_handled_fs_accesses(domain);
783+
landlock_union_access_masks(domain).fs;
792784
is_dom_check = true;
793785
} else {
794786
if (WARN_ON_ONCE(dentry_child1 || dentry_child2))

security/landlock/ruleset.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ static int merge_ruleset(struct landlock_ruleset *const dst,
387387
err = -EINVAL;
388388
goto out_unlock;
389389
}
390-
dst->access_masks[dst->num_layers - 1] = src->access_masks[0];
390+
dst->access_masks[dst->num_layers - 1] =
391+
landlock_upgrade_handled_access_masks(src->access_masks[0]);
391392

392393
/* Merges the @src inode tree. */
393394
err = merge_tree(dst, src, LANDLOCK_KEY_INODE);

0 commit comments

Comments
 (0)