Re: [PATCH] fork: clear p->mm when copy_process() fails
From: David Hildenbrand
Date: Thu Nov 19 2026 - 11:44:56 EST
On Thu, 19 Nov 2026 09:04:58 +0100, David Hildenbrand (Arm) wrote:
> When copy_process() fails after copy_mm(), the error path drops the mm
> reference but leaves p->mm set. Perf and BPF can still reach the
> task, and take a reference on the already freed mm through get_task_mm()
> or bpf_find_vma(), resulting in a use-after-free:
>
> copy_process() PERF_EVENT_IOC_SET_FILTER
> ============== =========================
> perf_event_init_task(p)
> copy_mm(p)
> a later step fails
> mmput(p->mm)
> /* frees the mm */
> perf_event_addr_filters_apply()
> get_task_mm(p)
> /* use-after-free */
>
> [...]
Applied, thanks!
tree: mm/core.git
branch: for-next-fixes
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we
can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
though the patches have already been applied. If possible, patch trailers
will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. Further, this is not a guarantee that the
patches will go upstream. If in doubt, please check the listed branch.
[1/1] fork: clear p->mm when copy_process() fails
https://git.kernel.org/mm/core/c/c9b8c9bd
--
Cheers,
David