FAILED: patch "[PATCH] landlock: Fix LANDLOCK_SCOPE_SIGNAL bypass on the SIGIO path" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-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.12.y
git checkout FETCH_HEAD
git cherry-pick -x 4b80320ca7ed03d6e683f95b6066565dc97b9f92
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072036-petticoat-useable-12b3@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 4b80320ca7ed03d6e683f95b6066565dc97b9f92 Mon Sep 17 00:00:00 2001
From: Bryam Vargas <[email protected]>
Date: Thu, 4 Jun 2026 23:16:56 +0000
Subject: [PATCH] landlock: Fix LANDLOCK_SCOPE_SIGNAL bypass on the SIGIO path
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
LANDLOCK_SCOPE_SIGNAL must prevent a sandboxed process from signaling processes outside its Landlock domain. It can be bypassed through the asynchronous SIGIO delivery path.
A sandboxed process that owns any file or socket can arm it with fcntl(fd, F_SETOWN, -pgid), fcntl(fd, F_SETSIG, SIGKILL) and O_ASYNC, so that an I/O event makes the kernel deliver the chosen signal to the whole process group. As the head of its process group's task list (the default position right after fork()) that group can also hold the non-sandboxed process that launched it, e.g. a supervisor or a security monitor. The sandbox can thus kill or signal the processes LANDLOCK_SCOPE_SIGNAL is meant to protect from it.
The scope is enforced in hook_file_send_sigiotask() against the Landlock domain recorded at F_SETOWN time, not the live domain of the sender. control_current_fowner() decides whether to record that domain and skips recording it when the fowner target is in the caller's thread group, which is safe only for a single-task target (PIDTYPE_PID, PIDTYPE_TGID). For a process group (PIDTYPE_PGID) pid_task() returns only one member; recording is skipped whenever that member shares the caller's thread group, and hook_file_send_sigiotask() then lets the signal fan out to the whole group unchecked.
Record the domain for every non single-process target so the scope is enforced against each group member at delivery time.
That recording is necessary but not sufficient on its own: the kernel signals a process group through its members' thread-group leaders, and the leader of the registrant's own process can carry a different Landlock domain than the sibling thread that armed the owner. domain_is_scoped() would then deny that leader, even though commit 18eb75f3af40 ("landlock: Always allow signals between threads of the same process") requires same-process delivery to be allowed. hook_task_kill() avoids this by evaluating same_thread_group() live, per recipient; the SIGIO path instead delegates the whole decision to a single registration-time check, which a process-group fan-out cannot honor.
So also record the registrant's thread group next to its domain and exempt it at delivery: hook_file_send_sigiotask() allows the signal whenever the recipient belongs to the registrant's own process, restoring the same-process guarantee while keeping out-of-domain group members blocked. The direct kill() path (hook_task_kill) already evaluates the live domain and is unaffected.
[mic: Check pid_type earlier and improve comment, fix commit message, fix comment formatting]
security/landlock/fs.c +14 -0
@@ -1900,6 +1900,14 @@ static bool control_current_fowner(struct fown_struct *const fown)*/ lockdep_assert_held (&fown->lock); +/* +* A process-group or session owner (PIDTYPE_PGID/PIDTYPE_SID) fans the +* signal out to every member at delivery time, so record the domain and +* let hook_file_send_sigiotask() check the live scope per recipient. +*/ +if (fown->pid_type !=PIDTYPE_PID && fown->pid_type !=PIDTYPE_TGID ) +return true; +/* * Some callers (e.g. fcntl_dirnotify) may not be in an RCU read-side * critical section.
@@ -1916,6 +1924,7 @@ static void hook_file_set_fowner(struct file *file) {struct landlock_ruleset *prev_dom;struct landlock_cred_security fown_subject = {}; +struct pid *prev_tg, *fown_tg =NULL ;size_t fown_layer =0 ;if (control_current_fowner (file_f_owner (file))) {
@@ -1928,21 +1937,26 @@ static void hook_file_set_fowner(struct file *file)if (new_subject) {landlock_get_ruleset (new_subject->domain); fown_subject = *new_subject; + fown_tg =get_pid (task_tgid (current)); } } prev_dom =landlock_file (file)->fown_subject.domain; + prev_tg =landlock_file (file)->fown_tg;landlock_file (file)->fown_subject = fown_subject; +landlock_file (file)->fown_tg = fown_tg;#ifdef CONFIG_AUDIT landlock_file (file)->fown_layer = fown_layer;#endif /* CONFIG_AUDIT*/ /* May be called in an RCU read-side critical section. */ landlock_put_ruleset_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); }
security/landlock/fs.h +10 -0
@@ -78,6 +78,16 @@ struct landlock_file_security {* euid. */ struct landlock_cred_security fown_subject; +/** +* @fown_tg: Thread group of the task that set the file owner, pinned +* while @fown_subject holds a domain. It lets +* hook_file_send_sigiotask() always allow a SIGIO delivered to the +* owner's own process -- e.g. the thread-group leader reached through a +* process-group owner -- matching the same-process exemption of +* hook_task_kill(). NULL when no domain is recorded. Protected by +* file->f_owner->lock, like @fown_subject. +*/ +struct pid *fown_tg; };#ifdef CONFIG_AUDIT
security/landlock/task.c +11 -0
@@ -411,6 +411,17 @@ static int hook_file_send_sigiotask(struct task_struct *tsk,if (!subject->domain)return 0 ; +/* +* Always allow delivery to the file owner's own process, including a +* thread-group leader reached through a process-group owner. This +* mirrors hook_task_kill()'s same-process exemption and preserves the +* guarantee of commit 18eb75f3af40 ("landlock: Always allow signals +* between threads of the same process"), which the registration-time +* check cannot honor for a process-group target. +*/ +if (task_tgid (tsk) ==landlock_file (fown->file)->fown_tg) +return 0 ; +scoped_guard (rcu) { is_scoped = domain_is_scoped(subject->domain,
Sasha Levin
maintainerPATCH 1/2 landlock: Prepare to use credential instead of domain for fowner
From: Mickaël Salaün <[email protected]>
[ Upstream commit 79625f1b3a3df63d3289a0781fdf121bc42966f7 ]
This cosmetic change is needed for audit support, specifically to be able to filter according to cross-execution boundaries.
struct landlock_file_security's size stay the same for now but it will increase with struct landlock_cred_security's size.
Only save Landlock domain in hook_file_set_fowner() if the current domain has LANDLOCK_SCOPE_SIGNAL, which was previously done for each hook_file_send_sigiotask() calls. This should improve a bit performance.
Replace hardcoded LANDLOCK_SCOPE_SIGNAL with the signal_scope.scope variable.
Use scoped guards for RCU read-side critical sections.
Stable-dep-of: 4b80320ca7ed ("landlock: Fix LANDLOCK_SCOPE_SIGNAL bypass on the SIGIO path")
--- security/landlock/fs.c | 37 +++++++++++++++++++++++++++++++------ security/landlock/fs.h | 23 +++++++++++++++++------ security/landlock/task.c | 25 ++++++++++++++++--------- 3 files changed, 64 insertions(+), 21 deletions(-)
security/landlock/fs.c +31 -6
@@ -1680,15 +1680,40 @@ 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_ruleset *new_dom =NULL ; +struct landlock_cred_security fown_subject = {}; +size_t fown_layer =0 ; + +/* +* Keep this local to match the layout expected by follow-up changes +* shared with audit-enabled kernels. +*/ + (void )fown_layer;if (control_current_fowner (file_f_owner (file))) { - new_dom =landlock_get_current_domain (); -landlock_get_ruleset (new_dom); +static const struct access_masks signal_scope = { + .scope =LANDLOCK_SCOPE_SIGNAL , + }; +struct landlock_ruleset *const current_domain = +landlock_get_current_domain (); +const struct landlock_cred_security applicable_subject = { + .domain = current_domain, + }; +const struct landlock_cred_security *new_subject =NULL ; + +if (landlock_get_applicable_domain (current_domain, signal_scope)) + new_subject = &applicable_subject; + +if (new_subject) { +landlock_get_ruleset (new_subject->domain); + fown_subject = *new_subject; + } } - prev_dom =landlock_file (file)->fown_domain; -landlock_file (file)->fown_domain = new_dom; + prev_dom =landlock_file (file)->fown_subject.domain; +landlock_file (file)->fown_subject = fown_subject; +#ifdef CONFIG_AUDIT +landlock_file (file)->fown_layer = fown_layer; +#endif /* CONFIG_AUDIT*/ /* May be called in an RCU read-side critical section. */ landlock_put_ruleset_deferred (prev_dom);
@@ -1696,7 +1721,7 @@ static void hook_file_set_fowner(struct file *file)static void hook_file_free_security (struct file *file) { -landlock_put_ruleset_deferred (landlock_file (file)->fown_domain); +landlock_put_ruleset_deferred (landlock_file (file)->fown_subject.domain); }static struct security_hook_list landlock_hooks[]__ro_after_init = {
security/landlock/fs.h +17 -6
@@ -1,9 +1,10 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* Landlock LSM - Filesystem management and hooks +* Landlock - Filesystem management and hooks * * Copyright © 2017-2020 Mickaël Salaün <[email protected]> * Copyright © 2018-2020 ANSSI +* Copyright © 2024-2025 Microsoft Corporation */ #ifndef _SECURITY_LANDLOCK_FS_H
@@ -13,6 +14,7 @@#include <linux/init.h> #include <linux/rcupdate.h> +#include "cred.h" #include "ruleset.h" #include "setup.h"
@@ -52,13 +54,22 @@ struct landlock_file_security {* needed to authorize later operations on the open file. */ access_mask_t allowed_access; + +#ifdef CONFIG_AUDIT +/** +* @fown_layer: Compatibility storage for follow-up fowner changes. +*/ +u8 fown_layer; +#endif /* CONFIG_AUDIT */ +/** -* @fown_domain: Domain of the task that set the PID that may receive a -* signal e.g., SIGURG when writing MSG_OOB to the related socket. -* This pointer is protected by the related file->f_owner->lock, as for -* fown_struct's members: pid, uid, and euid. +* @fown_subject: Landlock credential of the task that set the PID that +* may receive a signal e.g., SIGURG when writing MSG_OOB to the +* related socket. This pointer is protected by the related +* file->f_owner->lock, as for fown_struct's members: pid, uid, and +* euid. */ -struct landlock_ruleset *fown_domain; +struct landlock_cred_security fown_subject; };/**
security/landlock/task.c +16 -9
@@ -297,22 +297,29 @@ static int hook_task_kill(struct task_struct *const p,static int hook_file_send_sigiotask (struct task_struct *tsk,struct fown_struct *fown,int signum) { -const struct landlock_ruleset *dom; +const struct landlock_cred_security *subject;bool is_scoped = false;/* Lock already held by send_sigio() and send_sigurg(). */ lockdep_assert_held (&fown->lock); - dom =landlock_get_applicable_domain ( -landlock_file (fown->file)->fown_domain, signal_scope); + subject = &landlock_file (fown->file)->fown_subject; -/* Quick return for unowned socket. */ -if (!dom) +/* +* Quick return for unowned socket. +* +* subject->domain has already been filtered when saved by +* hook_file_set_fowner(), so there is no need to call +* landlock_get_applicable_subject() here. +*/ +if (!subject->domain)return 0 ; -rcu_read_lock (); - is_scoped =domain_is_scoped (dom,landlock_get_task_domain (tsk), -LANDLOCK_SCOPE_SIGNAL ); -rcu_read_unlock (); +scoped_guard (rcu) + { + is_scoped =domain_is_scoped (subject->domain, +landlock_get_task_domain (tsk), + signal_scope.scope); + }if (is_scoped)return -EPERM ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 landlock: Fix LANDLOCK_SCOPE_SIGNAL bypass on the SIGIO path
From: Bryam Vargas <[email protected]>
[ Upstream commit 4b80320ca7ed03d6e683f95b6066565dc97b9f92 ]
LANDLOCK_SCOPE_SIGNAL must prevent a sandboxed process from signaling processes outside its Landlock domain. It can be bypassed through the asynchronous SIGIO delivery path.
A sandboxed process that owns any file or socket can arm it with fcntl(fd, F_SETOWN, -pgid), fcntl(fd, F_SETSIG, SIGKILL) and O_ASYNC, so that an I/O event makes the kernel deliver the chosen signal to the whole process group. As the head of its process group's task list (the default position right after fork()) that group can also hold the non-sandboxed process that launched it, e.g. a supervisor or a security monitor. The sandbox can thus kill or signal the processes LANDLOCK_SCOPE_SIGNAL is meant to protect from it.
The scope is enforced in hook_file_send_sigiotask() against the Landlock domain recorded at F_SETOWN time, not the live domain of the sender. control_current_fowner() decides whether to record that domain and skips recording it when the fowner target is in the caller's thread group, which is safe only for a single-task target (PIDTYPE_PID, PIDTYPE_TGID). For a process group (PIDTYPE_PGID) pid_task() returns only one member; recording is skipped whenever that member shares the caller's thread group, and hook_file_send_sigiotask() then lets the signal fan out to the whole group unchecked.
Record the domain for every non single-process target so the scope is enforced against each group member at delivery time.
That recording is necessary but not sufficient on its own: the kernel signals a process group through its members' thread-group leaders, and the leader of the registrant's own process can carry a different Landlock domain than the sibling thread that armed the owner. domain_is_scoped() would then deny that leader, even though commit 18eb75f3af40 ("landlock: Always allow signals between threads of the same process") requires same-process delivery to be allowed. hook_task_kill() avoids this by evaluating same_thread_group() live, per recipient; the SIGIO path instead delegates the whole decision to a single registration-time check, which a process-group fan-out cannot honor.
So also record the registrant's thread group next to its domain and exempt it at delivery: hook_file_send_sigiotask() allows the signal whenever the recipient belongs to the registrant's own process, restoring the same-process guarantee while keeping out-of-domain group members blocked. The direct kill() path (hook_task_kill) already evaluates the live domain and is unaffected.
[mic: Check pid_type earlier and improve comment, fix commit message, fix comment formatting]
--- security/landlock/fs.c | 14 ++++++++++++++ security/landlock/fs.h | 10 ++++++++++ security/landlock/task.c | 11 +++++++++++ 3 files changed, 35 insertions(+)
security/landlock/fs.c +14 -0
@@ -1665,6 +1665,14 @@ static bool control_current_fowner(struct fown_struct *const fown)*/ lockdep_assert_held (&fown->lock); +/* +* A process-group or session owner (PIDTYPE_PGID/PIDTYPE_SID) fans the +* signal out to every member at delivery time, so record the domain and +* let hook_file_send_sigiotask() check the live scope per recipient. +*/ +if (fown->pid_type !=PIDTYPE_PID && fown->pid_type !=PIDTYPE_TGID ) +return true; +/* * Some callers (e.g. fcntl_dirnotify) may not be in an RCU read-side * critical section.
@@ -1681,6 +1689,7 @@ static void hook_file_set_fowner(struct file *file) {struct landlock_ruleset *prev_dom;struct landlock_cred_security fown_subject = {}; +struct pid *prev_tg, *fown_tg =NULL ;size_t fown_layer =0 ;/*
@@ -1706,21 +1715,26 @@ static void hook_file_set_fowner(struct file *file)if (new_subject) {landlock_get_ruleset (new_subject->domain); fown_subject = *new_subject; + fown_tg =get_pid (task_tgid (current)); } } prev_dom =landlock_file (file)->fown_subject.domain; + prev_tg =landlock_file (file)->fown_tg;landlock_file (file)->fown_subject = fown_subject; +landlock_file (file)->fown_tg = fown_tg;#ifdef CONFIG_AUDIT landlock_file (file)->fown_layer = fown_layer;#endif /* CONFIG_AUDIT*/ /* May be called in an RCU read-side critical section. */ landlock_put_ruleset_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); }
security/landlock/fs.h +10 -0
@@ -70,6 +70,16 @@ struct landlock_file_security {* euid. */ struct landlock_cred_security fown_subject; +/** +* @fown_tg: Thread group of the task that set the file owner, pinned +* while @fown_subject holds a domain. It lets +* hook_file_send_sigiotask() always allow a SIGIO delivered to the +* owner's own process -- e.g. the thread-group leader reached through a +* process-group owner -- matching the same-process exemption of +* hook_task_kill(). NULL when no domain is recorded. Protected by +* file->f_owner->lock, like @fown_subject. +*/ +struct pid *fown_tg; };/**
security/landlock/task.c +11 -0
@@ -314,6 +314,17 @@ static int hook_file_send_sigiotask(struct task_struct *tsk,if (!subject->domain)return 0 ; +/* +* Always allow delivery to the file owner's own process, including a +* thread-group leader reached through a process-group owner. This +* mirrors hook_task_kill()'s same-process exemption and preserves the +* guarantee of commit 18eb75f3af40 ("landlock: Always allow signals +* between threads of the same process"), which the registration-time +* check cannot honor for a process-group target. +*/ +if (task_tgid (tsk) ==landlock_file (fown->file)->fown_tg) +return 0 ; +scoped_guard (rcu) { is_scoped = domain_is_scoped(subject->domain,
Signature · 1 line
2.53.0