From: Kyle Hale Date: Mon, 7 Oct 2013 20:29:12 +0000 (-0500) Subject: more paranoid error checking X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=5a8d27bb121cfde8da7098c36984e16aa21db594 more paranoid error checking These changes handle the case in which v3_free_vm is called before several subsystems have been initialized. The ones that are particularly prone are the non-pointers in the v3_vm_info struct that have list_head elements. --- diff --git a/palacios/src/palacios/vmm_dev_mgr.c b/palacios/src/palacios/vmm_dev_mgr.c index 976f41d..c75e633 100644 --- a/palacios/src/palacios/vmm_dev_mgr.c +++ b/palacios/src/palacios/vmm_dev_mgr.c @@ -129,7 +129,7 @@ int v3_free_vm_devices(struct v3_vm_info * vm) { struct vm_device * dev; struct vm_device * tmp; - if (mgr) { + if (mgr && mgr->num_devs > 0) { list_for_each_entry_safe(dev, tmp, &(mgr->dev_list), dev_link) { v3_remove_device(dev); } diff --git a/palacios/src/palacios/vmm_intr.c b/palacios/src/palacios/vmm_intr.c index ee54bef..fa8c69f 100644 --- a/palacios/src/palacios/vmm_intr.c +++ b/palacios/src/palacios/vmm_intr.c @@ -69,11 +69,13 @@ void v3_deinit_intr_controllers(struct guest_info * core) { struct intr_controller * tmp; // clear out any controllers that were left around - list_for_each_entry_safe(ctrlr, tmp, &(intr_state->controller_list), ctrl_node) { - v3_remove_intr_controller(core, ctrlr); - } + if (*(void**)&intr_state->controller_list) { + list_for_each_entry_safe(ctrlr, tmp, &(intr_state->controller_list), ctrl_node) { + v3_remove_intr_controller(core, ctrlr); + } - v3_lock_deinit(&(intr_state->irq_lock)); + v3_lock_deinit(&(intr_state->irq_lock)); + } } @@ -92,12 +94,14 @@ void v3_deinit_intr_routers(struct v3_vm_info * vm) { struct intr_router * rtr = NULL; struct intr_router * tmp = NULL; - // clear out any controllers that were left around - list_for_each_entry_safe(rtr, tmp, &(vm->intr_routers.router_list), router_node) { - v3_remove_intr_router(vm, rtr); - } + // clear out any routers that were left around + if (*(void**)&vm->intr_routers.router_list) { + list_for_each_entry_safe(rtr, tmp, &(vm->intr_routers.router_list), router_node) { + v3_remove_intr_router(vm, rtr); + } - v3_lock_deinit(&(vm->intr_routers.irq_lock)); + v3_lock_deinit(&(vm->intr_routers.irq_lock)); + } } void * v3_register_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * priv_data) { diff --git a/palacios/src/palacios/vmm_shadow_paging.c b/palacios/src/palacios/vmm_shadow_paging.c index 444af7d..38dcc64 100644 --- a/palacios/src/palacios/vmm_shadow_paging.c +++ b/palacios/src/palacios/vmm_shadow_paging.c @@ -170,9 +170,15 @@ int v3_init_shdw_pg_state(struct guest_info * core) { int v3_deinit_shdw_pg_state(struct guest_info * core) { - struct v3_shdw_pg_impl * impl = core->vm_info->shdw_impl.current_impl; + struct v3_shdw_pg_impl * impl = NULL; + + if (!core || !core->vm_info) { + return -1; + } + + impl = core->vm_info->shdw_impl.current_impl; - if (impl->local_deinit(core) == -1) { + if (impl && impl->local_deinit(core) == -1) { PrintError(core->vm_info, core, "Error deinitializing shadow paging state\n"); return -1; } diff --git a/palacios/src/palacios/vmm_time.c b/palacios/src/palacios/vmm_time.c index b2f31a4..f7cbb9e 100644 --- a/palacios/src/palacios/vmm_time.c +++ b/palacios/src/palacios/vmm_time.c @@ -530,7 +530,9 @@ void v3_deinit_time_core(struct guest_info * core) { struct v3_timer * tmr = NULL; struct v3_timer * tmp = NULL; - list_for_each_entry_safe(tmr, tmp, &(time_state->timers), timer_link) { - v3_remove_timer(core, tmr); + if (*(void**)&time_state->timers) { + list_for_each_entry_safe(tmr, tmp, &(time_state->timers), timer_link) { + v3_remove_timer(core, tmr); + } } }