From: Oleg Nesterov <oleg@redhat.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: "Christian Brauner" <brauner@kernel.org>,
"Günther Noack" <gnoack@google.com>, "Tejun Heo" <tj@kernel.org>,
"Bart Van Assche" <bvanassche@acm.org>,
"Cen Zhang" <blbllhy@gmail.com>,
"James Morris" <jmorris@namei.org>,
"Lee Seong Hyeon" <ihopenre@gmail.com>,
"Marco Elver" <elver@google.com>, NeilBrown <neil@brown.name>,
"Nickolai Zeldovich" <nickolai@csail.mit.edu>,
"Paul Moore" <paul@paul-moore.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Serge E . Hallyn" <serge@hallyn.com>,
"Yihan Ding" <dingyihan@uniontech.com>,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] landlock: Do not hold exec_update_lock across the TSYNC wait
Date: Sun, 22 Nov 2026 18:35:12 +0100 [thread overview]
Message-ID: <awMn0L7RaQO_6qUc@redhat.com> (raw)
In-Reply-To: <20261120151554.2651743-1-mic@digikod.net>
On 11/20, Mickaël Salaün wrote:
>
> @@ -492,6 +533,19 @@ int landlock_restrict_sibling_threads(const struct cred *old_cred,
> size_t newly_discovered_threads;
> bool found_more_threads;
>
> + /*
> + * Serialize concurrent TSYNC operations to prevent deadlocks when
> + * multiple threads call landlock_restrict_self() simultaneously. If
> + * another operation got there first, gracefully yield by restarting the
> + * syscall. This allows the current thread to process pending
> + * task_works before retrying.
> + *
> + * sighand->siglock protects only the marker, not the wait below.
> + */
> + CLASS(current_tsync_marker, marker)();
> + if (!marker)
> + return restart_syscall();
> +
> atomic_set(&shared_ctx.preparation_error, 0);
> init_completion(&shared_ctx.all_prepared);
> init_completion(&shared_ctx.ready_to_commit);
> @@ -503,16 +557,6 @@ int landlock_restrict_sibling_threads(const struct cred *old_cred,
> (restrict_flags & LANDLOCK_RESTRICT_SELF_NO_NEW_PRIVS) ||
> task_no_new_privs(current);
>
> - /*
> - * Serialize concurrent TSYNC operations to prevent deadlocks when
> - * multiple threads call landlock_restrict_self() simultaneously.
> - * If the lock is already held, we gracefully yield by restarting the
> - * syscall. This allows the current thread to process pending
> - * task_works before retrying.
> - */
> - if (!down_write_trylock(¤t->signal->exec_update_lock))
> - return restart_syscall();
Just in case, the patch looks obviously correct, so feel free to add
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
-------------------------------------------------------------------------------
But when I look at this code...
Well, if we change landlock_restrict_sibling_threads() to rely on ->siglock,
it seems that it can be greatly simplified? I mean, it can roughly do:
...
for (nt nr_threads = 0;; tsync_works_grow_by(&works, nr_threads))
{
guard(spinlock_irq)(¤t->sighand->siglock);
if (!nr_threads) {
if (signal->flags & SIGNAL_LANDLOCK_TSYNC || ...)
return restart_syscall();
else
signal->flags |= SIGNAL_LANDLOCK_TSYNC;
}
if (nr_threads < get_nr_threads(current)) {
nr_threads = get_nr_threads(current));
continue;
}
for_other_threads(current, thread) {
if (thread->flags & PF_EXITING) // stable under siglock
continue;
ctx = tsync_works_provide(...); // can't fail
...
task_work_add(thread, &ctx->work, TWA_SIGNAL); // can't fail
}
break;
}
complete_all(&shared_ctx.ready_to_commit);
...
We can kill tsync_works_trim/tsync_works_contains_task/count_additional_threads/etc.
Sure, this needs another change even if I am right.
Oleg.
next prev parent reply other threads:[~2026-11-22 17:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 15:15 [PATCH] landlock: Do not hold exec_update_lock across the TSYNC wait Mickaël Salaün
2026-11-20 15:22 ` sashiko-bot
2026-11-21 21:46 ` Günther Noack
2026-11-23 9:37 ` Mickaël Salaün
2026-11-24 16:02 ` Günther Noack
2026-11-22 17:35 ` Oleg Nesterov [this message]
2026-11-23 13:15 ` Mickaël Salaün
2026-11-23 13:49 ` Oleg Nesterov
2026-11-24 15:09 ` Christian Brauner
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=awMn0L7RaQO_6qUc@redhat.com \
--to=oleg@redhat.com \
--cc=blbllhy@gmail.com \
--cc=brauner@kernel.org \
--cc=bvanassche@acm.org \
--cc=dingyihan@uniontech.com \
--cc=elver@google.com \
--cc=gnoack@google.com \
--cc=ihopenre@gmail.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=neil@brown.name \
--cc=nickolai@csail.mit.edu \
--cc=paul@paul-moore.com \
--cc=peterz@infradead.org \
--cc=serge@hallyn.com \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.