linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: torvalds@linux-foundation.org
Cc: jacobly.alt@gmail.com, regressions@lists.linux.dev,
	david@redhat.com, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, liam.howlett@oracle.com,
	Suren Baghdasaryan <surenb@google.com>,
	linux-mm@kvack.org, peterx@redhat.com, regressions@leemhuis.info,
	willy@infradead.org, bagasdotme@gmail.com,
	stable@vger.kernel.org, akpm@linux-foundation.org,
	ldufour@linux.ibm.com, linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 2/3] mm: lock newly mapped VMA which can be modified after it becomes visible
Date: Sat,  8 Jul 2023 12:12:11 -0700	[thread overview]
Message-ID: <20230708191212.4147700-2-surenb@google.com> (raw)
In-Reply-To: <20230708191212.4147700-1-surenb@google.com>

mmap_region adds a newly created VMA into VMA tree and might modify it
afterwards before dropping the mmap_lock. This poses a problem for page
faults handled under per-VMA locks because they don't take the mmap_lock
and can stumble on this VMA while it's still being modified. Currently
this does not pose a problem since post-addition modifications are done
only for file-backed VMAs, which are not handled under per-VMA lock.
However, once support for handling file-backed page faults with per-VMA
locks is added, this will become a race.
Fix this by write-locking the VMA before inserting it into the VMA tree.
Other places where a new VMA is added into VMA tree do not modify it
after the insertion, so do not need the same locking.

Cc: stable@vger.kernel.org
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
 mm/mmap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index c66e4622a557..84c71431a527 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2812,6 +2812,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
 	if (vma->vm_file)
 		i_mmap_lock_write(vma->vm_file->f_mapping);
 
+	/* Lock the VMA since it is modified after insertion into VMA tree */
+	vma_start_write(vma);
 	vma_iter_store(&vmi, vma);
 	mm->map_count++;
 	if (vma->vm_file) {
-- 
2.41.0.390.g38632f3daf-goog


  reply	other threads:[~2023-07-08 19:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-08 19:12 [PATCH v2 1/3] mm: lock a vma before stack expansion Suren Baghdasaryan
2023-07-08 19:12 ` Suren Baghdasaryan [this message]
2023-07-08 19:12 ` [PATCH v2 3/3] fork: lock VMAs of the parent process when forking Suren Baghdasaryan
2023-07-08 19:22   ` Suren Baghdasaryan
2023-07-08 21:18   ` Linus Torvalds
2023-07-08 22:36     ` Suren Baghdasaryan
2023-07-08 22:53       ` Linus Torvalds
2023-07-08 23:03         ` Suren Baghdasaryan
2023-08-04 21:46   ` Mateusz Guzik
2023-08-04 22:49     ` Linus Torvalds
2023-08-04 23:25       ` Mateusz Guzik
2023-08-05  0:14         ` Linus Torvalds
2023-08-05  0:26           ` Suren Baghdasaryan
2023-08-05  0:34             ` Suren Baghdasaryan
2023-08-05  0:49               ` Mateusz Guzik
2023-08-05  1:06                 ` Suren Baghdasaryan
2023-08-05  1:16                   ` Mateusz Guzik
2023-08-05  1:36                     ` Suren Baghdasaryan
2023-08-05  1:06           ` Mateusz Guzik
2023-08-05  1:42             ` Suren Baghdasaryan
2023-08-09 21:07               ` Mateusz Guzik
2023-08-10 20:31                 ` Suren Baghdasaryan

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=20230708191212.4147700-2-surenb@google.com \
    --to=surenb@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=bagasdotme@gmail.com \
    --cc=david@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jacobly.alt@gmail.com \
    --cc=ldufour@linux.ibm.com \
    --cc=liam.howlett@oracle.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=peterx@redhat.com \
    --cc=regressions@leemhuis.info \
    --cc=regressions@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.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).