Message ID | 20230708191212.4147700-2-surenb@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50D76EB64DC for <linux-mm@archiver.kernel.org>; Sat, 8 Jul 2023 19:12:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1FF28D0002; Sat, 8 Jul 2023 15:12:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD0CF6B0072; Sat, 8 Jul 2023 15:12:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C98CA8D0002; Sat, 8 Jul 2023 15:12:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BCB2F6B0071 for <linux-mm@kvack.org>; Sat, 8 Jul 2023 15:12:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 863DB1C7C0E for <linux-mm@kvack.org>; Sat, 8 Jul 2023 19:12:21 +0000 (UTC) X-FDA: 80989390482.03.E111F7E Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf28.hostedemail.com (Postfix) with ESMTP id B75CAC000F for <linux-mm@kvack.org>; Sat, 8 Jul 2023 19:12:19 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=rDyzKJgv; spf=pass (imf28.hostedemail.com: domain of 3ErWpZAYKCE89B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ErWpZAYKCE89B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688843539; a=rsa-sha256; cv=none; b=0c9Xn5EH+GY6qksAXeFsnz+lOLcH+l5KuftaQ0yGB0nWtTmyTUX9/76haNbjL67duy2xZb FHvVX98iOOyVxO8W8aIHgW4nhAxCt4i7UfkHxTxqwZTj68bT53gjtsuf9W/a/mls+Dk/jS BaIXRuTTKYiN42fHcQxkY3hV6bPJ+To= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=rDyzKJgv; spf=pass (imf28.hostedemail.com: domain of 3ErWpZAYKCE89B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ErWpZAYKCE89B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688843539; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z4rAZiN8CFc+wkQPvmF3sDwgaLYdtc/sQi/Gu45S9YQ=; b=3qvia3pl4tTjgj19aVSzg9+PxrdFN2Jf+Amrs4iIp+YhiYnAGH87znb4Cqy8QmYWwBa8o3 YWX8dUHlHdJIhOSUeoQgFJHB7woa8m6ANyO1hGNGvsLdEelyzXiVF7LoJTxytLFzLS/e5/ JqcslAbEbcHbWVN7N9QruKd/eC10fRs= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c6dd0e46a52so1950081276.2 for <linux-mm@kvack.org>; Sat, 08 Jul 2023 12:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688843539; x=1691435539; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Z4rAZiN8CFc+wkQPvmF3sDwgaLYdtc/sQi/Gu45S9YQ=; b=rDyzKJgvSb4iVFr4MU6yl+skVCEaDOmrNnUTQxW2AR6lwndLcFZirFs7K8NVbOet/l Hz1ezj81fpfDhby24QFHC8W4yNrvRhOZmkRPzGk0HoDpmSzVRvUFh46uDhRrvrsHj0T+ bWfsgAAuSrJUkxovFXIvpjT+3mNLViAPukrwkqTZEVh67uYSSdkV3/RB6xiSA1ML8ef8 x4SI1Wv4IyWtXrra9hN2OOMwSs1hHi6cndf596Frps7d08xkQhXDxEudvyECcS4PhaDT YUU3z/ec3eCdOsvrUHORdE6FKycuZJ6n6CZZT2tr9aAc7ZTwuikUkUWUt+zO7jA28nYB wf5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688843539; x=1691435539; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Z4rAZiN8CFc+wkQPvmF3sDwgaLYdtc/sQi/Gu45S9YQ=; b=JAfcL9zFlRp/jpnAxZU5Jaio6Ek6+7cOUFEiuJz0In9A9X7w/z1OFOb+v6TKcM4Bvy NJIggNirN1jFuoCVvo+IYrCu/mNDCEzStn64XDvgAEqxVdzlkkGjeCzlMWm38b76J7ZN 26EJO37RIlVeHJAG4POx4jYchdlrdwMQhsjdCC0vHBkqcCD5OYkKN+W5W0hKMueOv70t Nh+VC42zHZotrUyrsjkSn/h834pfgaClFtk39wjc+3OtjUm/2Zsdo6OZUlbHrgKW18xK gmUywjG3jbpj3AfaPhMTzpEezjA9d7bhkeTFmwvtefKSPwYBbsVOW/k/uPgn4LlU2eL5 i4Uw== X-Gm-Message-State: ABy/qLY1sO1ZTlGYYFQhdW8XEWdYewBr+ScEqaR8yn9zPvu8Q6ZbjLi+ Dr0kGKCXhC/fYzpyuAkh0hPffeKOaF4= X-Google-Smtp-Source: APBJJlHlFE3mHfSxux3qV7DD1eHyTN3Bj7OluqfqRLk3Ndt0avHOdBy2KrtMLyVg6El02lkP8km17cLgxIM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6f0:5193:79db:25b3]) (user=surenb job=sendgmr) by 2002:a25:b05:0:b0:c24:7d1c:6145 with SMTP id 5-20020a250b05000000b00c247d1c6145mr69068ybl.2.1688843538817; Sat, 08 Jul 2023 12:12:18 -0700 (PDT) Date: Sat, 8 Jul 2023 12:12:11 -0700 In-Reply-To: <20230708191212.4147700-1-surenb@google.com> Mime-Version: 1.0 References: <20230708191212.4147700-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.390.g38632f3daf-goog Message-ID: <20230708191212.4147700-2-surenb@google.com> Subject: [PATCH v2 2/3] mm: lock newly mapped VMA which can be modified after it becomes visible From: Suren Baghdasaryan <surenb@google.com> To: torvalds@linux-foundation.org Cc: akpm@linux-foundation.org, regressions@leemhuis.info, bagasdotme@gmail.com, jacobly.alt@gmail.com, willy@infradead.org, liam.howlett@oracle.com, david@redhat.com, peterx@redhat.com, ldufour@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, regressions@lists.linux.dev, Suren Baghdasaryan <surenb@google.com>, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B75CAC000F X-Stat-Signature: p4b8w385pp34jfpkrt9oymxa89hpk1ap X-Rspam-User: X-HE-Tag: 1688843539-394212 X-HE-Meta: U2FsdGVkX1/dEETuYrfOcbWUM+g7egmglMM/8u9vbxu0xd78RNyPScLBsf84XAPwghqlNdIadOMtzCeirMjG/TqG3nCYI7TrgfQpZRclbcU5UKeAVNvL7CxesKkhx5ZtwnOmADBWZJ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WXoEB6MBTo3Pm4vTBaM3zOol7UqUBgLP3GywpgHKfFcyMroGeJObVfJuEOeDGZA0rNZ+v8ORWJlrfRJZZzBI1bwVc76BBgH1l8zoXPjbDwv0ct72PmTjN+5SSVYpqXbc39f9xZLDag2+VXiJEEaQZ5g8P4PHVoj22gCe3yUr+A55Q2OVAVmYd/S7xRbZZhDTr5baZJCPqtCcGL/guhiW6BvF7jTKdrxYK93L6paG7xXY/A7N0XrAkNxdfKR4Cvoy+11Q1G7RkWI3wAh7YtzqkjbGiwJIUhvqdpmaFV4SuJsOJclMboqLADBOnKsKsvoPSifv7SlTIOf8TvTOESm6EWhkcashG6M6u2B6HJp8dF/Hmj+v7vK33hbdkDOfaksWedATOG8b13wYTIEY5wS6dr/0iLwVfUUXCYchgoZGkpP6zGooImS38gAaWMpGLLrpkgCDzb+Ql9BTOMOXRi7m/ZGCw2CSRdcE9zH6W8jNHt0nnVuZ4rqEoVGtBE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> |
Series |
[v2,1/3] mm: lock a vma before stack expansion
|
expand
|
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) {
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(+)