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

commit fe28fb033c3438e5c0f6a59da4ee7a9e4a905c55
Author: Abhishek Mishra <[email protected]>
AuthorDate: Thu Jul 16 18:55:30 2026 +0000

    fs: enforce permission checks when opening IPC pseudo-inodes
    
    Use inode_checkopenperm() for message queues, named semaphores, and
    shm, and reallocate mqueue state when reopening after the last close.
    
    Signed-off-by: Abhishek Mishra <[email protected]>
---
 fs/inode/fs_inode.c     | 11 ++++++++++-
 fs/mqueue/mq_open.c     | 20 ++++++++++++++++++++
 fs/semaphore/sem_open.c |  8 ++++++++
 fs/shm/shm_open.c       |  7 +++----
 4 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/fs/inode/fs_inode.c b/fs/inode/fs_inode.c
index 654b8f7a340..e89eb337489 100644
--- a/fs/inode/fs_inode.c
+++ b/fs/inode/fs_inode.c
@@ -275,7 +275,16 @@ int inode_checkopenperm(FAR struct inode *inode, int 
oflags)
 {
   FAR const struct file_operations *ops;
 
-  if (INODE_IS_PSEUDODIR(inode))
+  if (INODE_IS_NAMEDSEM(inode))
+    {
+#ifdef CONFIG_FS_PERMISSION
+      return inode_checkperm(inode, R_OK | W_OK);
+#else
+      return OK;
+#endif
+    }
+
+  if (INODE_IS_MQUEUE(inode) || INODE_IS_PSEUDODIR(inode))
     {
 #ifdef CONFIG_FS_PERMISSION
       return inode_checkperm(inode, fs_open_amode(oflags));
diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c
index 514f053997e..feeeea66761 100644
--- a/fs/mqueue/mq_open.c
+++ b/fs/mqueue/mq_open.c
@@ -262,6 +262,26 @@ static int file_mq_vopen(FAR struct file *mq, FAR const 
char *mq_name,
           goto errout_with_inode;
         }
 
+#ifdef CONFIG_FS_PERMISSION
+      ret = inode_checkopenperm(inode, oflags);
+      if (ret < 0)
+        {
+          goto errout_with_inode;
+        }
+#endif
+
+      if (inode->i_private == NULL)
+        {
+          ret = nxmq_alloc_msgq(NULL, &msgq);
+          if (ret < 0)
+            {
+              goto errout_with_inode;
+            }
+
+          inode->i_private = msgq;
+          msgq->inode      = inode;
+        }
+
       /* Associate the inode with a file structure */
 
       mq->f_oflags = oflags;
diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c
index 0fdac9dd2c9..e89e0de7461 100644
--- a/fs/semaphore/sem_open.c
+++ b/fs/semaphore/sem_open.c
@@ -138,6 +138,14 @@ int nxsem_open(FAR sem_t **sem, FAR const char *name, int 
oflags, ...)
           goto errout_with_inode;
         }
 
+#ifdef CONFIG_FS_PERMISSION
+      ret = inode_checkopenperm(inode, O_RDWR);
+      if (ret < 0)
+        {
+          goto errout_with_inode;
+        }
+#endif
+
       /* Return a reference to the semaphore, retaining the reference
        * count on the inode.
        */
diff --git a/fs/shm/shm_open.c b/fs/shm/shm_open.c
index dd609fc79c7..27279c39867 100644
--- a/fs/shm/shm_open.c
+++ b/fs/shm/shm_open.c
@@ -112,11 +112,10 @@ static int file_shm_open(FAR struct file *shm, FAR const 
char *name,
           goto errout_with_sem;
         }
 
-#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
-      if (((oflags & O_ACCMODE) != O_RDONLY && !(inode->i_mode & S_IWUSR)) ||
-          ((oflags & O_ACCMODE) != O_WRONLY && !(inode->i_mode & S_IRUSR)))
+#ifdef CONFIG_FS_PERMISSION
+      ret = inode_checkopenperm(inode, oflags);
+      if (ret < 0)
         {
-          ret = -EACCES;
           inode_release(inode);
           goto errout_with_sem;
         }

Reply via email to