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

From: Nadav Amit
Date: Thu Nov 10 2022 - 13:43:40 EST


On Nov 10, 2022, at 7:17 AM, Peter Xu <peterx@xxxxxxxxxx> wrote:

> +#ifdef CONFIG_DEBUG_VM
> + /*
> + * Having write bit for wr-protect-marked present ptes is fatal,
> + * because it means the uffd-wp bit will be ignored and write will
> + * just go through.
> + *
> + * Use any chance of pgtable walking to verify this (e.g., when
> + * page swapped out or being migrated for all purposes). It means
> + * something is already wrong. Tell the admin even before the
> + * process crashes. We also nail it with wrong pgtable setup.
> + */
> + WARN_ON_ONCE(wp && pte_write(pte));

How about VM_WARN_ON_ONCE() and no ifdef?