From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Don Koch <dkoch@verizon.com>, xen-devel@lists.xen.org
Cc: Keir Fraser <keir@xen.org>, Jan Beulich <jbeulich@suse.com>
Subject: Re: [PATCH v2] Sanity check xsave area when migrating or restoring from older Xen verions
Date: Sat, 18 Oct 2014 00:36:28 +0100 [thread overview]
Message-ID: <5441A7FC.5070001@citrix.com> (raw)
In-Reply-To: <1413565863-23629-1-git-send-email-dkoch@verizon.com>
On 17/10/2014 18:11, Don Koch wrote:
> Xen 4.3 and older transferred a maximum sized xsave area (as if all
> the available XCR0 bits were set); the new version only transfers
> based on the actual XCR0 bits. This may result in a smaller area if
> the last sections were missing (e.g., the LWP area from an AMD
> machine). If the size doesn't match the XCR0 derived size, the size is
> checked against the maximum size and the part of the xsave area
> between the actual and maximum used size is checked for zero data. If
> either the max size check or any part of the overflow area is
> non-zero, we return with an error.
>
> Signed-off-by: Don Koch <dkoch@verizon.com>
> ---
> xen/arch/x86/hvm/hvm.c | 29 ++++++++++++++++++++++++++++-
> 1 file changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index f0e1edc..bdebc67 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -1971,6 +1971,8 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
> struct vcpu *v;
> struct hvm_hw_cpu_xsave *ctxt;
> struct hvm_save_descriptor *desc;
> + u32 eax, ebx, ecx, edx;
> + uint8_t *overflow_start;
>
> /* Which vcpu is this? */
> vcpuid = hvm_load_instance(h);
> @@ -2041,8 +2043,32 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore mismatch: xsave length %u > %u\n",
> d->domain_id, vcpuid, desc->length, size);
This warning should be elided if we pass the zero-check.
> - return -EOPNOTSUPP;
> +
> + /* Check to see if the xsave_area is the maximum size.
> + If so, it is likely the save is from an older xen. */
> + cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
This check is bogus for heterogeneous hardware. We have no way of
calculating what the maximum xsave area size was on the sending side
should have been...
> + if ( desc->length !=
> + ecx + offsetof(struct hvm_hw_cpu_xsave, save_area) ) {
> + printk(XENLOG_G_WARNING
> + "HVM%d.%d restore mismatch: xsave length %u != %u\n",
> + d->domain_id, vcpuid, desc->length, ecx +
> + (u32)offsetof(struct hvm_hw_cpu_xsave, save_area));
> + return -EOPNOTSUPP;
> + }
> +
> + /* Make sure unused bytes are all zero. */
...which is fine, as we literally only care whether the overflow data is
all zeros of not.
It is is all empty, we really don't care how large it was supposed to be
before. If it is not empty, then something is certainly corrupt in this
record.
> + overflow_start = (uint8_t *)&ctxt->save_area -
> + offsetof(struct hvm_hw_cpu_xsave, save_area);
I am having a hard time working out whether this expression is correct.
As ctxt is superimposed on top of h->data, would it not make sense to
check h->data between the expected end, and the real length? h->data is
even the correct type for doing this with.
> + for (int i = size; i < desc->length; i++)
Style
> + {
> + if ( *(overflow_start + i) )
> + {
> + printk(XENLOG_G_WARNING
> + "HVM%d.%d restore mismatch: xsave[%d] has non-zero data: %x\n",
> + d->domain_id, vcpuid, i, *(overflow_start +i));
I don't think it is useful to print the value of the first non-zero
byte. I would reduce it just to "junk found in overflow space".
~Andrew
> + return -EOPNOTSUPP;
> + }
> + }
> }
> /* Checking finished */
>
next prev parent reply other threads:[~2014-10-17 23:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-17 17:11 [PATCH v2] Sanity check xsave area when migrating or restoring from older Xen verions Don Koch
2014-10-17 23:36 ` Andrew Cooper [this message]
2014-10-20 10:21 ` Jan Beulich
2014-10-20 12:54 ` Don Koch
2014-10-20 14:25 ` Jan Beulich
2014-10-20 13:27 ` Andrew Cooper
2014-10-20 14:21 ` Jan Beulich
2014-10-20 15:04 ` Don Koch
2014-10-20 15:09 ` Andrew Cooper
2014-10-20 12:54 ` Don Koch
2014-10-20 15:28 ` Jan Beulich
2014-10-20 15:40 ` Don Koch
2014-10-21 7:40 ` Jan Beulich
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=5441A7FC.5070001@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=dkoch@verizon.com \
--cc=jbeulich@suse.com \
--cc=keir@xen.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.