From 88161bfca5fa1a1375195ddbc995bdd70276aa95 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Wed, 10 May 2023 11:28:33 +0800 Subject: [PATCH] fs/mmap: add sanity check Signed-off-by: dongjiuzhu1 --- fs/mmap/fs_mmap.c | 7 +++++++ fs/mmap/fs_munmap.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c index f72633acc90..d4bb97f29d5 100644 --- a/fs/mmap/fs_mmap.c +++ b/fs/mmap/fs_mmap.c @@ -74,6 +74,13 @@ static int file_mmap_(FAR struct file *filep, FAR void *start, */ #ifdef CONFIG_DEBUG_FEATURES + /* A flags with MAP_PRIVATE and MAP_SHARED is invalid. */ + + if ((flags & MAP_PRIVATE) && (flags & MAP_SHARED)) + { + return -EINVAL; + } + /* Fixed mappings and protections are not currently supported. These * options could be supported in the KERNEL build with an MMU, but that * logic is not in place. diff --git a/fs/mmap/fs_munmap.c b/fs/mmap/fs_munmap.c index 85449c1ee5f..41f25a43b34 100644 --- a/fs/mmap/fs_munmap.c +++ b/fs/mmap/fs_munmap.c @@ -69,6 +69,13 @@ static int file_munmap_(FAR void *start, size_t length, bool kernel) mm_map_unlock(); } + /* If entry don't find, the start and length is invalid. */ + + if (entry == NULL) + { + return -EINVAL; + } + return ret; }