From 25d72077215cdec3b5eb884c7c363d2714ac2725 Mon Sep 17 00:00:00 2001 From: Abhishek Mishra Date: Wed, 20 May 2026 07:53:18 +0000 Subject: [PATCH] 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 --- fs/vfs/fs_chstat.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fs/vfs/fs_chstat.c b/fs/vfs/fs_chstat.c index 9b0c50c3933..1d1828992f5 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) {