Re: [PATCH v2 2/2] mm/uffd: Sanity check write bit for uffd-wp protected ptes

Peter Xu
2022-11-13T22:33:59Z

On Sat, Nov 12, 2022 at 06:06:22AM +0800, kernel test robot wrote:
> vim +306 arch/x86/include/asm/pgtable.h
>
> 290
> 291 #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
> 292 static inline int pte_uffd_wp(pte_t pte)
> 293 {
> 294 bool wp = pte_flags(pte) & _PAGE_UFFD_WP;
> 295
> 296 /*
> 297 * Having write bit for wr-protect-marked present ptes is fatal,
> 298 * because it means the uffd-wp bit will be ignored and write will
> 299 * just go through.
> 300 *
> 301 * Use any chance of pgtable walking to verify this (e.g., when
> 302 * page swapped out or being migrated for all purposes). It means
> 303 * something is already wrong. Tell the admin even before the
> 304 * process crashes. We also nail it with wrong pgtable setup.
> 305 */
> > 306 VM_WARN_ON_ONCE(wp && pte_write(pte));

I just saw the comment in check_pgprot() right below:

/* mmdebug.h can not be included here because of dependencies */
#ifdef CONFIG_DEBUG_VM
...
#endif

I'll repost, will be the same as v1 code-wise.

--
Peter Xu