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=1795047650; b=MFGA2+1tbb2UgBhaqxpdZmVepJ6L7QM6OyG+DpzMXOrbvS5FJkzSHoeFLJ0O5DqXlsMz +MZ+mbtWMYDQBuyR/nIMoVOAuH5LQ6FidwkvMOIz659DIBWUecBMp2Cznlo0YmKjT8orp udPT3bUJmV1gE7GvWJw3QSMbmBzBDAWSUIa44sOFJWMkOTk6ZxoaAT3QR9/SbDxmGOK2t EquEJ8+HMfsM84EqFoRS3S9rEHC3Sjcl0JIGKarrfYZU4os87TJ2pJhHwnDEtTqqtSue4 GoRFexFdUMfK8oVhq5cmCDF2GEDhuAmb3P8NjG7ZCDuy0rg6LZoNqnEZQ55lqAXxx6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795047650; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=/rZqDpRI9YKLTfIr9sEzNl8MX1aY7oyEWoaC5FSh4Uk=; b=iMTedcdzr5QdhMUZFtAe0uaL5o0K4WbReh8cmL/rmnOzSVbjbToBz3NLFBfnKQ+VsYZr F+62hDF23cvGXwAVwCd3K4j7cuD2Kuv6W1IaUfl1fpe1syYmk5rHEdLO0f59c1SX+mVWN LTGFR7/vGQZrNVV/YwIqpQ0pmpYexFz7BCdCxtpS5FJGWODSHB9Cda11ebG7Ur1JQKXfi ZjDOX33eej7bA5aoa+4avAx4rwCUjvBqW73C/0Ng8yGoHc83VuMD2+s75HFd1aB2Kyro7 I/5xRTcZZvcarFbLep3WMiMk/89p4Ijdm52UnpvfICROdV4ciSIKyZQQkkKeAbhCDMQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=skUJxdS6; 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 2E680606A320; Thu, 19 Nov 2026 00:20:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=skUJxdS6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88F421F000CC; Thu, 19 Nov 2026 00:20:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795047650; bh=/rZqDpRI9YKLTfIr9sEzNl8MX1aY7oyEWoaC5FSh4Uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=skUJxdS6Ul3E3aD+pNS4C/5qFizmIQmu9XuyxsanIVK2ehuBuOa4LGBUihnhKTMn8 2TP2X0WoxA8stSjx6QL2qrUl0KiZjHw1VnThD5lnc4TnRvhies7FOU77Tm+/A4ZlB/ CUCc6CWuxHI7BPit2n11L01OSphY+OapUBLgyzXg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Li Zhe , Andrew Morton , "David Hildenbrand (Arm)" , Muchun Song , Oscar Salvador , Peter Xu , Mike Rapoport , "Jose A. Perez de Azpillaga" , Sasha Levin Subject: [PATCH 6.1 1713/2857] mm/hugetlb: fix mremap move length truncation Date: Wed, 18 Nov 2026 15:45:47 +0100 Message-ID: <20261118150303.006838331@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Li Zhe [ Upstream commit dfb190302d2b4af86c6ae48af0d3b09f28b35460 ] Patch series "mm/hugetlb: fix mremap bugs", v3. This series fixes a few hugetlb mremap bugs. Patch 1 fixes the return type of move_hugetlb_page_tables(), so large hugetlb moves cannot be truncated when reported back to the generic mremap code. Patch 2 disables hugetlb PMD sharing for UFFD missing mode, so UFFDIO_POISON markers cannot become visible through shared PMD page tables. Patch 3 fixes the recursive i_mmap_rwsem deadlock in the hugetlb mremap path by avoiding the destination PMD sharing allocation path while the mapping lock is already held for write. This patch (of 3): move_hugetlb_page_tables() returns the number of bytes moved, but its return type is int while the generic move_page_tables() path uses unsigned long lengths. A hugetlb mremap() move length above INT_MAX can therefore be misreported to copy_vma_and_data(). The out-of-range conversion to int is implementation-defined; on common 64-bit builds, for example, a 4 GiB move can be reported as zero, making the caller treat the move as a failure and use the wrong length for rollback. Return unsigned long from move_hugetlb_page_tables(), matching move_page_tables() and preserving the full byte count. Link: https://lore.kernel.org/20261022034543.51226-1-lizhe.67@bytedance.com Link: https://lore.kernel.org/20261022034543.51226-2-lizhe.67@bytedance.com Fixes: 550a7d60bd5e ("mm, hugepages: add mremap() support for hugepage backed vma") Signed-off-by: Li Zhe Signed-off-by: Andrew Morton Acked-by: David Hildenbrand (Arm) Cc: Muchun Song Cc: Oscar Salvador Cc: Peter Xu Cc: Mike Rapoport Cc: Jose A. Perez de Azpillaga Cc: Signed-off-by: Sasha Levin --- include/linux/hugetlb.h | 15 ++++++--------- mm/hugetlb.c | 7 +++---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index a9f175cda955c..86262b82ef8ad 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -137,10 +137,9 @@ void hugepage_put_subpool(struct hugepage_subpool *spool); void hugetlb_dup_vma_private(struct vm_area_struct *vma); void clear_vma_resv_huge_pages(struct vm_area_struct *vma); -int move_hugetlb_page_tables(struct vm_area_struct *vma, - struct vm_area_struct *new_vma, - unsigned long old_addr, unsigned long new_addr, - unsigned long len); +unsigned long move_hugetlb_page_tables(struct vm_area_struct *vma, + struct vm_area_struct *new_vma, unsigned long old_addr, + unsigned long new_addr, unsigned long len); int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *, struct vm_area_struct *); long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, @@ -296,11 +295,9 @@ static inline int copy_hugetlb_page_range(struct mm_struct *dst, return 0; } -static inline int move_hugetlb_page_tables(struct vm_area_struct *vma, - struct vm_area_struct *new_vma, - unsigned long old_addr, - unsigned long new_addr, - unsigned long len) +static inline unsigned long move_hugetlb_page_tables(struct vm_area_struct *vma, + struct vm_area_struct *new_vma, unsigned long old_addr, + unsigned long new_addr, unsigned long len) { BUG(); return 0; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f036b1d5babc7..7d32a2e64da72 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5308,10 +5308,9 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr, spin_unlock(dst_ptl); } -int move_hugetlb_page_tables(struct vm_area_struct *vma, - struct vm_area_struct *new_vma, - unsigned long old_addr, unsigned long new_addr, - unsigned long len) +unsigned long move_hugetlb_page_tables(struct vm_area_struct *vma, + struct vm_area_struct *new_vma, unsigned long old_addr, + unsigned long new_addr, unsigned long len) { struct hstate *h = hstate_vma(vma); struct address_space *mapping = vma->vm_file->f_mapping; -- 2.53.0