From: Andrew Cooper Date: Tue, 20 Nov 2018 13:58:10 +0000 (+0100) Subject: x86/mm: Put the gfn on all paths after get_gfn_query() X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~2894 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d80988cfc04ee608bee722448e7c3bc8347ec04c;p=xen.git x86/mm: Put the gfn on all paths after get_gfn_query() c/s 7867181b2 "x86/PoD: correctly handle non-order-0 decrease-reservation requests" introduced an early exit in guest_remove_page() for unexpected p2m types. However, get_gfn_query() internally takes the p2m lock, and must be matched with a put_gfn() call later. Fix the erroneous comment beside the declaration of get_gfn_query(). This is XSA-277. Reported-by: Paul Durrant Signed-off-by: Andrew Cooper --- diff --git a/xen/common/memory.c b/xen/common/memory.c index b68efd4d9f..e894eba672 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -305,7 +305,11 @@ int guest_remove_page(struct domain *d, unsigned long gmfn) #ifdef CONFIG_X86 mfn = get_gfn_query(d, gmfn, &p2mt); if ( unlikely(p2mt == p2m_invalid) || unlikely(p2mt == p2m_mmio_dm) ) + { + put_gfn(d, gmfn); + return -ENOENT; + } if ( unlikely(p2m_is_paging(p2mt)) ) { diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index ac33f5086b..6d849a5ebd 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -448,10 +448,7 @@ static inline mfn_t __nonnull(3) get_gfn_type( return get_gfn_type_access(p2m_get_hostp2m(d), gfn, t, &a, q, NULL); } -/* Syntactic sugar: most callers will use one of these. - * N.B. get_gfn_query() is the _only_ one guaranteed not to take the - * p2m lock; none of the others can be called with the p2m or paging - * lock held. */ +/* Syntactic sugar: most callers will use one of these. */ #define get_gfn(d, g, t) get_gfn_type((d), (g), (t), P2M_ALLOC) #define get_gfn_query(d, g, t) get_gfn_type((d), (g), (t), 0) #define get_gfn_unshare(d, g, t) get_gfn_type((d), (g), (t), \