Re: [PATCH v2 23/31] mm/mempolicy: check access under exec_update_lock
From: Rik van Riel
Date: Fri Dec 04 2026 - 22:04:35 EST
On Fri, 2026-12-04 at 13:50 +0100, David Hildenbrand (Arm) wrote:
> From: Chris Mason <mason@xxxxxxxxxx>
>
> The access check in migrate_pages() can race with concurrent
> execve(): if
> the target task execs a setuid binary, migrate_pages() can migrate
> the
> pages of the new mm, which the checks would otherwise deny. The
> impact
> is limited, but we should just handle it consistently.
>
> kernel_migrate_pages() calls ptrace_may_access() on the target and
> takes
> its mm with get_task_mm() later, so the credentials that the check
> sees
> have to belong to that mm. execve() replaces the mm in exec_mmap()
> and
> the credentials in commit_creds(), and holds signal->exec_update_lock
> for writing across both.
>
> Let's fix it by holding the target's exec_update_lock for reading
> until
> we have grabbed the mm, as move_pages() does ever since
> commit 13f77972b94c ("mm/migrate: find_mm_struct: fix race between
> security checks and suid exec").
>
> Regarding dropping the RCU read lock earlier, as explained by Oleg:
>
> "kernel_migrate_pages() calls ptrace_may_access() under
> rcu_read_lock()
> for no reason. This is a leftover from before the commit
> 313674661925
> ("Unify migrate_pages and move_pages access checks"), where
> rcu_read_lock() was needed to protect __task_cred(task).
>
> So we can drop the RCU lock right after get_task_struct()."
>
> Waiting for concurrent execve() is not really relevant, and
> move_pages()
> already does the same.
>
> This has low urgency, as the impact is limited. No need to CC stable.
>
> Fixes: 313674661925 ("Unify migrate_pages and move_pages access
> checks")
> Reported-by: Oleg Nesterov <oleg@xxxxxxxxxx>
> Closes: https://lore.kernel.org/r/ahMt6xyUNnacZU8-@xxxxxxxxxx
> Suggested-by: Oleg Nesterov <oleg@xxxxxxxxxx>
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> [ david: simplify description and comment ]
> Acked-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
Reviewed-by: Rik van Riel <riel@xxxxxxxxxxx>
--
All Rights Reversed.