* [PATCH] mm/userfaultfd: Allow hugetlb change protection upon poison entry
@ 2024-04-05 23:19 peterx
2024-04-08 18:59 ` David Hildenbrand
0 siblings, 1 reply; 3+ messages in thread
From: peterx @ 2024-04-05 23:19 UTC (permalink / raw)
To: linux-mm, linux-kernel
Cc: Andrew Morton, peterx, Axel Rasmussen, David Hildenbrand,
linux-stable, syzbot+b07c8ac8eee3d4d8440f
From: Peter Xu <peterx@redhat.com>
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).
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: linux-stable <stable@vger.kernel.org> # 6.6+
Link: https://lore.kernel.org/r/000000000000920d5e0615602dd1@google.com
Reported-by: syzbot+b07c8ac8eee3d4d8440f@syzkaller.appspotmail.com
Fixes: fc71884a5f59 ("mm: userfaultfd: add new UFFDIO_POISON ioctl")
Signed-off-by: Peter Xu <peterx@redhat.com>
---
mm/hugetlb.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 8267e221ca5d..ba7162441adf 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6960,9 +6960,13 @@ long hugetlb_change_protection(struct vm_area_struct *vma,
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)) {
--
2.44.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/userfaultfd: Allow hugetlb change protection upon poison entry
2024-04-05 23:19 [PATCH] mm/userfaultfd: Allow hugetlb change protection upon poison entry peterx
@ 2024-04-08 18:59 ` David Hildenbrand
2024-04-08 20:39 ` Axel Rasmussen
0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand @ 2024-04-08 18:59 UTC (permalink / raw)
To: peterx, linux-mm, linux-kernel
Cc: Andrew Morton, Axel Rasmussen, linux-stable, syzbot+b07c8ac8eee3d4d8440f
On 06.04.24 01:19, peterx@redhat.com wrote:
> From: Peter Xu <peterx@redhat.com>
>
> 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).
>
> Cc: Axel Rasmussen <axelrasmussen@google.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: linux-stable <stable@vger.kernel.org> # 6.6+
> Link: https://lore.kernel.org/r/000000000000920d5e0615602dd1@google.com
> Reported-by: syzbot+b07c8ac8eee3d4d8440f@syzkaller.appspotmail.com
> Fixes: fc71884a5f59 ("mm: userfaultfd: add new UFFDIO_POISON ioctl")
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> mm/hugetlb.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 8267e221ca5d..ba7162441adf 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -6960,9 +6960,13 @@ long hugetlb_change_protection(struct vm_area_struct *vma,
> 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)) {
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/userfaultfd: Allow hugetlb change protection upon poison entry
2024-04-08 18:59 ` David Hildenbrand
@ 2024-04-08 20:39 ` Axel Rasmussen
0 siblings, 0 replies; 3+ messages in thread
From: Axel Rasmussen @ 2024-04-08 20:39 UTC (permalink / raw)
To: David Hildenbrand
Cc: peterx, linux-mm, linux-kernel, Andrew Morton, linux-stable,
syzbot+b07c8ac8eee3d4d8440f
Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>
Thanks for the fix, Peter!
On Mon, Apr 8, 2024 at 11:59 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 06.04.24 01:19, peterx@redhat.com wrote:
> > From: Peter Xu <peterx@redhat.com>
> >
> > 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).
> >
> > Cc: Axel Rasmussen <axelrasmussen@google.com>
> > Cc: David Hildenbrand <david@redhat.com>
> > Cc: linux-stable <stable@vger.kernel.org> # 6.6+
> > Link: https://lore.kernel.org/r/000000000000920d5e0615602dd1@google.com
> > Reported-by: syzbot+b07c8ac8eee3d4d8440f@syzkaller.appspotmail.com
> > Fixes: fc71884a5f59 ("mm: userfaultfd: add new UFFDIO_POISON ioctl")
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > mm/hugetlb.c | 10 +++++++---
> > 1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> > index 8267e221ca5d..ba7162441adf 100644
> > --- a/mm/hugetlb.c
> > +++ b/mm/hugetlb.c
> > @@ -6960,9 +6960,13 @@ long hugetlb_change_protection(struct vm_area_struct *vma,
> > 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)) {
>
> Reviewed-by: David Hildenbrand <david@redhat.com>
>
> --
> Cheers,
>
> David / dhildenb
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-08 20:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 23:19 [PATCH] mm/userfaultfd: Allow hugetlb change protection upon poison entry peterx
2024-04-08 18:59 ` David Hildenbrand
2024-04-08 20:39 ` Axel Rasmussen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox