mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
elf: handle AT_SECURE
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#define AT_PHENT 4
|
#define AT_PHENT 4
|
||||||
#define AT_PHNUM 5
|
#define AT_PHNUM 5
|
||||||
#define AT_ENTRY 9
|
#define AT_ENTRY 9
|
||||||
|
#define AT_SECURE 23
|
||||||
#define AT_EXECFN 31
|
#define AT_EXECFN 31
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -41,6 +42,7 @@ typedef struct {
|
|||||||
auxv64_t phent;
|
auxv64_t phent;
|
||||||
auxv64_t entry;
|
auxv64_t entry;
|
||||||
auxv64_t execfn;
|
auxv64_t execfn;
|
||||||
|
auxv64_t secure;
|
||||||
auxv64_t null;
|
auxv64_t null;
|
||||||
} auxv64list_t;
|
} auxv64list_t;
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,9 @@ int elf_load(vnode_t *vnode, void *base, void **entry, char **interpreter, auxv6
|
|||||||
auxv64->phnum.type = AT_PHNUM;
|
auxv64->phnum.type = AT_PHNUM;
|
||||||
auxv64->phent.type = AT_PHENT;
|
auxv64->phent.type = AT_PHENT;
|
||||||
auxv64->entry.type = AT_ENTRY;
|
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->phnum.val = header.phcount;
|
||||||
auxv64->phent.val = header.phsize;
|
auxv64->phent.val = header.phsize;
|
||||||
auxv64->entry.val = header.entry + (uintptr_t)base;
|
auxv64->entry.val = header.entry + (uintptr_t)base;
|
||||||
|
|||||||
@@ -258,12 +258,6 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
|
|||||||
VOP_RELEASE(interpnode);
|
VOP_RELEASE(interpnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
stack = elf_preparestack(STACK_TOP, &auxv64, argv, envp, path);
|
|
||||||
if (stack == NULL) {
|
|
||||||
ret.errno = ENOMEM;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
vattr_t vattr;
|
vattr_t vattr;
|
||||||
VOP_LOCK(node);
|
VOP_LOCK(node);
|
||||||
ret.errno = VOP_GETATTR(node, &vattr, NULL);
|
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)
|
if (ret.errno)
|
||||||
goto error;
|
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;
|
ret.ret = 0;
|
||||||
|
|
||||||
proc_stop_other_threads();
|
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_SP(context) = (uint64_t)stack;
|
||||||
CTX_IP(context) = (uint64_t)entry;
|
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(¤t_thread()->proc->cred, suid, sgid);
|
cred_doexec(¤t_thread()->proc->cred, suid, sgid);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|||||||
Reference in New Issue
Block a user