Re: [PATCH v2 23/31] mm/mempolicy: check access under exec_update_lock

From: sashiko-bot

Date: Sat Dec 05 2026 - 07:59:58 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm: deadlock with Landlock TSYNC in kernel_migrate_pages()
--

commit 9d12c1219637a5ef3eb648287c67efff3c7d9dff
Author: Chris Mason <mason@xxxxxxxxxx>

mm/mempolicy: check access under exec_update_lock

This commit acquires task->signal->exec_update_lock for reading in
kernel_migrate_pages() across the access checks until get_task_mm()
completes, and drops the RCU read lock right after get_task_struct().

> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 9e4e8ecd7e69a..8c1fe94a08971 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -1981,6 +1981,12 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode,
> goto out;
> }
> get_task_struct(task);
> + rcu_read_unlock();
> +
> + /* Exclude execve() until we have grabbed the MM from this task. */
> + err = down_read_killable(&task->signal->exec_update_lock);
> + if (err)
> + goto out_put;

[Severity: High]
Can taking task->signal->exec_update_lock unconditionally here deadlock with
Landlock thread synchronization when migrating the calling process or a
sibling thread?

When pid is 0 or refers to a sibling in the same thread group, task->signal
is current->signal. A sibling calling landlock_restrict_self() with
LANDLOCK_RESTRICT_SELF_TSYNC holds exec_update_lock for writing while queuing
TWA_SIGNAL task_work on every other thread and waiting for them to run it:

CPU0 CPU1
landlock_restrict_sibling_threads()
down_write_trylock(
&signal->exec_update_lock)
kernel_migrate_pages(0, ...)
down_read_killable(
&signal->exec_update_lock)
task_work_add(CPU1, ..., TWA_SIGNAL)
wait_for_completion_interruptible(
&shared_ctx.all_prepared)
<-- waits for CPU1's task_work

TWA_SIGNAL only wakes TASK_INTERRUPTIBLE tasks in __set_notify_signal(), and
signal_pending_state() does not treat TIF_NOTIFY_SIGNAL as pending for
TASK_KILLABLE waits. CPU1 stays blocked in down_read_killable() instead of
returning to run its task_work, while CPU0 holds exec_update_lock waiting.

An unprivileged multithreaded process can wedge both threads until killed.
Any third sibling already in restrict_one_thread()'s uninterruptible
wait_for_completion(&ctx->ready_to_commit) stays stuck in
TASK_UNINTERRUPTIBLE, tripping hung-task warnings or hung_task_panic.

Skipping exec_update_lock when same_thread_group(task, current) is true
(similar to how find_mm_struct() fast-paths !pid for move_pages()) avoids
this deadlock, since a sibling execve() reaps other threads in de_thread()
before exec_mmap().

--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-fixes_core_3-v2-0-9aad65727632@xxxxxxxxxx?part=23