patacongo commented on code in PR #8924:
URL: https://github.com/apache/nuttx/pull/8924#discussion_r1196567365


##########
fs/binfs/fs_binfs.c:
##########
@@ -470,21 +470,35 @@ static int binfs_stat(struct inode *mountpt,
                       const char *relpath, struct stat *buf)
 {
   finfo("Entry\n");
+  int index;
+#ifdef CONFIG_SCHED_USER_IDENTITY
+  int mode;
+#endif
 
   /* The requested directory must be the volume-relative "root" directory */
 
   if (relpath && relpath[0] != '\0')
     {
       /* Check if there is a file with this name. */
 
-      if (builtin_isavail(relpath) < 0)
+      index = builtin_isavail(relpath);
+      if (index < 0)
         {
           return -ENOENT;
         }
 
       /* It's a execute-only file name */
 
       buf->st_mode = S_IFREG | S_IXOTH | S_IXGRP | S_IXUSR;
+
+#ifdef CONFIG_SCHED_USER_IDENTITY
+      buf->st_uid = builtin_getuid(index);
+      buf->st_gid = builtin_getgid(index);
+
+      mode = builtin_getmode(index);
+      buf->st_mode |= (mode & S_ISUID) ? S_ISUID : 0;
+      buf->st_mode |= (mode & S_ISGID) ? S_ISGID : 0;
+#endif

Review Comment:
   This only applies to builtin applications.  Why?  Other applications on file 
systems can support modes too.



##########
sched/group/group_setegid.c:
##########
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * sched/group/group_setegid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <unistd.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <sched/sched.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: setegid
+ *
+ * Description:
+ *   The setegid() function sets the effective group ID of the calling
+ *   process to gid, given appropriate privileges.
+ *
+ * Input Parameters:
+ *   gid - Identity to set the various process's group ID attributes to.
+ *
+ * Returned Value:
+ *   Zero if successful and -1 in case of failure, in which case errno is set
+ *   to one of he following values:
+ *
+ *   EINVAL - The value of the uid argument is invalid and not supported by
+ *            the implementation.
+ *   EPERM  - The process does not have appropriate privileges and uid does
+ *            not match the effective group ID or the saved set-group-ID.
+ *
+ ****************************************************************************/
+
+int setegid(gid_t gid)
+{
+  FAR struct tcb_s *rtcb;
+  FAR struct task_group_s *rgroup;
+
+  /* Verify that the GID is in the valid range of 0 through INT16_MAX.
+   * OpenGroup.org does not specify a GID_MAX or GID_MIN.  Instead we use a
+   * priori knowledge that gid_t is type int16_t.
+   */
+
+  if ((uint16_t)gid > INT16_MAX)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  /* Get the currently executing thread's task group. */
+
+  rtcb   = this_task();
+  rgroup = rtcb->group;
+
+  /* Set the task group's group identity. */
+
+  DEBUGASSERT(rgroup != NULL);
+  rgroup->tg_egid = gid;
+  return OK;

Review Comment:
   Eventually, this needs to be fixed. And unprivileged task should not be 
permitted to change its effective GID.



##########
sched/group/group_seteuid.c:
##########
@@ -0,0 +1,86 @@
+/****************************************************************************
+ * sched/group/group_seteuid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <sched/sched.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: seteuid
+ *
+ * Description:
+ *   The seteuid() function sets the effective user ID of the calling process
+ *   to uid, given appropriate privileges.
+ *
+ * Input Parameters:
+ *   uid - User identity to set the various process's effective user ID
+ *   attributes to.
+ *
+ * Returned Value:
+ *   Zero if successful and -1 in case of failure, in which case errno is set
+ *   to one of he following values:
+ *
+ *   EINVAL - The value of the uid argument is invalid and not supported by
+ *            the implementation.
+ *   EPERM  - The process does not have appropriate privileges and uid does
+ *            not match the effective user ID or the saved set-user-ID.
+ *
+ ****************************************************************************/
+
+int seteuid(uid_t uid)
+{
+  FAR struct tcb_s *rtcb;
+  FAR struct task_group_s *rgroup;
+
+  /* Verify that the UID is in the valid range of 0 through INT16_MAX.
+   * OpenGroup.org does not specify a UID_MAX or UID_MIN.  Instead we use a
+   * priori knowledge that uid_t is type int16_t.
+   */
+
+  if ((uint16_t)uid > INT16_MAX)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  /* Get the currently executing thread's task group. */
+
+  rtcb   = this_task();
+  rgroup = rtcb->group;
+
+  /* Set the task group's group identity. */
+
+  DEBUGASSERT(rgroup != NULL);
+  rgroup->tg_euid = uid;
+  return OK;

Review Comment:
   Eventually, this needs to be fixed. And unprivileged task should not be 
permitted to change its effective GID.



##########
binfmt/builtin.c:
##########
@@ -106,6 +106,12 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
   binp->entrypt   = builtin->main;
   binp->stacksize = builtin->stacksize;
   binp->priority  = builtin->priority;
+#ifdef CONFIG_SCHED_USER_IDENTITY
+  binp->uid       = builtin->uid;
+  binp->gid       = builtin->gid;
+  binp->mode      = builtin->mode;
+#endif

Review Comment:
   For other find system types, it looks like these fields in binp would be 
uninitialized.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to