From: Peter Dinda Date: Sat, 7 Jul 2012 22:28:06 +0000 (-0500) Subject: Lots of pedantic error checking in Palacios proper, especially for memory X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=b7093fd3602ef2c796a1f8a0daded9d6aad0b756 Lots of pedantic error checking in Palacios proper, especially for memory --- diff --git a/palacios/include/palacios/vmm_config.h b/palacios/include/palacios/vmm_config.h index fe82063..a6e2b73 100644 --- a/palacios/include/palacios/vmm_config.h +++ b/palacios/include/palacios/vmm_config.h @@ -32,6 +32,8 @@ //#include +#define V3_MAX_TAG_LEN 256 + struct v3_vm_info; struct v3_vm_info * v3_config_guest( void * cfg_blob, void * priv_data); @@ -41,7 +43,7 @@ struct v3_cfg_file { void * data; uint64_t size; - char tag[256]; + char tag[V3_MAX_TAG_LEN]; struct list_head file_node; }; diff --git a/palacios/include/palacios/vmm_multitree.h b/palacios/include/palacios/vmm_multitree.h index 1fab8a2..070ca69 100644 --- a/palacios/include/palacios/vmm_multitree.h +++ b/palacios/include/palacios/vmm_multitree.h @@ -28,9 +28,10 @@ #include +#define V3_MTREE_NAME_LEN 50 struct v3_mtree { - char name[50]; + char name[V3_MTREE_NAME_LEN]; union { uint8_t flags; diff --git a/palacios/src/devices/8237_dma.c b/palacios/src/devices/8237_dma.c index 5d9a8da..0467c63 100644 --- a/palacios/src/devices/8237_dma.c +++ b/palacios/src/devices/8237_dma.c @@ -44,7 +44,11 @@ struct vm_device * v3_create_dma() { struct dma_state * dma = NULL; dma = (struct dma_state *)V3_Malloc(sizeof(struct dma_state)); - V3_ASSERT(dma != NULL); + + if (!dma) { + PrintError("Cannot allocate\n"); + return NULL; + } struct vm_device * dev = v3_create_device("DMA", &dev_ops, dma); diff --git a/palacios/src/devices/8254.c b/palacios/src/devices/8254.c index 5944cfa..d7659f8 100644 --- a/palacios/src/devices/8254.c +++ b/palacios/src/devices/8254.c @@ -736,7 +736,11 @@ static int pit_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { pit_state = (struct pit *)V3_Malloc(sizeof(struct pit)); - V3_ASSERT(pit_state != NULL); + if (!pit_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + pit_state->speaker = 0; pit_state->vm = vm; diff --git a/palacios/src/devices/8259a.c b/palacios/src/devices/8259a.c index 7e4b7a4..bfe90e5 100644 --- a/palacios/src/devices/8259a.c +++ b/palacios/src/devices/8259a.c @@ -867,7 +867,10 @@ static int pic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { state = (struct pic_internal *)V3_Malloc(sizeof(struct pic_internal)); - V3_ASSERT(state != NULL); + if (!state) { + PrintError("Cannot allocate in init\n"); + return -1; + } struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, state); diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c index 44ca08d..9951071 100644 --- a/palacios/src/devices/apic.c +++ b/palacios/src/devices/apic.c @@ -1877,6 +1877,12 @@ static int apic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { apic_dev = (struct apic_dev_state *)V3_Malloc(sizeof(struct apic_dev_state) + sizeof(struct apic_state) * vm->num_cores); + + if (!apic_dev) { + PrintError("Failed to allocate space for APIC\n"); + return -1; + } + apic_dev->num_apics = vm->num_cores; v3_lock_init(&(apic_dev->state_lock)); diff --git a/palacios/src/devices/cga.c b/palacios/src/devices/cga.c index d99275e..0b6b451 100644 --- a/palacios/src/devices/cga.c +++ b/palacios/src/devices/cga.c @@ -1220,6 +1220,12 @@ static int cga_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { PrintDebug("video: init_device\n"); video_state = (struct video_internal *)V3_Malloc(sizeof(struct video_internal)); + + if (!video_state) { + PrintError("Cannot allocate space for CGA state\n"); + return -1; + } + memset(video_state, 0, sizeof(struct video_internal)); struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, video_state); @@ -1233,7 +1239,15 @@ static int cga_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { video_state->dev = dev; video_state->framebuf_pa = (addr_t)V3_AllocPages(FRAMEBUF_SIZE / 4096); + + if (!video_state->framebuf_pa) { + PrintError("Cannot allocate frame buffer\n"); + V3_Free(video_state); + return -1; + } + video_state->framebuf = V3_VAddr((void *)(video_state->framebuf_pa)); + memset(video_state->framebuf, 0, FRAMEBUF_SIZE); PrintDebug("PA of array: %p\n", (void *)(video_state->framebuf_pa)); diff --git a/palacios/src/devices/cirrus_gfx_card.c b/palacios/src/devices/cirrus_gfx_card.c index ce25023..663f03b 100644 --- a/palacios/src/devices/cirrus_gfx_card.c +++ b/palacios/src/devices/cirrus_gfx_card.c @@ -425,10 +425,17 @@ static int cirrus_gfx_card_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg){ struct vm_device * pci_bus = v3_find_dev(vm, v3_cfg_val(cfg, "bus")); char * dev_id = v3_cfg_val(cfg, "ID"); + + if (!video_state) { + PrintError("Cannot allocate state in cirrus gfx\n"); + return -1; + } + struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, video_state); if (dev == NULL) { PrintError("Could not attach device %s\n", dev_id); + V3_Free(video_state) return -1; } @@ -436,6 +443,12 @@ static int cirrus_gfx_card_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg){ PrintDebug("Num Pages=%d\n", SIZE_OF_REGION / 4096); video_state->video_memory_pa = (addr_t)V3_AllocPages(SIZE_OF_REGION / 4096); + if (!video_state->video_memory_pa) { + PrintError("Cannot allocate video memory\n"); + V3_Free(video_state); + return -1; + } + video_state->video_memory = V3_VAddr((void *)video_state->video_memory_pa); memset(video_state->video_memory, 0, SIZE_OF_REGION); diff --git a/palacios/src/devices/curses_cons.c b/palacios/src/devices/curses_cons.c index 742180a..af66d77 100644 --- a/palacios/src/devices/curses_cons.c +++ b/palacios/src/devices/curses_cons.c @@ -242,19 +242,30 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) /* allocate state */ state = (struct cons_state *)V3_Malloc(sizeof(struct cons_state)); - V3_ASSERT(state); + + if (!state) { + PrintError("Cannot allocate curses state\n"); + V3_Free(state); + return -1; + } state->frontend_dev = frontend; state->cols = 80; state->rows = 25; state->framebuf = V3_Malloc(state->cols * state->rows * BYTES_PER_COL); + if (!state->framebuf) { + PrintError("Cannot allocate frame buffer\n"); + V3_Free(state); + return -1; + } /* open tty for screen display */ state->cons = v3_console_open(vm, state->cols, state->rows); if (!state->cons) { PrintError("Could not open console\n"); + V3_Free(state->framebuf); V3_Free(state); return -1; } @@ -264,6 +275,7 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) if (dev == NULL) { PrintError("Could not attach device %s\n", dev_id); + V3_Free(state->framebuf); V3_Free(state); return -1; } diff --git a/palacios/src/devices/disk_model.c b/palacios/src/devices/disk_model.c index b142547..74d40a1 100644 --- a/palacios/src/devices/disk_model.c +++ b/palacios/src/devices/disk_model.c @@ -91,6 +91,10 @@ static int connect_fn(struct v3_vm_info * vm, uint32_t seek_time = atoi(v3_cfg_val(cfg, "seek_us")); struct disk_state * model = (struct disk_state *)V3_Malloc(sizeof(struct disk_state)); + if (!model) { + PrintError("Cannot allocate\n"); + return -1; + } model->ops = ops; model->seek_usecs = seek_time; diff --git a/palacios/src/devices/i440fx.c b/palacios/src/devices/i440fx.c index 01e8088..800633f 100644 --- a/palacios/src/devices/i440fx.c +++ b/palacios/src/devices/i440fx.c @@ -78,6 +78,11 @@ static int i440_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { state = (struct i440_state *)V3_Malloc(sizeof(struct i440_state)); + if (!state) { + PrintError("Cannot allocate state\n"); + return -1; + } + state->pci = pci; struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, state); diff --git a/palacios/src/devices/io_apic.c b/palacios/src/devices/io_apic.c index 9d477de..a3bf731 100644 --- a/palacios/src/devices/io_apic.c +++ b/palacios/src/devices/io_apic.c @@ -388,6 +388,11 @@ static int ioapic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct io_apic_state * ioapic = (struct io_apic_state *)V3_Malloc(sizeof(struct io_apic_state)); + if (!ioapic) { + PrintError("Cannot allocate in init\n"); + return -1; + } + ioapic->apic_dev_data = apic_dev; struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, ioapic); diff --git a/palacios/src/devices/keyboard.c b/palacios/src/devices/keyboard.c index b451e2e..0c1837f 100644 --- a/palacios/src/devices/keyboard.c +++ b/palacios/src/devices/keyboard.c @@ -1131,6 +1131,11 @@ static int keyboard_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { kbd = (struct keyboard_internal *)V3_Malloc(sizeof(struct keyboard_internal)); + if (!kbd) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(kbd, 0, sizeof(struct keyboard_internal)); kbd->vm = vm; diff --git a/palacios/src/devices/lnx_virtio_balloon.c b/palacios/src/devices/lnx_virtio_balloon.c index af3a903..f6608d2 100644 --- a/palacios/src/devices/lnx_virtio_balloon.c +++ b/palacios/src/devices/lnx_virtio_balloon.c @@ -425,6 +425,12 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { virtio_state = (struct virtio_balloon_state *)V3_Malloc(sizeof(struct virtio_balloon_state)); + + if (!virtio_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(virtio_state, 0, sizeof(struct virtio_balloon_state)); diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index 6cdfa06..a8dba1c 100644 --- a/palacios/src/devices/lnx_virtio_blk.c +++ b/palacios/src/devices/lnx_virtio_blk.c @@ -602,6 +602,13 @@ static int connect_fn(struct v3_vm_info * vm, struct virtio_dev_state * virtio = (struct virtio_dev_state *)frontend_data; struct virtio_blk_state * blk_state = (struct virtio_blk_state *)V3_Malloc(sizeof(struct virtio_blk_state)); + + if (!blk_state) { + PrintError("Cannot allocate in connect\n"); + return -1; + } + + memset(blk_state, 0, sizeof(struct virtio_blk_state)); register_dev(virtio, blk_state); @@ -632,6 +639,12 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { virtio_state = (struct virtio_dev_state *)V3_Malloc(sizeof(struct virtio_dev_state)); + + if (!virtio_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(virtio_state, 0, sizeof(struct virtio_dev_state)); INIT_LIST_HEAD(&(virtio_state->dev_list)); diff --git a/palacios/src/devices/lnx_virtio_console.c b/palacios/src/devices/lnx_virtio_console.c index 0afefb8..0c0f4bc 100644 --- a/palacios/src/devices/lnx_virtio_console.c +++ b/palacios/src/devices/lnx_virtio_console.c @@ -434,6 +434,12 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { virtio_state = (struct virtio_console_state *)V3_Malloc(sizeof(struct virtio_console_state)); + + if (!virtio_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(virtio_state, 0, sizeof(struct virtio_console_state)); diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index 3c620b9..92dee7e 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -916,6 +916,11 @@ static int connect_fn(struct v3_vm_info * info, struct virtio_dev_state * virtio = (struct virtio_dev_state *)frontend_data; struct virtio_net_state * net_state = (struct virtio_net_state *)V3_Malloc(sizeof(struct virtio_net_state)); + if (!net_state) { + PrintError("Cannot allocate in connect\n"); + return -1; + } + memset(net_state, 0, sizeof(struct virtio_net_state)); register_dev(virtio, net_state); @@ -954,6 +959,12 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } virtio_state = (struct virtio_dev_state *)V3_Malloc(sizeof(struct virtio_dev_state)); + + if (!virtio_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(virtio_state, 0, sizeof(struct virtio_dev_state)); INIT_LIST_HEAD(&(virtio_state->dev_list)); diff --git a/palacios/src/devices/lnx_virtio_sym.c b/palacios/src/devices/lnx_virtio_sym.c index 010415f..33758ef 100644 --- a/palacios/src/devices/lnx_virtio_sym.c +++ b/palacios/src/devices/lnx_virtio_sym.c @@ -369,6 +369,12 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { virtio_state = (struct virtio_sym_state *)V3_Malloc(sizeof(struct virtio_sym_state)); + + if (!virtio_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(virtio_state, 0, sizeof(struct virtio_sym_state)); diff --git a/palacios/src/devices/lnx_virtio_symmod.c b/palacios/src/devices/lnx_virtio_symmod.c index d8172df..f579f27 100644 --- a/palacios/src/devices/lnx_virtio_symmod.c +++ b/palacios/src/devices/lnx_virtio_symmod.c @@ -622,6 +622,12 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } virtio_state = (struct virtio_sym_state *)V3_Malloc(sizeof(struct virtio_sym_state)); + + if (!virtio_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(virtio_state, 0, sizeof(struct virtio_sym_state)); virtio_state->vm = vm; diff --git a/palacios/src/devices/lnx_virtio_vnet.c b/palacios/src/devices/lnx_virtio_vnet.c index 5bf8ae0..f7795f5 100644 --- a/palacios/src/devices/lnx_virtio_vnet.c +++ b/palacios/src/devices/lnx_virtio_vnet.c @@ -575,6 +575,12 @@ static int dev_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } vnet_state = (struct virtio_vnet_state *)V3_Malloc(sizeof(struct virtio_vnet_state)); + + if (!vnet_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(vnet_state, 0, sizeof(struct virtio_vnet_state)); vnet_state->vm = vm; diff --git a/palacios/src/devices/ne2k.c b/palacios/src/devices/ne2k.c index 6e09ba8..420bc79 100644 --- a/palacios/src/devices/ne2k.c +++ b/palacios/src/devices/ne2k.c @@ -1218,6 +1218,12 @@ static int ne2k_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { char * macstr = v3_cfg_val(cfg, "mac"); nic_state = (struct ne2k_state *)V3_Malloc(sizeof(struct ne2k_state)); + + if (!nic_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(nic_state, 0, sizeof(struct ne2k_state)); nic_state->pci_bus = pci_bus; diff --git a/palacios/src/devices/netdisk.c b/palacios/src/devices/netdisk.c index a4c4fc8..2c89937 100644 --- a/palacios/src/devices/netdisk.c +++ b/palacios/src/devices/netdisk.c @@ -276,6 +276,11 @@ static int socket_init(struct disk_state * disk) { static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct disk_state * disk = (struct disk_state *)V3_Malloc(sizeof(struct disk_state)); + if (!disk) { + PrintError("Cannot allocate in init\n"); + return -1; + } + char * ip_str = v3_cfg_val(cfg, "IP"); char * port_str = v3_cfg_val(cfg, "port"); char * disk_tag = v3_cfg_val(cfg, "tag"); diff --git a/palacios/src/devices/nic_bridge.c b/palacios/src/devices/nic_bridge.c index 1033b52..0a5bc8e 100644 --- a/palacios/src/devices/nic_bridge.c +++ b/palacios/src/devices/nic_bridge.c @@ -94,6 +94,12 @@ static int nic_bridge_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } bridge = (struct nic_bridge_state *)V3_Malloc(sizeof(struct nic_bridge_state)); + + if (!bridge) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(bridge, 0, sizeof(struct nic_bridge_state)); struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, bridge); diff --git a/palacios/src/devices/nvram.c b/palacios/src/devices/nvram.c index d1f27a2..8c8830b 100644 --- a/palacios/src/devices/nvram.c +++ b/palacios/src/devices/nvram.c @@ -812,6 +812,11 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { PrintDebug("nvram: init_device\n"); nvram_state = (struct nvram_internal *)V3_Malloc(sizeof(struct nvram_internal) + 1000); + if (!nvram_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + PrintDebug("nvram: internal at %p\n", (void *)nvram_state); nvram_state->ide = ide; diff --git a/palacios/src/devices/os_debug.c b/palacios/src/devices/os_debug.c index 954c38a..9f4fbfa 100644 --- a/palacios/src/devices/os_debug.c +++ b/palacios/src/devices/os_debug.c @@ -147,6 +147,11 @@ static int debug_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { state = (struct debug_state *)V3_Malloc(sizeof(struct debug_state)); + if (!state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + PrintDebug("Creating OS Debug Device\n"); struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, state); diff --git a/palacios/src/devices/para_net.c b/palacios/src/devices/para_net.c index a42d99a..74b4466 100644 --- a/palacios/src/devices/para_net.c +++ b/palacios/src/devices/para_net.c @@ -39,6 +39,11 @@ static int tx_call(struct guest_info * info, uint_t call_no, void * priv_data) { addr_t pkt_gpa = info->vm_regs.rbx; int pkt_len = info->vm_regs.rcx; uchar_t * pkt = V3_Malloc(pkt_len); + + if (!pkt) { + PrintError("Cannot allocate in transmit!\n"); + return -1; + } PrintDebug("Transmitting Packet\n"); @@ -106,6 +111,11 @@ static int net_init(struct guest_info * vm, v3_cfg_tree_t * cfg) { state = (struct nic_state *)V3_Malloc(sizeof(struct nic_state)); + if (!state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + PrintDebug("Creating VMNet Device\n"); struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state); diff --git a/palacios/src/devices/pci.c b/palacios/src/devices/pci.c index 3eadbc5..42e4c3a 100644 --- a/palacios/src/devices/pci.c +++ b/palacios/src/devices/pci.c @@ -1202,6 +1202,12 @@ static struct v3_device_ops dev_ops = { static int pci_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct pci_internal * pci_state = V3_Malloc(sizeof(struct pci_internal)); + + if (!pci_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + int i = 0; char * dev_id = v3_cfg_val(cfg, "ID"); int ret = 0; diff --git a/palacios/src/devices/pci_passthrough.c b/palacios/src/devices/pci_passthrough.c index e8d72db..102c6eb 100644 --- a/palacios/src/devices/pci_passthrough.c +++ b/palacios/src/devices/pci_passthrough.c @@ -779,6 +779,10 @@ static int passthrough_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct vm_device * pci = v3_find_dev(vm, v3_cfg_val(cfg, "bus")); char * dev_id = v3_cfg_val(cfg, "ID"); + if (!state) { + PrintError("Cannot allocate in init\n"); + return -1; + } memset(state, 0, sizeof(struct pt_dev_state)); diff --git a/palacios/src/devices/piix3.c b/palacios/src/devices/piix3.c index 35925b5..0143de5 100644 --- a/palacios/src/devices/piix3.c +++ b/palacios/src/devices/piix3.c @@ -497,6 +497,11 @@ static int piix3_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct vm_device * pci = v3_find_dev(vm, v3_cfg_val(cfg, "bus")); char * dev_id = v3_cfg_val(cfg, "ID"); + if (!piix3) { + PrintError("Cannot allocate in init\n"); + return -1; + } + if (!pci) { PrintError("Could not find PCI device\n"); return -1; diff --git a/palacios/src/devices/ramdisk.c b/palacios/src/devices/ramdisk.c index a17d9ae..c8f9639 100644 --- a/palacios/src/devices/ramdisk.c +++ b/palacios/src/devices/ramdisk.c @@ -120,6 +120,12 @@ static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { disk = (struct disk_state *)V3_Malloc(sizeof(struct disk_state)); + + if (!disk) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(disk, 0, sizeof(struct disk_state)); disk->disk_image = file->data; diff --git a/palacios/src/devices/rtl8139.c b/palacios/src/devices/rtl8139.c index fde3ef9..18e966a 100644 --- a/palacios/src/devices/rtl8139.c +++ b/palacios/src/devices/rtl8139.c @@ -1806,6 +1806,12 @@ static int rtl8139_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { char * macstr = v3_cfg_val(cfg, "mac"); nic_state = (struct rtl8139_state *)V3_Malloc(sizeof(struct rtl8139_state)); + + if (!nic_state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(nic_state, 0, sizeof(struct rtl8139_state)); nic_state->pci_bus = pci_bus; diff --git a/palacios/src/devices/simple_pic.c b/palacios/src/devices/simple_pic.c index 96907df..06b6d01 100644 --- a/palacios/src/devices/simple_pic.c +++ b/palacios/src/devices/simple_pic.c @@ -82,12 +82,17 @@ static struct v3_device_ops dev_ops = { static int pic_init(struct guest_info * vm, void * cfg_data) { struct pic_internal * state = NULL; state = (struct pic_internal *)V3_Malloc(sizeof(struct pic_internal)); - V3_ASSERT(state != NULL); + + if (!state) { + PrintError("Cannot allocate in init\n"); + return -1; + } struct vm_device * dev = v3_allocate_device("SIMPLE_PIC", &dev_ops, state); if (v3_attach_device(vm, dev) == -1) { PrintError("Could not attach device %s\n", "SIMPLE_PIC"); + V3_Free(state); return -1; } diff --git a/palacios/src/devices/swapbypass_cache.c b/palacios/src/devices/swapbypass_cache.c index ec2bba8..2f6d75b 100644 --- a/palacios/src/devices/swapbypass_cache.c +++ b/palacios/src/devices/swapbypass_cache.c @@ -284,6 +284,11 @@ static int swap_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { swap = (struct swap_state *)V3_Malloc(sizeof(struct swap_state) + ((capacity / 4096) / 8)); + if (!swap) { + PrintError("Cannot allocate in init\n"); + return -1; + } + swap->vm = vm; swap->capacity = capacity; @@ -295,6 +300,13 @@ static int swap_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { swap->hdr = (union swap_header *)swap; swap->swap_base_addr = (addr_t)V3_AllocPages(swap->capacity / 4096); + + if (!swap->swap_base_addr) { + PrintError("Cannot allocate swap space\n"); + V3_Free(swap); + return -1; + } + swap->swap_space = (uint8_t *)V3_VAddr((void *)(swap->swap_base_addr)); memset(swap->swap_space, 0, swap->capacity); diff --git a/palacios/src/devices/swapbypass_cache2.c b/palacios/src/devices/swapbypass_cache2.c index dfd51ba..776c34a 100644 --- a/palacios/src/devices/swapbypass_cache2.c +++ b/palacios/src/devices/swapbypass_cache2.c @@ -540,6 +540,11 @@ static int connect_fn(struct v3_vm_info * vm, swap = (struct swap_state *)V3_Malloc(sizeof(struct swap_state)); + if (!swap) { + PrintError("Cannot allocate in connect\n"); + return -1; + } + swap->vm = vm; swap->cache_size = cache_size; swap->io_flag = 0; @@ -561,6 +566,12 @@ static int connect_fn(struct v3_vm_info * vm, INIT_LIST_HEAD(&(swap->entry_list)); INIT_LIST_HEAD(&(swap->free_list)); swap->entry_map = (struct cache_entry *)V3_Malloc(sizeof(struct cache_entry) * (cache_size / 4096)); + + if (!swap->entry_map) { + PrintError("Cannot allocate in connect\n"); + return -1; + } + for (i = 0; i < (cache_size / 4096); i++) { list_add(&(swap->entry_map[i].cache_node), &(swap->free_list)); @@ -571,6 +582,14 @@ static int connect_fn(struct v3_vm_info * vm, swap->active = 0; swap->cache_base_addr = (addr_t)V3_AllocPages(swap->cache_size / 4096); + + if (!swap->cache_base_addr) { + PrintError("Cannot allocate cache space\n"); + V3_Free(swap); + return -1; + } + + swap->cache = (uint8_t *)V3_VAddr((void *)(addr_t)(swap->cache_base_addr)); memset(swap->cache, 0, swap->cache_size); } diff --git a/palacios/src/devices/telnet_cons.c b/palacios/src/devices/telnet_cons.c index 7bda58b..9562306 100644 --- a/palacios/src/devices/telnet_cons.c +++ b/palacios/src/devices/telnet_cons.c @@ -528,6 +528,12 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct vm_device * frontend = v3_find_dev(vm, v3_cfg_val(frontend_cfg, "tag")); char * dev_id = v3_cfg_val(cfg, "ID"); + if (!state) { + PrintError("Cannot allocate in init\n"); + return -1; + } + + state->vm = vm; state->server_fd = 0; state->client_fd = 0; diff --git a/palacios/src/devices/timer.c b/palacios/src/devices/timer.c index 31c47de..97d5d7d 100644 --- a/palacios/src/devices/timer.c +++ b/palacios/src/devices/timer.c @@ -56,7 +56,11 @@ static struct v3_device_ops dev_ops = { static int timer_init(struct guest_info * vm, void * cfg_data) { struct timer_state * timer = NULL; timer = (struct timer_state *)V3_Malloc( sizeof(struct timer_state)); - V3_ASSERT(timer != NULL); + + if (!timer) { + PrintError("Cannot allocate in init\n"); + return -1; + } struct vm_device * dev = v3_allocate_device("TIMER", &dev_ops, timer); diff --git a/palacios/src/devices/tmpdisk.c b/palacios/src/devices/tmpdisk.c index 0be279f..879dc33 100644 --- a/palacios/src/devices/tmpdisk.c +++ b/palacios/src/devices/tmpdisk.c @@ -113,9 +113,21 @@ static int blk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { blk = (struct blk_state *)V3_Malloc(sizeof(struct blk_state)); + if (!blk) { + PrintError("Cannot allocate in init\n"); + return -1; + } + blk->capacity = capacity; blk->blk_base_addr = (addr_t)V3_AllocPages(blk->capacity / 4096); + + if (!blk->blk_base_addr) { + PrintError("Cannot allocate block space\n"); + V3_Free(blk); + return -1; + } + blk->blk_space = (uint8_t *)V3_VAddr((void *)(blk->blk_base_addr)); memset(blk->blk_space, 0, capacity); diff --git a/palacios/src/devices/vga.c b/palacios/src/devices/vga.c index a507f48..f9c4e90 100644 --- a/palacios/src/devices/vga.c +++ b/palacios/src/devices/vga.c @@ -2845,12 +2845,17 @@ static int vga_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { // Now allocate the maps for (i=0;imap[i] = (vga_map) V3_VAddr((void*)V3_AllocPages(MAP_SIZE/4096)); - if (!(vga->map[i])) { + void *temp; + + temp = (void*)V3_AllocPages(MAP_SIZE/4096); + if (!temp) { PrintError("vga: cannot allocate maps\n"); free_vga(vga); return -1; } + + vga->map[i] = (vga_map) V3_VAddr(temp); + memset(vga->map[i],0,MAP_SIZE); } diff --git a/palacios/src/devices/vnet_nic.c b/palacios/src/devices/vnet_nic.c index d66384d..29c1412 100644 --- a/palacios/src/devices/vnet_nic.c +++ b/palacios/src/devices/vnet_nic.c @@ -112,6 +112,12 @@ static int vnet_nic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend"); vnetnic = (struct vnet_nic_state *)V3_Malloc(sizeof(struct vnet_nic_state)); + + if (!vnetnic) { + PrintError("Cannot allocate in init\n"); + return -1; + } + memset(vnetnic, 0, sizeof(struct vnet_nic_state)); struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, vnetnic); diff --git a/palacios/src/extensions/ext_inspector.c b/palacios/src/extensions/ext_inspector.c index 5a440c1..4c58775 100644 --- a/palacios/src/extensions/ext_inspector.c +++ b/palacios/src/extensions/ext_inspector.c @@ -38,6 +38,12 @@ struct v3_inspector_state { static int init_inspector(struct v3_vm_info * vm, v3_cfg_tree_t * cfg, void ** priv_data) { struct v3_inspector_state * state = V3_Malloc(sizeof(struct v3_inspector_state)); + + if (!state) { + PrintError("Cannot allocate state in inspector\n"); + return -1; + } + memset(state, 0, sizeof(struct v3_inspector_state)); strncpy(state->state_tree.name, "vm->name", 50); diff --git a/palacios/src/extensions/ext_mcheck.c b/palacios/src/extensions/ext_mcheck.c index 2ab04ca..ea746f4 100644 --- a/palacios/src/extensions/ext_mcheck.c +++ b/palacios/src/extensions/ext_mcheck.c @@ -465,8 +465,8 @@ static int init_mcheck(struct v3_vm_info * vm, v3_cfg_tree_t * cfg, void ** priv state = (struct mcheck_state *)V3_Malloc(sizeof(struct mcheck_state)); if (state == NULL) { - PrintError(MSG_PRE "Failed to allocate machine-check architecture state.\n"); - return -1; + PrintError(MSG_PRE "Failed to allocate machine-check architecture state.\n"); + return -1; } diff --git a/palacios/src/extensions/ext_mtrr.c b/palacios/src/extensions/ext_mtrr.c index 7ff0dc0..1f22345 100644 --- a/palacios/src/extensions/ext_mtrr.c +++ b/palacios/src/extensions/ext_mtrr.c @@ -544,6 +544,13 @@ static int init_mtrrs(struct v3_vm_info * vm, v3_cfg_tree_t * cfg, void ** priv_ int ret = 0; state = V3_Malloc(sizeof(struct mtrr_state)); + + if (!state) { + PrintError("Cannot allocate in initializing MTRRs\n"); + return -1; + } + + memset(state, 0, sizeof(struct mtrr_state)); *priv_data = state; diff --git a/palacios/src/gears/ext_code_inject.c b/palacios/src/gears/ext_code_inject.c index d5bdfb8..4fb7e32 100644 --- a/palacios/src/gears/ext_code_inject.c +++ b/palacios/src/gears/ext_code_inject.c @@ -86,6 +86,12 @@ static int v3_plant_code (struct guest_info * core, struct v3_code_inject_info * // first back up old code inject->old_code = (char*)V3_Malloc(size); + + if (!inject->old_code) { + PrintError("Cannot allocate in planting code\n"); + return -1; + } + for (i = 0; i < size; i++) inject->old_code[i] = *(hva + i); @@ -178,6 +184,7 @@ static int inject_code_finish (struct guest_info * core, unsigned int hcall_id, } inject->old_code = V3_Malloc(MUNMAP_SIZE); + if (!inject->old_code) { PrintError("Problem mallocing old code segment\n"); return -1; @@ -506,6 +513,12 @@ int v3_do_inject (struct guest_info * core, struct v3_code_inject_info * inject, PrintDebug("Found a page we need to fault in\n"); inject->cont = (struct v3_cont *)V3_Malloc(sizeof(struct v3_cont)); + + if (!inject->cont) { + PrintError("Cannot allocate in doing inject\n"); + return -1; + } + ret = v3_gva_to_gpa(core, elf_gva, &elf_hva); if (ret == -1) { diff --git a/palacios/src/gears/ext_env_inject.c b/palacios/src/gears/ext_env_inject.c index 4988dcf..251029d 100644 --- a/palacios/src/gears/ext_env_inject.c +++ b/palacios/src/gears/ext_env_inject.c @@ -75,6 +75,12 @@ int v3_insert_env_inject (void * ginfo, char ** strings, int num_strings, char * struct v3_env_injects * injects = &env_injects; struct v3_env_inject_info * inject = V3_Malloc(sizeof(struct v3_env_inject_info)); + if (!inject) { + PrintError("Cannot allocate in inserting environment inject\n"); + return -1; + } + + memset(inject, 0, sizeof(struct v3_env_inject_info)); inject->env_vars = strings; diff --git a/palacios/src/gears/ext_execve_hook.c b/palacios/src/gears/ext_execve_hook.c index aa5bce2..c7307ab 100644 --- a/palacios/src/gears/ext_execve_hook.c +++ b/palacios/src/gears/ext_execve_hook.c @@ -99,6 +99,11 @@ int v3_hook_executable (struct v3_vm_info * vm, struct exec_hook * hook = V3_Malloc(sizeof(struct exec_hook)); struct v3_exec_hooks * hooks = &exec_hooks; addr_t key; + + if (!hook) { + PrintError("Cannot allocate in hooking exec\n"); + return -1; + } memset(hook, 0, sizeof(struct exec_hook)); diff --git a/palacios/src/gears/ext_process_environment.c b/palacios/src/gears/ext_process_environment.c index 7267866..531edaf 100644 --- a/palacios/src/gears/ext_process_environment.c +++ b/palacios/src/gears/ext_process_environment.c @@ -208,6 +208,12 @@ static int v3_copy_chunk_vmm32(struct guest_info * core, const char ** argstrs, /* account for new args */ argc += argcnt; var_dump.argv = (char**)V3_Malloc(sizeof(char*)*argc); + + if (!var_dump.argv) { + PrintError("Cannot allocate in copying\n"); + return -1; + } + var_dump.argc = argc; bytes += sizeof(uint32_t)*argc; @@ -223,6 +229,11 @@ static int v3_copy_chunk_vmm32(struct guest_info * core, const char ** argstrs, /* malloc room for the string */ char * tmpstr = (char*)V3_Malloc(strlen((char*)argvn) + 1); + if (!tmpstr) { + PrintError("Cannot allocate temporary\n"); + return -1; + } + /* copy the pointer */ var_dump.argv[i] = tmpstr; @@ -237,6 +248,12 @@ static int v3_copy_chunk_vmm32(struct guest_info * core, const char ** argstrs, int j = 0; while (j < argcnt) { char * tmpstr = (char*)V3_Malloc(strlen(argstrs[j]) + 1); + + if (!tmpstr) { + PrintError("Cannot allocate temp string\n"); + return -1; + } + strncpy(tmpstr, argstrs[i], strlen(argstrs[j]) + 1); var_dump.argv[i] = tmpstr; bytes += strlen(argstrs[j]) + 1; @@ -257,6 +274,12 @@ static int v3_copy_chunk_vmm32(struct guest_info * core, const char ** argstrs, envc += envcnt; var_dump.envp = (char**)V3_Malloc(sizeof(char*)*envc); + + if (!var_dump.envp) { + PrintError("Cannot allocate var dump\n"); + return -1; + } + var_dump.envc = envc; bytes += sizeof(uint32_t)*envc; @@ -271,6 +294,11 @@ static int v3_copy_chunk_vmm32(struct guest_info * core, const char ** argstrs, /* malloc room for the string */ char * tmpstr = (char*)V3_Malloc(strlen((char*)envpn) + 1); + + if (!tmpstr) { + PrintError("Cannot allocate temp string\n"); + return -1; + } /* copy the pointer */ var_dump.envp[i] = tmpstr; @@ -286,6 +314,12 @@ static int v3_copy_chunk_vmm32(struct guest_info * core, const char ** argstrs, j = 0; while (j < envcnt) { char * tmpstr = (char*)V3_Malloc(strlen(envstrs[j]) + 1); + + if (!tmpstr) { + PrintError("Cannot allocate temp string\n"); + return -1; + } + strncpy(tmpstr, envstrs[j], strlen(envstrs[j]) + 1); var_dump.envp[i] = tmpstr; bytes += strlen(envstrs[j]) + 1; @@ -452,6 +486,12 @@ static int v3_copy_chunk_vmm64(struct guest_info * core, const char ** argstrs, /* account for new strings */ argc += argcnt; var_dump.argv = (char**)V3_Malloc(sizeof(char*)*argc); + + if (!var_dump.argv) { + PrintError("Cannot allocate var dump\n"); + return -1; + } + var_dump.argc = argc; bytes += sizeof(char*)*argc; @@ -467,6 +507,11 @@ static int v3_copy_chunk_vmm64(struct guest_info * core, const char ** argstrs, /* malloc room for the string */ char * tmpstr = (char*)V3_Malloc(strlen((char*)argvn) + 1); + if (!tmpstr) { + PrintError("Cannot allocate temp string\n"); + return -1; + } + /* copy the pointer */ var_dump.argv[i] = tmpstr; @@ -481,6 +526,12 @@ static int v3_copy_chunk_vmm64(struct guest_info * core, const char ** argstrs, int j = 0; while (j < argcnt) { char * tmpstr = (char*)V3_Malloc(strlen(argstrs[j]) + 1); + + if (!tmpstr) { + PrintError("Cannot allocate temp string\n"); + return -1; + } + strncpy(tmpstr, argstrs[j], strlen(argstrs[j]) + 1); var_dump.argv[i] = tmpstr; bytes += strlen(argstrs[j]) + 1; @@ -501,6 +552,12 @@ static int v3_copy_chunk_vmm64(struct guest_info * core, const char ** argstrs, envc += envcnt; var_dump.envp = (char**)V3_Malloc(sizeof(char*)*envc); + + if (!var_dump.envp) { + PrintError("Cannot allocate var dump\n"); + return -1; + } + var_dump.envc = envc; bytes += sizeof(uint64_t)*(envc); @@ -516,6 +573,11 @@ static int v3_copy_chunk_vmm64(struct guest_info * core, const char ** argstrs, /* malloc room for the string */ char * tmpstr = (char*)V3_Malloc(strlen((char*)envpn) + 1); + + if (!tmpstr) { + PrintError("Cannot allocate temp string\n"); + return -1; + } /* copy the pointer */ var_dump.envp[i] = tmpstr; @@ -531,6 +593,12 @@ static int v3_copy_chunk_vmm64(struct guest_info * core, const char ** argstrs, j = 0; while (j < envcnt) { char * tmpstr = (char*)V3_Malloc(strlen(envstrs[j]) + 1); + + if (!tmpstr) { + PrintError("Cannot allocate temp string\n"); + return -1; + } + strncpy(tmpstr, envstrs[i], strlen(envstrs[j]) + 1); var_dump.envp[i] = tmpstr; bytes += strlen(envstrs[j]) + 1; diff --git a/palacios/src/gears/ext_sw_intr.c b/palacios/src/gears/ext_sw_intr.c index f73b5eb..4739d51 100644 --- a/palacios/src/gears/ext_sw_intr.c +++ b/palacios/src/gears/ext_sw_intr.c @@ -182,6 +182,7 @@ int v3_hook_swintr (struct guest_info * core, struct v3_swintr_hook * hook = (struct v3_swintr_hook*)V3_Malloc(sizeof(struct v3_swintr_hook)); if (hook == NULL) { + PrintError("Cannot allocate for swintr hook\n"); return -1; } diff --git a/palacios/src/gears/ext_syscall_hijack.c b/palacios/src/gears/ext_syscall_hijack.c index 51b55b1..7aab405 100644 --- a/palacios/src/gears/ext_syscall_hijack.c +++ b/palacios/src/gears/ext_syscall_hijack.c @@ -363,6 +363,7 @@ int v3_hook_syscall (struct guest_info * core, if (hook == NULL) { + PrintError("Cannot allocate for syscall hook\n"); return -1; } diff --git a/palacios/src/interfaces/vmm_host_hypercall.c b/palacios/src/interfaces/vmm_host_hypercall.c index 0299268..ab57698 100644 --- a/palacios/src/interfaces/vmm_host_hypercall.c +++ b/palacios/src/interfaces/vmm_host_hypercall.c @@ -142,7 +142,8 @@ int v3_register_host_hypercall(host_vm_info_t * vm, struct bounce_data *b = V3_Malloc(sizeof(struct bounce_data)); if (!b) { - return -1; + PrintError("Unable to allocate in registering host hypercall\n"); + return -1; } b->hypercall=hypercall; @@ -152,7 +153,9 @@ int v3_register_host_hypercall(host_vm_info_t * vm, hypercall_id, bounce, b) < 0) { - return -1; + PrintError("Cannot register host hypercall\n"); + V3_Free(b); + return -1; } return 0; diff --git a/palacios/src/interfaces/vmm_packet.c b/palacios/src/interfaces/vmm_packet.c index b46325e..07c86ee 100644 --- a/palacios/src/interfaces/vmm_packet.c +++ b/palacios/src/interfaces/vmm_packet.c @@ -43,6 +43,11 @@ struct v3_packet * v3_packet_connect(struct v3_vm_info * vm, packet = V3_Malloc(sizeof(struct v3_packet)); + if (!packet) { + PrintError("Cannot allocate in connecting packet\n"); + return NULL; + } + memcpy(packet->dev_mac, vm_mac, ETH_ALEN); packet->input = input; packet->guest_packet_data = guest_packet_data; diff --git a/palacios/src/interfaces/vmm_stream.c b/palacios/src/interfaces/vmm_stream.c index 4b391ac..27269d3 100644 --- a/palacios/src/interfaces/vmm_stream.c +++ b/palacios/src/interfaces/vmm_stream.c @@ -38,6 +38,11 @@ struct v3_stream * v3_stream_open(struct v3_vm_info * vm, const char * name, stream = V3_Malloc(sizeof(struct v3_stream)); + if (!stream) { + PrintError("Cannot allocate in opening a stream\n"); + return NULL; + } + stream->input = input; stream->guest_stream_data = guest_stream_data; stream->host_stream_data = stream_hooks->open(stream, name, vm->host_priv_data); diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_cache.c b/palacios/src/palacios/mmu/vmm_shdw_pg_cache.c index 32e9d24..ae0db99 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_cache.c +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_cache.c @@ -220,6 +220,12 @@ static int add_rmap(struct v3_vm_info * vm, struct shdw_pg_data * pg_data, addr_ if (rmap_list == NULL) { rmap_list = V3_Malloc(sizeof(struct list_head)); + + if (!rmap_list) { + PrintError("Cannot allocate\n"); + return -1; + } + INIT_LIST_HEAD(rmap_list); v3_htable_insert(cache_state->reverse_map, gpa, (addr_t)rmap_list); @@ -227,6 +233,11 @@ static int add_rmap(struct v3_vm_info * vm, struct shdw_pg_data * pg_data, addr_ entry = V3_Malloc(sizeof(struct rmap_entry)); + if (!entry) { + PrintError("Cannot allocate\n"); + return -1; + } + entry->gva = gva; entry->gpa = pg_data->tuple.gpa; entry->pt_type = pg_data->tuple.pt_type; @@ -282,6 +293,12 @@ static int update_rmap_entries(struct v3_vm_info * vm, addr_t gpa) { static int link_shdw_pg(struct shdw_pg_data * child_pg, struct shdw_pg_data * parent_pg, addr_t gva) { struct shdw_back_ptr * back_ptr = V3_Malloc(sizeof(struct shdw_back_ptr)); + + if (!back_ptr) { + PrintError("Cannot allocate\n"); + return -1; + } + memset(back_ptr, 0, sizeof(struct shdw_back_ptr)); back_ptr->pg_data = parent_pg; @@ -369,7 +386,18 @@ static struct shdw_pg_data * create_shdw_pt(struct v3_vm_info * vm, addr_t gpa, if (cache_state->pgs_in_cache < cache_state->max_cache_pgs) { pg_data = V3_Malloc(sizeof(struct shdw_pg_data)); + if (!pg_data) { + PrintError("Cannot allocate\n"); + return NULL; + } + pg_data->hpa = (addr_t)V3_AllocPages(1); + + if (!pg_data->hpa) { + PrintError("Cannot allocate page for shadow page table\n"); + return NULL; + } + pg_data->hva = (void *)V3_VAddr((void *)pg_data->hpa); } else if (cache_state->pgs_in_free_list) { @@ -449,6 +477,12 @@ static int cache_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { V3_Print("Shadow Page Cache initialization\n"); cache_state = V3_Malloc(sizeof(struct cache_vm_state)); + + if (!cache_state) { + PrintError("Cannot allocate\n"); + return -1; + } + memset(cache_state, 0, sizeof(struct cache_vm_state)); cache_state->page_htable = v3_create_htable(0, cache_hash_fn, cache_eq_fn); diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_kvm.c b/palacios/src/palacios/mmu/vmm_shdw_pg_kvm.c index c955790..72e63af 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_kvm.c +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_kvm.c @@ -118,6 +118,11 @@ static void shadow_free_page (struct guest_info * core, struct shadow_page_cache V3_FreePages((void *)page->page_pa, 1); page->page_pa=(addr_t)V3_AllocPages(1); + + if (!page->page_pa) { + PrintError("Freeing shadow page failed on allocation\n"); + return; + } list_add(&page->link,&core->free_pages); ++core->n_free_shadow_pages; @@ -178,6 +183,7 @@ static int alloc_shadow_pages(struct guest_info * core) INIT_LIST_HEAD(&page_header->link); if (!(page_header->page_pa = (addr_t)V3_AllocPages(1))) { + PrintError("Allocation failed in allocating shadow page\n"); goto error_1; } addr_t shdw_page = (addr_t)V3_VAddr((void *)(page_header->page_pa)); @@ -619,7 +625,7 @@ static void shadow_zap_page(struct guest_info * core, struct shadow_page_cache_d } shadow_page_put_page(core, page, shadow_pde); PrintDebug("zap_parent: pde: shadow %p\n",(void *)*((addr_t *)shadow_pde)); - memset((void *)shadow_pde, 0, sizeof(struct pde32)); + memset((void *)shadow_pde, 0, sizeof(uint32_t)); } shadow_page_unlink_children(core, page); @@ -675,7 +681,7 @@ int shadow_zap_hierarchy_32(struct guest_info * core, struct shadow_page_cache_d guest_pde = (pde32_t*)&(guest_pd[i]); present = shadow_pde->present; if (shadow_pde->present) PrintDebug("ulink_child: pde shadow %x\n", *((uint32_t*)shadow_pde)); - memset((void*)shadow_pde, 0, sizeof(struct pde32)); + memset((void*)shadow_pde, 0, sizeof(uint32_t)); if (present != 1) continue; struct shadow_page_cache_data *shdw_page; diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_kvm_32.h b/palacios/src/palacios/mmu/vmm_shdw_pg_kvm_32.h index 8a2e094..7035d16 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_kvm_32.h +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_kvm_32.h @@ -85,7 +85,7 @@ static inline int fix_write_pf_32(struct guest_info * core, pte32_t * shadow_pte } if (guest_pte->present == 0) { - memset((void *)shadow_pte, 0, sizeof(struct pte32)); + memset((void *)shadow_pte, 0, sizeof(uint32_t)); PrintDebug("\twrpf: guest non present\n"); return 0; } diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_kvm_64.h b/palacios/src/palacios/mmu/vmm_shdw_pg_kvm_64.h index 93a84eb..fbf0a31 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_kvm_64.h +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_kvm_64.h @@ -115,7 +115,7 @@ static inline int fix_write_pf_64(struct guest_info *core, pte64_t *shadow_pte, } if (guest_pte->present == 0) { - memset((void*)shadow_pte, 0, sizeof(struct pte64)); + memset((void*)shadow_pte, 0, sizeof(uint64_t)); PrintDebug("\tWritePf: Guest Not Present\n"); return 0; } diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_swapbypass.c b/palacios/src/palacios/mmu/vmm_shdw_pg_swapbypass.c index 0b0a776..001e917 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_swapbypass.c +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_swapbypass.c @@ -206,6 +206,12 @@ static addr_t map_swp_page(struct v3_vm_info * vm, pte32_t * shadow_pte, pte32_t if (shdw_ptr_list == NULL) { shdw_ptr_list = (struct list_head *)V3_Malloc(sizeof(struct list_head)); + + if (!shdw_ptr_list) { + PrintError("Cannot allocate\n"); + return 0; + } + #ifdef V3_CONFIG_SWAPBYPASS_TELEMETRY swap_state->list_size++; #endif @@ -272,8 +278,19 @@ static struct shadow_page_data * create_new_shadow_pt(struct guest_info * core) // else page_tail = (struct shadow_page_data *)V3_Malloc(sizeof(struct shadow_page_data)); + + if (!page_tail) { + PrintError("Cannot allocate\n"); + return -1; + } + page_tail->page_pa = (addr_t)V3_AllocPages(1); + if (!page_tail->page_pa) { + PrintError("Cannot allocate page\n"); + return NULL; + } + PrintDebug("Allocating new shadow Page: %p (cur_cr3=%p)\n", (void *)(addr_t)page_tail->page_pa, (void *)(addr_t)cur_cr3); @@ -419,6 +436,12 @@ static int sb_local_init(struct guest_info * core) { swapbypass_state = (struct swapbypass_local_state *)V3_Malloc(sizeof(struct swapbypass_local_state)); + if (!swapbypass_state) { + PrintError("Cannot allocate\n"); + return -1; + } + + INIT_LIST_HEAD(&(swapbypass_state->page_list)); state->local_impl_data = swapbypass_state; diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb.c b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb.c index 60b2d21..06e416a 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb.c +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb.c @@ -82,8 +82,19 @@ static struct shadow_page_data * create_new_shadow_pt(struct guest_info * core) // else page_tail = (struct shadow_page_data *)V3_Malloc(sizeof(struct shadow_page_data)); + + if (!page_tail) { + PrintError("Cannot allocate\n"); + return NULL; + } + page_tail->page_pa = (addr_t)V3_AllocPages(1); + if (!page_tail->page_pa) { + PrintError("Cannot allocate page\n"); + return NULL; + } + PrintDebug("Allocating new shadow Page: %p (cur_cr3=%p)\n", (void *)(addr_t)page_tail->page_pa, (void *)(addr_t)cur_cr3); @@ -117,6 +128,11 @@ static int vtlb_local_init(struct guest_info * core) { vtlb_state = (struct vtlb_local_state *)V3_Malloc(sizeof(struct vtlb_local_state)); + if (!vtlb_state) { + PrintError("Cannot allocate\n"); + return -1; + } + INIT_LIST_HEAD(&(vtlb_state->page_list)); state->local_impl_data = vtlb_state; diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index c98a48b..facdb18 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -938,6 +938,11 @@ void v3_init_svm_cpu(int cpu_id) { // Setup the host state save area host_vmcbs[cpu_id] = (addr_t)V3_AllocPages(4); + if (!host_vmcbs[cpu_id]) { + PrintError("Failed to allocate VMCB\n"); + return; + } + /* 64-BIT-ISSUE */ // msr.e_reg.high = 0; //msr.e_reg.low = (uint_t)host_vmcb; @@ -1177,6 +1182,11 @@ void Init_VMCB_pe(vmcb_t *vmcb, struct guest_info vm_info) { ctrl_area->instrs.IOIO_PROT = 1; ctrl_area->IOPM_BASE_PA = (uint_t)V3_AllocPages(3); + + if (!ctrl_area->IOPM_BASE_PA) { + PrintError("Cannot allocate IO bitmap\n"); + return; + } { reg_ex_t tmp_reg; diff --git a/palacios/src/palacios/svm_io.c b/palacios/src/palacios/svm_io.c index 4ad954d..ff85d09 100644 --- a/palacios/src/palacios/svm_io.c +++ b/palacios/src/palacios/svm_io.c @@ -46,9 +46,19 @@ static int update_map(struct v3_vm_info * vm, uint16_t port, int hook_read, int int v3_init_svm_io_map(struct v3_vm_info * vm) { + void *temp; + vm->io_map.update_map = update_map; - vm->io_map.arch_data = V3_VAddr(V3_AllocPages(3)); + temp = V3_AllocPages(3); + + if (!temp) { + PrintError("Cannot allocate io bitmap\n"); + return -1; + } + + vm->io_map.arch_data = V3_VAddr(temp); + memset(vm->io_map.arch_data, 0xff, PAGE_SIZE_4KB * 3); diff --git a/palacios/src/palacios/svm_msr.c b/palacios/src/palacios/svm_msr.c index b90f4a0..f8ae00f 100644 --- a/palacios/src/palacios/svm_msr.c +++ b/palacios/src/palacios/svm_msr.c @@ -82,11 +82,20 @@ static int update_map(struct v3_vm_info * vm, uint_t msr, int hook_reads, int ho int v3_init_svm_msr_map(struct v3_vm_info * vm) { + void *temp; struct v3_msr_map * msr_map = &(vm->msr_map); msr_map->update_map = update_map; - msr_map->arch_data = V3_VAddr(V3_AllocPages(2)); + temp = V3_AllocPages(2); + + if (!temp) { + PrintError("Cannot allocate msr bitmap\n"); + return -1; + } + + msr_map->arch_data = V3_VAddr(temp); + memset(msr_map->arch_data, 0xff, PAGE_SIZE_4KB * 2); v3_refresh_msr_map(vm); diff --git a/palacios/src/palacios/vmm_chkpt_stores.h b/palacios/src/palacios/vmm_chkpt_stores.h index 3c2572b..61115a4 100644 --- a/palacios/src/palacios/vmm_chkpt_stores.h +++ b/palacios/src/palacios/vmm_chkpt_stores.h @@ -223,9 +223,23 @@ static void * dir_open_ctx(void * store_data, ctx = V3_Malloc(sizeof(struct file_ctx)); + + if (!ctx) { + PrintError("Cannot allocate\n"); + return NULL; + } + memset(ctx, 0, sizeof(struct file_ctx)); ctx->filename = V3_Malloc(strlen(url) + strlen(name) + 5); + + if (!ctx->filename) { + PrintError("Cannot allocate\n"); + V3_Free(ctx); + return -1; + } + + memset(ctx->filename, 0, strlen(url) + strlen(name) + 5); snprintf(ctx->filename, strlen(url) + strlen(name) + 5, "%s/%s", url, name); diff --git a/palacios/src/palacios/vmm_config.c b/palacios/src/palacios/vmm_config.c index 0efbf83..ea772ce 100644 --- a/palacios/src/palacios/vmm_config.c +++ b/palacios/src/palacios/vmm_config.c @@ -131,11 +131,23 @@ static struct v3_config * parse_config(void * cfg_blob) { offset += 8; cfg = (struct v3_config *)V3_Malloc(sizeof(struct v3_config)); + + if (!cfg) { + PrintError("Unable to allocate while parsing\n"); + return NULL; + } + memset(cfg, 0, sizeof(struct v3_config)); cfg->blob = cfg_blob; INIT_LIST_HEAD(&(cfg->file_list)); cfg->file_table = v3_create_htable(0, file_hash_fn, file_eq_fn); + + if (!(cfg->file_table)) { + PrintError("Unable to allocate hash table while parsing\n"); + V3_Free(cfg); + return NULL; + } xml_len = *(uint32_t *)(cfg_blob + offset); offset += 4; @@ -162,12 +174,14 @@ static struct v3_config * parse_config(void * cfg_blob) { if (!file) { PrintError("Could not allocate file structure\n"); + v3_free_htable(cfg->file_table,0,0); + V3_Free(cfg); return NULL; } V3_Print("File index=%d id=%s\n", idx, id); - strncpy(file->tag, id, 256); + strncpy(file->tag, id, V3_MAX_TAG_LEN); file->size = hdr->size; file->data = cfg_blob + hdr->offset; @@ -428,6 +442,12 @@ static int post_config_core(struct guest_info * info, v3_cfg_tree_t * cfg) { static struct v3_vm_info * allocate_guest(int num_cores) { int guest_state_size = sizeof(struct v3_vm_info) + (sizeof(struct guest_info) * num_cores); struct v3_vm_info * vm = V3_Malloc(guest_state_size); + + if (!vm) { + PrintError("Unable to allocate space for guest data structures\n"); + return NULL; + } + int i = 0; memset(vm, 0, guest_state_size); diff --git a/palacios/src/palacios/vmm_cpuid.c b/palacios/src/palacios/vmm_cpuid.c index ca7ef86..06aac52 100644 --- a/palacios/src/palacios/vmm_cpuid.c +++ b/palacios/src/palacios/vmm_cpuid.c @@ -173,6 +173,12 @@ int v3_cpuid_add_fields(struct v3_vm_info * vm, uint32_t cpuid, if (hook == NULL) { struct masked_cpuid * mask = V3_Malloc(sizeof(struct masked_cpuid)); + + if (!mask) { + PrintError("Unable to alocate space for cpu id mask\n"); + return -1; + } + memset(mask, 0, sizeof(struct masked_cpuid)); mask->rax_mask = rax_mask; @@ -186,6 +192,7 @@ int v3_cpuid_add_fields(struct v3_vm_info * vm, uint32_t cpuid, if (v3_hook_cpuid(vm, cpuid, mask_hook, mask) == -1) { PrintError("Error hooking cpuid %d\n", cpuid); + V3_Free(mask); return -1; } } else { @@ -262,6 +269,12 @@ int v3_hook_cpuid(struct v3_vm_info * vm, uint32_t cpuid, } hook = (struct v3_cpuid_hook *)V3_Malloc(sizeof(struct v3_cpuid_hook)); + + if (!hook) { + PrintError("Cannot allocate memory to hook cpu id\n"); + return -1; + } + hook->cpuid = cpuid; hook->private_data = private_data; hook->hook_fn = hook_fn; diff --git a/palacios/src/palacios/vmm_dev_mgr.c b/palacios/src/palacios/vmm_dev_mgr.c index b045de9..0b16196 100644 --- a/palacios/src/palacios/vmm_dev_mgr.c +++ b/palacios/src/palacios/vmm_dev_mgr.c @@ -24,6 +24,9 @@ #ifdef V3_CONFIG_CHECKPOINT #include + +#define V3_MAX_DEVICE_NAME 32 + #endif @@ -138,7 +141,7 @@ int v3_save_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { struct v3_chkpt_ctx * dev_mgr_ctx = NULL; uint32_t num_saved_devs = 0; - uint32_t table_len = mgr->num_devs * 32; + uint32_t table_len = mgr->num_devs * V3_MAX_DEVICE_NAME; char * name_table = NULL; uint32_t tbl_offset = 0; @@ -161,8 +164,8 @@ int v3_save_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { list_for_each_entry(dev, &(mgr->dev_list), dev_link) { if (dev->ops->save) { - strncpy(name_table + tbl_offset, dev->name, 32); - tbl_offset += 32; + strncpy(name_table + tbl_offset, dev->name, V3_MAX_DEVICE_NAME); + tbl_offset += V3_MAX_DEVICE_NAME; num_saved_devs++; } else { PrintDebug("Skipping device %s\n"); @@ -176,7 +179,7 @@ int v3_save_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { return -1; } - if (v3_chkpt_save(dev_mgr_ctx, "names", num_saved_devs*32, name_table) == -1) { + if (v3_chkpt_save(dev_mgr_ctx, "names", num_saved_devs*V3_MAX_DEVICE_NAME, name_table) == -1) { PrintError("Unable to store names of devices\n"); v3_chkpt_close_ctx(dev_mgr_ctx); V3_Free(name_table); @@ -240,7 +243,7 @@ int v3_load_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { V3_Print("Loading State for %d devices\n", num_devs); - name_table = V3_Malloc(32 * num_devs); + name_table = V3_Malloc(V3_MAX_DEVICE_NAME * num_devs); if (!name_table) { PrintError("Unable to allocate space for device table\n"); @@ -248,7 +251,7 @@ int v3_load_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { return -1; } - if (v3_chkpt_load(dev_mgr_ctx, "names", 32 * num_devs, name_table) == -1) { + if (v3_chkpt_load(dev_mgr_ctx, "names", V3_MAX_DEVICE_NAME * num_devs, name_table) == -1) { PrintError("Unable to load device name table\n"); v3_chkpt_close_ctx(dev_mgr_ctx); V3_Free(name_table); @@ -257,7 +260,7 @@ int v3_load_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { v3_chkpt_close_ctx(dev_mgr_ctx); for (i = 0; i < num_devs; i++) { - char * name = &(name_table[i * 32]); + char * name = &(name_table[i * V3_MAX_DEVICE_NAME]); struct v3_chkpt_ctx * dev_ctx = NULL; dev = v3_find_dev(vm, name); @@ -506,6 +509,7 @@ struct vm_device * v3_add_device(struct v3_vm_info * vm, dev = (struct vm_device *)V3_Malloc(sizeof(struct vm_device)); if (dev == NULL) { + PrintError("Cannot allocate in adding a device\n"); return NULL; } @@ -569,6 +573,12 @@ int v3_dev_add_blk_frontend(struct v3_vm_info * vm, struct blk_frontend * frontend = NULL; frontend = (struct blk_frontend *)V3_Malloc(sizeof(struct blk_frontend)); + + if (!frontend) { + PrintError("Cannot allocate in adding a block front end\n"); + return -1; + } + memset(frontend, 0, sizeof(struct blk_frontend)); frontend->connect = connect; @@ -632,6 +642,12 @@ int v3_dev_add_net_frontend(struct v3_vm_info * vm, struct net_frontend * frontend = NULL; frontend = (struct net_frontend *)V3_Malloc(sizeof(struct net_frontend)); + + if (!frontend) { + PrintError("Cannot allocate in adding a net front end\n"); + return -1; + } + memset(frontend, 0, sizeof(struct net_frontend)); frontend->connect = connect; @@ -694,6 +710,12 @@ int v3_dev_add_console_frontend(struct v3_vm_info * vm, struct cons_frontend * frontend = NULL; frontend = (struct cons_frontend *)V3_Malloc(sizeof(struct cons_frontend)); + + if (!frontend) { + PrintError("Cannot allocate in adding a console front end\n"); + return -1; + } + memset(frontend, 0, sizeof(struct cons_frontend)); frontend->connect = connect; @@ -757,6 +779,12 @@ int v3_dev_add_char_frontend(struct v3_vm_info * vm, struct char_frontend * frontend = NULL; frontend = (struct char_frontend *)V3_Malloc(sizeof(struct char_frontend)); + + if (!frontend) { + PrintError("Cannot allocate in adding a char front end\n"); + return -1; + } + memset(frontend, 0, sizeof(struct char_frontend)); frontend->connect = connect; diff --git a/palacios/src/palacios/vmm_direct_paging.c b/palacios/src/palacios/vmm_direct_paging.c index b044b1f..421c3aa 100644 --- a/palacios/src/palacios/vmm_direct_paging.c +++ b/palacios/src/palacios/vmm_direct_paging.c @@ -33,7 +33,15 @@ static addr_t create_generic_pt_page() { void * page = 0; - page = V3_VAddr(V3_AllocPages(1)); + void *temp; + + temp = V3_AllocPages(1); + if (!temp) { + PrintError("Cannot allocate page\n"); + return 0; + } + + page = V3_VAddr(temp); memset(page, 0, PAGE_SIZE); return (addr_t)page; diff --git a/palacios/src/palacios/vmm_hypercall.c b/palacios/src/palacios/vmm_hypercall.c index 6cb51e0..6899640 100644 --- a/palacios/src/palacios/vmm_hypercall.c +++ b/palacios/src/palacios/vmm_hypercall.c @@ -136,6 +136,11 @@ int v3_register_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id, struct hypercall * hcall = (struct hypercall *)V3_Malloc(sizeof(struct hypercall)); + if (!hcall) { + PrintError("Cannot allocate in registering hypercall\n"); + return -1; + } + hcall->id = hypercall_id; hcall->priv_data = priv_data; hcall->hcall_fn = hypercall; diff --git a/palacios/src/palacios/vmm_intr.c b/palacios/src/palacios/vmm_intr.c index 02b8fbd..06d5254 100644 --- a/palacios/src/palacios/vmm_intr.c +++ b/palacios/src/palacios/vmm_intr.c @@ -98,6 +98,11 @@ void v3_deinit_intr_routers(struct v3_vm_info * vm) { void * v3_register_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * priv_data) { struct intr_controller * ctrlr = (struct intr_controller *)V3_Malloc(sizeof(struct intr_controller)); + if (!ctrlr) { + PrintError("Cannot allocate in registering an interrupt controller\n"); + return NULL; + } + ctrlr->priv_data = priv_data; ctrlr->ctrl_ops = ops; @@ -131,6 +136,11 @@ void v3_remove_intr_controller(struct guest_info * core, void * handle) { void * v3_register_intr_router(struct v3_vm_info * vm, struct intr_router_ops * ops, void * priv_data) { struct intr_router * router = (struct intr_router *)V3_Malloc(sizeof(struct intr_router)); + if (!router) { + PrintError("Cannot allocate in registering an interrupt router\n"); + return NULL; + } + router->priv_data = priv_data; router->router_ops = ops; @@ -175,12 +185,15 @@ int v3_hook_irq(struct v3_vm_info * vm, { struct v3_irq_hook * hook = (struct v3_irq_hook *)V3_Malloc(sizeof(struct v3_irq_hook)); + if (hook == NULL) { + PrintError("Cannot allocate when hooking an irq\n"); return -1; } if (get_irq_hook(vm, irq) != NULL) { PrintError("IRQ %d already hooked\n", irq); + V3_Free(hook); return -1; } @@ -191,6 +204,8 @@ int v3_hook_irq(struct v3_vm_info * vm, if (V3_Hook_Interrupt(vm, irq)) { PrintError("hook_irq: failed to hook irq %d\n", irq); + vm->intr_routers.hooks[irq] = NULL; + V3_Free(hook); return -1; } else { PrintDebug("hook_irq: hooked irq %d\n", irq); diff --git a/palacios/src/palacios/vmm_io.c b/palacios/src/palacios/vmm_io.c index 3642c3a..8ed88d8 100644 --- a/palacios/src/palacios/vmm_io.c +++ b/palacios/src/palacios/vmm_io.c @@ -128,6 +128,12 @@ int v3_hook_io_port(struct v3_vm_info * vm, uint16_t port, void * priv_data) { struct v3_io_hook * io_hook = (struct v3_io_hook *)V3_Malloc(sizeof(struct v3_io_hook)); + if (!io_hook) { + PrintError("Cannot allocate in hooking an I/O port\n"); + return -1; + } + + io_hook->port = port; if (!read) { diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index 7c11414..390de61 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -124,6 +124,12 @@ struct v3_mem_region * v3_create_mem_region(struct v3_vm_info * vm, uint16_t cor } entry = (struct v3_mem_region *)V3_Malloc(sizeof(struct v3_mem_region)); + + if (!entry) { + PrintError("Cannot allocate in creating a memory region\n"); + return NULL; + } + memset(entry, 0, sizeof(struct v3_mem_region)); entry->guest_start = guest_addr_start; diff --git a/palacios/src/palacios/vmm_mem_hook.c b/palacios/src/palacios/vmm_mem_hook.c index 98aabdc..ef2ff34 100644 --- a/palacios/src/palacios/vmm_mem_hook.c +++ b/palacios/src/palacios/vmm_mem_hook.c @@ -52,10 +52,28 @@ static int mem_eq_fn(addr_t key1, addr_t key2) { } int v3_init_mem_hooks(struct v3_vm_info * vm) { + void *temp; + struct v3_mem_hooks * hooks = &(vm->mem_hooks); - hooks->hook_hvas_1 = V3_VAddr(V3_AllocPages(vm->num_cores)); - hooks->hook_hvas_2 = V3_VAddr(V3_AllocPages(vm->num_cores)); + temp = V3_AllocPages(vm->num_cores); + + if (!temp) { + PrintError("Cannot allocate space for mem hooks\n"); + return -1; + } + + hooks->hook_hvas_1 = V3_VAddr(temp); + + temp = V3_AllocPages(vm->num_cores); + + if (!temp) { + PrintError("Cannot allocate space for mem hooks\n"); + V3_FreePages(hooks->hook_hvas_1,vm->num_cores); + return -1; + } + + hooks->hook_hvas_2 = V3_VAddr(temp); INIT_LIST_HEAD(&(hooks->hook_list)); @@ -317,6 +335,11 @@ int v3_hook_write_mem(struct v3_vm_info * vm, uint16_t core_id, struct mem_hook * hook = V3_Malloc(sizeof(struct mem_hook)); struct v3_mem_hooks * hooks = &(vm->mem_hooks); + if (!hook) { + PrintError("Cannot allocate in hooking memory for full access\n"); + return -1; + } + memset(hook, 0, sizeof(struct mem_hook)); hook->write = write; @@ -359,6 +382,11 @@ int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id, struct mem_hook * hook = V3_Malloc(sizeof(struct mem_hook)); struct v3_mem_hooks * hooks = &(vm->mem_hooks); + if (!hook) { + PrintError("Cannot allocate in hooking memory for writing\n"); + return -1; + } + memset(hook, 0, sizeof(struct mem_hook)); hook->write = write; @@ -366,12 +394,20 @@ int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id, hook->priv_data = priv_data; entry = v3_create_mem_region(vm, core_id, guest_addr_start, guest_addr_end); + + if (!entry) { + PrintError("Cannot create memory region\n"); + V3_Free(hook); + return -1; + } + hook->region = entry; entry->unhandled = handle_mem_hook; entry->priv_data = hook; if (v3_insert_mem_region(vm, entry)) { + PrintError("Cannot insert memory region\n"); V3_Free(entry); V3_Free(hook); return -1; diff --git a/palacios/src/palacios/vmm_multitree.c b/palacios/src/palacios/vmm_multitree.c index 309d1a0..c448e62 100644 --- a/palacios/src/palacios/vmm_multitree.c +++ b/palacios/src/palacios/vmm_multitree.c @@ -59,8 +59,14 @@ struct v3_mtree * v3_mtree_create_node(struct v3_mtree * root, char * name) { PrintDebug("Creating Node %s\n", name); + + if (!node) { + PrintError("Cannot allocate multitree node\n"); + return NULL; + } + memset(node, 0, sizeof(struct v3_mtree)); - strncpy(node->name, name, 50); + strncpy(node->name, name, V3_MTREE_NAME_LEN); if ((ret = __insert_mtree_node(root, node))) { PrintError("Insertion failure\n"); diff --git a/palacios/src/palacios/vmm_queue.c b/palacios/src/palacios/vmm_queue.c index 20fa255..28d41ac 100644 --- a/palacios/src/palacios/vmm_queue.c +++ b/palacios/src/palacios/vmm_queue.c @@ -27,6 +27,12 @@ void v3_init_queue(struct v3_queue * queue) { struct v3_queue * v3_create_queue() { struct v3_queue * tmp_queue = V3_Malloc(sizeof(struct v3_queue)); + + if (!tmp_queue) { + PrintError("Cannot allocate a queue\n"); + return NULL; + } + v3_init_queue(tmp_queue); return tmp_queue; } @@ -35,6 +41,11 @@ void v3_enqueue(struct v3_queue * queue, addr_t entry) { struct v3_queue_entry * q_entry = V3_Malloc(sizeof(struct v3_queue_entry)); unsigned int flags = 0; + if (!q_entry) { + PrintError("Cannot allocate a queue entry for enqueue\n"); + return ; + } + flags = v3_lock_irqsave(queue->lock); q_entry->entry = entry; list_add_tail(&(q_entry->entry_list), &(queue->entries)); diff --git a/palacios/src/palacios/vmm_ringbuffer.c b/palacios/src/palacios/vmm_ringbuffer.c index af24280..0797a72 100644 --- a/palacios/src/palacios/vmm_ringbuffer.c +++ b/palacios/src/palacios/vmm_ringbuffer.c @@ -25,6 +25,12 @@ void NO_INST v3_init_ringbuf(struct v3_ringbuf * ring, uint_t size) { ring->buf = V3_Malloc(size); + + if (!(ring->buf)) { + PrintError("Cannot init a ring buffer\n"); + return; + } + ring->size = size; ring->start = 0; @@ -36,6 +42,11 @@ NO_INST struct v3_ringbuf * v3_create_ringbuf(uint_t size) { struct v3_ringbuf * ring = (struct v3_ringbuf *)V3_Malloc(sizeof(struct v3_ringbuf)); + if (!ring) { + PrintError("Cannot allocate a ring buffer\n"); + return NULL; + } + v3_init_ringbuf(ring, size); return ring; diff --git a/palacios/src/palacios/vmm_string.c b/palacios/src/palacios/vmm_string.c index 75a8975..af102f7 100644 --- a/palacios/src/palacios/vmm_string.c +++ b/palacios/src/palacios/vmm_string.c @@ -71,6 +71,11 @@ void * memcpy(void * dst, const void * src, size_t n) { #ifdef V3_CONFIG_BUILT_IN_MEMMOVE void * memmove(void * dst, const void * src, size_t n) { uint8_t * tmp = (uint8_t *)V3_Malloc(n); + + if (!tmp) { + PrintError("Cannot allocate in built-in memmove\n"); + return NULL; + } memcpy(tmp, src, n); memcpy(dst, tmp, n); @@ -285,6 +290,12 @@ char * strdup(const char * s1) { char *ret; ret = V3_Malloc(strlen(s1) + 1); + + if (!ret) { + PrintError("Cannot allocate in built-in strdup\n"); + return NULL; + } + strcpy(ret, s1); return ret; diff --git a/palacios/src/palacios/vmm_symmod.c b/palacios/src/palacios/vmm_symmod.c index 5f14566..36a7685 100644 --- a/palacios/src/palacios/vmm_symmod.c +++ b/palacios/src/palacios/vmm_symmod.c @@ -78,6 +78,13 @@ int V3_init_symmod() { capsule = V3_Malloc(sizeof(struct v3_sym_capsule)); + + if (!capsule) { + PrintError("Cannot allocate in initializing symmod\n"); + return -1; + } + + memset(capsule, 0, sizeof(struct v3_sym_capsule)); capsule->name = tmp_def->name; @@ -95,6 +102,7 @@ int V3_init_symmod() { capsule->guest_size = capsule->size; capsule->capsule_data = NULL; } else { + V3_Free(capsule) return -1; } @@ -104,6 +112,7 @@ int V3_init_symmod() { (addr_t)(tmp_def->name), (addr_t)(capsule)) == 0) { PrintError("Could not insert module %s to master list\n", tmp_def->name); + V3_Free(capsule); return -1; } @@ -180,6 +189,11 @@ static int symbol_hcall_handler(struct guest_info * core, hcall_id_t hcall_id, v new_symbol = (struct v3_symbol *)V3_Malloc(sizeof(struct v3_symbol)); + if (!new_symbol) { + PrintError("Cannot allocate in symbiotic hcall handler\n"); + return -1; + } + strncpy(new_symbol->name, sym_name, 256); new_symbol->linkage = tmp_symbol->value; diff --git a/palacios/src/palacios/vmm_symspy.c b/palacios/src/palacios/vmm_symspy.c index caf1a8c..1698d0b 100644 --- a/palacios/src/palacios/vmm_symspy.c +++ b/palacios/src/palacios/vmm_symspy.c @@ -118,6 +118,11 @@ static int symspy_msr_write(struct guest_info * core, uint_t msr, struct v3_msr int v3_init_symspy_vm(struct v3_vm_info * vm, struct v3_symspy_global_state * state) { state->global_page_pa = (addr_t)V3_AllocPages(1); + if (!state->global_page_pa) { + PrintError("Cannot allocate page\n"); + return -1; + } + state->sym_page = (struct v3_symspy_global_page *)V3_VAddr((void *)state->global_page_pa); memset(state->sym_page, 0, PAGE_SIZE_4KB); @@ -133,6 +138,11 @@ int v3_init_symspy_vm(struct v3_vm_info * vm, struct v3_symspy_global_state * st int v3_init_symspy_core(struct guest_info * core, struct v3_symspy_local_state * state) { state->local_page_pa = (addr_t)V3_AllocPages(1); + + if (!state->local_page_pa) { + PrintError("Cannot allocate page\n"); + return -1; + } state->local_page = (struct v3_symspy_local_page *)V3_VAddr((void *)state->local_page_pa); memset(state->local_page, 0, PAGE_SIZE_4KB); diff --git a/palacios/src/palacios/vmm_telemetry.c b/palacios/src/palacios/vmm_telemetry.c index 0195cfe..1fb128a 100644 --- a/palacios/src/palacios/vmm_telemetry.c +++ b/palacios/src/palacios/vmm_telemetry.c @@ -162,6 +162,11 @@ static struct exit_event * get_exit(struct guest_info * info, uint_t exit_code) static inline struct exit_event * create_exit(uint_t exit_code) { struct exit_event * evt = V3_Malloc(sizeof(struct exit_event)); + if (!evt) { + PrintError("Cannot allocate in createing exit in telemetry\n"); + return NULL; + } + evt->exit_code = exit_code; evt->cnt = 0; evt->handler_time = 0; @@ -219,6 +224,11 @@ void v3_add_telemetry_cb(struct v3_vm_info * vm, struct v3_telemetry_state * telemetry = &(vm->telemetry); struct telemetry_cb * cb = (struct telemetry_cb *)V3_Malloc(sizeof(struct telemetry_cb)); + if (!cb) { + PrintError("Cannot allocate in adding a telemtry callback\n"); + return ; + } + cb->private_data = private_data; cb->telemetry_fn = telemetry_fn; diff --git a/palacios/src/palacios/vmm_time.c b/palacios/src/palacios/vmm_time.c index 7cf7853..d9ca1d6 100644 --- a/palacios/src/palacios/vmm_time.c +++ b/palacios/src/palacios/vmm_time.c @@ -162,6 +162,12 @@ struct v3_timer * v3_add_timer(struct guest_info * info, void * private_data) { struct v3_timer * timer = NULL; timer = (struct v3_timer *)V3_Malloc(sizeof(struct v3_timer)); + + if (!timer) { + PrintError("Cannot allocate in adding a timer\n"); + return NULL; + } + V3_ASSERT(timer != NULL); timer->ops = ops; diff --git a/palacios/src/palacios/vmm_xed.c b/palacios/src/palacios/vmm_xed.c index e35b4b0..350840b 100644 --- a/palacios/src/palacios/vmm_xed.c +++ b/palacios/src/palacios/vmm_xed.c @@ -167,6 +167,12 @@ int v3_init_decoder(struct guest_info * info) { } xed_state_t * decoder_state = (xed_state_t *)V3_Malloc(sizeof(xed_state_t)); + + if (!decoder_state) { + PrintError("Cannot allocate in initializing decoder\n"); + return -1; + } + xed_state_zero(decoder_state); xed_state_init(decoder_state, XED_MACHINE_MODE_LEGACY_32, diff --git a/palacios/src/palacios/vmm_xml.c b/palacios/src/palacios/vmm_xml.c index d09a176..3581d98 100644 --- a/palacios/src/palacios/vmm_xml.c +++ b/palacios/src/palacios/vmm_xml.c @@ -67,6 +67,7 @@ static void * tmp_realloc(void * old_ptr, size_t old_size, size_t new_size) { new_buf = V3_Malloc(new_size); if (new_buf == NULL) { + PrintError("Cannot allocate in tmp_realloc in xml\n"); return NULL; } @@ -302,6 +303,12 @@ static void v3_xml_char_content(struct v3_xml_root * root, char * s, size_t len, char * tmp = NULL; tmp = V3_Malloc((l = strlen(xml->txt)) + len); + + if (!tmp) { + PrintError("Cannot allocate in xml char content\n"); + return ; + } + strcpy(tmp, xml->txt); xml->txt = tmp; } @@ -362,6 +369,12 @@ static void v3_xml_free_attr(char **attr) { static struct v3_xml * v3_xml_new(const char * name) { struct v3_xml_root * root = (struct v3_xml_root *)V3_Malloc(sizeof(struct v3_xml_root)); + + if (!root) { + PrintError("Cannot allocate in xml_new\n"); + return NULL; + } + memset(root, 0, sizeof(struct v3_xml_root)); root->xml.name = (char *)name; @@ -457,6 +470,12 @@ static struct v3_xml * v3_xml_add_child(struct v3_xml * xml, const char * name, } child = (struct v3_xml *)V3_Malloc(sizeof(struct v3_xml)); + + if (!child) { + PrintError("Cannot allocate in xml_add_child\n"); + return NULL; + } + memset(child, 0, sizeof(struct v3_xml)); child->name = (char *)name; @@ -565,12 +584,31 @@ static struct v3_xml * parse_str(char * buf, size_t len) { ((attr_cnt * (2 * sizeof(char *))) + (2 * sizeof(char *)))); + if (!attr) { + PrintError("Cannot reallocate in xml parse string\n"); + return NULL; + } + attr[last_idx] = tmp_realloc(attr[last_idx - 2], attr_cnt, (attr_cnt + 1)); + + if (!attr[last_idx]) { + PrintError("Cannot reallocate in xml parse string\n"); + return NULL; + } + } else { attr = V3_Malloc(4 * sizeof(char *)); + if (!attr) { + PrintError("Cannot allocate in xml parse string\n"); + return NULL; + } attr[last_idx] = V3_Malloc(2); + if (!attr[last_idx]) { + PrintError("Cannot alloocate in xml parse string\n"); + return NULL; + } } attr[attr_idx] = buf; // set attribute name @@ -734,6 +772,12 @@ struct v3_xml * v3_xml_parse(char * buf) { str_len = strlen(buf); xml_buf = (char *)V3_Malloc(str_len + 1); + + if (!xml_buf) { + PrintError("Cannot allocate in xml parse\n"); + return NULL; + } + strcpy(xml_buf, buf); return parse_str(xml_buf, str_len); @@ -825,10 +869,26 @@ struct v3_xml * v3_xml_set_attr(struct v3_xml * xml, const char * name, const ch // first attribute xml->attr = V3_Malloc(4 * sizeof(char *)); + if (!xml->attr) { + PrintError("Cannot allocate in xml set attr\n"); + return NULL; + } + // empty list of malloced names/vals xml->attr[1] = strdup(""); + + if (!xml->attr[1]) { + PrintError("Cannot strdup in xml set attr\n"); + return NULL; + } + } else { xml->attr = tmp_realloc(xml->attr, l * sizeof(char *), (l + 4) * sizeof(char *)); + + if (!xml->attr) { + PrintError("Cannot reallocate in xml set attr\n"); + return NULL; + } } // set attribute name @@ -841,6 +901,12 @@ struct v3_xml * v3_xml_set_attr(struct v3_xml * xml, const char * name, const ch strlen(xml->attr[l + 1]), (c = strlen(xml->attr[l + 1])) + 2); + + if (!xml->attr[l + 3]) { + PrintError("Cannot reallocate in xml set attr\n"); + return NULL; + } + // set name/value as not malloced strcpy(xml->attr[l + 3] + c, " "); @@ -1057,7 +1123,14 @@ char * v3_xml_tostr(struct v3_xml * xml) { struct v3_xml * o = (xml) ? xml->ordered : NULL; struct v3_xml_root * root = (struct v3_xml_root *)xml; size_t len = 0, max = V3_XML_BUFSIZE; - char *s = strcpy(V3_Malloc(max), ""); + char *s = V3_Malloc(max); + + if (!s) { + PrintError("Cannot allocate in xml tostrr\n"); + return NULL; + } + + strcpy(s, ""); if (! xml || ! xml->name) return tmp_realloc(s, max, len + 1); while (root->xml.parent) root = (struct v3_xml_root *)root->xml.parent; // root tag diff --git a/palacios/src/palacios/vmx.c b/palacios/src/palacios/vmx.c index d9fc081..a80b8f2 100644 --- a/palacios/src/palacios/vmx.c +++ b/palacios/src/palacios/vmx.c @@ -92,11 +92,17 @@ static int inline check_vmcs_read(vmcs_field_t field, void * val) { static addr_t allocate_vmcs() { + void *temp; struct vmcs_data * vmcs_page = NULL; PrintDebug("Allocating page\n"); - vmcs_page = (struct vmcs_data *)V3_VAddr(V3_AllocPages(1)); + temp = V3_AllocPages(1); + if (!temp) { + PrintError("Cannot allocate VMCS\n"); + return -1; + } + vmcs_page = (struct vmcs_data *)V3_VAddr(temp); memset(vmcs_page, 0, 4096); vmcs_page->revision = hw_info.basic_info.revision; @@ -547,6 +553,12 @@ static void __init_vmx_vmcs(void * arg) { int vmx_ret = 0; vmx_state = (struct vmx_data *)V3_Malloc(sizeof(struct vmx_data)); + + if (!vmx_state) { + PrintError("Unable to allocate in initializing vmx vmcs\n"); + return; + } + memset(vmx_state, 0, sizeof(struct vmx_data)); PrintDebug("vmx_data pointer: %p\n", (void *)vmx_state); diff --git a/palacios/src/palacios/vmx_ept.c b/palacios/src/palacios/vmx_ept.c index a66ad6b..d239bd2 100644 --- a/palacios/src/palacios/vmx_ept.c +++ b/palacios/src/palacios/vmx_ept.c @@ -27,8 +27,15 @@ static struct vmx_ept_msr * ept_info = NULL; static addr_t create_ept_page() { + void * temp; void * page = 0; - page = V3_VAddr(V3_AllocPages(1)); + + temp = V3_AllocPages(1); + if (!temp) { + PrintError("Cannot allocate EPT page\n"); + return 0; + } + page = V3_VAddr(temp); memset(page, 0, PAGE_SIZE); return (addr_t)page; diff --git a/palacios/src/palacios/vmx_io.c b/palacios/src/palacios/vmx_io.c index 1dbe95e..1c33f11 100644 --- a/palacios/src/palacios/vmx_io.c +++ b/palacios/src/palacios/vmx_io.c @@ -47,9 +47,17 @@ static int update_map(struct v3_vm_info * vm, uint16_t port, int hook_read, int } int v3_init_vmx_io_map(struct v3_vm_info * vm) { + void *temp; + vm->io_map.update_map = update_map; - - vm->io_map.arch_data = V3_VAddr(V3_AllocPages(2)); + + temp = V3_AllocPages(2); + if (!temp) { + PrintError("Cannot allocate io bitmap\n"); + return -1; + } + + vm->io_map.arch_data = V3_VAddr(temp); memset(vm->io_map.arch_data, 0xff, PAGE_SIZE_4KB * 2); v3_refresh_io_map(vm); diff --git a/palacios/src/palacios/vmx_msr.c b/palacios/src/palacios/vmx_msr.c index ae64331..bb70fa7 100644 --- a/palacios/src/palacios/vmx_msr.c +++ b/palacios/src/palacios/vmx_msr.c @@ -67,11 +67,18 @@ static int update_map(struct v3_vm_info * vm, uint_t msr, int hook_reads, int ho } int v3_init_vmx_msr_map(struct v3_vm_info * vm) { + void *temp; + struct v3_msr_map * msr_map = &(vm->msr_map); msr_map->update_map = update_map; - msr_map->arch_data = V3_VAddr(V3_AllocPages(1)); + temp = V3_AllocPages(1); + if (!temp) { + PrintError("Cannot allocat MSR bitmap\n"); + return -1; + } + msr_map->arch_data = V3_VAddr(temp); memset(msr_map->arch_data, 0xff, PAGE_SIZE_4KB); v3_refresh_msr_map(vm); diff --git a/palacios/src/vnet/vnet_core.c b/palacios/src/vnet/vnet_core.c index 9c931ba..c2ebaf0 100644 --- a/palacios/src/vnet/vnet_core.c +++ b/palacios/src/vnet/vnet_core.c @@ -254,6 +254,12 @@ int v3_vnet_add_route(struct v3_vnet_route route) { unsigned long flags; new_route = (struct vnet_route_info *)Vnet_Malloc(sizeof(struct vnet_route_info)); + + if (!new_route) { + PrintError("Cannot allocate new route\n"); + return -1; + } + memset(new_route, 0, sizeof(struct vnet_route_info)); #ifdef V3_CONFIG_DEBUG_VNET @@ -452,13 +458,19 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { PrintDebug("VNET/P Core: match_route: Matches=%d\n", num_matches); - if (num_matches == 0) { + if (num_matches <= 0) { return NULL; } matches = (struct route_list *)Vnet_Malloc(sizeof(struct route_list) + (sizeof(struct vnet_route_info *) * num_matches)); + + if (!matches) { + PrintError("VNET/P Core: Unable to allocate matches\n"); + return NULL; + } + matches->num_routes = num_matches; { @@ -478,9 +490,11 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { int i; int cpu = V3_Get_CPU(); + Vnet_Print(2, "VNET/P Core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n", cpu, pkt->size, pkt->src_id, pkt->src_type, pkt->dst_id, pkt->dst_type); + if(net_debug >= 4){ v3_hexdump(pkt->data, pkt->size, NULL, 0); } @@ -491,15 +505,16 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { vnet_state.stats.rx_pkts++; look_into_cache(pkt, &matched_routes); + if (matched_routes == NULL) { - PrintDebug("VNET/P Core: send pkt Looking into routing table\n"); + PrintDebug("VNET/P Core: sending pkt - matching route\n"); matched_routes = match_route(pkt); if (matched_routes) { add_route_to_cache(pkt, matched_routes); } else { - PrintDebug("VNET/P Core: Could not find route for packet... discards packet\n"); + PrintDebug("VNET/P Core: Could not find route for packet... discarding packet\n"); vnet_unlock_irqrestore(vnet_state.lock, flags); return 0; /* do we return -1 here?*/ } @@ -558,7 +573,7 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, new_dev = (struct vnet_dev *)Vnet_Malloc(sizeof(struct vnet_dev)); if (new_dev == NULL) { - Vnet_Print(0, "Malloc fails\n"); + Vnet_Print(0, "VNET/P Core: Unable to allocate a new device\n"); return -1; } @@ -568,7 +583,7 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, new_dev->private_data = priv_data; new_dev->vm = vm; new_dev->dev_id = 0; - new_dev->quote = quotequote = quotepoll = poll_state; flags = vnet_lock_irqsave(vnet_state.lock); @@ -582,7 +597,7 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, v3_enqueue(vnet_state.poll_devs, (addr_t)new_dev); } } else { - PrintError("VNET/P: Device with the same MAC is already there\n"); + PrintError("VNET/P: Device with the same MAC has already been added\n"); } vnet_unlock_irqrestore(vnet_state.lock, flags); @@ -616,7 +631,7 @@ int v3_vnet_del_dev(int dev_id){ Vnet_Free(dev); - PrintDebug("VNET/P Core: Remove Device: dev_id %d\n", dev_id); + PrintDebug("VNET/P Core: Removed Device: dev_id %d\n", dev_id); return 0; } @@ -673,7 +688,7 @@ int v3_vnet_add_bridge(struct v3_vm_info * vm, tmp_bridge = (struct vnet_brg_dev *)Vnet_Malloc(sizeof(struct vnet_brg_dev)); if (tmp_bridge == NULL) { - PrintError("Malloc Fails\n"); + PrintError("VNET/P Core: Unable to allocate new bridge\n"); vnet_state.bridge = NULL; return -1; } @@ -701,7 +716,7 @@ void v3_vnet_del_bridge(uint8_t type) { if (vnet_state.bridge != NULL && vnet_state.bridge->type == type) { tmp_bridge = vnet_state.bridge; - vnet_state.bridge = NULL; + vnet_state.bridge = NULL; } vnet_unlock_irqrestore(vnet_state.lock, flags); @@ -774,6 +789,8 @@ static int vnet_tx_flush(void * args){ } } + + Vnet_Free(tq); Vnet_Print(0, "VNET/P Polling Thread Done.\n"); @@ -816,6 +833,9 @@ void v3_deinit_vnet(){ vnet_thread_stop(vnet_state.pkt_flush_thread); // At this point there should be no lock-holder + Vnet_Free(vnet_state.poll_devs); + + PrintDebug("Deiniting Device List\n"); // close any devices we have open deinit_devices_list(); diff --git a/palacios/src/vnet/vnet_host.c b/palacios/src/vnet/vnet_host.c index b537e2a..459f6b7 100644 --- a/palacios/src/vnet/vnet_host.c +++ b/palacios/src/vnet/vnet_host.c @@ -24,7 +24,14 @@ struct vnet_host_hooks * host_hooks; struct vnet_thread * vnet_start_thread(int (*func)(void *), void *arg, char * name){ if((host_hooks) && host_hooks->thread_start){ + struct vnet_thread * thread = Vnet_Malloc(sizeof(struct vnet_thread)); + + if (!thread) { + PrintError("Cannot allocate space to create a vnet thread\n"); + return NULL; + } + thread->host_thread = host_hooks->thread_start(func, arg, name); if(thread->host_thread){ @@ -42,7 +49,14 @@ struct vnet_timer * vnet_create_timer(unsigned long interval, void * priv_data){ if((host_hooks) && host_hooks->timer_create){ struct vnet_timer * timer = Vnet_Malloc(sizeof(struct vnet_timer)); + + if (!timer) { + PrintError("Cannot allocate space to create a vnet timer\n"); + return NULL; + } + timer->host_timer = host_hooks->timer_create(interval, timer_fun, priv_data); + return timer; }