Skip to content

Commit 1412ecb

Browse files
x-y-zakpm00
authored andcommitted
mm/huge_memory: check new folio order when split a folio
A folio can only be split into lower orders. Since there are no new_order checks in debugfs, any new_order can be passed via debugfs into split_huge_page_to_list_to_order(). Check new_order to make sure it is smaller than input folio order. Link: https://lkml.kernel.org/r/20240307181854.138928-1-zi.yan@sent.com Fixes: c010d47 ("mm: thp: split huge page to any lower order pages") Signed-off-by: Zi Yan <ziy@nvidia.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/linux-mm/7dda9283-b437-4cf8-ab0d-83c330deb9c0@moroto.mountain/ Cc: David Hildenbrand <david@redhat.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Yang Shi <shy828301@gmail.com> Cc: Yu Zhao <yuzhao@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent d221dd5 commit 1412ecb

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

mm/huge_memory.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,6 +3052,9 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
30523052
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
30533053
VM_BUG_ON_FOLIO(!folio_test_large(folio), folio);
30543054

3055+
if (new_order >= folio_order(folio))
3056+
return -EINVAL;
3057+
30553058
/* Cannot split anonymous THP to order-1 */
30563059
if (new_order == 1 && folio_test_anon(folio)) {
30573060
VM_WARN_ONCE(1, "Cannot split to order-1 folio");

0 commit comments

Comments
 (0)