Re: [RFC PATCH 3/3] nSVM: use svm->nested.save to load vmcb12 registers and avoid TOC/TOU races
From: Maxim Levitsky
Date: Tue Sep 14 2021 - 07:39:43 EST
On Tue, 2021-09-14 at 12:52 +0200, Emanuele Giuseppe Esposito wrote:
> > I would do it this way:
> >
> > struct svm_nested_state {
> > ...
> > /* cached fields from the vmcb12 */
> > struct vmcb_control_area_cached ctl;
> > struct vmcb_save_area_cached save;
> > ...
> > };
> >
> >
>
> The only thing that requires a little bit of additional work when
> applying this is svm_get_nested_state() (and theoretically
> svm_set_nested_state(), in option 2). In this function, nested.ctl is
> copied in user_vmcb->control. But now nested.ctl is not anymore a
> vmcb_control_area, so the sizes differ.
>
> There are 2 options here:
> 1) copy nested.ctl into a full vmcb_control_area, and copy it to user
> space without modifying the API. The advantage is that the API is left
> intact, but an additional copy is required.
Thankfully there KVM_GET_NESTED_STATE is not performance critical at all,
so a copy isn't that big problem, other that it is a bit ugly.
Ugh..
>
> 2) modify KVM_GET_NESTED_STATE and KVM_SET_NESTED_STATE to handle
> vmcb_control_area_cached. Advantage is that there is a lightweight copy
> + the benefits explained by you in the previous email (no unset field).
That would break the KVM_GET_NESTED_STATE ABI without a very good reason,
especially since some of the currently unused fields in the ctl (there
are I think very few of them), might became used later on, needing
to break the ABI again.
Best regards,
Maxim Levitsky
>
> I am not sure which one is the preferred way here.
>
> Thank you,
> Emanuele
>