This is a note to let you know that I've just added the patch titled mm/userfaultfd: allow hugetlb change protection upon poison entry to the 6.8-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: mm-userfaultfd-allow-hugetlb-change-protection-upon-poison-entry.patch and it can be found in the queue-6.8 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From c5977c95dff182d6ee06f4d6f60bcb0284912969 Mon Sep 17 00:00:00 2001 From: Peter Xu <peterx@xxxxxxxxxx> Date: Fri, 5 Apr 2024 19:19:20 -0400 Subject: mm/userfaultfd: allow hugetlb change protection upon poison entry From: Peter Xu <peterx@xxxxxxxxxx> commit c5977c95dff182d6ee06f4d6f60bcb0284912969 upstream. After UFFDIO_POISON, there can be two kinds of hugetlb pte markers, either the POISON one or UFFD_WP one. Allow change protection to run on a poisoned marker just like !hugetlb cases, ignoring the marker irrelevant of the permission. Here the two bits are mutual exclusive. For example, when install a poisoned entry it must not be UFFD_WP already (by checking pte_none() before such install). And it also means if UFFD_WP is set there must have no POISON bit set. It makes sense because UFFD_WP is a bit to reflect permission, and permissions do not apply if the pte is poisoned and destined to sigbus. So here we simply check uffd_wp bit set first, do nothing otherwise. Attach the Fixes to UFFDIO_POISON work, as before that it should not be possible to have poison entry for hugetlb (e.g., hugetlb doesn't do swap, so no chance of swapin errors). Link: https://lkml.kernel.org/r/20240405231920.1772199-1-peterx@xxxxxxxxxx Link: https://lore.kernel.org/r/000000000000920d5e0615602dd1@xxxxxxxxxx Fixes: fc71884a5f59 ("mm: userfaultfd: add new UFFDIO_POISON ioctl") Signed-off-by: Peter Xu <peterx@xxxxxxxxxx> Reported-by: syzbot+b07c8ac8eee3d4d8440f@xxxxxxxxxxxxxxxxxxxxxxxxx Reviewed-by: David Hildenbrand <david@xxxxxxxxxx> Reviewed-by: Axel Rasmussen <axelrasmussen@xxxxxxxxxx> Cc: <stable@xxxxxxxxxxxxxxx> [6.6+] Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- mm/hugetlb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6943,9 +6943,13 @@ long hugetlb_change_protection(struct vm if (!pte_same(pte, newpte)) set_huge_pte_at(mm, address, ptep, newpte, psize); } else if (unlikely(is_pte_marker(pte))) { - /* No other markers apply for now. */ - WARN_ON_ONCE(!pte_marker_uffd_wp(pte)); - if (uffd_wp_resolve) + /* + * Do nothing on a poison marker; page is + * corrupted, permissons do not apply. Here + * pte_marker_uffd_wp()==true implies !poison + * because they're mutual exclusive. + */ + if (pte_marker_uffd_wp(pte) && uffd_wp_resolve) /* Safe to modify directly (non-present->none). */ huge_pte_clear(mm, address, ptep, psize); } else if (!huge_pte_none(pte)) { Patches currently in stable-queue which might be from peterx@xxxxxxxxxx are queue-6.8/mm-swapops-update-check-in-is_pfn_swap_entry-for-hwpoison-entries.patch queue-6.8/mm-userfaultfd-allow-hugetlb-change-protection-upon-poison-entry.patch