mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
fs/vfs: validate chmod and chown callers in inode_chstat()
Add pseudoFS caller validation for chmod and chown operations using the caller's effective uid. Align behavior with POSIX semantics by allowing owner/root chmod and root-only chown. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
This commit is contained in:
parent
0cfa6f1b96
commit
25d7207721
1 changed files with 28 additions and 0 deletions
|
|
@ -32,6 +32,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue