From: Don Koch Subject: [PATCH v3] Sanity check xsave area when migrating or restoring from older Xen verions Date: Mon, 20 Oct 2014 16:40:07 -0400 Message-ID: <1413837607-14801-1-git-send-email-dkoch@verizon.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Andrew Cooper , Keir Fraser , Don Koch , Jan Beulich List-Id: xen-devel@lists.xenproject.org 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 part of the xsave area between the XCR0 specified and transferred size is checked for zero data. If any part of the overflow area is non-zero, we return with an error. Signed-off-by: Don Koch --- Changes in V3: - use h->data for zero check - remove max size check (use size that was sent) - fix error message (drop first byte value) - fix "for" issues xen/arch/x86/hvm/hvm.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index f0e1edc..a88b37d 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1971,6 +1971,7 @@ 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; + int i, overflow_start; /* Which vcpu is this? */ vcpuid = hvm_load_instance(h); @@ -2020,6 +2021,7 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h) return -EOPNOTSUPP; } h->cur += sizeof (*desc); + overflow_start = h->cur; ctxt = (struct hvm_hw_cpu_xsave *)&h->data[h->cur]; h->cur += desc->length; @@ -2041,7 +2043,18 @@ 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); - return -EOPNOTSUPP; + + /* Make sure missing bytes are all zero. */ + for ( i = size; i < desc->length; i++ ) + { + if ( h->data[overflow_start + i] ) + { + printk(XENLOG_G_WARNING + "HVM%d.%d restore mismatch: xsave has non-zero data starting at %d\n", + d->domain_id, vcpuid, i); + return -EOPNOTSUPP; + } + } } /* Checking finished */ -- 1.8.3.1