FAILED: patch "[PATCH] landlock: Work around gcc-16 -Wuninitialized warning" failed to apply to 7.2-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 7.2-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.2.y
git checkout FETCH_HEAD
git cherry-pick -x c4e941bb7654bcbdfb0b6f3341dc2acfdf235c8d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092944-secrecy-crouch-5bf3@gregkh' --subject-prefix 'PATCH 7.2.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From c4e941bb7654bcbdfb0b6f3341dc2acfdf235c8d Mon Sep 17 00:00:00 2001
From: Arnd Bergmann <[email protected]>
Date: Tue, 15 Sep 2026 22:10:30 +0200
Subject: [PATCH] landlock: Work around gcc-16 -Wuninitialized warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
gcc has a bug with -ftrivial-auto-var-init=pattern that produces a warning for correct code that uses sparse bitfields:
security/landlock/fs.c: In function 'is_access_to_paths_allowed.isra':security/landlock/fs.c:767:28: error: '_layer_masks_child1' is used uninitialized [-Werror=uninitialized]
767 | struct layer_masks _layer_masks_child1, _layer_masks_child2;
| ^~~~~~~~~~~~~~~~~~~
security/landlock/fs.c:767:28: note: '_layer_masks_child1' declared here
767 | struct layer_masks _layer_masks_child1, _layer_masks_child2;
| ^~~~~~~~~~~~~~~~~~~
security/landlock/fs.c: In function 'hook_unix_find':
security/landlock/fs.c:1649:28: error: 'layer_masks' is used uninitialized [-Werror=uninitialized]
1649 | struct layer_masks layer_masks;
| ^~~~~~~~~~~
security/landlock/fs.c:1649:28: note: 'layer_masks' declared here
1649 | struct layer_masks layer_masks;
| ^~~~~~~~~~~To work around this, change the definition of struct layer_mask to use an explictit padding field.
[mic: Use BITS_PER_TYPE(), fix kdoc warnings, fix commit message according to v2 changes]
security/landlock/access.h +8 -0
@@ -61,6 +61,10 @@ union access_masks_all {static_assert (sizeof (typeof_member (union access_masks_all ,masks )) ==sizeof (typeof_member (union access_masks_all ,all ))); +#define _LANDLOCK_LAYER_MASK_PADDING \ + (BITS_PER_TYPE(access_mask_t) - LANDLOCK_NUM_ACCESS_MAX - \ + IS_ENABLED(CONFIG_SECURITY_LANDLOCK_LOG)) +/** * struct layer_mask - The access rights and rule flags for a layer. *
@@ -81,6 +85,10 @@ struct layer_mask {*/ access_mask_t quiet : 1;#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ +/** +* @__pad: Padding for the compiler's bitfield initialization. +*/ + access_mask_t __pad : _LANDLOCK_LAYER_MASK_PADDING; } __packed__aligned(sizeof(access_mask_t)) ;/*
Sasha Levin
maintainerPATCH 1/5 landlock: Prepare ruleset and domain type split
From: Mickaël Salaün <[email protected]>
[ Upstream commit e76ef456bb673c7fc5def433502a338631df0ebf ]
Rulesets and domains serve fundamentally different purposes: a ruleset is mutable and user-facing, created by landlock_create_ruleset(), while a domain is immutable after construction and enforced on tasks via landlock_restrict_self(). Today both are represented by struct landlock_ruleset, which conflates mutable and immutable state in a single type: the lock field is unused by domains, the hierarchy field is unused by rulesets, and lifecycle functions must handle both cases.
Prepare for a clean type split by introducing two new structures:
- struct landlock_rules: the red-black tree roots and rule count, shared by both rulesets and domains. Decoupling rule storage from the domain API lets the backing data structure change independently (e.g. to a hash table, cf. [1]).
- struct landlock_domain: the immutable domain enforced on tasks, with no lock field because its rules and access masks are fixed once construction completes. The name reflects the role, not the internal data structure.
Add the domain lifecycle helpers (landlock_get_domain(), landlock_put_domain(), landlock_put_domain_deferred()) and move domain.o from landlock-$(CONFIG_AUDIT) to landlock-y, because these are needed unconditionally, not just for audit logging.
No behavioral change. The new types and lifecycle functions are not yet used by any caller.
Stable-dep-of: c4e941bb7654 ("landlock: Work around gcc-16 -Wuninitialized warning")
--- security/landlock/Makefile | 6 +-- security/landlock/domain.c | 36 +++++++++++++++++ security/landlock/domain.h | 70 ++++++++++++++++++++++++++++++++ security/landlock/ruleset.c | 71 ++++++++++++++++----------------- security/landlock/ruleset.h | 79 +++++++++++++++++++++++++++---------- 5 files changed, 202 insertions(+), 60 deletions(-)
security/landlock/Makefile +3 -3
@@ -8,11 +8,11 @@ landlock-y := \ cred.o \ task.o \ fs.o \ - tsync.o + tsync.o \ + domain.o landlock-$(CONFIG_INET) += net.o landlock-$(CONFIG_AUDIT) += \ id.o \ - audit.o \ - domain.o + audit.o
security/landlock/domain.c +36 -0
@@ -5,6 +5,7 @@* Copyright © 2016-2020 Mickaël Salaün <[email protected]> * Copyright © 2018-2020 ANSSI * Copyright © 2024-2025 Microsoft Corporation +* Copyright © 2026 Cloudflare, Inc. */ #include <kunit/test.h>
@@ -15,14 +16,49 @@#include <linux/mm.h> #include <linux/path.h> #include <linux/pid.h> +#include <linux/refcount.h> #include <linux/sched.h> #include <linux/signal.h> +#include <linux/slab.h> #include <linux/uidgid.h> +#include <linux/workqueue.h> #include "access.h" #include "common.h" #include "domain.h" #include "id.h" +#include "ruleset.h" + +static void free_domain (struct landlock_domain *const domain) +{ +might_sleep (); +landlock_free_rules (&domain->rules); +landlock_put_hierarchy (domain->hierarchy); +kfree (domain); +} + +void landlock_put_domain (struct landlock_domain *const domain) +{ +might_sleep (); +if (domain &&refcount_dec_and_test (&domain->usage)) +free_domain (domain); +} + +static void free_domain_work (struct work_struct *const work) +{ +struct landlock_domain *domain; + + domain = container_of(work, struct landlock_domain, work_free); +free_domain (domain); +} + +void landlock_put_domain_deferred (struct landlock_domain *const domain) +{ +if (domain &&refcount_dec_and_test (&domain->usage)) { +INIT_WORK (&domain->work_free, free_domain_work); +schedule_work (&domain->work_free); + } +}#ifdef CONFIG_AUDIT
security/landlock/domain.h +70 -0
94 lines not on this page · raw message
security/landlock/ruleset.c +35 -36
189 lines not on this page · raw message
security/landlock/ruleset.h +58 -21
132 lines not on this page · raw message
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/5 landlock: Move domain query functions to domain.c
From: Mickaël Salaün <[email protected]>
[ Upstream commit 2bbba0905a795b46c20159cecf44033c96b87d22 ]
Grouping domain-specific code in one compilation unit reduces coupling between domain and ruleset implementations.
Move the access-check functions that only operate on a domain (rule lookup, layer unmasking, layer-mask init, access-mask union) from ruleset.[ch] to domain.[ch]. They evaluate whether a domain grants a requested access during the pathwalk and network checks and do not modify the domain.
The merge and inherit chain stays in ruleset.c for now because it calls the static create_ruleset() allocator; a following commit moves it once the domain type switch eliminates that dependency.
No behavioral change. The functions move with unchanged signatures and bodies.
Stable-dep-of: c4e941bb7654 ("landlock: Work around gcc-16 -Wuninitialized warning")
--- security/landlock/domain.c | 162 ++++++++++++++++++++++++++++++++++++ security/landlock/domain.h | 38 +++++++++ security/landlock/net.c | 1 + security/landlock/ruleset.c | 150 --------------------------------- security/landlock/ruleset.h | 38 --------- 5 files changed, 201 insertions(+), 188 deletions(-)
security/landlock/domain.c +162 -0
@@ -11,11 +11,15 @@#include <kunit/test.h> #include <linux/bitops.h> #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/cred.h> +#include <linux/err.h> #include <linux/file.h> #include <linux/mm.h> +#include <linux/overflow.h> #include <linux/path.h> #include <linux/pid.h> +#include <linux/rbtree.h> #include <linux/refcount.h> #include <linux/sched.h> #include <linux/signal.h>
@@ -27,6 +31,7 @@#include "common.h" #include "domain.h" #include "id.h" +#include "limits.h" #include "ruleset.h" static void free_domain (struct landlock_domain *const domain)
@@ -60,6 +65,163 @@ void landlock_put_domain_deferred(struct landlock_domain *const domain) } } +/* The returned access has the same lifetime as the domain. */ +const struct landlock_rule * +landlock_find_rule (const struct landlock_ruleset *const ruleset, +const struct landlock_id id) +{ +const struct rb_root *root; +const struct rb_node *node; + + root =landlock_get_rule_root ((struct landlock_rules *)&ruleset->rules, + id.type); +if (IS_ERR (root)) +return NULL ; + node = root->rb_node; + +while (node) { +struct landlock_rule *this = + rb_entry(node, struct landlock_rule, node); + +if (this->key.data == id.key.data) +return this; +if (this->key.data < id.key.data) + node = node->rb_right; +else + node = node->rb_left; + } +return NULL ; +} + +/** +* landlock_unmask_layers - Remove the access rights in @masks which are +* granted in @rule +* +* Updates the set of (per-layer) unfulfilled access rights @masks so that all +* the access rights granted in @rule are removed from it (because they are now +* fulfilled). +* +* @rule: A rule that grants a set of access rights for each layer. +* @masks: A matrix of unfulfilled access rights for each layer. +* +* Return: True if the request is allowed (i.e. the access rights granted all +* remaining unfulfilled access rights and masks has no leftover set bits). +*/ +bool landlock_unmask_layers (const struct landlock_rule *const rule, +struct layer_masks *masks) +{ +if (!masks) +return true; +if (!rule) +return false; + +/* +* An access is granted if, for each policy layer, at least one rule +* encountered on the pathwalk grants the requested access, regardless +* of its position in the layer stack. We must then check the remaining +* layers for each inode, from the first added layer to the last one. +* When there are multiple requested accesses, for each policy layer, +* the full set of requested accesses may not be granted by only one +* rule, but by the union (binary OR) of multiple rules. For example, +* /a/b <execute> + /a <read> grants /a/b <execute + read>. +* +* This function is called once per matching rule during the pathwalk, +* progressively clearing bits in @masks. The overall access decision +* is per-layer: access is granted iff masks->layers[l].access == 0 for +* all layers l. When two independent mechanisms can each grant access +* within a layer (e.g. a path rule OR a scope exception), the +* composition must evaluate per-layer: FOR-ALL l (A(l) OR B(l)), not +* (FOR-ALL l A(l)) OR (FOR-ALL l B(l)), to prevent bypass when +* different layers grant via different mechanisms. +*/ +for (size_t i =0 ; i < rule->num_layers; i++) { +const struct landlock_layer *const layer = &rule->layers[i]; + +/* Clear the bits where the layer in the rule grants access. */ + masks->layers[layer->level -1 ].access &= ~layer->access; + +#ifdef CONFIG_AUDIT +/* Collect rule flags for each layer. */ +if (layer->flags.quiet) + masks->layers[layer->level -1 ].quiet = true; +#endif /* CONFIG_AUDIT */ + } + +for (size_t i =0 ; i <ARRAY_SIZE (masks->layers); i++) { +if (masks->layers[i].access) +return false; + } +return true; +} + +typedef access_mask_t +get_access_mask_t (const struct landlock_ruleset *const ruleset, +const u16 layer_level); + +/** +* landlock_init_layer_masks - Initialize layer masks from an access request +* +* Populates @masks such that for each access right in @access_request, the bits +* for all the layers are set where this access right is handled. Rule flags +* are also zeroed. +* +* @domain: The domain that defines the current restrictions. +* @access_request: The requested access rights to check. +* @masks: Layer access masks to populate. +* @key_type: The key type to switch between access masks of different types. +* +* Return: An access mask where each access right bit is set which is handled in +* any of the active layers in @domain. +*/ +access_mask_t +landlock_init_layer_masks (const struct landlock_ruleset *const domain, +const access_mask_t access_request, +struct layer_masks *const masks, +const enum landlock_key_type key_type) +{ +access_mask_t handled_accesses =0 ; +get_access_mask_t *get_access_mask; + +switch (key_type) { +case LANDLOCK_KEY_INODE : + get_access_mask = landlock_get_fs_access_mask; +break ; + +#if IS_ENABLED (CONFIG_INET ) +case LANDLOCK_KEY_NET_PORT : + get_access_mask = landlock_get_net_access_mask; +break ; +#endif /* IS_ENABLED(CONFIG_INET) */ + +default : +WARN_ON_ONCE (1 ); +return 0 ; + } + +/* An empty access request can happen because of O_WRONLY | O_RDWR. */ +if (!access_request) +return 0 ; + +for (size_t i =0 ; i < domain->num_layers; i++) { +const access_mask_t handled =get_access_mask (domain, i); + + masks->layers[i].access = access_request & handled; + handled_accesses |= masks->layers[i].access; +#ifdef CONFIG_AUDIT + masks->layers[i].quiet = false; +#endif /* CONFIG_AUDIT */ + } +for (size_t i = domain->num_layers; i <ARRAY_SIZE (masks->layers); + i++) { + masks->layers[i].access =0 ; +#ifdef CONFIG_AUDIT + masks->layers[i].quiet = false; +#endif /* CONFIG_AUDIT */ + } + +return handled_accesses; +} +#ifdef CONFIG_AUDIT /**
security/landlock/domain.h +38 -0
@@ -234,12 +234,50 @@ struct landlock_domain { }; }; +/** +* landlock_union_access_masks - Return all access rights handled in the +* domain +* +* @domain: Landlock ruleset (used as a domain) +* +* Return: An access_masks result of the OR of all the domain's access masks. +*/ +static inline struct access_masks +landlock_union_access_masks (const struct landlock_ruleset *const domain) +{ +union access_masks_all matches = {}; +size_t layer_level; + +for (layer_level =0 ; layer_level < domain->num_layers; layer_level++) { +union access_masks_all layer = { + .masks = domain->access_masks[layer_level], + }; + + matches.all |= layer.all; + } + +return matches.masks; +} +void landlock_put_domain (struct landlock_domain *const domain);void landlock_put_domain_deferred (struct landlock_domain *const domain); DEFINE_FREE(landlock_put_domain, struct landlock_domain *, if (!IS_ERR_OR_NULL(_T)) landlock_put_domain(_T)) +const struct landlock_rule * +landlock_find_rule (const struct landlock_ruleset *const ruleset, +const struct landlock_id id); + +bool landlock_unmask_layers (const struct landlock_rule *const rule, +struct layer_masks *masks); + +access_mask_t +landlock_init_layer_masks (const struct landlock_ruleset *const domain, +const access_mask_t access_request, +struct layer_masks *masks, +const enum landlock_key_type key_type); +static inline void landlock_get_domain (struct landlock_domain *const domain) {if (domain)
security/landlock/net.c +1 -0
@@ -15,6 +15,7 @@#include "audit.h" #include "common.h" #include "cred.h" +#include "domain.h" #include "limits.h" #include "net.h" #include "ruleset.h"
security/landlock/ruleset.c +0 -150
153 lines not on this page · raw message
security/landlock/ruleset.h +0 -38
@@ -235,10 +235,6 @@ struct landlock_ruleset * landlock_merge_ruleset(struct landlock_ruleset *const parent, struct landlock_ruleset *const ruleset); -const struct landlock_rule * -landlock_find_rule (const struct landlock_ruleset *const ruleset, -const struct landlock_id id); -/** * landlock_get_rule_root - Get the root of a rule tree by key type *
@@ -272,31 +268,6 @@ static inline void landlock_get_ruleset(struct landlock_ruleset *const ruleset)refcount_inc (&ruleset->usage); } -/** -* landlock_union_access_masks - Return all access rights handled in the -* domain -* -* @domain: Landlock ruleset (used as a domain) -* -* Return: An access_masks result of the OR of all the domain's access masks. -*/ -static inline struct access_masks -landlock_union_access_masks (const struct landlock_ruleset *const domain) -{ -union access_masks_all matches = {}; -size_t layer_level; - -for (layer_level =0 ; layer_level < domain->num_layers; layer_level++) { -union access_masks_all layer = { - .masks = domain->access_masks[layer_level], - }; - - matches.all |= layer.all; - } - -return matches.masks; -} - static inline void landlock_add_fs_access_mask(struct landlock_ruleset *const ruleset, const access_mask_t fs_access_mask,
@@ -355,13 +326,4 @@ landlock_get_scope_mask(const struct landlock_ruleset *const ruleset, return ruleset->access_masks[layer_level].scope; } -bool landlock_unmask_layers (const struct landlock_rule *const rule, -struct layer_masks *masks); - -access_mask_t -landlock_init_layer_masks (const struct landlock_ruleset *const domain, -const access_mask_t access_request, -struct layer_masks *masks, -const enum landlock_key_type key_type); -#endif /* _SECURITY_LANDLOCK_RULESET_H */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/5 landlock: Split struct landlock_domain from struct landlock_ruleset
In reply to Sasha LevinFrom: Mickaël Salaün <[email protected]>
[ Upstream commit 38411604162e6abe02741d3c364a4df46d6f612f ]
Switch all domain users to the new struct landlock_domain type introduced by a previous commit, eliminating the conflation between mutable rulesets and immutable domains. landlock_merge_ruleset() now returns and allocates a struct landlock_domain, and the merge and inherit helpers move next to it; the former static insert_rule() is exported as landlock_store_rule() for its new caller across the translation-unit boundary.
The merge destination is now a private struct landlock_domain still under construction (owned by the calling thread, not yet shared), so the merge and inherit helpers lock only the source ruleset: the previous lock of both destination and source collapses to a single mutex_lock(&src->lock).
Rename the per-layer access-mask field from access_masks to handled_masks, naming it by the role it plays (the rights each layer handles) rather than by its type, paralleling the struct access_masks quiet_masks field. Drop the now domain-only fields (hierarchy, work_free, num_layers) from struct landlock_ruleset.
The new struct landlock_domain field in cred.h pulls in domain.h, which includes audit.h, which previously included cred.h, forming an include cycle. Break it by having audit.h forward-declare the struct landlock_cred_security and struct landlock_hierarchy it uses instead of including cred.h.
Stable-dep-of: c4e941bb7654 ("landlock: Work around gcc-16 -Wuninitialized warning")
--- security/landlock/access.h | 2 +- security/landlock/audit.c | 12 +- security/landlock/audit.h | 4 +- security/landlock/cred.c | 6 +- security/landlock/cred.h | 21 ++- security/landlock/domain.c | 258 +++++++++++++++++++++++++- security/landlock/domain.h | 43 ++++- security/landlock/fs.c | 25 ++- security/landlock/net.c | 3 +- security/landlock/ruleset.c | 338 +++++------------------------------ security/landlock/ruleset.h | 141 +++------------ security/landlock/syscalls.c | 10 +- security/landlock/task.c | 20 +-- 13 files changed, 403 insertions(+), 480 deletions(-)
security/landlock/access.h +1 -1
@@ -19,7 +19,7 @@/* * All access rights that are denied by default whether they are handled or not -* by a ruleset/layer. This must be ORed with all ruleset->access_masks[] +* 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(). */
security/landlock/audit.c +6 -6
@@ -138,7 +138,7 @@ static void log_domain(struct landlock_hierarchy *const hierarchy) }static struct landlock_hierarchy * -get_hierarchy (const struct landlock_ruleset *const domain,const size_t layer) +get_hierarchy (const struct landlock_domain *const domain,const size_t layer) {struct landlock_hierarchy *hierarchy = domain->hierarchy;ssize_t i;
@@ -171,7 +171,7 @@ static void test_get_hierarchy(struct kunit *const test) .parent = &dom1_hierarchy, .id = 30, }; -struct landlock_ruleset dom2 = { +struct landlock_domain dom2 = { .hierarchy = &dom2_hierarchy, .num_layers =3 , };
@@ -185,7 +185,7 @@ static void test_get_hierarchy(struct kunit *const test)#endif /* CONFIG_SECURITY_LANDLOCK_KUNIT_TEST */ /* Get the youngest layer that denied the access_request. */ -static size_t get_denied_layer (const struct landlock_ruleset *const domain, +static size_t get_denied_layer (const struct landlock_domain *const domain,access_mask_t *const access_request,const struct layer_masks *masks) {
@@ -205,7 +205,7 @@ static size_t get_denied_layer(const struct landlock_ruleset *const domain,static void test_get_denied_layer (struct kunit *const test) { -const struct landlock_ruleset dom = { +const struct landlock_domain dom = { .num_layers =5 , };const struct layer_masks masks = {
@@ -682,8 +682,8 @@ void landlock_log_denial(const struct landlock_cred_security *const subject,* Only domains which previously appeared in the audit logs are logged again. * This is useful to know when a domain will never show again in the audit log. * -* Called in a work queue scheduled by landlock_put_ruleset_deferred() called -* by hook_cred_free(). +* Called in a work queue scheduled by landlock_put_domain_deferred() called by +* hook_cred_free(). */ void landlock_log_drop_domain (const struct landlock_hierarchy *const hierarchy) {
security/landlock/audit.h +3 -1
@@ -12,7 +12,9 @@#include <linux/lsm_audit.h> #include "access.h" -#include "cred.h" + +struct landlock_cred_security ; +struct landlock_hierarchy ;enum landlock_request_type {LANDLOCK_REQUEST_PTRACE =1 ,
security/landlock/cred.c +3 -3
@@ -22,7 +22,7 @@ static void hook_cred_transfer(struct cred *const new,const struct landlock_cred_security *const old_llcred =landlock_cred (old); -landlock_get_ruleset (old_llcred->domain); +landlock_get_domain (old_llcred->domain); *landlock_cred (new) = *old_llcred; }
@@ -35,10 +35,10 @@ static int hook_cred_prepare(struct cred *const new,static void hook_cred_free (struct cred *const cred) { -struct landlock_ruleset *const dom =landlock_cred (cred)->domain; +struct landlock_domain *const dom =landlock_cred (cred)->domain;if (dom) -landlock_put_ruleset_deferred (dom); +landlock_put_domain_deferred (dom); }#ifdef CONFIG_AUDIT
security/landlock/cred.h +10 -11
@@ -16,6 +16,7 @@#include <linux/rcupdate.h> #include "access.h" +#include "domain.h" #include "limits.h" #include "ruleset.h" #include "setup.h"
@@ -31,9 +32,9 @@*/ struct landlock_cred_security {/** -* @domain: Immutable ruleset enforced on a task. +* @domain: Immutable domain enforced on a task. */ -struct landlock_ruleset *domain; +struct landlock_domain *domain;#ifdef CONFIG_AUDIT /**
@@ -70,22 +71,20 @@ landlock_cred(const struct cred *cred)static inline void landlock_cred_copy (struct landlock_cred_security *dst,const struct landlock_cred_security *src) { -landlock_put_ruleset (dst->domain); +landlock_put_domain (dst->domain); *dst = *src; -landlock_get_ruleset (src->domain); +landlock_get_domain (src->domain); } -static inline struct landlock_ruleset *landlock_get_current_domain (void ) +static inline struct landlock_domain *landlock_get_current_domain (void ) {return landlock_cred (current_cred ())->domain; } -/* -* The call needs to come from an RCU read-side critical section. -*/ -static inline const struct landlock_ruleset * +/* The call needs to come from an RCU read-side critical section. */ +static inline const struct landlock_domain *landlock_get_task_domain (const struct task_struct *const task) {return landlock_cred (__task_cred (task))->domain;
@@ -126,7 +125,7 @@ landlock_get_applicable_subject(const struct cred *const cred,const union access_masks_all masks_all = { .masks = masks, }; -const struct landlock_ruleset *domain; +const struct landlock_domain *domain;ssize_t layer_level;if (!cred)
@@ -139,7 +138,7 @@ landlock_get_applicable_subject(const struct cred *const cred,for (layer_level = domain->num_layers -1 ; layer_level >=0 ; layer_level--) {union access_masks_all layer = { - .masks = domain->access_masks[layer_level], + .masks = domain->handled_masks[layer_level], };if (layer.all & masks_all.all) {
security/landlock/domain.c +254 -4
300 lines not on this page · raw message
security/landlock/domain.h +35 -8
92 lines not on this page · raw message
security/landlock/fs.c +12 -13
@@ -337,12 +337,11 @@ int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,if (!d_is_dir (path->dentry) && !access_mask_subset (access_rights,ACCESS_FILE ))return -EINVAL ; -if (WARN_ON_ONCE (ruleset->num_layers !=1 )) -return -EINVAL ;/* Transforms relative access rights to absolute ones. */ access_rights |=LANDLOCK_MASK_ACCESS_FS & - ~landlock_get_fs_access_mask (ruleset,0 ); + ~(ruleset->handled_masks.fs | + _LANDLOCK_ACCESS_FS_INITIALLY_DENIED); id.key.object =get_inode_object (d_backing_inode (path->dentry));if (IS_ERR (id.key.object))return PTR_ERR (id.key.object);
@@ -365,7 +364,7 @@ int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,* Returns NULL if no rule is found or if @dentry is negative. */ static const struct landlock_rule * -find_rule (const struct landlock_ruleset *const domain, +find_rule (const struct landlock_domain *const domain,const struct dentry *const dentry) {const struct landlock_rule *rule;
@@ -750,7 +749,7 @@ static void test_is_eacces_with_write(struct kunit *const test)* Return: True if the access request is granted, false otherwise. */ static bool -is_access_to_paths_allowed(const struct landlock_ruleset *const domain, +is_access_to_paths_allowed(const struct landlock_domain *const domain, const struct path *const path, const access_mask_t access_request_parent1, struct layer_masks *layer_masks_parent1,
@@ -1051,7 +1050,7 @@ static access_mask_t maybe_remove(const struct dentry *const dentry)* Return: True if all the domain access rights are allowed for @dir, false if * the walk reached @mnt_root. */ -static bool collect_domain_accesses (const struct landlock_ruleset *const domain, +static bool collect_domain_accesses (const struct landlock_domain *const domain,const struct dentry *const mnt_root,struct dentry *dir,struct layer_masks *layer_masks_dom)
@@ -1618,8 +1617,8 @@ static int hook_path_truncate(const struct path *const path)* @masks: Layer access masks to unmask * @access: Access bits that control scoping */ -static void unmask_scoped_access (const struct landlock_ruleset *const client, -const struct landlock_ruleset *const server, +static void unmask_scoped_access (const struct landlock_domain *const client, +const struct landlock_domain *const server,struct layer_masks *const masks,const access_mask_t access) {
@@ -1673,7 +1672,7 @@ static void unmask_scoped_access(const struct landlock_ruleset *const client,static int hook_unix_find (const struct path *const path,struct sock *other,int flags) { -const struct landlock_ruleset *dom_other; +const struct landlock_domain *dom_other;const struct landlock_cred_security *subject;struct layer_masks layer_masks;struct landlock_request request = {};
@@ -1968,7 +1967,7 @@ static bool control_current_fowner(struct fown_struct *const fown)static void hook_file_set_fowner (struct file *file) { -struct landlock_ruleset *prev_dom; +struct landlock_domain *prev_dom;struct landlock_cred_security fown_subject = {};struct pid *prev_tg, *fown_tg =NULL ;size_t fown_layer =0 ;
@@ -1981,7 +1980,7 @@ static void hook_file_set_fowner(struct file *file)landlock_get_applicable_subject (current_cred (), signal_scope, &fown_layer);if (new_subject) { -landlock_get_ruleset (new_subject->domain); +landlock_get_domain (new_subject->domain); fown_subject = *new_subject; fown_tg =get_pid (task_tgid (current)); }
@@ -1996,14 +1995,14 @@ static void hook_file_set_fowner(struct file *file)#endif /* CONFIG_AUDIT*/ /* May be called in an RCU read-side critical section. */ -landlock_put_ruleset_deferred (prev_dom); +landlock_put_domain_deferred (prev_dom);put_pid (prev_tg); }static void hook_file_free_security (struct file *file) {put_pid (landlock_file (file)->fown_tg); -landlock_put_ruleset_deferred (landlock_file (file)->fown_subject.domain); +landlock_put_domain_deferred (landlock_file (file)->fown_subject.domain); }static struct security_hook_list landlock_hooks[]__ro_after_init = {
security/landlock/net.c +1 -2
@@ -33,8 +33,7 @@ int landlock_append_net_rule(struct landlock_ruleset *const ruleset,BUILD_BUG_ON (sizeof (port) >sizeof (id.key.data));/* Transforms relative access rights to absolute ones. */ - access_rights |=LANDLOCK_MASK_ACCESS_NET & - ~landlock_get_net_access_mask (ruleset,0 ); + access_rights |=LANDLOCK_MASK_ACCESS_NET & ~ruleset->handled_masks.net;mutex_lock (&ruleset->lock); err =landlock_insert_rule (ruleset, id, access_rights, flags);
security/landlock/ruleset.c +41 -297
420 lines not on this page · raw message
security/landlock/ruleset.h +23 -118
177 lines not on this page · raw message
security/landlock/syscalls.c +4 -6
@@ -308,8 +308,6 @@ static struct landlock_ruleset *get_ruleset_from_fd(const int fd,if (!(fd_file (ruleset_f)->f_mode & mode))return ERR_PTR (-EPERM ); ruleset =fd_file (ruleset_f)->private_data; -if (WARN_ON_ONCE (ruleset->num_layers !=1 )) -return ERR_PTR (-EINVAL );landlock_get_ruleset (ruleset);return ruleset; }
@@ -367,7 +365,7 @@ static int add_rule_path_beneath(struct landlock_ruleset *const ruleset,return -ENOMSG ;/* Checks that allowed_access matches the @ruleset constraints. */ - mask = ruleset->access_masks[0 ].fs; + mask = ruleset->handled_masks.fs;if ((path_beneath_attr.allowed_access | mask) != mask)return -EINVAL ;
@@ -408,7 +406,7 @@ static int add_rule_net_port(struct landlock_ruleset *ruleset,return -ENOMSG ;/* Checks that allowed_access matches the @ruleset constraints. */ - mask =landlock_get_net_access_mask (ruleset,0 ); + mask = ruleset->handled_masks.net;if ((net_port_attr.allowed_access | mask) != mask)return -EINVAL ;
@@ -595,7 +593,7 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32,* manipulating the current credentials because they are * dedicated per thread. */ -struct landlock_ruleset *const new_dom = +struct landlock_domain *const new_dom =landlock_merge_ruleset (new_llcred->domain, ruleset);if (IS_ERR (new_dom)) {abort_creds (new_cred);
@@ -610,7 +608,7 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32,#endif /* CONFIG_AUDIT */ /* Replaces the old (prepared) domain. */ -landlock_put_ruleset (new_llcred->domain); +landlock_put_domain (new_llcred->domain); new_llcred->domain = new_dom;#ifdef CONFIG_AUDIT
security/landlock/task.c +10 -10
@@ -41,8 +41,8 @@* Return: True if @parent is an ancestor of or equal to @child, false * otherwise. */ -static bool domain_scope_le (const struct landlock_ruleset *const parent, -const struct landlock_ruleset *const child) +static bool domain_scope_le (const struct landlock_domain *const parent, +const struct landlock_domain *const child) {const struct landlock_hierarchy *walker;
@@ -63,8 +63,8 @@ static bool domain_scope_le(const struct landlock_ruleset *const parent,return false; } -static int domain_ptrace (const struct landlock_ruleset *const parent, -const struct landlock_ruleset *const child) +static int domain_ptrace (const struct landlock_domain *const parent, +const struct landlock_domain *const child) {if (domain_scope_le (parent, child))return 0 ;
@@ -96,7 +96,7 @@ static int hook_ptrace_access_check(struct task_struct *const child,return 0 ;scoped_guard (rcu) { -const struct landlock_ruleset *const child_dom = +const struct landlock_domain *const child_dom =landlock_get_task_domain (child); err =domain_ptrace (parent_subject->domain, child_dom); }
@@ -135,7 +135,7 @@ static int hook_ptrace_access_check(struct task_struct *const child,static int hook_ptrace_traceme (struct task_struct *const parent) {const struct landlock_cred_security *parent_subject; -const struct landlock_ruleset *child_dom; +const struct landlock_domain *child_dom;int err; child_dom =landlock_get_current_domain ();
@@ -176,8 +176,8 @@ static int hook_ptrace_traceme(struct task_struct *const parent)* Return: True if @server is in a different domain from @client and @client * is scoped to access @server (i.e. access should be denied), false otherwise. */ -static bool domain_is_scoped (const struct landlock_ruleset *const client, -const struct landlock_ruleset *const server, +static bool domain_is_scoped (const struct landlock_domain *const client, +const struct landlock_domain *const server,access_mask_t scope) {int client_layer, server_layer;
@@ -236,9 +236,9 @@ static bool domain_is_scoped(const struct landlock_ruleset *const client, }static bool sock_is_scoped (struct sock *const other, -const struct landlock_ruleset *const domain) +const struct landlock_domain *const domain) { -const struct landlock_ruleset *dom_other; +const struct landlock_domain *dom_other;/* The credentials will not change. */ lockdep_assert_held (&unix_sk (other)->lock);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/5 landlock: Split denial logging from audit into common framework
In reply to Sasha LevinFrom: Mickaël Salaün <[email protected]>
[ Upstream commit e761a88cedeb46de17b6d9e8c7c41c7671e83a6b ]
Tracepoint emission requires the denial framework (layer identification, request validation) without depending on CONFIG_AUDIT. Separate the denial logging infrastructure from the audit-specific code by introducing a common log framework.
Create CONFIG_SECURITY_LANDLOCK_LOG, enabled by default when CONFIG_AUDIT is set; a following commit extends it to CONFIG_TRACEPOINTS when the first tracepoint consumer is added. Move the common framework (the request types, the layer identification and request validation, and the landlock_log_denial() and landlock_log_free_domain() entry points) into log.c and log.h, and keep the audit-specific record formatting in audit.c. log.o is built for CONFIG_SECURITY_LANDLOCK_LOG and audit.o for CONFIG_AUDIT, so the common framework is available to a tracepoints-only build. The entry points dispatch to no-op static inline audit stubs without CONFIG_AUDIT, so the call sites stay unconditional. Rename the former landlock_log_drop_domain() to landlock_log_free_domain() to match the landlock_free_domain tracepoint added in a following commit.
landlock_log_denial() counts denials even without audit, so its declaration and no-op stub are guarded by CONFIG_SECURITY_LANDLOCK_LOG, not CONFIG_AUDIT; a CONFIG_AUDIT guard would expose the stub and clash with log.c's definition in a tracepoints-only build.
Widen the ID allocation (id.o and the landlock_init_id() / landlock_get_id_range() declarations) and the log-state representation (the domain_exec and log_subdomains_off credential fields, the landlock_hierarchy log fields, and the code that maintains them) from CONFIG_AUDIT to CONFIG_SECURITY_LANDLOCK_LOG, so each field and its writer share one guard and are available to tracing without audit support.
Widen the denial-path state that feeds the per-denial logging decision the same way, so the "logged" verdict is computed identically whether or not CONFIG_AUDIT is set. Widening fown_layer is what keeps the file-owner-signal path valid without audit: otherwise hook_file_send_sigiotask() would leave layer_plus_one at zero, tripping the is_valid_request() canary and dropping the LANDLOCK_SCOPE_SIGNAL denial from tracing.
The ruleset-level quiet_masks stays on no CONFIG guard: it is builder state validated and stored from user input, kept available so LANDLOCK_ADD_RULE_QUIET flags are accepted and ignored, not rejected, when CONFIG_SECURITY_LANDLOCK_LOG is disabled.
Stable-dep-of: c4e941bb7654 ("landlock: Work around gcc-16 -Wuninitialized warning")
--- security/landlock/Kconfig | 5 + security/landlock/Makefile | 6 +- security/landlock/access.h | 4 +- security/landlock/audit.c | 485 ++------------------------------- security/landlock/audit.h | 61 ++--- security/landlock/cred.c | 8 +- security/landlock/cred.h | 8 +- security/landlock/domain.c | 20 +- security/landlock/domain.h | 14 +- security/landlock/fs.c | 27 +- security/landlock/fs.h | 8 +- security/landlock/id.h | 6 +- security/landlock/log.c | 502 +++++++++++++++++++++++++++++++++++ security/landlock/log.h | 77 ++++++ security/landlock/net.c | 2 +- security/landlock/syscalls.c | 12 +- security/landlock/task.c | 6 +- 17 files changed, 681 insertions(+), 570 deletions(-) create mode 100644 security/landlock/log.c create mode 100644 security/landlock/log.h
security/landlock/Kconfig +5 -0
@@ -21,6 +21,11 @@ config SECURITY_LANDLOCK you should also prepend "landlock," to the content of CONFIG_LSM to enable Landlock at boot time. +config SECURITY_LANDLOCK_LOG + bool + depends on SECURITY_LANDLOCK + default y if AUDIT + config SECURITY_LANDLOCK_KUNIT_TEST bool "KUnit tests for Landlock" if !KUNIT_ALL_TESTS depends on KUNIT=y
security/landlock/Makefile +4 -2
@@ -13,6 +13,8 @@ landlock-y := \ landlock-$(CONFIG_INET) += net.o -landlock-$(CONFIG_AUDIT) += \ +landlock-$(CONFIG_SECURITY_LANDLOCK_LOG) += \ id.o \ - audit.o + log.o + +landlock-$(CONFIG_AUDIT) += audit.o
security/landlock/access.h +2 -2
@@ -74,13 +74,13 @@ struct layer_mask {* @access: The unfulfilled access rights for this layer. */ access_mask_t access : LANDLOCK_NUM_ACCESS_MAX; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG /** * @quiet: Whether we have encountered a rule with the quiet flag for * this layer. Used to control logging. */ access_mask_t quiet : 1; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ } __packed__aligned(sizeof(access_mask_t)) ;/*
security/landlock/audit.c +19 -466
534 lines not on this page · raw message
security/landlock/audit.h +16 -45
84 lines not on this page · raw message
security/landlock/cred.c +4 -4
@@ -41,7 +41,7 @@ static void hook_cred_free(struct cred *const cred)landlock_put_domain_deferred (dom); } -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG static int hook_bprm_creds_for_exec (struct linux_binprm *const bprm) {
@@ -50,16 +50,16 @@ static int hook_bprm_creds_for_exec(struct linux_binprm *const bprm)return 0 ; } -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ static struct security_hook_list landlock_hooks[]__ro_after_init = {LSM_HOOK_INIT (cred_prepare, hook_cred_prepare),LSM_HOOK_INIT (cred_transfer, hook_cred_transfer),LSM_HOOK_INIT (cred_free, hook_cred_free), -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOGLSM_HOOK_INIT (bprm_creds_for_exec, hook_bprm_creds_for_exec), -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ };__init void landlock_add_cred_hooks (void )
security/landlock/cred.h +4 -4
@@ -36,7 +36,7 @@ struct landlock_cred_security {*/ struct landlock_domain *domain; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG /** * @domain_exec: Bitmask identifying the domain layers that were enforced by * the current task's executed file (i.e. no new execve(2) since
@@ -50,17 +50,17 @@ struct landlock_cred_security {* not require a current domain. */ u8 log_subdomains_off : 1; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ } __packed; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG /* Makes sure all layer executions can be stored. */ static_assert (BITS_PER_TYPE (typeof_member(struct landlock_cred_security , domain_exec)) >= LANDLOCK_MAX_NUM_LAYERS); -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ static inline struct landlock_cred_security *landlock_cred (const struct cred *cred)
security/landlock/domain.c +10 -10
@@ -172,11 +172,11 @@ bool landlock_unmask_layers(const struct landlock_rule *const rule,/* Clear the bits where the layer in the rule grants access. */ masks->layers[layer->level -1 ].access &= ~layer->access; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG /* Collect rule flags for each layer. */ if (layer->flags.quiet) masks->layers[layer->level -1 ].quiet = true; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ }for (size_t i =0 ; i <ARRAY_SIZE (masks->layers); i++) {
@@ -239,16 +239,16 @@ landlock_init_layer_masks(const struct landlock_domain *const domain, masks->layers[i].access = access_request & handled; handled_accesses |= masks->layers[i].access; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG masks->layers[i].quiet = false; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ }for (size_t i = domain->num_layers; i <ARRAY_SIZE (masks->layers); i++) { masks->layers[i].access =0 ; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG masks->layers[i].quiet = false; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ }return handled_accesses;
@@ -465,14 +465,14 @@ landlock_merge_ruleset(struct landlock_domain *const parent,if (err)return ERR_PTR (err); -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG new_dom->hierarchy->quiet_masks = ruleset->quiet_masks; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ return no_free_ptr (new_dom); } -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG /** * get_current_exe - Get the current's executable path, if any
@@ -754,4 +754,4 @@ kunit_test_suite(test_suite);#endif /* CONFIG_SECURITY_LANDLOCK_KUNIT_TEST */ -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */
security/landlock/domain.h +7 -7
@@ -22,7 +22,7 @@#include <linux/workqueue.h> #include "access.h" -#include "audit.h" +#include "log.h" #include "ruleset.h" enum landlock_log_status {
@@ -85,7 +85,7 @@ struct landlock_hierarchy {*/ refcount_t usage; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG /** * @log_status: Whether this domain should be logged or not. Because * concurrent log entries may be created at the same time, it is still
@@ -120,10 +120,10 @@ struct landlock_hierarchy {* logged) if the related object is marked as quiet. */ struct access_masks quiet_masks; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ }; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG deny_masks_t landlock_get_deny_masks(const access_mask_t all_existing_optional_access,
@@ -146,7 +146,7 @@ landlock_free_hierarchy_details(struct landlock_hierarchy *const hierarchy) kfree(hierarchy->details); } -#else /* CONFIG_AUDIT */ +#else /* CONFIG_SECURITY_LANDLOCK_LOG */ static inline int landlock_init_hierarchy_log (struct landlock_hierarchy *const hierarchy)
@@ -159,7 +159,7 @@ landlock_free_hierarchy_details(struct landlock_hierarchy *const hierarchy) { } -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ static inline void landlock_get_hierarchy (struct landlock_hierarchy *const hierarchy)
@@ -173,7 +173,7 @@ static inline void landlock_put_hierarchy(struct landlock_hierarchy *hierarchy)while (hierarchy &&refcount_dec_and_test (&hierarchy->usage)) {const struct landlock_hierarchy *const freeme = hierarchy; -landlock_log_drop_domain (hierarchy); +landlock_log_free_domain (hierarchy);landlock_free_hierarchy_details (hierarchy); hierarchy = hierarchy->parent;kfree (freeme);
security/landlock/fs.c +14 -13
@@ -43,12 +43,12 @@#include <uapi/linux/landlock.h> #include "access.h" -#include "audit.h" #include "common.h" #include "cred.h" #include "domain.h" #include "fs.h" #include "limits.h" +#include "log.h" #include "object.h" #include "ruleset.h" #include "setup.h"
@@ -933,10 +933,11 @@ is_access_to_paths_allowed(const struct landlock_domain *const domain,path_put (&walker_path);/* -* Check CONFIG_AUDIT to enable elision of log_request_parent* and -* associated caller's stack variables thanks to dead code elimination. +* Check CONFIG_SECURITY_LANDLOCK_LOG to enable elision of +* log_request_parent* and associated caller's stack variables thanks to +* dead code elimination. */ -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG if (!allowed_parent1 && log_request_parent1) { log_request_parent1->type =LANDLOCK_REQUEST_FS_ACCESS ; log_request_parent1->audit.type =LSM_AUDIT_DATA_PATH ;
@@ -952,7 +953,7 @@ is_access_to_paths_allowed(const struct landlock_domain *const domain, log_request_parent2->access = access_masked_parent2; log_request_parent2->layer_masks = layer_masks_parent2; } -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ return allowed_parent1 && allowed_parent2; }
@@ -1830,14 +1831,14 @@ static int hook_file_open(struct file *const file)* file access rights in the opened struct file. */ landlock_file (file)->allowed_access = allowed_access; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG landlock_file (file)->deny_masks =landlock_get_deny_masks ( _LANDLOCK_ACCESS_FS_OPTIONAL, optional_access, &layer_masks);landlock_file (file)->quiet_optional_accesses =landlock_get_quiet_optional_accesses ( _LANDLOCK_ACCESS_FS_OPTIONAL,landlock_file (file)->deny_masks, &layer_masks); -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ if (access_mask_subset (open_access_request, allowed_access))return 0 ;
@@ -1871,10 +1872,10 @@ static int hook_file_truncate(struct file *const file) }, .all_existing_optional_access = _LANDLOCK_ACCESS_FS_OPTIONAL, .access =LANDLOCK_ACCESS_FS_TRUNCATE , -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG .deny_masks =landlock_file (file)->deny_masks, .quiet_optional_accesses = landlock_file(file)->quiet_optional_accesses, -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ });return -EACCES ; }
@@ -1911,10 +1912,10 @@ static int hook_file_ioctl_common(const struct file *const file, }, .all_existing_optional_access = _LANDLOCK_ACCESS_FS_OPTIONAL, .access =LANDLOCK_ACCESS_FS_IOCTL_DEV , -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG .deny_masks =landlock_file (file)->deny_masks, .quiet_optional_accesses = landlock_file(file)->quiet_optional_accesses, -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ });return -EACCES ; }
@@ -1990,9 +1991,9 @@ static void hook_file_set_fowner(struct file *file) prev_tg =landlock_file (file)->fown_tg;landlock_file (file)->fown_subject = fown_subject;landlock_file (file)->fown_tg = fown_tg; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG landlock_file (file)->fown_layer = fown_layer; -#endif /* CONFIG_AUDIT*/ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ /* May be called in an RCU read-side critical section. */ landlock_put_domain_deferred (prev_dom);
security/landlock/fs.h +4 -4
@@ -57,7 +57,7 @@ struct landlock_file_security {*/ access_mask_t allowed_access; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG /** * @deny_masks: Domain layer levels that deny an optional access (see * _LANDLOCK_ACCESS_FS_OPTIONAL).
@@ -75,7 +75,7 @@ struct landlock_file_security {* LANDLOCK_SCOPE_SIGNAL. */ u8 fown_layer; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ /** * @fown_subject: Landlock credential of the task that set the PID that
@@ -97,7 +97,7 @@ struct landlock_file_security {struct pid *fown_tg; }; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG /* Makes sure all layers can be identified. */ /* clang-format off */
@@ -113,7 +113,7 @@ static_assert(BITS_PER_TYPE(typeof_member(struct landlock_file_security, quiet_optional_accesses)) >= HWEIGHT(_LANDLOCK_ACCESS_FS_OPTIONAL)); -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ /** * struct landlock_superblock_security - Superblock security blob
security/landlock/id.h +3 -3
@@ -8,18 +8,18 @@#ifndef _SECURITY_LANDLOCK_ID_H#define _SECURITY_LANDLOCK_ID_H -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG void __init landlock_init_id (void );u64 landlock_get_id_range (size_t number_of_ids); -#else /* CONFIG_AUDIT */ +#else /* CONFIG_SECURITY_LANDLOCK_LOG */ static inline void __init landlock_init_id (void ) { } -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ #endif /* _SECURITY_LANDLOCK_ID_H */
security/landlock/log.c new file +502 -0
502 lines not on this page · raw message
security/landlock/log.h new file +77 -0
77 lines not on this page · raw message
security/landlock/net.c +1 -1
@@ -12,11 +12,11 @@#include <linux/socket.h> #include <net/ipv6.h> -#include "audit.h" #include "common.h" #include "cred.h" #include "domain.h" #include "limits.h" +#include "log.h" #include "net.h" #include "ruleset.h"
security/landlock/syscalls.c +6 -6
@@ -574,11 +574,11 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32, new_llcred =landlock_cred (new_cred); -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG prev_log_subdomains = !new_llcred->log_subdomains_off; new_llcred->log_subdomains_off = !prev_log_subdomains || !log_subdomains; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ /* * The only case when a ruleset may not be set is if
@@ -600,20 +600,20 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32,return PTR_ERR (new_dom); } -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG new_dom->hierarchy->log_same_exec = log_same_exec; new_dom->hierarchy->log_new_exec = log_new_exec;if ((!log_same_exec && !log_new_exec) || !prev_log_subdomains) new_dom->hierarchy->log_status =LANDLOCK_LOG_DISABLED ; -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ /* Replaces the old (prepared) domain. */ landlock_put_domain (new_llcred->domain); new_llcred->domain = new_dom; -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG new_llcred->domain_exec |=BIT (new_dom->num_layers -1 ); -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ }if (flags &LANDLOCK_RESTRICT_SELF_TSYNC ) {
security/landlock/task.c +3 -3
@@ -20,11 +20,11 @@#include <net/af_unix.h> #include <net/sock.h> -#include "audit.h" #include "common.h" #include "cred.h" #include "domain.h" #include "fs.h" +#include "log.h" #include "ruleset.h" #include "setup.h" #include "task.h"
@@ -435,9 +435,9 @@ static int hook_file_send_sigiotask(struct task_struct *tsk, .type = LSM_AUDIT_DATA_TASK, .u.tsk = tsk, }, -#ifdef CONFIG_AUDIT +#ifdef CONFIG_SECURITY_LANDLOCK_LOG .layer_plus_one = landlock_file(fown->file)->fown_layer + 1, -#endif /* CONFIG_AUDIT */ +#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ });return -EPERM ; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/5 landlock: Work around gcc-16 -Wuninitialized warning
In reply to Sasha LevinFrom: Arnd Bergmann <[email protected]>
[ Upstream commit c4e941bb7654bcbdfb0b6f3341dc2acfdf235c8d ]
gcc has a bug with -ftrivial-auto-var-init=pattern that produces a warning for correct code that uses sparse bitfields:
security/landlock/fs.c: In function 'is_access_to_paths_allowed.isra':security/landlock/fs.c:767:28: error: '_layer_masks_child1' is used uninitialized [-Werror=uninitialized]
767 | struct layer_masks _layer_masks_child1, _layer_masks_child2;
| ^~~~~~~~~~~~~~~~~~~
security/landlock/fs.c:767:28: note: '_layer_masks_child1' declared here
767 | struct layer_masks _layer_masks_child1, _layer_masks_child2;
| ^~~~~~~~~~~~~~~~~~~
security/landlock/fs.c: In function 'hook_unix_find':
security/landlock/fs.c:1649:28: error: 'layer_masks' is used uninitialized [-Werror=uninitialized]
1649 | struct layer_masks layer_masks;
| ^~~~~~~~~~~
security/landlock/fs.c:1649:28: note: 'layer_masks' declared here
1649 | struct layer_masks layer_masks;
| ^~~~~~~~~~~To work around this, change the definition of struct layer_mask to use an explictit padding field.
[mic: Use BITS_PER_TYPE(), fix kdoc warnings, fix commit message according to v2 changes]
--- security/landlock/access.h | 8 ++++++++ 1 file changed, 8 insertions(+)
security/landlock/access.h +8 -0
@@ -61,6 +61,10 @@ union access_masks_all {static_assert (sizeof (typeof_member (union access_masks_all ,masks )) ==sizeof (typeof_member (union access_masks_all ,all ))); +#define _LANDLOCK_LAYER_MASK_PADDING \ + (BITS_PER_TYPE(access_mask_t) - LANDLOCK_NUM_ACCESS_MAX - \ + IS_ENABLED(CONFIG_SECURITY_LANDLOCK_LOG)) +/** * struct layer_mask - The access rights and rule flags for a layer. *
@@ -81,6 +85,10 @@ struct layer_mask {*/ access_mask_t quiet : 1;#endif /* CONFIG_SECURITY_LANDLOCK_LOG */ +/** +* @__pad: Padding for the compiler's bitfield initialization. +*/ + access_mask_t __pad : _LANDLOCK_LAYER_MASK_PADDING; } __packed__aligned(sizeof(access_mask_t)) ;/*
Signature · 1 line
2.53.0
Mickaël Salaün
maintainerPATCH v2 1/1 landlock: Work around gcc-16 -Wuninitialized warning
In reply to Sasha LevinFrom: Arnd Bergmann <[email protected]>
[ Upstream commit c4e941bb7654bcbdfb0b6f3341dc2acfdf235c8d ]
gcc has a bug with -ftrivial-auto-var-init=pattern that produces a warning for correct code that uses sparse bitfields:
security/landlock/fs.c: In function 'is_access_to_paths_allowed.isra':security/landlock/fs.c:767:28: error: '_layer_masks_child1' is used uninitialized [-Werror=uninitialized]
767 | struct layer_masks _layer_masks_child1, _layer_masks_child2;
| ^~~~~~~~~~~~~~~~~~~
security/landlock/fs.c:767:28: note: '_layer_masks_child1' declared here
767 | struct layer_masks _layer_masks_child1, _layer_masks_child2;
| ^~~~~~~~~~~~~~~~~~~
security/landlock/fs.c: In function 'hook_unix_find':
security/landlock/fs.c:1649:28: error: 'layer_masks' is used uninitialized [-Werror=uninitialized]
1649 | struct layer_masks layer_masks;
| ^~~~~~~~~~~
security/landlock/fs.c:1649:28: note: 'layer_masks' declared here
1649 | struct layer_masks layer_masks;
| ^~~~~~~~~~~To work around this, change the definition of struct layer_mask to use an explictit padding field.
[mic: Use BITS_PER_TYPE(), fix kdoc warnings, fix commit message according to v2 changes]
---
Changes since v1:
https://patch.msgid.link/[email protected]
- Drop the four context-only prerequisite backports and use CONFIG_AUDIT to calculate the target's padding width.
--- security/landlock/access.h | 8 ++++++++ 1 file changed, 8 insertions(+)
security/landlock/access.h +8 -0
@@ -61,6 +61,10 @@ union access_masks_all {static_assert (sizeof (typeof_member (union access_masks_all ,masks )) ==sizeof (typeof_member (union access_masks_all ,all ))); +#define _LANDLOCK_LAYER_MASK_PADDING \ + (BITS_PER_TYPE(access_mask_t) - LANDLOCK_NUM_ACCESS_MAX - \ + IS_ENABLED(CONFIG_AUDIT)) +/** * struct layer_mask - The access rights and rule flags for a layer. *
@@ -81,6 +85,10 @@ struct layer_mask {*/ access_mask_t quiet : 1;#endif /* CONFIG_AUDIT */ +/** +* @__pad: Padding for the compiler's bitfield initialization. +*/ + access_mask_t __pad : _LANDLOCK_LAYER_MASK_PADDING; } __packed__aligned(sizeof(access_mask_t)) ;/*