From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794273967; b=rhV69AS2C/48fb3Q8MV29lQ8Y+Ami+Wvgj59Y8MBMZVik1+ZUVjQ/TAe7I1EgjFr3AWO kkulcKgIOMhz6e9B6TAftMZhoGUtXskECnsqqF/GsJVLMj0J3PlmdGp52rHH3ijzJTDau 55NvCakvXqfv/CU3lEwxCnPOvvzo9iKIxDC1A07KsHMGBUqWKOHXms17H/BXThS3QKHXp i3B+CvCdOGrL5XK89XI7pAEmd5g+zuLrWwR/fh1FxdcHbRnijkjgFakFuSzN9/+n4E6yC YjjmrTIAVto8pPiuoIe8a/oP/PATFG+p+nAVsvsSmjKRQ6NkqjLQ6vIn2UnppO1m3Dw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794273967; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=jSQ/i9bKdIZqlJoUYFxuizD4QPIC/fiyALy73V0HsHQ=; b=Xk2XB8qtFJQoZiUNh3L72eDswmnoGp+0am/H/VmXwwj7cKChSCwxO7qgLvTzufmh9PhM UlUEyos3DJkJWr09josHBQ7YCvBazh3nJs12HhJasAGaMd0TwJR2BTrdB8XQoPKwsmIBY VzhJ5CPuJi/I/yIBfcBh3RaF5D0xDH5J7UYzTs/VBEBuqFriRoPOHv8vvNgnZ/3b/wVX6 sdxlyY4uzC17Z/CkCvzwijuRHrhPBZsx69a0ZU3PtvrGn/+qnSVChgZ6A0vIxoupRH2L9 eOZ/HP7ljkTIHWpcnjpSCfVGwUl/j+JrKIUpIC1GysuadbEbhmqI5PgkIrDuWTPHM7A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hCsTG0TB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A15360A2603 for ; Tue, 10 Nov 2026 01:26:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hCsTG0TB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60BD21F0089F; Tue, 10 Nov 2026 01:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794273966; bh=jSQ/i9bKdIZqlJoUYFxuizD4QPIC/fiyALy73V0HsHQ=; h=From:To:Cc:Subject:Date; b=hCsTG0TBkBDzvdYEEXt5h02Zqx0NzCQbEjkz8QpRJfKuNWaukAj4Mt10o0vdKOyUU ngRow/hg9BEfrUiqSMi244bTIT1AFSAZ1HGPLBdD4kmZh8CcuH1PiDcheCnljp8srG CFcPy82DZVd4ydWlnn7ymIMbUHC+PwG1wcbgnBV0yEcdWCNgaffHkjlL46cWXLxVrM o5OtoxRpO2c400+unyWo60vbjtvLRWs8CFFnsZxRmAb/NFfhlb2XfjuTn5sqgPEA3w cogdm/15gxp2RSzrzEd6Dn/Uu94y9LKqAjedz+9sXimA0x1HAW1K7ZupUdnW8zmza2 8TtVfiqGf5KXQ== From: Sasha Levin To: david@kernel.org, josef@toxicpanda.com, ljs@kernel.org, riel@surriel.com, vbabka@kernel.org, baohua@kernel.org, pfalcato@suse.de, harry@kernel.org, kas@kernel.org, sj@kernel.org, usama.anjum@arm.com Cc: stable@vger.kernel.org Subject: FAILED: patch "[PATCH] fork: take mmap_lock before copying mm_struct" failed to apply to 5.10-stable tree Date: Mon, 9 Nov 2026 20:26:04 -0500 Message-ID: <20261109202604-failed-5.10-ef694e2d2101@kernel.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.10-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y git checkout FETCH_HEAD git cherry-pick -x ef694e2d210111cc08c52fd25da9ab130170bfa3 # git commit -s git send-email --to '' --in-reply-to '20261109202604-failed-5.10-ef694e2d2101@kernel.org' --subject-prefix 'PATCH 5.10.y' 'HEAD^..' Thanks, Sasha ------------------ original commit in Linus's tree ------------------ >From ef694e2d210111cc08c52fd25da9ab130170bfa3 Mon Sep 17 00:00:00 2001 From: "David Hildenbrand (Arm)" Date: Sat, 31 Oct 2026 10:39:31 +0100 Subject: [PATCH] fork: take mmap_lock before copying mm_struct dup_mm() copies the parent's mm_struct before dup_mmap() takes the mmap_lock. A concurrent brk() can leave the child with a stale mm->brk and newer heap mappings, causing later brk() requests to fail. Other operations (e.g., PR_SET_MM) on the parent's mm_struct can similarly cause inconsistencies. As a simple and robust fix, grab the parent's mmap_lock earlier. This way we don't need to update individual mm fields in dup_mmap() and keep missing ones. Stop updating the 4 existing members (total_vm, data_vm, exec_vm, stack_vm), as that is now no longer required. Keep releasing the parent's mmap_lock in dup_mmap(), before userfaultfd completion, to avoid moving the userfaultfd handling into the caller. This should get cleaned up later. Move uprobe_start_dup_mmap() to preserve the lock ordering. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Reported-by: Josef Bacik Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Rik van Riel Reviewed-by: Vlastimil Babka (SUSE) Reviewed-by: Barry Song Reviewed-by: Pedro Falcato Reviewed-by: Harry Yoo (Meta) Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: SJ Park Tested-by: Muhammad Usama Anjum Link: https://patch.msgid.link/20261031-fixes_core-v3-2-d6437171ecc3@kernel.org Signed-off-by: David Hildenbrand (Arm) --- kernel/fork.c | 20 ++++++++++++++------ mm/mmap.c | 8 +------- mm/nommu.c | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 8b108ed371529..5efceb8d58a78 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1533,12 +1533,19 @@ static struct mm_struct *dup_mm(struct task_struct *tsk, if (!mm) goto fail_nomem; + uprobe_start_dup_mmap(); + if (mmap_write_lock_killable(oldmm)) { + free_mm(mm); + goto fail_uprobe; + } + memcpy(mm, oldmm, sizeof(*mm)); - if (!mm_init(mm, tsk)) - goto fail_nomem; + if (!mm_init(mm, tsk)) { + mmap_write_unlock(oldmm); + goto fail_uprobe; + } - uprobe_start_dup_mmap(); err = dup_mmap(mm, oldmm); if (err) goto free_pt; @@ -1557,9 +1564,10 @@ static struct mm_struct *dup_mm(struct task_struct *tsk, mm->binfmt = NULL; mm_init_owner(mm, NULL); mmput(mm); - if (err) - uprobe_end_dup_mmap(); - + if (!err) + return NULL; +fail_uprobe: + uprobe_end_dup_mmap(); fail_nomem: return NULL; } diff --git a/mm/mmap.c b/mm/mmap.c index 148ba01c03739..7618e72766a52 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1713,8 +1713,7 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) LIST_HEAD(uf); VMA_ITERATOR(vmi, mm, 0); - if (mmap_write_lock_killable(oldmm)) - return -EINTR; + mmap_assert_write_locked(oldmm); flush_cache_dup_mm(oldmm); uprobe_dup_mmap(oldmm, mm); /* @@ -1725,11 +1724,6 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) /* No ordering required: file already has been exposed. */ dup_mm_exe_file(mm, oldmm); - mm->total_vm = oldmm->total_vm; - mm->data_vm = oldmm->data_vm; - mm->exec_vm = oldmm->exec_vm; - mm->stack_vm = oldmm->stack_vm; - /* Use __mt_dup() to efficiently build an identical maple tree. */ retval = __mt_dup(&oldmm->mm_mt, &mm->mm_mt, GFP_KERNEL); if (unlikely(retval)) diff --git a/mm/nommu.c b/mm/nommu.c index 91ab65afda705..6c6f953296746 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1887,7 +1887,7 @@ subsys_initcall(init_admin_reserve); int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) { - mmap_write_lock(oldmm); + mmap_assert_write_locked(oldmm); dup_mm_exe_file(mm, oldmm); mmap_write_unlock(oldmm); return 0; -- 2.53.0