-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAL/Linux-SGX] Fix Trusted Files degenerating to Allowed Files on fork
Previously, Trusted Files feature had the following bug: after fork, the metadata of currently-opened-in-parent-process TFs (SHA256 hashes for each chunk of the file) was not available in the child SGX enclave. This effectively degenerated all currently-opened TFs into Allowed Files, and thus the child enclave lost integrity guarantees in these TFs. An attacker could substitute the TF contents on the storage with arbitrary code/data, and the child enclave would not notice this. This bug was exposed only in the child process (child SGX enclave) and only in these scenarios: - fork without execve: the child continues reading from one of the file descriptors pointing to a trusted file opened before `fork()`; - fork with execve: the child reads from an inherited file descriptor pointing to a trusted file. This commit also adds a test to verify this bug is fixed. Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
- Loading branch information
Dmitrii Kuvaiskii
committed
Mar 7, 2024
1 parent
95020e1
commit d82e885
Showing
13 changed files
with
192 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
/* Copyright (C) 2024 Intel Corporation */ | ||
|
||
#include <err.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
|
||
#include "common.h" | ||
#include "rw_file.h" | ||
|
||
#define FILENAME "fork_and_access_file_testfile" | ||
#define MAX_BUF_SIZE 256 | ||
|
||
char g_parent_buf[MAX_BUF_SIZE]; | ||
char g_child_buf[MAX_BUF_SIZE]; | ||
|
||
int main(void) { | ||
int fd = CHECK(open(FILENAME, O_RDONLY)); | ||
|
||
ssize_t parent_read_ret = CHECK(posix_fd_read(fd, g_parent_buf, sizeof(g_parent_buf))); | ||
CHECK(lseek(fd, 0, SEEK_SET)); | ||
|
||
pid_t p = CHECK(fork()); | ||
if (p == 0) { | ||
ssize_t child_read_ret = CHECK(posix_fd_read(fd, g_child_buf, sizeof(g_child_buf))); | ||
if (child_read_ret != parent_read_ret || | ||
memcmp(g_child_buf, g_parent_buf, child_read_ret)) { | ||
errx(1, "child read data different from what parent read"); | ||
} | ||
exit(0); | ||
} | ||
|
||
int status = 0; | ||
CHECK(wait(&status)); | ||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) | ||
errx(1, "child died with status: %#x", status); | ||
|
||
CHECK(close(fd)); | ||
puts("TEST OK"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
set breakpoint pending on | ||
set pagination off | ||
set backtrace past-main on | ||
|
||
# We want to check what happens in the child process after fork() | ||
set follow-fork-mode child | ||
|
||
# Cannot detach after fork because of some bug in SGX version of GDB (GDB would segfault) | ||
set detach-on-fork off | ||
|
||
tbreak fork | ||
commands | ||
echo BREAK ON FORK\n | ||
|
||
shell echo "WRITING NEW CONTENT IN FORK_AND_ACCESS_FILE_TESTFILE" > fork_and_access_file_testfile | ||
|
||
tbreak die_or_inf_loop | ||
commands | ||
echo EXITING GDB WITH A GRAMINE ERROR\n | ||
quit | ||
end | ||
|
||
tbreak exit | ||
commands | ||
echo EXITING GDB WITHOUT A GRAMINE ERROR\n | ||
quit | ||
end | ||
|
||
continue | ||
end | ||
|
||
run |
20 changes: 20 additions & 0 deletions
20
libos/test/regression/fork_and_access_file.manifest.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
loader.entrypoint = "file:{{ gramine.libos }}" | ||
libos.entrypoint = "{{ entrypoint }}" | ||
|
||
loader.env.LD_LIBRARY_PATH = "/lib" | ||
|
||
fs.mounts = [ | ||
{ path = "/lib", uri = "file:{{ gramine.runtimedir(libc) }}" }, | ||
{ path = "/{{ entrypoint }}", uri = "file:{{ binary_dir }}/{{ entrypoint }}" }, | ||
] | ||
|
||
sgx.max_threads = {{ '1' if env.get('EDMM', '0') == '1' else '16' }} | ||
sgx.debug = true | ||
sgx.edmm_enable = {{ 'true' if env.get('EDMM', '0') == '1' else 'false' }} | ||
|
||
sgx.trusted_files = [ | ||
"file:{{ gramine.libos }}", | ||
"file:{{ gramine.runtimedir(libc) }}/", | ||
"file:{{ binary_dir }}/{{ entrypoint }}", | ||
"file:fork_and_access_file_testfile", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fork_and_access_file_testfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters