@@ -25,6 +25,11 @@ static_assert(BITS_PER_TYPE(access_mask_t) >= LANDLOCK_NUM_ACCESS_FS);
2525/* Makes sure for_each_set_bit() and for_each_clear_bit() calls are OK. */
2626static_assert (sizeof (unsigned long ) >= sizeof (access_mask_t ));
2727
28+ /* Ruleset access masks. */
29+ typedef u16 access_masks_t ;
30+ /* Makes sure all ruleset access rights can be stored. */
31+ static_assert (BITS_PER_TYPE (access_masks_t ) >= LANDLOCK_NUM_ACCESS_FS );
32+
2833typedef u16 layer_mask_t ;
2934/* Makes sure all layers can be checked. */
3035static_assert (BITS_PER_TYPE (layer_mask_t ) >= LANDLOCK_MAX_NUM_LAYERS );
@@ -110,7 +115,7 @@ struct landlock_ruleset {
110115 * section. This is only used by
111116 * landlock_put_ruleset_deferred() when @usage reaches zero.
112117 * The fields @lock, @usage, @num_rules, @num_layers and
113- * @fs_access_masks are then unused.
118+ * @access_masks are then unused.
114119 */
115120 struct work_struct work_free ;
116121 struct {
@@ -137,7 +142,7 @@ struct landlock_ruleset {
137142 */
138143 u32 num_layers ;
139144 /**
140- * @fs_access_masks : Contains the subset of filesystem
145+ * @access_masks : Contains the subset of filesystem
141146 * actions that are restricted by a ruleset. A domain
142147 * saves all layers of merged rulesets in a stack
143148 * (FAM), starting from the first layer to the last
@@ -148,13 +153,13 @@ struct landlock_ruleset {
148153 * layers are set once and never changed for the
149154 * lifetime of the ruleset.
150155 */
151- access_mask_t fs_access_masks [];
156+ access_masks_t access_masks [];
152157 };
153158 };
154159};
155160
156161struct landlock_ruleset *
157- landlock_create_ruleset (const access_mask_t fs_access_mask );
162+ landlock_create_ruleset (const access_mask_t access_mask );
158163
159164void landlock_put_ruleset (struct landlock_ruleset * const ruleset );
160165void landlock_put_ruleset_deferred (struct landlock_ruleset * const ruleset );
@@ -177,4 +182,26 @@ static inline void landlock_get_ruleset(struct landlock_ruleset *const ruleset)
177182 refcount_inc (& ruleset -> usage );
178183}
179184
185+ static inline void
186+ landlock_add_fs_access_mask (struct landlock_ruleset * const ruleset ,
187+ const access_mask_t fs_access_mask ,
188+ const u16 layer_level )
189+ {
190+ access_mask_t fs_mask = fs_access_mask & LANDLOCK_MASK_ACCESS_FS ;
191+
192+ /* Should already be checked in sys_landlock_create_ruleset(). */
193+ WARN_ON_ONCE (fs_access_mask != fs_mask );
194+ ruleset -> access_masks [layer_level ] |=
195+ (fs_mask << LANDLOCK_SHIFT_ACCESS_FS );
196+ }
197+
198+ static inline access_mask_t
199+ landlock_get_fs_access_mask (const struct landlock_ruleset * const ruleset ,
200+ const u16 layer_level )
201+ {
202+ return (ruleset -> access_masks [layer_level ] >>
203+ LANDLOCK_SHIFT_ACCESS_FS ) &
204+ LANDLOCK_MASK_ACCESS_FS ;
205+ }
206+
180207#endif /* _SECURITY_LANDLOCK_RULESET_H */
0 commit comments