mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
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 <mishra.abhishek2808@gmail.com>
This commit is contained in:
parent
4bbe61ead5
commit
fe28fb033c
4 changed files with 41 additions and 5 deletions
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue