This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 25d72077215 fs/vfs: validate chmod and chown callers in inode_chstat()
25d72077215 is described below
commit 25d72077215cdec3b5eb884c7c363d2714ac2725
Author: Abhishek Mishra <[email protected]>
AuthorDate: Wed May 20 07:53:18 2026 +0000
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 <[email protected]>
---
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 <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)
{