From 7ee7a3749bcb5d39ced5a1ee3e8284b2bb9abc29 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Tue, 6 Apr 2021 16:17:42 +0200 Subject: [PATCH] common: map_vcpu_info() cosmetics MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use ENXIO instead of EINVAL to cover the two cases of the address not satisfying the requirements. This will make an issue here better stand out at the call site. Also add a missing compat-mode related size check: If the sizes differed, other code in the function would need changing. Accompany this by a change to the initial sizeof() expression, tying it to the type of the variable we're actually after (matching e.g. the alignof() added by XSA-327). Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné Acked-by: Julien Grall --- xen/common/domain.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index d85984638a..cdda0d1f29 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1427,17 +1427,18 @@ int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset) struct page_info *page; unsigned int align; - if ( offset > (PAGE_SIZE - sizeof(vcpu_info_t)) ) - return -EINVAL; + if ( offset > (PAGE_SIZE - sizeof(*new_info)) ) + return -ENXIO; #ifdef CONFIG_COMPAT + BUILD_BUG_ON(sizeof(*new_info) != sizeof(new_info->compat)); if ( has_32bit_shinfo(d) ) align = alignof(new_info->compat); else #endif align = alignof(*new_info); if ( offset & (align - 1) ) - return -EINVAL; + return -ENXIO; if ( !mfn_eq(v->vcpu_info_mfn, INVALID_MFN) ) return -EINVAL; -- 2.30.2