libxl: Fix bootloader-related virtual memory leak on pv build failure
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 18 Nov 2015 15:34:54 +0000 (15:34 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 8 Dec 2015 15:30:53 +0000 (15:30 +0000)
commit40412e3c99722229f1ec93cd95fc8486d778f5df
tree54fdf7de946eb59cff6a22cfc8f9720adfda5934
parenteedecb3cf0b2ce1ffc2eb08f3c73f88d42c382c9
libxl: Fix bootloader-related virtual memory leak on pv build failure

The bootloader may call libxl__file_reference_map(), which mmap's the
pv_kernel and pv_ramdisk into process memory.  This was only unmapped,
however, on the success path of libxl__build_pv().  If there were a
failure anywhere between libxl_bootloader.c:parse_bootloader_result()
and the end of libxl__build_pv(), the calls to
libxl__file_reference_unmap() would be skipped, leaking the mapped
virtual memory.

Ideally this would be fixed by adding the unmap calls to the
destruction path for libxl__domain_build_state.  Unfortunately the
lifetime of the libxl__domain_build_state is opaque, and it doesn't
have a proper destruction path.  But, the only thing in it that isn't
from the gc are these bootloader references, and they are only ever
set for one libxl__domain_build_state, the one which is
libxl__domain_create_state.build_state.

So we can clean up in the exit path from libxl__domain_create_*, which
always comes through domcreate_complete.

Remove the now-redundant unmaps in libxl__build_pv's success path.

This is XSA-160.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Tested-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl_create.c
tools/libxl/libxl_dom.c