Skip to content

Commit

Permalink
[Pal] Remove unused host e{u,g}id from PAL structures
Browse files Browse the repository at this point in the history
Signed-off-by: Borys Popławski <borysp@invisiblethingslab.com>
  • Loading branch information
boryspoplawski authored and Dmitrii Kuvaiskii committed Apr 5, 2022
1 parent 832441b commit c56a353
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 42 deletions.
6 changes: 1 addition & 5 deletions Pal/src/host/Linux-SGX/db_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,7 @@ static void do_preheat_enclave(void) {
__attribute_no_stack_protector
noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* uptr_args,
size_t args_size, char* uptr_env, size_t env_size,
int parent_stream_fd, unsigned int host_euid, unsigned int host_egid,
sgx_target_info_t* uptr_qe_targetinfo,
int parent_stream_fd, sgx_target_info_t* uptr_qe_targetinfo,
struct pal_topo_info* uptr_topo_info) {
/* All our arguments are coming directly from the urts. We are responsible to check them. */
int ret;
Expand Down Expand Up @@ -952,9 +951,6 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char*
ocall_exit(1, /*is_exitgroup=*/true);
}

g_pal_linuxsgx_state.host_euid = host_euid;
g_pal_linuxsgx_state.host_egid = host_egid;

/* Set up page allocator and slab manager. There is no need to provide any initial memory pool,
* because the slab manager can use normal allocations (`_DkVirtualMemoryAlloc`) right away. */
init_slab_mgr(/*mem_pool=*/NULL, /*mem_pool_size=*/0);
Expand Down
2 changes: 0 additions & 2 deletions Pal/src/host/Linux-SGX/ecall_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ typedef struct {
char* ms_env;
size_t ms_env_size;
int ms_parent_stream_fd;
unsigned int ms_host_euid;
unsigned int ms_host_egid;
sgx_target_info_t* ms_qe_targetinfo;
struct pal_topo_info* ms_topo_info;

Expand Down
1 change: 0 additions & 1 deletion Pal/src/host/Linux-SGX/enclave_ecalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ void handle_ecall(long ecall_index, void* ecall_args, void* exit_target, void* e
pal_linux_main(READ_ONCE(ms->ms_libpal_uri), READ_ONCE(ms->ms_libpal_uri_len),
READ_ONCE(ms->ms_args), READ_ONCE(ms->ms_args_size), READ_ONCE(ms->ms_env),
READ_ONCE(ms->ms_env_size), READ_ONCE(ms->ms_parent_stream_fd),
READ_ONCE(ms->ms_host_euid), READ_ONCE(ms->ms_host_egid),
READ_ONCE(ms->ms_qe_targetinfo), topo_info);
} else {
// ENCLAVE_START already called (maybe successfully, maybe not), so
Expand Down
7 changes: 1 addition & 6 deletions Pal/src/host/Linux-SGX/pal_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ extern struct pal_linuxsgx_state {
sgx_target_info_t qe_targetinfo; /* received from untrusted host, use carefully */
sgx_report_body_t enclave_info; /* cached self-report result, trusted */

/* These are obviously untrusted, but we use them only for operations on the host. */
unsigned int host_euid;
unsigned int host_egid;

/* remaining heap usable by application */
void* heap_min;
void* heap_max;
Expand All @@ -60,8 +56,7 @@ extern size_t g_pal_internal_mem_size;

noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* uptr_args,
size_t args_size, char* uptr_env, size_t env_size,
int parent_stream_fd, unsigned int host_euid, unsigned int host_egid,
sgx_target_info_t* uptr_qe_targetinfo,
int parent_stream_fd, sgx_target_info_t* uptr_qe_targetinfo,
struct pal_topo_info* uptr_topo_info);
void pal_start_thread(void);

Expand Down
5 changes: 1 addition & 4 deletions Pal/src/host/Linux-SGX/sgx_enclave.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,7 @@ static int start_rpc(size_t threads_cnt) {
}

int ecall_enclave_start(char* libpal_uri, char* args, size_t args_size, char* env,
size_t env_size, int parent_stream_fd, unsigned int host_euid,
unsigned int host_egid, sgx_target_info_t* qe_targetinfo,
size_t env_size, int parent_stream_fd, sgx_target_info_t* qe_targetinfo,
struct pal_topo_info* topo_info) {
g_rpc_queue = NULL;

Expand All @@ -856,8 +855,6 @@ int ecall_enclave_start(char* libpal_uri, char* args, size_t args_size, char* en
ms.ms_env = env;
ms.ms_env_size = env_size;
ms.ms_parent_stream_fd = parent_stream_fd;
ms.ms_host_euid = host_euid;
ms.ms_host_egid = host_egid;
ms.ms_qe_targetinfo = qe_targetinfo;
ms.ms_topo_info = topo_info;
ms.rpc_queue = g_rpc_queue;
Expand Down
4 changes: 2 additions & 2 deletions Pal/src/host/Linux-SGX/sgx_enclave.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "pal_topology.h"

int ecall_enclave_start(char* libpal_uri, char* args, size_t args_size, char* env, size_t env_size,
int parent_stream_fd, unsigned int host_euid, unsigned int host_egid,
sgx_target_info_t* qe_targetinfo, struct pal_topo_info* topo_info);
int parent_stream_fd, sgx_target_info_t* qe_targetinfo,
struct pal_topo_info* topo_info);

int ecall_thread_start(void);

Expand Down
2 changes: 1 addition & 1 deletion Pal/src/host/Linux-SGX/sgx_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz

/* start running trusted PAL */
ecall_enclave_start(enclave->libpal_uri, args, args_size, env, env_size, parent_stream_fd,
DO_SYSCALL(getuid), DO_SYSCALL(getgid), &qe_targetinfo, &topo_info);
&qe_targetinfo, &topo_info);

unmap_tcs();
DO_SYSCALL(munmap, alt_stack, ALT_STACK_SIZE);
Expand Down
21 changes: 2 additions & 19 deletions Pal/src/host/Linux/db_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ char* g_pal_internal_mem_addr = NULL;
const size_t g_page_size = PRESET_PAGESIZE;

static void read_info_from_stack(void* initial_rsp, int* out_argc, const char*** out_argv,
const char*** out_envp, int* out_host_euid, int* out_host_egid,
elf_addr_t* out_sysinfo_ehdr) {
const char*** out_envp, elf_addr_t* out_sysinfo_ehdr) {
/* The stack layout on program entry is:
*
* argc <-- `initial_rsp` points here
Expand All @@ -67,8 +66,6 @@ static void read_info_from_stack(void* initial_rsp, int* out_argc, const char***
const char** e = envp;
for (; *e; e++) {}

bool host_euid_set = false;
bool host_egid_set = false;
*out_sysinfo_ehdr = 0;
for (elf_auxv_t* av = (elf_auxv_t*)(e + 1); av->a_type != AT_NULL; av++) {
switch (av->a_type) {
Expand All @@ -77,22 +74,11 @@ static void read_info_from_stack(void* initial_rsp, int* out_argc, const char***
INIT_FAIL(PAL_ERROR_INVAL, "Unexpected AT_PAGESZ auxiliary vector");
}
break;
case AT_EUID:
*out_host_euid = av->a_un.a_val;
host_euid_set = true;
break;
case AT_EGID:
*out_host_egid = av->a_un.a_val;
host_egid_set = true;
break;
case AT_SYSINFO_EHDR:
*out_sysinfo_ehdr = av->a_un.a_val;
break;
}
}
if (!host_euid_set || !host_egid_set) {
INIT_FAIL(PAL_ERROR_INVAL, "Missing AT_EUID or AT_EGID in auxiliary vector");
}

*out_argc = argc;
*out_argv = argv;
Expand Down Expand Up @@ -199,9 +185,8 @@ noreturn void pal_linux_main(void* initial_rsp, void* fini_callback) {
int argc;
const char** argv;
const char** envp;
int host_euid = -1, host_egid = -1; // has to be set, otherwise GCC erroneously emits a warning
elf_addr_t sysinfo_ehdr;
read_info_from_stack(initial_rsp, &argc, &argv, &envp, &host_euid, &host_egid, &sysinfo_ehdr);
read_info_from_stack(initial_rsp, &argc, &argv, &envp, &sysinfo_ehdr);

if (argc < 4)
print_usage_and_exit(argv[0]); // may be NULL!
Expand Down Expand Up @@ -378,8 +363,6 @@ noreturn void pal_linux_main(void* initial_rsp, void* fini_callback) {
}

g_pal_linux_state.host_pid = DO_SYSCALL(getpid);
g_pal_linux_state.host_euid = host_euid;
g_pal_linux_state.host_egid = host_egid;

PAL_HANDLE parent = NULL;
char* manifest = NULL;
Expand Down
2 changes: 0 additions & 2 deletions Pal/src/host/Linux/pal_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ struct timeval;
extern struct pal_linux_state {
const char** host_environ;
unsigned int host_pid;
unsigned int host_euid;
unsigned int host_egid;
unsigned long memory_quota;
long int (*vdso_clock_gettime)(long int clk, struct timespec* tp);
} g_pal_linux_state;
Expand Down

0 comments on commit c56a353

Please sign in to comment.