1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Landlock LSM - Access types and helpers
5 * Copyright © 2016-2020 Mickaël Salaün <mic@digikod.net>
6 * Copyright © 2018-2020 ANSSI
7 * Copyright © 2024-2025 Microsoft Corporation
10 #ifndef _SECURITY_LANDLOCK_ACCESS_H
11 #define _SECURITY_LANDLOCK_ACCESS_H
13 #include <linux/bitops.h>
14 #include <linux/build_bug.h>
15 #include <linux/kernel.h>
16 #include <uapi/linux/landlock.h>
21 * All access rights that are denied by default whether they are handled or not
22 * 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, see
24 * landlock_upgrade_handled_access_masks().
26 /* clang-format off */
27 #define _LANDLOCK_ACCESS_FS_INITIALLY_DENIED ( \
28 LANDLOCK_ACCESS_FS_REFER)
31 typedef u16 access_mask_t
;
33 /* Makes sure all filesystem access rights can be stored. */
34 static_assert(BITS_PER_TYPE(access_mask_t
) >= LANDLOCK_NUM_ACCESS_FS
);
35 /* Makes sure all network access rights can be stored. */
36 static_assert(BITS_PER_TYPE(access_mask_t
) >= LANDLOCK_NUM_ACCESS_NET
);
37 /* Makes sure all scoped rights can be stored. */
38 static_assert(BITS_PER_TYPE(access_mask_t
) >= LANDLOCK_NUM_SCOPE
);
39 /* Makes sure for_each_set_bit() and for_each_clear_bit() calls are OK. */
40 static_assert(sizeof(unsigned long) >= sizeof(access_mask_t
));
42 /* Ruleset access masks. */
44 access_mask_t fs
: LANDLOCK_NUM_ACCESS_FS
;
45 access_mask_t net
: LANDLOCK_NUM_ACCESS_NET
;
46 access_mask_t scope
: LANDLOCK_NUM_SCOPE
;
49 union access_masks_all
{
50 struct access_masks masks
;
54 /* Makes sure all fields are covered. */
55 static_assert(sizeof(typeof_member(union access_masks_all
, masks
)) ==
56 sizeof(typeof_member(union access_masks_all
, all
)));
58 typedef u16 layer_mask_t
;
60 /* Makes sure all layers can be checked. */
61 static_assert(BITS_PER_TYPE(layer_mask_t
) >= LANDLOCK_MAX_NUM_LAYERS
);
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
)
68 * All access rights that are denied by default whether they are
69 * explicitly handled or not.
72 access_masks
.fs
|= _LANDLOCK_ACCESS_FS_INITIALLY_DENIED
;
77 #endif /* _SECURITY_LANDLOCK_ACCESS_H */