fix: add check to mmap to ensure file isn't mapped over stack segment

This commit is contained in:
EDiasAlberto
2024-12-05 16:05:08 +00:00
parent e779e8ac7c
commit 5cf79b5389

View File

@@ -426,6 +426,10 @@ syscall_mmap (int fd, void *addr)
if (file_size == 0) if (file_size == 0)
return MMAP_FAILURE; return MMAP_FAILURE;
/* ensures the page for mmap does not overlap with the stack */
if (addr >= (thread_current ()->curr_esp - PGSIZE))
return MMAP_FAILURE;
/* Check and ensure that there is enough space in the user virtual memory to /* Check and ensure that there is enough space in the user virtual memory to
hold the entire file. */ hold the entire file. */
for (off_t ofs = 0; ofs < file_size; ofs += PGSIZE) for (off_t ofs = 0; ofs < file_size; ofs += PGSIZE)