mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mickaël Salaün" <mic@digikod.net>
To: Oleg Nesterov <oleg@redhat.com>
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,
	"Jann Horn" <jannh@google.com>
Subject: Re: [PATCH] landlock: Do not hold exec_update_lock across the TSYNC wait
Date: Mon, 23 Nov 2026 14:15:07 +0100	[thread overview]
Message-ID: <20261123.ungeuh7Taish@digikod.net> (raw)
In-Reply-To: <awMn0L7RaQO_6qUc@redhat.com>

On Sun, Nov 22, 2026 at 06:35:12PM +0100, Oleg Nesterov wrote:
> 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(&current->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>

Thanks for the review.

> 
> -------------------------------------------------------------------------------
> 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)(&current->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.

That would indeed be simpler, but a single pass would misses threads
that a sibling is creating at the same time: the cred is copied before
taking siglock and only fatal_signal_pending is checked.

Keeping the rescan loop and walking under siglock would be correct and
would drop tsync_works_trim() and count_additional_threads().  However,
it would hold siglock with IRQ disabled across a task_work_add() for
every thread, which /proc/<pid>/stat readers would then wait for.  That
is bounded and not worse than what SIGCONT already does, but the RCU
walk avoids it entirely, so I'm wondering if it's worth it.

> 
> Sure, this needs another change even if I am right.

Yes, I'll send a follow-up if needed.

> 
> Oleg.
> 
> 

  reply	other threads:[~2026-11-23 13:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 15:15 Mickaël Salaün
2026-11-21 21:46 ` Günther Noack
2026-11-23  9:37   ` Mickaël Salaün
2026-11-22 17:35 ` Oleg Nesterov
2026-11-23 13:15   ` Mickaël Salaün [this message]
2026-11-23 13:49     ` Oleg Nesterov

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=20261123.ungeuh7Taish@digikod.net \
    --to=mic@digikod.net \
    --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=jannh@google.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=nickolai@csail.mit.edu \
    --cc=oleg@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®