Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.

Commit 4cb9821

Browse files
[Pal] Remove unused parent pid from various structures
Signed-off-by: Borys Popławski <[email protected]>
1 parent 9abe0d8 commit 4cb9821

File tree

8 files changed

+7
-24
lines changed

8 files changed

+7
-24
lines changed

Pal/src/host/Linux-SGX/db_main.c

+2-10
Original file line numberDiff line numberDiff line change
@@ -584,15 +584,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char*
584584

585585
/* For {p,u,g}ids we can at least do some minimal checking. */
586586

587-
/* ppid should be positive when interpreted as signed. It's 0 if we don't
588-
* have a graphene parent process. */
589-
if (sec_info.ppid > INT32_MAX) {
590-
log_error("Invalid sec_info.ppid: %u", sec_info.ppid);
591-
ocall_exit(1, /*is_exitgroup=*/true);
592-
}
593-
g_pal_sec.ppid = sec_info.ppid;
594-
595-
/* As ppid but we always have a pid, so 0 is invalid. */
587+
/* pid should be positive when interpreted as signed. */
596588
if (sec_info.pid > INT32_MAX || sec_info.pid == 0) {
597589
log_error("Invalid sec_info.pid: %u", sec_info.pid);
598590
ocall_exit(1, /*is_exitgroup=*/true);
@@ -670,7 +662,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char*
670662
/* if there is a parent, create parent handle */
671663
PAL_HANDLE parent = NULL;
672664
uint64_t instance_id = 0;
673-
if (g_pal_sec.ppid) {
665+
if (g_pal_sec.stream_fd != PAL_IDX_POISON) {
674666
if ((ret = init_child_process(&parent, &instance_id)) < 0) {
675667
log_error("Failed to initialize child process: %d", ret);
676668
ocall_exit(1, /*is_exitgroup=*/true);

Pal/src/host/Linux-SGX/pal_linux.h

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#define IS_UNIX_ERR INTERNAL_SYSCALL_ERRNO_RANGE
3030

3131
extern struct pal_linux_state {
32-
PAL_NUM parent_process_id;
3332
PAL_NUM process_id;
3433

3534
const char** host_environ;

Pal/src/host/Linux-SGX/pal_security.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef char PAL_SEC_STR[255];
1313

1414
struct pal_sec {
1515
/* host credentials */
16-
PAL_IDX ppid, pid, uid, gid;
16+
PAL_IDX pid, uid, gid;
1717

1818
/* enclave information */
1919
sgx_target_info_t qe_targetinfo;
@@ -25,7 +25,8 @@ struct pal_sec {
2525
/* remaining heap usable by application */
2626
PAL_PTR heap_min, heap_max;
2727

28-
/* child's stream FD created and sent over by parent */
28+
/* Child's stream FD created and sent over by parent.
29+
* If set to `PAL_IDX_POISON`, we have no parent (this is the first process). */
2930
PAL_IDX stream_fd;
3031

3132
PAL_NUM online_logical_cores;

Pal/src/host/Linux-SGX/sgx_main.c

+2
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,8 @@ int main(int argc, char* argv[], char* envp[]) {
10871087
print_usage_and_exit(argv[0]);
10881088
}
10891089

1090+
g_pal_enclave.pal_sec.stream_fd = PAL_IDX_POISON;
1091+
10901092
if (first_process) {
10911093
g_pal_enclave.is_first_process = true;
10921094

Pal/src/host/Linux-SGX/sgx_process.c

-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ extern char* g_pal_loader_path;
2525
extern char* g_libpal_path;
2626

2727
struct proc_args {
28-
unsigned int parent_process_id;
2928
int stream_fd;
3029
size_t application_path_size; // application path will follow this struct on the pipe.
3130
size_t manifest_size; // manifest will follow application path on the pipe.
@@ -99,9 +98,7 @@ int sgx_create_process(size_t nargs, const char** args, int* stream_fd, const ch
9998
/* TODO: add error checking. */
10099
INLINE_SYSCALL(close, 1, fds[0]); /* child stream */
101100

102-
struct pal_sec* pal_sec = &g_pal_enclave.pal_sec;
103101
struct proc_args proc_args;
104-
proc_args.parent_process_id = pal_sec->pid;
105102
proc_args.stream_fd = fds[0];
106103
proc_args.application_path_size = strlen(g_pal_enclave.application_path);
107104
proc_args.manifest_size = strlen(manifest);
@@ -191,7 +188,6 @@ int sgx_init_child_process(int parent_pipe_fd, struct pal_sec* pal_sec, char** a
191188
goto out;
192189
}
193190

194-
pal_sec->ppid = proc_args.parent_process_id;
195191
pal_sec->stream_fd = proc_args.stream_fd;
196192

197193
*application_path_out = application_path;

Pal/src/host/Linux/db_main.c

-3
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,6 @@ noreturn void pal_linux_main(void* initial_rsp, void* fini_callback) {
265265
g_linux_state.gid = g_gid;
266266
g_linux_state.process_id = g_linux_state.pid;
267267

268-
if (!g_linux_state.parent_process_id)
269-
g_linux_state.parent_process_id = g_linux_state.process_id;
270-
271268
PAL_HANDLE parent = NULL;
272269
char* manifest = NULL;
273270
uint64_t instance_id = 0;

Pal/src/host/Linux/db_process.c

-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ struct proc_param {
9494
};
9595

9696
struct proc_args {
97-
PAL_NUM parent_process_id;
9897
uint64_t instance_id;
9998
struct pal_sec pal_sec;
10099

@@ -168,7 +167,6 @@ int _DkProcessCreate(PAL_HANDLE* handle, const char** args) {
168167
}
169168

170169
proc_args->instance_id = g_pal_state.instance_id;
171-
proc_args->parent_process_id = g_linux_state.parent_process_id;
172170
memcpy(&proc_args->pal_sec, &g_pal_sec, sizeof(struct pal_sec));
173171
proc_args->memory_quota = g_linux_state.memory_quota;
174172

@@ -286,7 +284,6 @@ void init_child_process(int parent_pipe_fd, PAL_HANDLE* parent_handle, char** ma
286284
manifest[proc_args.manifest_data_size] = '\0';
287285
data_iter += proc_args.manifest_data_size;
288286

289-
g_linux_state.parent_process_id = proc_args.parent_process_id;
290287
g_linux_state.memory_quota = proc_args.memory_quota;
291288
memcpy(&g_pal_sec, &proc_args.pal_sec, sizeof(struct pal_sec));
292289

Pal/src/host/Linux/pal_linux.h

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ struct timespec;
3131
struct timeval;
3232

3333
extern struct pal_linux_state {
34-
PAL_NUM parent_process_id;
3534
PAL_NUM process_id;
3635

3736
#ifdef DEBUG

0 commit comments

Comments
 (0)