From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381509; b=dac5Zx0518ZI/g0rrpVVeimHuHOPIZaiOIHx01SPZYRCrJaUw2SesnKhthEwY8jh6lSL 4bxWGdnj2ou3IetdXDWE1D83j8yz55vUHZsoDqh+kSQ4AQ0GJX1h2YsfPbgZDX/gHd+gn HCUJpX9/hQZZxDnfbOZk9tVHpeuHfvebIWLCnHNIZFObuIw4K5+DqRrQSOTbEvbfXPbvf i9kWMWQkqhLm52gBrQUrKZG6L1bl/ZnQ+lFbC5teSW6XwFWC6Gy39HJMA2/rIJ5TJJPb3 e0tD8sxCisoS1NxDt1ep7iMQ7mh3BNteJpKsWnO20FUomgNIRYRnmr39iL2x1Em/Ncg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381509; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=g9RniVQ6zpouAVK2VXQYRnydylPgKSqhM2neCVmPD7c=; b=VoGYdLXuPES7ERfQRsSIWQMccQnFfYKBbyOcqOKoaQdy6xOL1BkMDsM1s77xD614RrXl i6p0ufImFKTQohdwkSjKFJqIZeQYs51jd2s7cWNLiHfO6D2LX8HFLzvtxamtC83+kfnzD 2CTmHXYYYgG7/zFhZvwNQpWtaR8c5c0SgCC69m/J/JoPZCT7nbWfo9kBJJrLXTFgoIVG5 UP8izRIbUPH6bm8I28QKHqpPty998IwDjdD3qv7v7K+UxdjeJSA9RlRXlPHpazxUywSAX jsC4Hypo30/TaL4UU7ETfZrWv5uUhI6uSMC5qOf68b4Peeaijio/Kbf1k3CjPfpiY5Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=QD5uBXEM; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F226606A686; Fri, 4 Dec 2026 10:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=QD5uBXEM Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBE661F0092C; Fri, 4 Dec 2026 10:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381509; bh=g9RniVQ6zpouAVK2VXQYRnydylPgKSqhM2neCVmPD7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QD5uBXEM03y8MItR7EpFZXbweZAGHkUVN/BVEnG0gzfNhyQiUyPHPeDxe9a7ZBtMr Pmpx+ZZdBj4zlZgd7iT+Pic9F+/MCXb7jic4GwawbmC8pgDLJ+hbehGhPPGlNYdAkT DRlK+t9Ib3uWHlBNiK3qLjywaQiBIp1uiLsFqAP8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?G=C3=BCnther=20Noack?= , Tingmao Wang , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Sasha Levin Subject: [PATCH 7.3 734/742] landlock: Wrap per-layer access masks in struct layer_config Date: Fri, 4 Dec 2026 19:09:58 +0900 Message-ID: <20261204100654.598762313@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mickaël Salaün [ Upstream commit 68ba67106a3c7529672b7f2189916442a1ee09b5 ] The domain layer FAM stores struct access_masks values directly, while a ruleset stores the equivalent single mutable value. Per-category permissions need additional per-layer data beyond the handled-access bitfields. Introduce struct layer_config as the common value type. Keeping the handled bitfields in its .handled member leaves struct access_masks as a lightweight parameter type for functions that only need those bitfields, while the complete layer can be snapshotted with one assignment. At this point struct layer_config only wraps the four-byte access_masks, so it does not grow the per-domain allocation: the maximum 16-entry FAM remains 64 bytes. No functional change. Cc: Günther Noack Reviewed-by: Günther Noack Reviewed-by: Tingmao Wang Link: https://patch.msgid.link/20261014082718.1435842-3-mic@digikod.net Signed-off-by: Mickaël Salaün Stable-dep-of: 0ad8ea7fa7dc ("landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/trace/events/landlock.h | 6 +++--- security/landlock/access.h | 32 +++++++++++++++++++++++--------- security/landlock/cred.h | 2 +- security/landlock/domain.c | 10 +++++----- security/landlock/domain.h | 29 ++++++++++++++--------------- security/landlock/fs.c | 2 +- security/landlock/net.c | 2 +- security/landlock/ruleset.c | 6 +++--- security/landlock/ruleset.h | 5 ++--- security/landlock/syscalls.c | 4 ++-- 10 files changed, 55 insertions(+), 43 deletions(-) --- a/include/trace/events/landlock.h +++ b/include/trace/events/landlock.h @@ -353,9 +353,9 @@ TRACE_EVENT(landlock_create_ruleset, TP_fast_assign( __entry->ruleset_id = ruleset->id; __entry->ruleset_version = ruleset->version; - __entry->handled_fs = ruleset->handled_masks.fs; - __entry->handled_net = ruleset->handled_masks.net; - __entry->scoped = ruleset->handled_masks.scope; + __entry->handled_fs = ruleset->layer.handled.fs; + __entry->handled_net = ruleset->layer.handled.net; + __entry->scoped = ruleset->layer.handled.scope; ), TP_printk("ruleset=%llx.%llu handled_fs=%s handled_net=%s scoped=%s", --- a/security/landlock/access.h +++ b/security/landlock/access.h @@ -19,9 +19,9 @@ /* * All access rights that are denied by default whether they are handled or not - * by a ruleset/layer. This must be ORed with all domain->handled_masks[] - * entries when we need to get the absolute handled access masks, see - * landlock_upgrade_handled_access_masks(). + * by a ruleset/layer. This must be ORed with the .handled field of all + * domain->layers[] entries when we need to get the absolute handled access + * masks, see landlock_upgrade_handled_layer_config(). */ /* clang-format off */ #define _LANDLOCK_ACCESS_FS_INITIALLY_DENIED ( \ @@ -45,7 +45,7 @@ static_assert(BITS_PER_TYPE(access_mask_ /* Makes sure for_each_set_bit() and for_each_clear_bit() calls are OK. */ static_assert(sizeof(unsigned long) >= sizeof(access_mask_t)); -/* Ruleset access masks. */ +/* Access masks (bitfields only). */ struct access_masks { access_mask_t fs : LANDLOCK_NUM_ACCESS_FS; access_mask_t net : LANDLOCK_NUM_ACCESS_NET; @@ -61,6 +61,20 @@ union access_masks_all { static_assert(sizeof(typeof_member(union access_masks_all, masks)) == sizeof(typeof_member(union access_masks_all, all))); +/** + * struct layer_config - Per-layer access configuration + * + * A ruleset stores one mutable layer and a domain stores a flexible array of + * immutable layers. + */ +struct layer_config { + /** + * @handled: Bitmask of access rights handled (i.e. restricted) by this + * layer. + */ + struct access_masks handled; +}; + #define _LANDLOCK_LAYER_MASK_PADDING \ (BITS_PER_TYPE(access_mask_t) - LANDLOCK_NUM_ACCESS_MAX - \ IS_ENABLED(CONFIG_SECURITY_LANDLOCK_LOG)) @@ -131,17 +145,17 @@ static_assert(BITS_PER_TYPE(deny_masks_t static_assert(HWEIGHT(LANDLOCK_MAX_NUM_LAYERS) == 1); /* Upgrades with all initially denied by default access rights. */ -static inline struct access_masks -landlock_upgrade_handled_access_masks(struct access_masks access_masks) +static inline struct layer_config +landlock_upgrade_handled_layer_config(struct layer_config layer_config) { /* * All access rights that are denied by default whether they are * explicitly handled or not. */ - if (access_masks.fs) - access_masks.fs |= _LANDLOCK_ACCESS_FS_INITIALLY_DENIED; + if (layer_config.handled.fs) + layer_config.handled.fs |= _LANDLOCK_ACCESS_FS_INITIALLY_DENIED; - return access_masks; + return layer_config; } /* Checks the subset relation between access masks. */ --- a/security/landlock/cred.h +++ b/security/landlock/cred.h @@ -138,7 +138,7 @@ landlock_get_applicable_subject(const st for (layer_level = domain->num_layers - 1; layer_level >= 0; layer_level--) { union access_masks_all layer = { - .masks = domain->handled_masks[layer_level], + .masks = domain->layers[layer_level].handled, }; if (layer.all & masks_all.all) { --- a/security/landlock/domain.c +++ b/security/landlock/domain.c @@ -50,7 +50,7 @@ static struct landlock_domain *create_do struct landlock_domain *new_domain; build_check_domain(); - new_domain = kzalloc_flex(*new_domain, handled_masks, num_layers, + new_domain = kzalloc_flex(*new_domain, layers, num_layers, GFP_KERNEL_ACCOUNT); if (!new_domain) return ERR_PTR(-ENOMEM); @@ -328,8 +328,8 @@ static int merge_ruleset(struct landlock if (WARN_ON_ONCE(dst->num_layers < 1)) return -EINVAL; - dst->handled_masks[dst->num_layers - 1] = - landlock_upgrade_handled_access_masks(src->handled_masks); + dst->layers[dst->num_layers - 1] = + landlock_upgrade_handled_layer_config(src->layer); /* Merges the @src inode tree. */ err = merge_tree(dst, src, LANDLOCK_KEY_INODE); @@ -404,8 +404,8 @@ static int inherit_ruleset(struct landlo /* * Copies the parent layer stack and leaves a space for the new layer. */ - memcpy(child->handled_masks, parent->handled_masks, - flex_array_size(parent, handled_masks, parent->num_layers)); + memcpy(child->layers, parent->layers, + flex_array_size(parent, layers, parent->num_layers)); if (WARN_ON_ONCE(!parent->hierarchy)) return -EINVAL; --- a/security/landlock/domain.h +++ b/security/landlock/domain.h @@ -217,7 +217,7 @@ struct landlock_domain { * @work_free: Enables to free a domain within a lockless * section. This is only used by landlock_put_domain_deferred() * when @usage reaches zero. The fields @usage, @num_layers and - * @handled_masks are then unused. + * @layers are then unused. */ struct work_struct work_free; struct { @@ -233,15 +233,14 @@ struct landlock_domain { */ u32 num_layers; /** - * @handled_masks: Contains the subset of filesystem and - * network actions that are restricted by a domain. A - * domain saves all layers of merged rulesets in a stack - * (FAM), starting from the first layer to the last one. - * These layers are used when merging rulesets, for user - * space backward compatibility (i.e. future-proof), and - * to properly handle merged rulesets without - * overlapping access rights. These layers are set once - * and never changed for the lifetime of the domain. + * @layers: Per-layer access configuration. A domain + * saves all layers of merged rulesets in a stack (FAM), + * starting from the first layer to the last one. These + * layers are used when merging rulesets, for user space + * backward compatibility (i.e. future-proof), and to + * properly handle merged rulesets without overlapping + * access rights. These layers are set once and never + * changed for the lifetime of the domain. * * Not annotated with __counted_by(num_layers): clang * miscomputes the counter address for a FAM nested in @@ -249,7 +248,7 @@ struct landlock_domain { * FORTIFY: * https://github.com/llvm/llvm-project/pull/228309 */ - struct access_masks handled_masks[]; + struct layer_config layers[]; }; }; }; @@ -259,7 +258,7 @@ landlock_get_fs_access_mask(const struct const u16 layer_level) { /* Handles all initially denied by default access rights. */ - return domain->handled_masks[layer_level].fs | + return domain->layers[layer_level].handled.fs | _LANDLOCK_ACCESS_FS_INITIALLY_DENIED; } @@ -267,14 +266,14 @@ static inline access_mask_t landlock_get_net_access_mask(const struct landlock_domain *const domain, const u16 layer_level) { - return domain->handled_masks[layer_level].net; + return domain->layers[layer_level].handled.net; } static inline access_mask_t landlock_get_scope_mask(const struct landlock_domain *const domain, const u16 layer_level) { - return domain->handled_masks[layer_level].scope; + return domain->layers[layer_level].handled.scope; } /** @@ -293,7 +292,7 @@ landlock_union_access_masks(const struct for (layer_level = 0; layer_level < domain->num_layers; layer_level++) { union access_masks_all layer = { - .masks = domain->handled_masks[layer_level], + .masks = domain->layers[layer_level].handled, }; matches.all |= layer.all; --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -342,7 +342,7 @@ int landlock_append_fs_rule(struct landl /* Transforms relative access rights to absolute ones. */ access_rights |= LANDLOCK_MASK_ACCESS_FS & - ~(ruleset->handled_masks.fs | + ~(ruleset->layer.handled.fs | _LANDLOCK_ACCESS_FS_INITIALLY_DENIED); id.key.object = get_inode_object(d_backing_inode(path->dentry)); if (IS_ERR(id.key.object)) --- a/security/landlock/net.c +++ b/security/landlock/net.c @@ -35,7 +35,7 @@ int landlock_append_net_rule(struct land BUILD_BUG_ON(sizeof(port) > sizeof(id.key.data)); /* Transforms relative access rights to absolute ones. */ - access_rights |= LANDLOCK_MASK_ACCESS_NET & ~ruleset->handled_masks.net; + access_rights |= LANDLOCK_MASK_ACCESS_NET & ~ruleset->layer.handled.net; mutex_lock(&ruleset->lock); err = landlock_insert_rule(ruleset, id, access_rights, flags); --- a/security/landlock/ruleset.c +++ b/security/landlock/ruleset.c @@ -64,20 +64,20 @@ landlock_create_ruleset(const access_mas LANDLOCK_MASK_ACCESS_FS; WARN_ON_ONCE(fs_access_mask != mask); - new_ruleset->handled_masks.fs |= mask; + new_ruleset->layer.handled.fs |= mask; } if (net_access_mask) { const access_mask_t mask = net_access_mask & LANDLOCK_MASK_ACCESS_NET; WARN_ON_ONCE(net_access_mask != mask); - new_ruleset->handled_masks.net |= mask; + new_ruleset->layer.handled.net |= mask; } if (scope_mask) { const access_mask_t mask = scope_mask & LANDLOCK_MASK_SCOPE; WARN_ON_ONCE(scope_mask != mask); - new_ruleset->handled_masks.scope |= mask; + new_ruleset->layer.handled.scope |= mask; } return new_ruleset; } --- a/security/landlock/ruleset.h +++ b/security/landlock/ruleset.h @@ -188,10 +188,9 @@ struct landlock_ruleset { */ struct access_masks quiet_masks; /** - * @handled_masks: Contains the subset of filesystem and network actions - * that are handled by this ruleset. + * @layer: Access configuration for this ruleset's single mutable layer. */ - struct access_masks handled_masks; + struct layer_config layer; }; struct landlock_ruleset * --- a/security/landlock/syscalls.c +++ b/security/landlock/syscalls.c @@ -377,7 +377,7 @@ static int add_rule_path_beneath(struct return -ENOMSG; /* Checks that allowed_access matches the @ruleset constraints. */ - mask = ruleset->handled_masks.fs; + mask = ruleset->layer.handled.fs; if ((path_beneath_attr.allowed_access | mask) != mask) return -EINVAL; @@ -418,7 +418,7 @@ static int add_rule_net_port(struct land return -ENOMSG; /* Checks that allowed_access matches the @ruleset constraints. */ - mask = ruleset->handled_masks.net; + mask = ruleset->layer.handled.net; if ((net_port_attr.allowed_access | mask) != mask) return -EINVAL;