Re: [PATCH 4/4] fs/proc/task_mmu: write-protect only with ptrace attach
From: Pedro Falcato
Date: Fri Nov 27 2026 - 17:25:00 EST
On Fri, Nov 27, 2026 at 07:45:43PM +0000, Lorenzo Stoakes (ARM) wrote:
> The abomination known as PM_SCAN_WP_MATCHING, which makes PAGEMAP_SCAN not
> scan but mutate for eldritch uffd-wp purposes, also lacks a permission
> check when scanning the mm of another process.
>
> It defaults to PTRACE_MODE_READ, which is insufficient for this accursed
> operation.
>
> Therefore actually check for permissions correctly, and also make sure the
> mm is as expected when doing so.
>
> As it stands, a task may currently manipulate page tables of the remote
> process, write-protecting uffd-wp marked pages, allocating page tables and
> splitting THP, and invoking MMU notifiers as needed.
>
> The check is made at the time of the ioctl against its caller, as
> lock_trace() does for other /proc files, rather than at open.
>
> A tracker which passes READ but not ATTACH on another process now gets
> EACCES for PM_SCAN_WP_MATCHING, whether it opened the pagemap file itself
> or was handed the descriptor.
>
> Also update the pagemap documentation to reflect the change.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
Reviewed-by: Pedro Falcato <pfalcato@xxxxxxx>
--
Pedro