Re: [kvm-unit-tests PATCH v2 4/4] x86/access: Try emulation for CR0.WP test as well

Sean Christopherson
2023-03-31T16:30:08Z

On Fri, Mar 31, 2023, Mathias Krause wrote:
> Enhance the CR.WP toggling test to do additional tests via the emulator
> as these used to trigger bugs when CR0.WP is guest owned.
>
> Link: https://lore.kernel.org/kvm/ea3a8fbc-2bf8-7442-e498-3e5818384c83@grsecurity.net/
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> ---
> x86/access.c | 46 +++++++++++++++++++++++++++++++---------------
> 1 file changed, 31 insertions(+), 15 deletions(-)
>
> diff --git a/x86/access.c b/x86/access.c
> index ae5e7d8e8892..21967434bc18 100644
> --- a/x86/access.c
> +++ b/x86/access.c
> @@ -1107,27 +1107,43 @@ static int check_write_cr0wp(ac_pt_env_t *pt_env)
> * We load CR0.WP with the inverse value of what would be used during
> * the access test and toggle EFER.NX to flush and rebuild the current
> * MMU context based on that value.
> + *
> + * This used to trigger a bug in the emulator we try to test via FEP.
> */
> + for (;;) {

As suggested in patch 2, I'm pretty sure it's easier to use a helper, and have
the print statement react to at->flags.