stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Suren Baghdasaryan <surenb@google.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 6.4 3/8] mm: lock newly mapped VMA which can be modified after it becomes visible
Date: Sun,  9 Jul 2023 13:14:09 +0200	[thread overview]
Message-ID: <20230709111345.397858220@linuxfoundation.org> (raw)
In-Reply-To: <20230709111345.297026264@linuxfoundation.org>

From: Suren Baghdasaryan <surenb@google.com>

commit 33313a747e81af9f31d0d45de78c9397fa3655eb upstream.

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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 mm/mmap.c |    2 ++
 1 file changed, 2 insertions(+)

--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2804,6 +2804,8 @@ cannot_expand:
 	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) {



  parent reply	other threads:[~2023-07-09 11:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09 11:14 [PATCH 6.4 0/8] 6.4.3-rc1 review Greg Kroah-Hartman
2023-07-09 11:14 ` [PATCH 6.4 1/8] mm: disable CONFIG_PER_VMA_LOCK until its fixed Greg Kroah-Hartman
2023-07-09 11:14 ` [PATCH 6.4 2/8] mm: lock a vma before stack expansion Greg Kroah-Hartman
2023-07-09 11:14 ` Greg Kroah-Hartman [this message]
2023-07-09 11:14 ` [PATCH 6.4 4/8] mm: lock newly mapped VMA with corrected ordering Greg Kroah-Hartman
2023-07-09 11:14 ` [PATCH 6.4 5/8] mm: call arch_swap_restore() from do_swap_page() Greg Kroah-Hartman
2023-07-09 11:14 ` [PATCH 6.4 6/8] bootmem: remove the vmemmap pages from kmemleak in free_bootmem_page Greg Kroah-Hartman
2023-07-09 11:14 ` [PATCH 6.4 7/8] fork: lock VMAs of the parent process when forking Greg Kroah-Hartman
2023-07-09 12:39   ` Thorsten Leemhuis
2023-07-09 13:32     ` Greg Kroah-Hartman
2023-07-09 16:04       ` Suren Baghdasaryan
2023-07-09 16:09         ` Greg Kroah-Hartman
2023-07-09 19:53           ` Suren Baghdasaryan
2023-07-09 20:24             ` Suren Baghdasaryan
2023-07-09 20:40               ` Greg Kroah-Hartman
2023-07-09 11:14 ` [PATCH 6.4 8/8] fork: lock VMAs of the parent process when forking, again Greg Kroah-Hartman

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=20230709111345.397858220@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=torvalds@linux-foundation.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).