execve: SUID and SGID

This commit is contained in:
Matheus
2024-08-24 21:53:05 -03:00
parent cd51d4eaf0
commit 4308317ea5
3 changed files with 29 additions and 0 deletions
+16
View File
@@ -262,6 +262,11 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
goto error;
}
vattr_t vattr;
ret.errno = VOP_GETATTR(node, &vattr, NULL);
if (ret.errno)
goto error;
ret.ret = 0;
sched_stopotherthreads();
@@ -281,6 +286,17 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
CTX_SP(context) = (uint64_t)stack;
CTX_IP(context) = (uint64_t)entry;
int suid = -1;
int sgid = -1;
if (vattr.mode & V_ATTR_MODE_SUID)
suid = vattr.uid;
if (vattr.mode & V_ATTR_MODE_SGID)
sgid = vattr.gid;
cred_doexec(&_cpu()->thread->proc->cred, suid, sgid);
error:
free(path);
if (argv)