linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dawei Li <set_pte_at@outlook.com>
To: akpm@linux-foundation.org, hch@lst.de
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Dawei Li <set_pte_at@outlook.com>
Subject: [PATCH] mm: mmap lock holding assertion on remap_pfn_range
Date: Mon, 19 Sep 2022 23:47:32 +0800	[thread overview]
Message-ID: <TYCP286MB23233CBD7126B624E1832699CA4D9@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM> (raw)

remap_pfn_range() creates/modifies the mapping between user virtual
address and physical address, the caller of which must hold mmap
writer lock to achieve access consistency of mapping.

The callers fall into categories below:
1) fops->mmap() implemented by driver
For this case, mmap_lock has been taken externally, the rule holds true.

2) Some arch codes do mapping on their own(vdso e.g.), rather than via
fops->mmap().

3) Some driver codes do mapping into user address space, for some
reasons, the mapping is not implemented by fops->mmap().

For the last two cases, an explicit assertion must be made.

Signed-off-by: Dawei Li <set_pte_at@outlook.com>
---
 mm/memory.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/memory.c b/mm/memory.c
index 118e5f023597..fd0ec1250974 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2551,6 +2551,11 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr,
 {
 	int err;
 
+	if (!vma->vm_mm)
+		return -EINVAL;
+
+	mmap_assert_write_locked(vma->vm_mm);
+
 	err = track_pfn_remap(vma, &prot, pfn, addr, PAGE_ALIGN(size));
 	if (err)
 		return -EINVAL;
-- 
2.25.1



             reply	other threads:[~2022-09-19 15:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19 15:47 Dawei Li [this message]
2022-09-19 20:57 ` [PATCH] mm: mmap lock holding assertion on remap_pfn_range 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=TYCP286MB23233CBD7126B624E1832699CA4D9@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM \
    --to=set_pte_at@outlook.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).