From: Jan Beulich Date: Fri, 28 Mar 2014 12:30:10 +0000 (+0100) Subject: x86/HVM: simplify do_hvm_op() X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~5333 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8d134c2e12730a4a3dce9873f4671f6dd8860baf;p=xen.git x86/HVM: simplify do_hvm_op() - boundary checks in HVMOP_modified_memory, HVMOP_set_mem_type, and HVMOP_set_mem_access: all of these already check for overflow, so there's no need to range check the first _and_ last PFN (checking the last one suffices) - copying back interface structures that were previously copied from guest memory can use __copy_to_...(), since copy_from_...() already did the address range validation Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper Reviewed-by: Tim Deegan --- diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index b0da8e75db..c74287d098 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4291,7 +4291,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) a.value = d->arch.hvm_domain.params[a.index]; break; } - rc = copy_to_guest(arg, &a, 1) ? -EFAULT : 0; + rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; } HVM_DBG_LOG(DBG_LEVEL_HCALL, "%s param %u = %"PRIx64, @@ -4389,8 +4389,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) goto param_fail3; rc = -EINVAL; - if ( (a.first_pfn > domain_get_maximum_gpfn(d)) || - ((a.first_pfn + a.nr - 1) < a.first_pfn) || + if ( ((a.first_pfn + a.nr - 1) < a.first_pfn) || ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) ) goto param_fail3; @@ -4419,7 +4418,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) /* Check for continuation if it's not the last interation */ if ( a.nr > 0 && hypercall_preempt_check() ) { - if ( copy_to_guest(arg, &a, 1) ) + if ( __copy_to_guest(arg, &a, 1) ) rc = -EFAULT; else rc = -EAGAIN; @@ -4468,7 +4467,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) a.mem_type = HVMMEM_ram_rw; else a.mem_type = HVMMEM_mmio_dm; - rc = copy_to_guest(arg, &a, 1) ? -EFAULT : 0; + rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; } param_fail_getmemtype: @@ -4504,8 +4503,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) goto param_fail4; rc = -EINVAL; - if ( (a.first_pfn > domain_get_maximum_gpfn(d)) || - ((a.first_pfn + a.nr - 1) < a.first_pfn) || + if ( ((a.first_pfn + a.nr - 1) < a.first_pfn) || ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) ) goto param_fail4; @@ -4561,7 +4559,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) /* Check for continuation if it's not the last interation */ if ( a.nr > 0 && hypercall_preempt_check() ) { - if ( copy_to_guest(arg, &a, 1) ) + if ( __copy_to_guest(arg, &a, 1) ) rc = -EFAULT; else rc = -EAGAIN; @@ -4598,9 +4596,8 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = -EINVAL; if ( (a.first_pfn != ~0ull) && - ((a.first_pfn > domain_get_maximum_gpfn(d)) || - ((a.first_pfn + a.nr - 1) < a.first_pfn) || - ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d))) ) + (((a.first_pfn + a.nr - 1) < a.first_pfn) || + ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d))) ) goto param_fail5; rc = p2m_set_mem_access(d, a.first_pfn, a.nr, a.hvmmem_access); @@ -4649,7 +4646,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) goto param_fail6; a.hvmmem_access = access; - rc = copy_to_guest(arg, &a, 1) ? -EFAULT : 0; + rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; param_fail6: rcu_unlock_domain(d);