VM,MFS: better handling of some exceptional cases

Fix for problems reported by Alejandro Hernández:
	. VM unmap: handle case where there is no nextvr

Fixes for problems found by running Melkor ELF fuzzing tool:
	. VM: better handle case where region prealloc fails by
	  freeing memory that was allocated so far
	. MFS fs_readwrite: EOF check should happen for read and
	  peek requests, not just read

This fixes #4.

Change-Id: I2adf4eebdfb4c48a297beff0478eed5c917a53a4
This commit is contained in:
Ben Gras 2014-11-06 14:39:32 +01:00
parent 957802cd0c
commit f53651de01
2 changed files with 6 additions and 7 deletions

View file

@ -69,7 +69,7 @@ ssize_t fs_readwrite(ino_t ino_nr, struct fsdriver_data *data, size_t nrbytes,
if (chunk > nrbytes)
chunk = nrbytes;
if (call == FSC_READ) {
if (call != FSC_WRITE) {
bytes_left = f_size - position;
if (position >= f_size) break; /* we are beyond EOF */
if (chunk > (unsigned int) bytes_left) chunk = bytes_left;

View file

@ -493,10 +493,7 @@ struct vir_region *map_page_region(struct vmproc *vmp, vir_bytes minv,
if(map_handle_memory(vmp, newregion, 0, length, 1,
NULL, 0, 0) != OK) {
printf("VM: map_page_region: prealloc failed\n");
free(newregion->physblocks);
USE(newregion,
newregion->physblocks = NULL;);
SLABFREE(newregion);
map_free(newregion);
return NULL;
}
}
@ -1283,8 +1280,10 @@ int map_unmap_range(struct vmproc *vmp, vir_bytes unmap_start, vir_bytes length)
return r;
}
region_start_iter(&vmp->vm_regions_avl, &v_iter, nextvr->vaddr, AVL_EQUAL);
assert(region_get_iter(&v_iter) == nextvr);
if(nextvr) {
region_start_iter(&vmp->vm_regions_avl, &v_iter, nextvr->vaddr, AVL_EQUAL);
assert(region_get_iter(&v_iter) == nextvr);
}
}
return OK;