All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,stable@vger.kernel.org,leon@kernel.org,
	jgg@ziepe.ca,zihengw03@163.com,akpm@linux-foundation.org
Subject: + lib-test_hmm-hold-devmem_lock-in-dmirror_fops_release.patch added to mm-unstable branch
Date: Sat, 05 Dec 2026 14:34:10 -0800	[thread overview]
Message-ID: <20261205223411.4C9DC1F0092B@smtp.kernel.org> (raw)
In-Reply-To: <20261205074354.83986-1-zihengw03@163.com>


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 <zihengw03@163.com>
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 <zihengw03@163.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: <stable@vger.kernel.org>

 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


  parent reply	other threads:[~2026-12-05 22:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  7:43 [PATCH] lib/test_hmm: hold devmem_lock in dmirror_fops_release() Ziheng Wei
2026-12-05 22:34 ` Andrew Morton
2026-12-05 23:50   ` Andrew Morton
2026-12-06  2:47     ` Ziheng Wei
2026-12-05 22:34 ` Andrew Morton [this message]
2026-12-05 23:51 ` + lib-test_hmm-serialize-chunk-removal-with-migration.patch added to mm-unstable branch Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205223411.4C9DC1F0092B@smtp.kernel.org \
    --to=akpm@linux-foundation.org \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zihengw03@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.