FAILED: patch "[PATCH] landlock: Account all audit data allocations to user space" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-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-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x b232bd12789fa57405b5092f28788be97aae9999
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071622-boil-spotlight-afbb@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From b232bd12789fa57405b5092f28788be97aae9999 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]>
Date: Wed, 13 May 2026 20:03:08 +0200
Subject: [PATCH] landlock: Account all audit data allocations to user space
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mark the kzalloc_flex() of struct landlock_details with GFP_KERNEL_ACCOUNT so the allocation is charged to the calling task, like the other Landlock per-domain allocations which have used GFP_KERNEL_ACCOUNT forever.
Every property of landlock_details is caller-attributable: allocated by landlock_restrict_self(2), owned by the caller's landlock_hierarchy, contents are the caller's pid, uid, comm, and exe_path, lifetime bounded by the caller's domain. While the caller may not know nor control the size of this allocation (i.e. exe_path), this data should still be accounted for it.
The deciding factor is whether userspace can trigger the allocation, not whether the size of the data is known nor controlled by the caller. This aligns with the kmemcg accounting policy established by commit 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg").
No new failure modes: the hierarchy and ruleset are allocated before details and are already accounted, so landlock_restrict_self(2) already returns -ENOMEM under memcg pressure. This change widens that existing failure window slightly; it does not introduce a new error code.
security/landlock/domain.c +5 -4
@@ -90,11 +90,12 @@ static struct landlock_details *get_current_details(void)return ERR_CAST (buffer);/* -* Create the new details according to the path's length. Do not -* allocate with GFP_KERNEL_ACCOUNT because it is independent from the -* caller. +* Create the new details according to the path's length. Account to +* the calling task's memcg, like the other Landlock per-domain +* allocations, even if it may not control the related size. */ - details =kzalloc_flex (*details, exe_path, path_size); + details = +kzalloc_flex (*details, exe_path, path_size,GFP_KERNEL_ACCOUNT );if (!details)return ERR_PTR (-ENOMEM );
security/landlock/domain.h +1 -4
@@ -33,10 +33,7 @@ enum landlock_log_status {* Rarely accessed, mainly when logging the first domain's denial. * * The contained pointers are initialized at the domain creation time and never -* changed again. Contrary to most other Landlock object types, this one is -* not allocated with GFP_KERNEL_ACCOUNT because its size may not be under the -* caller's control (e.g. unknown exe_path) and the data is not explicitly -* requested nor used by tasks. +* changed again. */ struct landlock_details {/**
Sasha Levin
maintainerPATCH 1/2 landlock: Fix formatting
From: Mickaël Salaün <[email protected]>
[ Upstream commit 405ca72dc589dd746e5ee5378bb9d9ee7f844010 ]
Auto-format with clang-format -i security/landlock/*.[ch]
Stable-dep-of: b232bd12789f ("landlock: Account all audit data allocations to user space")
--- security/landlock/domain.c | 3 +-- security/landlock/ruleset.c | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-)
security/landlock/domain.c +1 -2
@@ -94,8 +94,7 @@ static struct landlock_details *get_current_details(void)* allocate with GFP_KERNEL_ACCOUNT because it is independent from the * caller. */ - details = -kzalloc (struct_size (details, exe_path, path_size),GFP_KERNEL ); + details =kzalloc_flex (*details, exe_path, path_size);if (!details)return ERR_PTR (-ENOMEM );
security/landlock/ruleset.c +3 -4
@@ -33,9 +33,8 @@ static struct landlock_ruleset *create_ruleset(const u32 num_layers) {struct landlock_ruleset *new_ruleset; - new_ruleset = -kzalloc (struct_size (new_ruleset, access_masks, num_layers), -GFP_KERNEL_ACCOUNT ); + new_ruleset =kzalloc_flex (*new_ruleset, access_masks, num_layers, +GFP_KERNEL_ACCOUNT );if (!new_ruleset)return ERR_PTR (-ENOMEM );refcount_set (&new_ruleset->usage,1 );
@@ -553,7 +552,7 @@ landlock_merge_ruleset(struct landlock_ruleset *const parent,return new_dom; new_dom->hierarchy = -kzalloc (sizeof (*new_dom->hierarchy),GFP_KERNEL_ACCOUNT ); +kzalloc_obj (*new_dom->hierarchy,GFP_KERNEL_ACCOUNT );if (!new_dom->hierarchy)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 landlock: Account all audit data allocations to user space
From: Mickaël Salaün <[email protected]>
[ Upstream commit b232bd12789fa57405b5092f28788be97aae9999 ]
Mark the kzalloc_flex() of struct landlock_details with GFP_KERNEL_ACCOUNT so the allocation is charged to the calling task, like the other Landlock per-domain allocations which have used GFP_KERNEL_ACCOUNT forever.
Every property of landlock_details is caller-attributable: allocated by landlock_restrict_self(2), owned by the caller's landlock_hierarchy, contents are the caller's pid, uid, comm, and exe_path, lifetime bounded by the caller's domain. While the caller may not know nor control the size of this allocation (i.e. exe_path), this data should still be accounted for it.
The deciding factor is whether userspace can trigger the allocation, not whether the size of the data is known nor controlled by the caller. This aligns with the kmemcg accounting policy established by commit 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg").
No new failure modes: the hierarchy and ruleset are allocated before details and are already accounted, so landlock_restrict_self(2) already returns -ENOMEM under memcg pressure. This change widens that existing failure window slightly; it does not introduce a new error code.
--- security/landlock/domain.c | 9 +++++---- security/landlock/domain.h | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-)
security/landlock/domain.c +5 -4
@@ -90,11 +90,12 @@ static struct landlock_details *get_current_details(void)return ERR_CAST (buffer);/* -* Create the new details according to the path's length. Do not -* allocate with GFP_KERNEL_ACCOUNT because it is independent from the -* caller. +* Create the new details according to the path's length. Account to +* the calling task's memcg, like the other Landlock per-domain +* allocations, even if it may not control the related size. */ - details =kzalloc_flex (*details, exe_path, path_size); + details = +kzalloc_flex (*details, exe_path, path_size,GFP_KERNEL_ACCOUNT );if (!details)return ERR_PTR (-ENOMEM );
security/landlock/domain.h +1 -4
@@ -33,10 +33,7 @@ enum landlock_log_status {* Rarely accessed, mainly when logging the first domain's denial. * * The contained pointers are initialized at the domain creation time and never -* changed again. Contrary to most other Landlock object types, this one is -* not allocated with GFP_KERNEL_ACCOUNT because its size may not be under the -* caller's control (e.g. unknown exe_path) and the data is not explicitly -* requested nor used by tasks. +* changed again. */ struct landlock_details {/**
Signature · 1 line
2.53.0