From c7cbee7a3378333e686a06eeacf44805887aa8d5 Mon Sep 17 00:00:00 2001 From: Abhishek Mishra Date: Sat, 3 Oct 2026 09:28:37 +0000 Subject: [PATCH] fs/smartfs: mask reserved flags from stat mode. SMARTFS_DIRENT_RESERVED uses bits that overlap S_ISUID, S_ISGID, and S_ISVTX. smartfs_stat_common() currently clears only S_IFMT, allowing reserved directory-entry flags to appear in st_mode and ls output as setuid and setgid bits. Preserve only SMARTFS_DIRENT_MODE when constructing st_mode. Assisted-by: GPT-5.6 Sol Signed-off-by: Abhishek Mishra --- fs/smartfs/smartfs_smart.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index d473da2eb98..2a4cf132922 100644 --- a/fs/smartfs/smartfs_smart.c +++ b/fs/smartfs/smartfs_smart.c @@ -1047,10 +1047,12 @@ static int smartfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case FIOC_FILEPATH: { FAR char *path = (FAR char *)(uintptr_t)arg; + ret = inode_getpath(inode, path, PATH_MAX); if (ret >= 0) { size_t len = strlen(path); + if (path[len - 1] != '/') { path[len++] = '/'; @@ -2131,9 +2133,12 @@ static void smartfs_stat_common(FAR struct smartfs_mountpt_s *fs, } else { - /* Mask out the file type */ + /* Preserve only the permission bits. The other directory-entry + * flags include SMARTFS_DIRENT_RESERVED, which overlaps the POSIX + * setuid, setgid, and sticky mode bits. + */ - buf->st_mode = entry->flags & ~S_IFMT; + buf->st_mode = entry->flags & SMARTFS_DIRENT_MODE; /* Add the file type based on the SmartFS entry flags */