mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 01:05:54 +08:00
binfmt: support euid of process set from the file system
From posix spec, if set-user-ID bit is set in the file permissions, then the effective user ID of the new process shall be set to the user ID of the new process image file. Let's ignore whether ST_NOSUID is set on the mounted file system. https://pubs.opengroup.org/onlinepubs/007904875/functions/exec.html test step: hello example build as a module and call geteuid and getegid API. then set file binary set-user-ID bit on the host. $ chmod +s apps/bin/hello nsh> mount -t hostfs -o fs=. /data nsh> ls -l /data/apps/bin/hello -rwsrwsr-x 1000 1000 9264 /data/apps/bin/hello nsh> /data/apps/bin/hello geteuid:1000 getegid:1000 Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -279,6 +280,18 @@ int exec_module(FAR struct binary_s *binp,
|
||||
|
||||
pid = tcb->cmn.pid;
|
||||
|
||||
#ifdef CONFIG_SCHED_USER_IDENTITY
|
||||
if (binp->mode & S_ISUID)
|
||||
{
|
||||
tcb->cmn.group->tg_euid = binp->uid;
|
||||
}
|
||||
|
||||
if (binp->mode & S_ISGID)
|
||||
{
|
||||
tcb->cmn.group->tg_egid = binp->gid;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then activate the task at the provided priority */
|
||||
|
||||
nxtask_activate((FAR struct tcb_s *)tcb);
|
||||
|
||||
Reference in New Issue
Block a user