Re: [PATCH] lib/test_hmm: hold devmem_lock in dmirror_fops_release()

From: Andrew Morton

Date: Sat Dec 05 2026 - 17:34:08 EST


On Sat, 5 Dec 2026 15:43:54 +0800 Ziheng Wei <zihengw03@xxxxxxx> wrote:

> dmirror_fops_release() iterates mdevice->devmem_chunks[0..devmem_count-1]
> and calls dmirror_device_evict_chunk() without holding
> mdevice->devmem_lock. A concurrent HMM_DMIRROR_RELEASE ioctl calling
> dmirror_device_remove_chunks() under devmem_lock can free each chunk and
> the devmem_chunks array while dmirror_fops_release() is walking them,
> causing a use-after-free.
>
> Protect the devmem_chunks walk in dmirror_fops_release() with
> mdevice->devmem_lock, matching dmirror_device_remove_chunks().
>
> Found by LLM-assisted static analysis.

lgtm, thanks.

> Compile-tested on x86_64.

That's a bit concerning. Please find a way to runtime test things.
Your LLM might already be able to do this in its own sandbox.