This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d754cdf145 fs/procfs: refuse MAP_SHARED mappings with ENODEV
0d754cdf145 is described below

commit 0d754cdf14507f8eed4b21808d082e745283e29c
Author: yukangzhi <[email protected]>
AuthorDate: Wed Nov 18 23:59:49 2026 +0800

    fs/procfs: refuse MAP_SHARED mappings with ENODEV
    
    PSE52 RT_mmap TP25 and RT_mmap_P TP28 call mmap(MAP_SHARED) on
    /proc/version and expect ENODEV, because the file does not support
    mapping. procfs has no mmap callback, so file_mmap_() keeps ret at
    -ENOTTY and falls back to rammap(), which copies the content into RAM
    and returns a valid address.
    
    A shared mapping of a procfs file has nothing to share: the content is
    generated on every read. Add a procfs mmap callback that returns
    -ENODEV for MAP_SHARED and -ENOTTY otherwise, so MAP_PRIVATE still
    gets a private copy through rammap().
    
    Refusing every MAP_SHARED mapping without an mmap callback in
    fs_mmap.c was not chosen: FAT, littlefs and other file systems rely on
    the rammap() fallback for read-only shared mappings.
    
    Signed-off-by: yukangzhi <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/procfs/fs_procfs.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c
index f9645e8d58f..e4314c6cf39 100644
--- a/fs/procfs/fs_procfs.c
+++ b/fs/procfs/fs_procfs.c
@@ -27,6 +27,7 @@
 #include <nuttx/config.h>
 
 #include <sys/types.h>
+#include <sys/mman.h>
 #include <sys/statfs.h>
 #include <sys/stat.h>
 
@@ -245,6 +246,8 @@ static int     procfs_poll(FAR struct file *filep, FAR 
struct pollfd_s *fds,
                  bool setup);
 static int     procfs_ioctl(FAR struct file *filep, int cmd,
                  unsigned long arg);
+static int     procfs_mmap(FAR struct file *filep,
+                 FAR struct mm_map_entry_s *map);
 
 static int     procfs_dup(FAR const struct file *oldp,
                  FAR struct file *newp);
@@ -293,7 +296,7 @@ const struct mountpt_operations g_procfs_operations =
   procfs_write,      /* write */
   NULL,              /* seek */
   procfs_ioctl,      /* ioctl */
-  NULL,              /* mmap */
+  procfs_mmap,       /* mmap */
   NULL,              /* truncate */
   procfs_poll,       /* poll */
   NULL,              /* readv */
@@ -576,6 +579,27 @@ static int procfs_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
   return -ENOTTY;
 }
 
+/****************************************************************************
+ * Name: procfs_mmap
+ *
+ * Description:
+ *   procfs content is generated on read and has no backing store to share,
+ *   so a MAP_SHARED mapping is refused.  -ENOTTY lets file_mmap_() give a
+ *   private mapping a copy through rammap().
+ *
+ ****************************************************************************/
+
+static int procfs_mmap(FAR struct file *filep,
+                       FAR struct mm_map_entry_s *map)
+{
+  if ((map->flags & MAP_SHARED) != 0)
+    {
+      return -ENODEV;
+    }
+
+  return -ENOTTY;
+}
+
 /****************************************************************************
  * Name: procfs_dup
  *

Reply via email to