From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 248B136CE19; Sat, 17 Oct 2026 16:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792255994; cv=none; b=TNMkmFgP/2RnzEpMeyUGmWD0UWz+wckLPf2dHwRZvAA5C951ZiAIqmKfV5en2fUwutQWY5HN2xajFx3ERVhWcsJpw3IuLh8/H0sGSjazzEhau2oUFp2hmVHZ3yQPTDI1BYupJHkSJn3C54d5YYFEB8j8Fz7E8HJRqmuBlJGJiGs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792255994; c=relaxed/simple; bh=OCnQX6C1j1FTFmKWCFaIED42AIAdDfjfBPJMDxx+L30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kja3Ku9x8folvfGYls9d4sIJgguvlEaIbjWSAnOmog6+66T+Rq3ANIzGtkGTeQ0yoWk71/K+xN5Q1XgKlnW4e8REwlteMMXZ9fYOXVegegzsJhgUIktkNT5KczuP2LL7Nid7d0Y39NdlO0hdRr46IsLswStoXOBFo7BsjvCXMq4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cd7RIIfC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cd7RIIfC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A8891F000C4; Sat, 17 Oct 2026 16:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792255993; bh=UG8h/mW3UdC3XN0MBZwTZUZDKwH88siEju1bL4NOa3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cd7RIIfCXZkBGGz3P3Vl/1FXBrWZt5Eg5mdSoi5eANv3MKuVZRj9svOSDgpJK3v8X F5K5+2Wz2POdHPWn3fIkjpbVwnEB5+5FQsIJSGZkLApn8juTdW7i0d3BcL8BzE5ZFE R2kdqa4blKOteqWJwd6+TEz7HPM4z4/DvEpFiXMY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Lorenzo Stoakes (ARM)" , syzbot+f12658786a4153df5113@syzkaller.appspotmail.com, "Vlastimil Babka (SUSE)" , Kunwu Chan , Pedro Falcato , Jann Horn , "Liam R. Howlett" , Li Xinhai , Andrew Morton , Sasha Levin Subject: [PATCH 6.6 0089/1674] mm/mremap: reset unfaulted VMA page offset for MREMAP_DONTUNMAP Date: Sat, 17 Oct 2026 17:39:21 +0200 Message-ID: <20261017160433.424328676@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lorenzo Stoakes (ARM) [ Upstream commit 35b0fb391b0df57383bc15985bb769f4555c97ba ] Uniquely an mremap() invocation using the MREMAP_DONTUNMAP flag can reset a faulted VMA into an unfaulted one. It does so after the page tables have been moved to the copied VMA with MREMAP_DONTUNMAP leaving the old VMA in place which is naturally unfaulted as the page tables it had are no longer present. However, in doing so, it violates the invariant that the anonymous page offset of an unfaulted VMA is vma->vm_start >> PAGE_SHIFT. This is because a VMA may have been faulted in, mremap()'d (causing a delta between its page offset and vma->vm_start >> PAGE_SHIFT), and then mremap()'d again with MREMAP_DONTUNMAP resulting in the unfaulting. This condition is a violation of a fundamental assumption in mm, but now also triggers an assert in assert_sane_pgoff() which explicitly checks for this condition. Correct it by resetting the VMA's page offset at the point of completing the MREMAP_DONTUNMAP operation. Link: https://lore.kernel.org/20260825-fix-mremap-dontunmap-pgoff-v1-1-39a40b2c98b3@kernel.org Fixes: 1583aa278f5f ("mm: mremap: unlink anon_vmas when mremap with MREMAP_DONTUNMAP success") Signed-off-by: Lorenzo Stoakes (ARM) Reported-by: syzbot+f12658786a4153df5113@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/6a87853b.ae6ddae5.3da009.0023.GAE@google.com/ Tested-by: syzbot+f12658786a4153df5113@syzkaller.appspotmail.com Acked-by: Vlastimil Babka (SUSE) Reviewed-by: Kunwu Chan Reviewed-by: Pedro Falcato Cc: Jann Horn Cc: Liam R. Howlett Cc: Li Xinhai Cc: Signed-off-by: Andrew Morton [ adapted dontunmap_complete() changes to move_vma() using direct vm_pgoff assignment instead of unavailable helpers. ] Signed-off-by: Sasha Levin --- mm/mremap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index d458ef218a372..d35f603c9738e 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -714,8 +714,18 @@ static unsigned long move_vma(struct vm_area_struct *vma, * table has been moved. */ if (new_vma != vma && vma->vm_start == old_addr && - vma->vm_end == (old_addr + old_len)) + vma->vm_end == (old_addr + old_len)) { + const pgoff_t pgoff_unfaulted = vma->vm_start >> PAGE_SHIFT; + unlink_anon_vmas(vma); + /* + * The VMA is now unfaulted and it is an invariant that + * unfaulted anonymous VMAs have page offset equal to + * vma->vm_start >> PAGE_SHIFT. + */ + if (vma_is_anonymous(vma) && !vma->vm_file) + vma->vm_pgoff = pgoff_unfaulted; + } /* Because we won't unmap we don't need to touch locked_vm */ return new_addr; -- 2.53.0