From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796510051; b=YyPJBKR4L30gVOAJp5mIfUvex5d5Ozkt28R0DBbPhmrdtfIw7QjdgoRDWoXhkSM7/ck3 o0NjByuajt2hZiT67TXouU3LEiD1NtFv6p6Nw9HoupZ5ZYQUAdINgi2l+dTSI/G6GCDay XAnCM6lK2UI6jT33lMCZ3+bcSPo6HahDQyy0w0h+5WMpCD+/lYcS3b1jLK2BX9Wb6q/us O6p4ABoXGY9PPVbF+ctEeCbxcNA25KVl7ZVHxRElcWgBmH8zjwfWHeY0eHhRF2RR27Y5Y k2EyVPRXmxcj+WXqCriBKhb/wzA/NLqUPbA+S7Eio0QaE1nkU6fVmlpAzlI1H8SP+bA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796510051; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=LPm9wMEEnAg6bHK8Wvs7aI0AHJMjm0YOSdGVQ0vbuVs=; b=opXE71rZAbt6ULoe/ZNsYT0mbfdjae2fbglxrJYGcOQfkCvWxCkO12kiddldSp2sCi+R JHymSAztYZZYzMeHF6sxVu42hg4mvcUiU8ZoRBLd2ucSgEaBtW0JaZE7po/PtME7cs5yw Q01yCmmMtz0Am9wuTm4jYNasXJk87KJEvMZXagZVMTTwtoD32g90r6FjCH5V1XWvsE9fk NzwhQlo8YYAC8r8liCDbEiS9/scwtQCexcWS+PpggwsMFOZdDhpJlIfBFZLEciR8+Qh6e V3OnEW20Cc7L3fBn/VieJ2uKICmdCXs6ljx22TfevOvzJd1nZnYm3ijN1qZJ1A5r+tQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=fFznO6+e; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F781606A31F; Sat, 5 Dec 2026 22:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=fFznO6+e Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C9DC1F0092B; Sat, 5 Dec 2026 22:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796510051; bh=LPm9wMEEnAg6bHK8Wvs7aI0AHJMjm0YOSdGVQ0vbuVs=; h=Date:To:From:In-Reply-To:References:Subject; b=fFznO6+eQN3SNz9/clVG14nEbZdCiGVsoeAAobZ3K7x/8gSZwdf+UFHwTCxrGVUx2 09yfigP0kji2HwukcI5cWn86s8dDxaGkAAwAxx0ixAAzZmU7cg7pJ3Gacyvrhc3nyz R8WT/FhL+XN60ALWG2TTWVfD3yGHb7W6tcuF7NuM= Date: Sat, 05 Dec 2026 14:34:10 -0800 To: mm-commits@vger.kernel.org,stable@vger.kernel.org,leon@kernel.org, jgg@ziepe.ca,zihengw03@163.com,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261205074354.83986-1-zihengw03@163.com> References: <20261205074354.83986-1-zihengw03@163.com> Subject: + lib-test_hmm-hold-devmem_lock-in-dmirror_fops_release.patch added to mm-unstable branch Message-Id: <20261205223411.4C9DC1F0092B@smtp.kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: lib/test_hmm: hold devmem_lock in dmirror_fops_release() has been added to the -mm mm-unstable branch. Its filename is lib-test_hmm-hold-devmem_lock-in-dmirror_fops_release.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/lib-test_hmm-hold-devmem_lock-in-dmirror_fops_release.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Ziheng Wei Subject: lib/test_hmm: hold devmem_lock in dmirror_fops_release() Date: Sat, 5 Dec 2026 15:43:54 +0800 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. Link: https://patch.msgid.link/20261205074354.83986-1-zihengw03@163.com Fixes: 744dd97752ef ("lib: test_hmm: evict device pages on file close to avoid use-after-free") Signed-off-by: Ziheng Wei Signed-off-by: Andrew Morton Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: lib/test_hmm.c | 2 ++ 1 file changed, 2 insertions(+) --- a/lib/test_hmm.c~lib-test_hmm-hold-devmem_lock-in-dmirror_fops_release +++ a/lib/test_hmm.c @@ -245,6 +245,7 @@ static int dmirror_fops_release(struct i mmu_interval_notifier_remove(&dmirror->notifier); + mutex_lock(&mdevice->devmem_lock); if (mdevice->devmem_chunks) { for (i = 0; i < mdevice->devmem_count; i++) { struct dmirror_chunk *devmem = @@ -253,6 +254,7 @@ static int dmirror_fops_release(struct i dmirror_device_evict_chunk(devmem); } } + mutex_unlock(&mdevice->devmem_lock); xa_destroy(&dmirror->pt); kfree(dmirror); _ Patches currently in -mm which might be from zihengw03@163.com are lib-test_hmm-hold-devmem_lock-in-dmirror_fops_release.patch