Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions fs/vfs/fs_chstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <errno.h>

#include <nuttx/fs/fs.h>
#include <nuttx/sched.h>

#include "inode/inode.h"

Expand Down Expand Up @@ -410,6 +411,11 @@ int lutimens(FAR const char *path, const struct timespec times[2])
int inode_chstat(FAR struct inode *inode,
FAR const struct stat *buf, int flags, int resolve)
{
#ifdef CONFIG_SCHED_USER_IDENTITY
FAR struct tcb_s *rtcb;
uid_t euid;
#endif

DEBUGASSERT(inode != NULL && buf != NULL);

#ifdef CONFIG_PSEUDOFS_SOFTLINKS
Expand Down Expand Up @@ -443,6 +449,28 @@ int inode_chstat(FAR struct inode *inode,
}
#endif

#ifdef CONFIG_SCHED_USER_IDENTITY
rtcb = nxsched_self();
if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL &&
rtcb->group != NULL)
{
euid = rtcb->group->tg_euid;

if ((flags & (CH_STAT_UID | CH_STAT_GID)) != 0 && euid != 0)
{
return -EPERM;
}

#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
if ((flags & CH_STAT_MODE) != 0 &&
euid != 0 && euid != inode->i_owner)
{
return -EPERM;
}
#endif
}
#endif

#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
if (flags & CH_STAT_MODE)
{
Expand Down
Loading