Re: [PATCH v2] fork: reset pointer tag of vmapped thread stack before vfree

From: Uladzislau Rezki

Date: Tue Sep 15 2026 - 13:10:40 EST


On Mon, Sep 14, 2026 at 10:44:26AM +0100, Lorenzo Stoakes (ARM) wrote:
> +cc Ulad for vmalloc stuff.
>
> Please don't send a v2 in-reply-to a v1 or any other email.
>
> Send the patch entirely separately.
>
> I really need to write a bot to say this :)...
>
> On Mon, Sep 14, 2026 at 05:33:00PM +0800, Shaobo Huang wrote:
> > thread_stack_free_rcu() frees the vmalloc'd thread stack via
> > vfree(vm_area->addr). In RCU callback context, vfree() routes to
> > vfree_atomic(), which calls llist_add((struct llist_node *)addr, ...)
> > and writes 8 bytes to the base of the region being freed.
> >
> > With KASAN_SW_TAGS, vm_area->addr carries a random tag. If
> > kasan_unpoison_task_stack_below() has rewritten the shadow covering
> > [base, sp] to KASAN_TAG_KERNEL (0xff) -- which it does on every CPU
> > resume for the current task's stack -- the llist_add store checks
> > shadow[base] (0xff) against the pointer tag (random) and reports an
> > invalid-access, although writing to the base of a stack queued for
> > deferred free is legitimate.
> >
> > Reset the pointer tag to KASAN_TAG_KERNEL before vfree() so that
> > kasan_check_range() short-circuits the check, the same way the task
> > accesses its own stack at runtime via sp. The vmalloc lookup is safe:
> > __find_vmap_area() resets the tag before comparing against va_start.
> >
> > Fixes: 9f7d416c3612 ("kprobes: Unpoison stack in jprobe_return() for KASAN")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Assisted-by: zhipuai:glm-5.2
>
> Thanks for adding this!
>
> New convention is to say:
>
> Assisted-by: LLM
>
> Rather than to list the agent.
>
> See https://docs.kernel.org/process/coding-assistants.html
>
> > Signed-off-by: Shaobo Huang <huangshaobo3@xxxxxxxxxx>
>
> Looks reasonable to me so, with nits addressed:
>
> Acked-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
>
> But I would like Ulad's input on this from vmalloc side.
>
Makes sense to me even though we do it in the __find_vmap_area()
but we also use an "addr" in other paths.

LGTM:

Reviewed-by: Uladzislau Rezki (Sony) <urezki@xxxxxxxxx>

--
Uladzislau Rezki