diff --git a/fs/vfs/fs_chstat.c b/fs/vfs/fs_chstat.c index 9b0c50c39339e..1d1828992f5c4 100644 --- a/fs/vfs/fs_chstat.c +++ b/fs/vfs/fs_chstat.c @@ -32,6 +32,7 @@ #include #include +#include #include "inode/inode.h" @@ -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 @@ -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) {