From 7860f3863f2b00f5c7f35c15adfb6b38363c2d1e Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Thu, 5 Dec 2024 17:11:02 +0000 Subject: [PATCH] fix: add check to mmap to ensure file isn't mapped over stack segment (ed1223) --- src/userprog/syscall.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 44a8505..4e73e63 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -426,6 +426,10 @@ syscall_mmap (int fd, void *addr) if (file_size == 0) return MMAP_FAILURE; + /* Ensure that the mmap page doesn't 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 hold the entire file. */ for (off_t ofs = 0; ofs < file_size; ofs += PGSIZE)