This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch releases/13.1
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 23453724255d5a5e0dfcb67213c5136298844a4d
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 12 18:36:57 2026 +0200

    fs/vfs: Keep the set-user-ID, set-group-ID and sticky bits in chmod().
    
    chmod(), lchmod() and fchmod() masked the mode with 0777, so a program
    could not set S_ISUID, S_ISGID or S_ISVTX, although exec() of a binary
    with S_ISUID sets the effective user ID.
    
    Mask the mode with 07777.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 fs/vfs/fs_chstat.c  | 4 ++--
 fs/vfs/fs_fchstat.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/vfs/fs_chstat.c b/fs/vfs/fs_chstat.c
index a8adcb342a3..f4f53ce941f 100644
--- a/fs/vfs/fs_chstat.c
+++ b/fs/vfs/fs_chstat.c
@@ -215,7 +215,7 @@ int chmod(FAR const char *path, mode_t mode)
 {
   struct stat buf;
 
-  buf.st_mode = mode & 0777;
+  buf.st_mode = mode & 07777;
 
   return chstat(path, &buf, CH_STAT_MODE, 1);
 }
@@ -241,7 +241,7 @@ int lchmod(FAR const char *path, mode_t mode)
 {
   struct stat buf;
 
-  buf.st_mode = mode & 0777;
+  buf.st_mode = mode & 07777;
 
   return chstat(path, &buf, CH_STAT_MODE, 0);
 }
diff --git a/fs/vfs/fs_fchstat.c b/fs/vfs/fs_fchstat.c
index fd64700b2b0..2810cade41a 100644
--- a/fs/vfs/fs_fchstat.c
+++ b/fs/vfs/fs_fchstat.c
@@ -221,7 +221,7 @@ int fchmod(int fd, mode_t mode)
 {
   struct stat buf;
 
-  buf.st_mode = mode & 0777;
+  buf.st_mode = mode & 07777;
 
   return fchstat(fd, &buf, CH_STAT_MODE);
 }

Reply via email to