xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@linaro.org>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
	Xen-devel <xen-devel@lists.xen.org>
Cc: Julien Grall <julien.grall@arm.com>,
	Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: Re: [PATCH for-4.10] x86/hvm: Don't corrupt the HVM context stream when writing the MSR record
Date: Tue, 21 Nov 2017 10:39:58 +0000	[thread overview]
Message-ID: <eb83d754-7195-4e4e-f89d-c5d4c9aaa098@linaro.org> (raw)
In-Reply-To: <1510872316-13762-1-git-send-email-andrew.cooper3@citrix.com>

Hi,

On 11/16/2017 10:45 PM, Andrew Cooper wrote:
> Ever since it was introduced in c/s bd1f0b45ff, hvm_save_cpu_msrs() has had a
> bug whereby it corrupts the HVM context stream if some, but fewer than the
> maximum number of MSRs are written.
> 
> _hvm_init_entry() creates an hvm_save_descriptor with length for
> msr_count_max, but in the case that we write fewer than max, h->cur only moves
> forward by the amount of space used, causing the subsequent
> hvm_save_descriptor to be written within the bounds of the previous one.
> 
> To resolve this, reduce the length reported by the descriptor to match the
> actual number of bytes used.
> 
> A typical failure on the destination side looks like:
> 
>      (XEN) HVM4 restore: CPU_MSR 0
>      (XEN) HVM4.0 restore: not enough data left to read 56 MSR bytes
>      (XEN) HVM4 restore: failed to load entry 20/0
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> CC: Julien Grall <julien.grall@arm.com>
> 
> This wants backporting to all stable trees, so should also be considered for
> inclusion into 4.10 at this point.

Release-acked-by: Julien Grall <julien.grall@linaro.org>

Cheers,

> ---
>   xen/arch/x86/hvm/hvm.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index 0af498a..c5e8467 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -1330,6 +1330,7 @@ static int hvm_save_cpu_msrs(struct domain *d, hvm_domain_context_t *h)
>   
>       for_each_vcpu ( d, v )
>       {
> +        struct hvm_save_descriptor *d = _p(&h->data[h->cur]);
>           struct hvm_msr *ctxt;
>           unsigned int i;
>   
> @@ -1348,8 +1349,13 @@ static int hvm_save_cpu_msrs(struct domain *d, hvm_domain_context_t *h)
>               ctxt->msr[i]._rsvd = 0;
>   
>           if ( ctxt->count )
> +        {
> +            /* Rewrite length to indicate how much space we actually used. */
> +            d->length = HVM_CPU_MSR_SIZE(ctxt->count);
>               h->cur += HVM_CPU_MSR_SIZE(ctxt->count);
> +        }
>           else
> +            /* or rewind and remove the descriptor from the stream. */
>               h->cur -= sizeof(struct hvm_save_descriptor);
>       }
>   
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

      parent reply	other threads:[~2017-11-21 10:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-16 22:45 [PATCH for-4.10] x86/hvm: Don't corrupt the HVM context stream when writing the MSR record Andrew Cooper
2017-11-17 10:58 ` Wei Liu
2017-11-17 12:15 ` Jan Beulich
2017-11-20 13:34   ` Andrew Cooper
2017-11-21 10:39 ` Julien Grall [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=eb83d754-7195-4e4e-f89d-c5d4c9aaa098@linaro.org \
    --to=julien.grall@linaro.org \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=julien.grall@arm.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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;
as well as URLs for NNTP newsgroup(s).