tools/libxl: Fix free() of wild pointer in libxl__initiate_device_remove()
PATCH 1/1 tools/libxl: Fix free() of wild pointer in libxl__initiate_device_remove()
libxl__initiate_device_remove() had a preexisting error path issue where libxl_dominfo_dispose() could be called on a libxl_dominfo object before it had been initialised with libxl_dominfo_init().
This was safe until c/s ab44401 added the pointer ssid_label, which point libxl_dominfo_dispose() free()s.
Unconditionally initialise info in libxl__initiate_device_remove() before taking an error path which will free it.
Coverity-ID: 1223212
--- tools/libxl/libxl_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxl/libxl_device.c +2 -1
@@ -772,6 +772,8 @@ void libxl__initiate_device_remove(libxl__egc *egc,uint32_t my_domid, domid = aodev->dev->domid;int rc =0 ; +libxl_dominfo_init (&info); + rc =libxl__get_domid (gc, &my_domid);if (rc) {LOG (ERROR ,"unable to get my domid" );
@@ -779,7 +781,6 @@ void libxl__initiate_device_remove(libxl__egc *egc, }if (my_domid ==LIBXL_TOOLSTACK_DOMID ) { -libxl_dominfo_init (&info); rc =libxl_domain_info (CTX , &info, domid);if (rc) {LOG (ERROR ,"unable to get info for domain %d" , domid);
Signature · 1 line
1.7.10.4
PATCH v2 1/1 tools/libxl: Fix free() of wild pointer in libxl__initiate_device_remove()
libxl__initiate_device_remove() had a preexisting error path issue where libxl_dominfo_dispose() could be called on a libxl_dominfo object before it had been initialised with libxl_dominfo_init().
This was safe until c/s ab44401 "xl / libxl: push parsing of SSID and CPU pool ID down to libxl" added the ssid_label string into libxl_dominfo, which libxl_dominfo_dispose() will free().
Unconditionally initialise info in libxl__initiate_device_remove() before taking an error path which will free it.
Coverity-ID: 1223212
--
v2: Clearer commit message
--- tools/libxl/libxl_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxl/libxl_device.c +2 -1
@@ -772,6 +772,8 @@ void libxl__initiate_device_remove(libxl__egc *egc,uint32_t my_domid, domid = aodev->dev->domid;int rc =0 ; +libxl_dominfo_init (&info); + rc =libxl__get_domid (gc, &my_domid);if (rc) {LOG (ERROR ,"unable to get my domid" );
@@ -779,7 +781,6 @@ void libxl__initiate_device_remove(libxl__egc *egc, }if (my_domid ==LIBXL_TOOLSTACK_DOMID ) { -libxl_dominfo_init (&info); rc =libxl_domain_info (CTX , &info, domid);if (rc) {LOG (ERROR ,"unable to get info for domain %d" , domid);
Signature · 1 line
1.7.10.4
Quoted 8 lines · Andrew Cooper
libxl__initiate_device_remove()had a preexisting error path issue wherelibxl_dominfo_dispose()could be called on alibxl_dominfoobject before it had been initialised withlibxl_dominfo_init().This was safe until c/s ab44401 "xl / libxl: push parsing of SSID and CPU pool ID down to libxl" added the
ssid_labelstring intolibxl_dominfo, whichlibxl_dominfo_dispose()willfree().
Quoted 5 lines
Unconditionally initialise info in
libxl__initiate_device_remove()before taking an error path which will free it.Coverity-ID: 1223212
Signed-off-by Andrew Cooper <[email protected]>
Thanks
Wei.
Andrew Cooper writes ("[PATCH] tools/libxl: Fix free() of wild pointer in libxl__initiate_device_remove()"):
Quoted 7 lines
libxl__initiate_device_remove()had a preexisting error path issue wherelibxl_dominfo_dispose()could be called on alibxl_dominfoobject before it had been initialised withlibxl_dominfo_init().This was safe until c/s ab44401 added the pointer
ssid_label, which pointlibxl_dominfo_dispose()free()s.
Quoted 7 lines
Unconditionally initialise info in
libxl__initiate_device_remove()before taking an error path which will free it.Coverity-ID: 1223212
Signed-off-by Andrew Cooper <[email protected]>CC Wei Liu <[email protected]>CC Ian Campbell <[email protected]>
Ian Jackson writes ("Re: [PATCH] tools/libxl: Fix free() of wild pointer in libxl__initiate_device_remove()"):
Quoted 4 lines
Andrew Cooper writes ("[PATCH]
tools/libxl: Fixfree()of wild pointer inlibxl__initiate_device_remove()"):Quoted 3 lines
libxl__initiate_device_remove()had a preexisting error path issue wherelibxl_dominfo_dispose()could be called on alibxl_dominfoobject before it had been initialised withlibxl_dominfo_init().
...
Quoted 2 lines
Acked-by Ian Jackson <[email protected]>Committed-by Ian Jackson <[email protected]>
This has been backported to 4.4. It isn't applicable to 4.3 and earlier.
FYI:
While investigating why it didn't apply, I discovered that the changeset blamed by Andrew isn't actually the real culprit.
The real culprit IMO is f39b1af257e3 "libxl: remove the Qemu bodge for driver domain devices" which was by Roger and acked by me. That change moves libxl_dominfo_init(&info) from the start of the function to a branch of an if(), but doesn't move the corresponding variable. Ie it introduced a violation of our principle that variables should all be initialised to a (noop)-freeable value; that violation was latent bug.
Ian.