Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D6D5D241F7 for ; Thu, 23 Nov 2023 12:03:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Xl6Mpsbi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FA6EC433C7; Thu, 23 Nov 2023 12:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1700741019; bh=MvXo/o23VJFxKHUsrla+cJUgVYdWUE+MZlJG+7D6ziE=; h=Subject:To:Cc:From:Date:From; b=Xl6Mpsbioj2yuuEjqdncARI7uXf6D4oqunA6X7gFR5CUTPULxt49WdHgrzc8BfbGH vNaNVCbXJR1GKFYQis4z35mnnzuIEkXer0+vQDe4cNN6rkLAmvxqLOiWHNRpPyfoh4 zl4tJk28rcJEHQG1R4NH+AY3HAYbCPSEiSVz73z0= Subject: FAILED: patch "[PATCH] mm/hugetlb: use nth_page() in place of direct struct page" failed to apply to 6.5-stable tree To: ziy@nvidia.com,akpm@linux-foundation.org,david@redhat.com,mike.kravetz@oracle.com,rppt@kernel.org,songmuchun@bytedance.com,stable@vger.kernel.org,tsbogend@alpha.franken.de,willy@infradead.org Cc: From: Date: Thu, 23 Nov 2023 12:03:32 +0000 Message-ID: <2023112332-cackle-possum-a2e1@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.5-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-6.5.y git checkout FETCH_HEAD git cherry-pick -x 426056efe835cf4864ccf4c328fe3af9146fc539 # git commit -s git send-email --to '' --in-reply-to '2023112332-cackle-possum-a2e1@gregkh' --subject-prefix 'PATCH 6.5.y' HEAD^.. Possible dependencies: 426056efe835 ("mm/hugetlb: use nth_page() in place of direct struct page manipulation") 458568c92953 ("mm/hugetlb: prepare hugetlb_follow_page_mask() for FOLL_PIN") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ From 426056efe835cf4864ccf4c328fe3af9146fc539 Mon Sep 17 00:00:00 2001 From: Zi Yan Date: Wed, 13 Sep 2023 16:12:45 -0400 Subject: [PATCH] mm/hugetlb: use nth_page() in place of direct struct page manipulation When dealing with hugetlb pages, manipulating struct page pointers directly can get to wrong struct page, since struct page is not guaranteed to be contiguous on SPARSEMEM without VMEMMAP. Use nth_page() to handle it properly. A wrong or non-existing page might be tried to be grabbed, either leading to a non freeable page or kernel memory access errors. No bug is reported. It comes from code inspection. Link: https://lkml.kernel.org/r/20230913201248.452081-3-zi.yan@sent.com Fixes: 57a196a58421 ("hugetlb: simplify hugetlb handling in follow_page_mask") Signed-off-by: Zi Yan Reviewed-by: Muchun Song Cc: David Hildenbrand Cc: Matthew Wilcox (Oracle) Cc: Mike Kravetz Cc: Mike Rapoport (IBM) Cc: Thomas Bogendoerfer Cc: Signed-off-by: Andrew Morton diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7c90c43574a6..a945efe2858a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6493,7 +6493,7 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, } } - page += ((address & ~huge_page_mask(h)) >> PAGE_SHIFT); + page = nth_page(page, ((address & ~huge_page_mask(h)) >> PAGE_SHIFT)); /* * Note that page may be a sub-page, and with vmemmap