From: Christian Brauner <brauner@kernel.org>
To: Jann Horn <jannh@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
linux-fsdevel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
selinux@vger.kernel.org, Kees Cook <kees@kernel.org>,
linux-mm@kvack.org, linux-security-module@vger.kernel.org,
apparmor@lists.ubuntu.com, David Hildenbrand <david@kernel.org>,
"Christian Brauner (Amutable)" <brauner@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH RFC 12/19] apparmor: revalidate inherited files before taking exec_update_lock
Date: Tue, 24 Nov 2026 23:58:35 +0100 [thread overview]
Message-ID: <20261124-work-exec-update_lock-v1-12-e489035395b8@kernel.org> (raw)
In-Reply-To: <20261124-work-exec-update_lock-v1-0-e489035395b8@kernel.org>
When an exec changes the profile aa_inherit_files() revalidates the
controlling terminal and the inherited files against the new label.
Everything the new label isn't allowed to use is taken away from the
task. This is done from apparmor_bprm_committing_creds() which runs with
exec_update_lock held for writing.
Taking a file away closes it and so calls its ->flush() method which can
block waiting on the filesystem. So a hung filesystem blocks everyone
who needs the exec_update_lock of that task. And a FUSE server that
looks at the task it serves the flush request for deadlocks:
exec FUSE server
begin_new_exec()
exec_mmap()
down_write(exec_update_lock)
security_bprm_committing_creds()
aa_inherit_files()
replace_fd()
filp_close()
fuse_flush()
do_task_stat()
down_read(exec_update_lock)
With a FUSE server that reads /proc/<pid>/stat of the task that sent the
flush request the exec hangs until the server is killed:
task:aa-target state:S pid:98
Call Trace:
__schedule+0x53e/0x13f0
schedule+0x36/0x100
request_wait_answer+0x1a9/0x320
fuse_chan_send+0x110/0x250
fuse_flush+0x1af/0x1f0
filp_flush+0x33/0x90
filp_close+0x12/0x30
aa_inherit_files+0x191/0x2a0
apparmor_bprm_committing_creds+0x61/0x90
security_bprm_committing_creds+0x19/0x30
begin_new_exec+0x6dc/0xf90
load_elf_binary+0x12a/0x1990
bprm_execve+0x39d/0x870
do_execveat_common.isra.0+0x165/0x180
__x64_sys_execve+0x38/0x50
do_syscall_64+0x110/0x600
entry_SYSCALL_64_after_hwframe+0x77/0x7f
task:aa-fuse state:D pid:97
Call Trace:
__schedule+0x53e/0x13f0
schedule+0x36/0x100
schedule_preempt_disabled+0x11/0x20
rwsem_down_read_slowpath+0x186/0x5f0
down_read_killable+0x78/0x1b0
do_task_stat+0x87/0x10c0
proc_single_show+0x67/0xe0
seq_read_iter+0x11c/0x480
seq_read+0x127/0x1c0
vfs_read+0xd8/0x4a0
ksys_read+0x7c/0x110
do_syscall_64+0x110/0x600
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The flush is a forced request so the exec can't even be killed while it
waits for the reply.
This is the same problem that commit e780259b54e6 ("exec:
do_close_on_exec() before taking exec_update_lock") fixed for
close-on-exec files.
Fix this by moving the revalidation into the new bprm_revalidate_files
hook which is called before exec_update_lock is taken.
Fixes: 6650527444da ("proc: protect ptrace_may_access() with exec_update_lock (part 1)")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
security/apparmor/lsm.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index eaebc3c60c5af..e40619b0f4ba9 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -951,10 +951,13 @@ static int apparmor_setprocattr(const char *name, void *value,
}
/**
- * apparmor_bprm_committing_creds - do task cleanup on committing new creds
+ * apparmor_bprm_revalidate_files - revalidate inherited files on exec
* @bprm: binprm for the exec (NOT NULL)
+ *
+ * Called before exec_update_lock is taken as closing files may block in
+ * the filesystem.
*/
-static void apparmor_bprm_committing_creds(const struct linux_binprm *bprm)
+static void apparmor_bprm_revalidate_files(const struct linux_binprm *bprm)
{
struct aa_label *label = aa_current_raw_label();
struct aa_label *new_label = cred_label(bprm->cred);
@@ -965,6 +968,21 @@ static void apparmor_bprm_committing_creds(const struct linux_binprm *bprm)
return;
aa_inherit_files(bprm->cred, current->files);
+}
+
+/**
+ * apparmor_bprm_committing_creds - do task cleanup on committing new creds
+ * @bprm: binprm for the exec (NOT NULL)
+ */
+static void apparmor_bprm_committing_creds(const struct linux_binprm *bprm)
+{
+ struct aa_label *label = aa_current_raw_label();
+ struct aa_label *new_label = cred_label(bprm->cred);
+
+ /* bail out if unconfined or not changing profile */
+ if ((new_label->proxy == label->proxy) ||
+ (unconfined(new_label)))
+ return;
current->pdeath_signal = 0;
@@ -1860,6 +1878,7 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {
LSM_HOOK_INIT(cred_transfer, apparmor_cred_transfer),
LSM_HOOK_INIT(bprm_creds_for_exec, apparmor_bprm_creds_for_exec),
+ LSM_HOOK_INIT(bprm_revalidate_files, apparmor_bprm_revalidate_files),
LSM_HOOK_INIT(bprm_committing_creds, apparmor_bprm_committing_creds),
LSM_HOOK_INIT(bprm_committed_creds, apparmor_bprm_committed_creds),
--
2.53.0
next prev parent reply other threads:[~2026-11-24 23:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 22:58 [PATCH RFC 00/19] exec: move sleeping work out of exec_update_lock Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 01/19] proc: copy namespace link after dropping exec_update_lock Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 02/19] kcmp: look up epoll target without exec_update_lock held Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 03/19] perf: copy counter values after dropping ctx->mutex Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 04/19] perf: copy ioctl arguments without ctx->mutex held Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 05/19] selinux: close inherited files that can't be replaced Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 06/19] exec: move unshare_sighand() before exec_mmap() Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 07/19] selftests/exec: test exec with a task sleeping in a page fault Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 08/19] selftests/exec: test exec with a shared signal table Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 09/19] lsm: add security_bprm_revalidate_files() Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 10/19] bpf: mark bprm_revalidate_files as sleepable Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 11/19] selinux: revalidate inherited files before taking exec_update_lock Christian Brauner
2026-11-24 23:49 ` bot+bpf-ci
2026-11-24 22:58 ` Christian Brauner [this message]
2026-11-24 22:58 ` [PATCH RFC 13/19] exec: drop exec_update_lock after the credentials are committed Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 14/19] exec: switch time namespace after dropping exec_update_lock Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 15/19] exec: don't take the mmap lock of the old mm Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 16/19] exit: don't take the mmap lock in exit_mm() Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 17/19] proc: look up map_files vma without exec_update_lock held Christian Brauner
2026-11-24 23:09 ` sashiko-bot
2026-11-24 22:58 ` [PATCH RFC 18/19] vfork: wake up the parent once the child has left the mm Christian Brauner
2026-11-24 23:49 ` bot+bpf-ci
2026-11-24 22:58 ` [PATCH RFC 19/19] selftests/exec: test when a vfork() parent is woken up Christian Brauner
2026-11-24 23:15 ` [PATCH RFC 00/19] exec: move sleeping work out of exec_update_lock sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124-work-exec-update_lock-v1-12-e489035395b8@kernel.org \
--to=brauner@kernel.org \
--cc=acme@kernel.org \
--cc=apparmor@lists.ubuntu.com \
--cc=bpf@vger.kernel.org \
--cc=david@kernel.org \
--cc=jannh@google.com \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=selinux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox