[PATCH] landlock: Do not hold exec_update_lock across the TSYNC wait

Oleg Nesterov oleg at redhat.com
Sun Nov 22 17:35:12 UTC 2026


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

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

Oleg.




More information about the Linux-security-module-archive mailing list