You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by li...@apache.org on 2026/10/14 07:14:56 UTC
(nuttx) 02/02: fs/vfs: Keep the set-user-ID, set-group-ID and sticky bits in chmod().
This is an automated email from the ASF dual-hosted git repository.
linguini1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5fe5005b7772ac2f9e9d9257cd56603f54971714
Author: Marco Casaroli <ma...@gmail.com>
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 <ma...@gmail.com>
---
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 6fdc6e31a48..e06ce347288 100644
--- a/fs/vfs/fs_chstat.c
+++ b/fs/vfs/fs_chstat.c
@@ -218,7 +218,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);
}
@@ -244,7 +244,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);
}