From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 02/22] libxc: introduce xc_dom_seg_to_ptr_pages Date: Fri, 7 Jun 2013 19:35:11 +0100 Message-ID: <1370630131-7306-3-git-send-email-ian.jackson@eu.citrix.com> References: <1370630131-7306-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1370630131-7306-1-git-send-email-ian.jackson@eu.citrix.com> 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.xensource.com Cc: andrew.cooper3@citrix.com, mattjd@gmail.com, Ian Jackson , security@xen.org List-Id: xen-devel@lists.xenproject.org Provide a version of xc_dom_seg_to_ptr which returns the number of guest pages it has actually mapped. This is useful for callers who want to do range checking; we will use this later in this series. This is part of the fix to a security issue, XSA-55. Signed-off-by: Ian Jackson Acked-by: Ian Campbell Reviewed-by: Konrad Rzeszutek Wilk --- tools/libxc/xc_dom.h | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/libxc/xc_dom.h b/tools/libxc/xc_dom.h index 6a72aa9..44fbe53 100644 --- a/tools/libxc/xc_dom.h +++ b/tools/libxc/xc_dom.h @@ -278,14 +278,26 @@ void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t first, void xc_dom_unmap_one(struct xc_dom_image *dom, xen_pfn_t pfn); void xc_dom_unmap_all(struct xc_dom_image *dom); -static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom, - struct xc_dom_seg *seg) +static inline void *xc_dom_seg_to_ptr_pages(struct xc_dom_image *dom, + struct xc_dom_seg *seg, + xen_pfn_t *pages_out) { xen_vaddr_t segsize = seg->vend - seg->vstart; unsigned int page_size = XC_DOM_PAGE_SIZE(dom); xen_pfn_t pages = (segsize + page_size - 1) / page_size; + void *retval; + + retval = xc_dom_pfn_to_ptr(dom, seg->pfn, pages); + + if ( pages_out != NULL ) + *pages_out = retval ? pages : 0; + return retval; +} - return xc_dom_pfn_to_ptr(dom, seg->pfn, pages); +static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom, + struct xc_dom_seg *seg) +{ + return xc_dom_seg_to_ptr_pages(dom, seg, NULL); } static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom, -- 1.7.2.5