From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACF40EB64DC for ; Sun, 9 Jul 2023 11:14:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229773AbjGILOd (ORCPT ); Sun, 9 Jul 2023 07:14:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230366AbjGILOb (ORCPT ); Sun, 9 Jul 2023 07:14:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1594131 for ; Sun, 9 Jul 2023 04:14:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5053460BC9 for ; Sun, 9 Jul 2023 11:14:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57B1BC433C8; Sun, 9 Jul 2023 11:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1688901269; bh=Exg2umoa2RAIPiqQWbX4vIcq/IpYSk0UO2K02rH4ug0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YcxHT1EGh/FN6usYPydpWa2MPJa8wzHFE3ycoH+vYu2IfWFvIedrQLunSuJ2HwtJ/ vXyA9HdoUPt0pceZDYH4buyKIAauj/8PiKil+NwiwKF0tHeXD1cP6vPo7qyw7cF9wE So5PKF+0FckqlWBAk5gXk/KuQFNhQRmYDheSTRFw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Suren Baghdasaryan , Linus Torvalds Subject: [PATCH 6.4 2/8] mm: lock a vma before stack expansion Date: Sun, 9 Jul 2023 13:14:08 +0200 Message-ID: <20230709111345.373476152@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230709111345.297026264@linuxfoundation.org> References: <20230709111345.297026264@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Suren Baghdasaryan commit c137381f71aec755fbf47cd4e9bd4dce752c054c upstream. With recent changes necessitating mmap_lock to be held for write while expanding a stack, per-VMA locks should follow the same rules and be write-locked to prevent page faults into the VMA being expanded. Add the necessary locking. Cc: stable@vger.kernel.org Signed-off-by: Suren Baghdasaryan Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/mmap.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1975,6 +1975,8 @@ static int expand_upwards(struct vm_area return -ENOMEM; } + /* Lock the VMA before expanding to prevent concurrent page faults */ + vma_start_write(vma); /* * vma->vm_start/vm_end cannot change under us because the caller * is required to hold the mmap_lock in read mode. We need the @@ -2062,6 +2064,8 @@ int expand_downwards(struct vm_area_stru return -ENOMEM; } + /* Lock the VMA before expanding to prevent concurrent page faults */ + vma_start_write(vma); /* * vma->vm_start/vm_end cannot change under us because the caller * is required to hold the mmap_lock in read mode. We need the