From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: Peter Xu <peterx@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Nadav Amit <nadav.amit@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Axel Rasmussen <axelrasmussen@google.com>,
David Hildenbrand <david@redhat.com>
Subject: Re: [PATCH v4] mm/page_table_check: Support userfault wr-protect entries
Date: Wed, 17 Apr 2024 17:46:56 -0400 [thread overview]
Message-ID: <CA+CK2bB9x+ErL+Kx+50DL-8gRSYW6vFen+bFe+cgXPKfuwpG3g@mail.gmail.com> (raw)
In-Reply-To: <20240417212549.2766883-1-peterx@redhat.com>
On Wed, Apr 17, 2024 at 5:25 PM Peter Xu <peterx@redhat.com> wrote:
>
> Allow page_table_check hooks to check over userfaultfd wr-protect criteria
> upon pgtable updates. The rule is no co-existance allowed for any writable
> flag against userfault wr-protect flag.
>
> This should be better than c2da319c2e, where we used to only sanitize such
> issues during a pgtable walk, but when hitting such issue we don't have a
> good chance to know where does that writable bit came from [1], so that
> even the pgtable walk exposes a kernel bug (which is still helpful on
> triaging) but not easy to track and debug.
>
> Now we switch to track the source. It's much easier too with the recent
> introduction of page table check.
>
> There are some limitations with using the page table check here for
> userfaultfd wr-protect purpose:
>
> - It is only enabled with explicit enablement of page table check configs
> and/or boot parameters, but should be good enough to track at least
> syzbot issues, as syzbot should enable PAGE_TABLE_CHECK[_ENFORCED] for
> x86 [1]. We used to have DEBUG_VM but it's now off for most distros,
> while distros also normally not enable PAGE_TABLE_CHECK[_ENFORCED], which
> is similar.
>
> - It conditionally works with the ptep_modify_prot API. It will be
> bypassed when e.g. XEN PV is enabled, however still work for most of the
> rest scenarios, which should be the common cases so should be good
> enough.
>
> - Hugetlb check is a bit hairy, as the page table check cannot identify
> hugetlb pte or normal pte via trapping at set_pte_at(), because of the
> current design where hugetlb maps every layers to pte_t... For example,
> the default set_huge_pte_at() can invoke set_pte_at() directly and lose
> the hugetlb context, treating it the same as a normal pte_t. So far it's
> fine because we have huge_pte_uffd_wp() always equals to pte_uffd_wp() as
> long as supported (x86 only). It'll be a bigger problem when we'll
> define _PAGE_UFFD_WP differently at various pgtable levels, because then
> one huge_pte_uffd_wp() per-arch will stop making sense first.. as of now
> we can leave this for later too.
>
> This patch also removes commit c2da319c2e altogether, as we have something
> better now.
>
> [1] https://lore.kernel.org/all/000000000000dce0530615c89210@google.com/
>
> Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> v2:
> - Rename __page_table_check_pxx() to page_table_check_pxx_flags(),
> meanwhile move the pte check out of the loop [Pasha]
> - Fix build issues reported from the bot, also added SWP_DEVICE_WRITE which
> was overlooked before
> v3:
> - Add missing doc update [Pasha]
> v4:
> - Fix wordings in doc, use more elegant swap helpers [Pasha]
> ---
> Documentation/mm/page_table_check.rst | 9 +++++++-
> arch/x86/include/asm/pgtable.h | 18 +---------------
> mm/page_table_check.c | 30 +++++++++++++++++++++++++++
> 3 files changed, 39 insertions(+), 18 deletions(-)
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Thanks,
Pasha
prev parent reply other threads:[~2024-04-17 21:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-17 21:25 Peter Xu
2024-04-17 21:46 ` Pasha Tatashin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+CK2bB9x+ErL+Kx+50DL-8gRSYW6vFen+bFe+cgXPKfuwpG3g@mail.gmail.com \
--to=pasha.tatashin@soleen.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nadav.amit@gmail.com \
--cc=peterx@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox