elf: handle AT_SECURE

This commit is contained in:
Matheus
2025-11-04 18:46:49 -03:00
parent 5d79c7840d
commit 3308a2a39b
3 changed files with 25 additions and 16 deletions
+2
View File
@@ -28,6 +28,7 @@
#define AT_PHENT 4
#define AT_PHNUM 5
#define AT_ENTRY 9
#define AT_SECURE 23
#define AT_EXECFN 31
typedef struct {
@@ -41,6 +42,7 @@ typedef struct {
auxv64_t phent;
auxv64_t entry;
auxv64_t execfn;
auxv64_t secure;
auxv64_t null;
} auxv64list_t;
+3 -1
View File
@@ -162,7 +162,9 @@ int elf_load(vnode_t *vnode, void *base, void **entry, char **interpreter, auxv6
auxv64->phnum.type = AT_PHNUM;
auxv64->phent.type = AT_PHENT;
auxv64->entry.type = AT_ENTRY;
auxv64->secure.type = AT_SECURE;
auxv64->secure.val = 0; // set later by whoever called elf_load
auxv64->phnum.val = header.phcount;
auxv64->phent.val = header.phsize;
auxv64->entry.val = header.entry + (uintptr_t)base;
+20 -15
View File
@@ -258,12 +258,6 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
VOP_RELEASE(interpnode);
}
stack = elf_preparestack(STACK_TOP, &auxv64, argv, envp, path);
if (stack == NULL) {
ret.errno = ENOMEM;
goto error;
}
vattr_t vattr;
VOP_LOCK(node);
ret.errno = VOP_GETATTR(node, &vattr, NULL);
@@ -271,6 +265,26 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
if (ret.errno)
goto error;
int suid = -1;
int sgid = -1;
if (vattr.mode & V_ATTR_MODE_SUID) {
suid = vattr.uid;
auxv64.secure.val = 1;
}
if (vattr.mode & V_ATTR_MODE_SGID) {
sgid = vattr.gid;
auxv64.secure.val = 1;
}
stack = elf_preparestack(STACK_TOP, &auxv64, argv, envp, path);
if (stack == NULL) {
ret.errno = ENOMEM;
goto error;
}
ret.ret = 0;
proc_stop_other_threads();
@@ -297,15 +311,6 @@ 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(&current_thread()->proc->cred, suid, sgid);
error: