Skip to content

Commit 50794dd

Browse files
committed
fixup! fixup! [LibOS] Test-cases for SPLRB (2)
Signed-off-by: g2flyer <[email protected]>
1 parent 4201693 commit 50794dd

File tree

10 files changed

+59
-45
lines changed

10 files changed

+59
-45
lines changed

libos/test/fs/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tests = {
4242
},
4343
'open_close': {},
4444
'open_flags': {},
45+
'pf_rollback': {},
4546
'read_write': {},
4647
'read_write_mmap': {},
4748
'seek_tell': {},
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919
#include <unistd.h>
2020

2121
#include "common.h"
22-
#include "rw_file.h"
22+
23+
/* TODO (MST): this is "borrowed" from common/include/api.h. replace below with `#include "api.h"`
24+
* once i figured out how to fix the meson.build files .... */
25+
#define __UNUSED(x) \
26+
do { \
27+
(void)(x); \
28+
} while (0)
2329

2430
static const char message1[] = "first message\n";
2531
static const size_t message1_len = sizeof(message1) - 1;
@@ -57,19 +63,25 @@ static int create_file(const char* path, const char* str, size_t len) {
5763
/* dummy functions which are gdb break-point targets */
5864
#pragma GCC push_options
5965
#pragma GCC optimize("O0")
60-
static void adversary_save_file(const char* path) {}
61-
static void adversary_reset_file(const char* path) {}
62-
static void adversary_delete_file(const char* path) {}
66+
static void adversary_save_file(const char* path) {
67+
__UNUSED(path); /* neeed in gdb though! */
68+
}
69+
static void adversary_reset_file(const char* path) {
70+
__UNUSED(path); /* neeed in gdb though! */
71+
}
72+
static void adversary_delete_file(const char* path) {
73+
__UNUSED(path); /* neeed in gdb though! */
74+
}
6375
#pragma GCC pop_options
6476

6577
#define test_report(result) printf("%s: %s\n", result, __func__)
6678

6779
static void test_open_pre_existing(const char* path1, const char* path2) {
6880
int fd = open(path1, O_RDWR);
6981
if (fd < 0) {
70-
test_report("OK");
71-
} else {
7282
test_report("FAIL");
83+
} else {
84+
test_report("OK");
7385
}
7486
}
7587

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ python
1515
test_function=gdb.selected_frame().older().name()
1616
operation=gdb.selected_frame().name()
1717
internal_path=gdb.selected_frame().read_var('path').string()
18-
external_path=re.sub(r'/tmp_enc/pm_[^/]*/', './tmp_enc/', internal_path)
18+
external_path=re.sub(r'/tmp/enc_input/', './tmp/enc_input/', internal_path)
1919
external_path_saved=external_path+"._saved_"
2020

2121
# execute and report result for pytest digestion
@@ -37,7 +37,7 @@ python
3737
test_function=gdb.selected_frame().older().name()
3838
operation=gdb.selected_frame().name()
3939
internal_path=gdb.selected_frame().read_var('path').string()
40-
external_path=re.sub(r'/tmp_enc/pm_[^/]*/', './tmp_enc/', internal_path)
40+
external_path=re.sub(r'/tmp/enc_input/', './tmp/enc_input/', internal_path)
4141
external_path_saved=external_path+"._saved_"
4242

4343
# execute and report result for pytest digestion
@@ -59,7 +59,7 @@ python
5959
test_function=gdb.selected_frame().older().name()
6060
operation=gdb.selected_frame().name()
6161
internal_path=gdb.selected_frame().read_var('path').string()
62-
external_path=re.sub(r'/tmp_enc/pm_[^/]*/', './tmp_enc/', internal_path)
62+
external_path=re.sub(r'/tmp/enc_input/', './tmp/enc_input/', internal_path)
6363
external_path_saved=external_path+"._saved_"
6464

6565
# execute and report result for pytest digestion

libos/test/regression/pf_rollback.manifest.template renamed to libos/test/fs/pf_rollback.manifest.template

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
loader.entrypoint = "file:{{ gramine.libos }}"
2+
loader.log_level ="trace" # DEBUG
23
libos.entrypoint = "{{ entrypoint }}"
34

45
loader.env.LD_LIBRARY_PATH = "/lib:{{ arch_libdir }}:/usr/{{ arch_libdir }}"
@@ -9,9 +10,9 @@ fs.mounts = [
910
{ path = "/{{ entrypoint }}", uri = "file:{{ binary_dir }}/{{ entrypoint }}" },
1011
{ path = "/bin", uri = "file:/bin" },
1112

12-
{ type = "encrypted", protection_mode = "strict", path = "/tmp_enc/pm_strict", uri = "file:tmp_enc", key_name = "my_custom_key" },
13-
{ type = "encrypted", protection_mode = "non-strict", path = "/tmp_enc/pm_non_strict", uri = "file:tmp_enc", key_name = "my_custom_key" },
14-
{ type = "encrypted", protection_mode = "none", path = "/tmp_enc/pm_none", uri = "file:tmp_enc", key_name = "my_custom_key" },
13+
{ type = "encrypted", protection_mode = "strict", path = "/tmp/enc_input/pm_strict", uri = "file:tmp/enc_input/pn_strict" },
14+
{ type = "encrypted", protection_mode = "non-strict", path = "/tmp/enc_input/pm_non_strict", uri = "file:tmp/enc_input/pm_non_strict" },
15+
{ type = "encrypted", protection_mode = "none", path = "/tmp/enc_input/pm_none", uri = "file:tmp/enc_input/pm_none" },
1516
]
1617

1718
sgx.max_threads = {{ '1' if env.get('EDMM', '0') == '1' else '16' }}
@@ -27,4 +28,3 @@ sgx.trusted_files = [
2728

2829
# See the `keys.c` test.
2930
fs.insecure__keys.default = "ffeeddccbbaa99887766554433221100"
30-
fs.insecure__keys.my_custom_key = "00112233445566778899aabbccddeeff"

libos/test/fs/test_enc.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,35 @@ def test_500_invalid(self):
238238
else:
239239
print('[!] Fail: successfully decrypted file: ' + name)
240240
self.fail()
241+
242+
def test_600_gdb_pf_rollback(self):
243+
# To run this test manually, encrypt a <file1> with the default key from manifest and use:
244+
# GDB=1 GDB_SCRIPT=pf_rollback.gdb gramine-[sgx|direct] pf_rollback <file1> <file2>
245+
#
246+
# This test checks rollback protection.
247+
# TODO (MST): loop for /pm_strict, /pm_non_strict & /pm_none
248+
try:
249+
mode_dir = self.ENCRYPTED_DIR + "/pm_strict"
250+
os.mkdir(mode_dir)
251+
file1 = mode_dir + "/file1"
252+
file2 = mode_dir + "/file2"
253+
self.__encrypt_file(self.INPUT_FILES[-1], file1)
254+
self.__encrypt_file(self.INPUT_FILES[-1], file2) # DEBUG: remove me eventually
255+
stdout, _ = self.run_gdb(['pf_rollback', file1, file2], 'pf_rollback.gdb', hide_tty=False)
256+
# TODO (MST): This test is not yet implemented.
257+
# - define expected sequence for each test
258+
259+
# - test_open_pre_existing
260+
self.assertIn('FAIL: test_open_pre_existing', stdout)
261+
# - test_test # DEBUG: remove me eventually
262+
self.assertIn('OK: test_test in adversary_save_file', stdout)
263+
self.assertIn('OK: test_test in adversary_reset_file', stdout)
264+
self.assertIn(f'OK: test_test in adversary_delete_file({file1})', stdout)
265+
self.assertIn(f'OK: test_test in adversary_delete_file({file2})', stdout)
266+
self.assertIn('EXITING GDB WITHOUT A GRAMINE ERROR', stdout)
267+
self.assertNotIn('EXITING GDB WITH A GRAMINE ERROR', stdout)
268+
finally:
269+
# restore the trusted file contents (modified by the GDB script in this test)
270+
with open('fork_and_access_file_testfile', 'w') as f:
271+
f.write('fork_and_access_file_testfile')
272+

libos/test/fs/tests.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ manifests = [
1313
"multiple_writers",
1414
"open_close",
1515
"open_flags",
16+
"pf_rollback",
1617
"read_write",
1718
"read_write_mmap",
1819
"seek_tell",

libos/test/regression/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ tests = {
8484
'c_args': '-fopenmp',
8585
'link_args': '-fopenmp',
8686
},
87-
'pf_rollback': {},
8887
'pipe': {},
8988
'pipe_nonblocking': {},
9089
'pipe_ocloexec': {},

libos/test/regression/test_libos.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,35 +1385,6 @@ def test_020_gdb_fork_and_access_file_bug(self):
13851385
with open('fork_and_access_file_testfile', 'w') as f:
13861386
f.write('fork_and_access_file_testfile')
13871387

1388-
# TODO: move me to fs so i can benefit from plumbug from TC_50_EncryptedFiles
1389-
def test_030_gdb_pf_rollback(self):
1390-
# To run this test manually, use:
1391-
# GDB=1 GDB_SCRIPT=pf_rollback.gdb gramine-[sgx|direct] pf_rollback <file1> <file2>
1392-
#
1393-
# This test checks rollback protection.
1394-
try:
1395-
file1='/tmp_enc/pm_strict/file1'
1396-
file2='/tmp_enc/pm_strict/file2'
1397-
# TODO (MST): pre-create a version of file1
1398-
stdout, _ = self.run_gdb(['pf_rollback', file1, file2], 'pf_rollback.gdb')
1399-
# TODO (MST): This test is not yet implemented.
1400-
# - loop for /tmp_enc/pm_strict, /tmp_enc/pm_non_strict, /tmp_enc/pm_none
1401-
# - define expected sequence for each test
1402-
1403-
# - test_open_pre_existing
1404-
self.assertIn('FAIL: test_open_pre_existing', stdout)
1405-
# - test_test
1406-
self.assertIn('OK: test_test in adversary_save_file', stdout)
1407-
self.assertIn('OK: test_test in adversary_reset_file', stdout)
1408-
self.assertIn(f'OK: test_test in adversary_delete_file({file1})', stdout)
1409-
self.assertIn(f'OK: test_test in adversary_delete_file({file2})', stdout)
1410-
self.assertIn('EXITING GDB WITHOUT A GRAMINE ERROR', stdout)
1411-
self.assertNotIn('EXITING GDB WITH A GRAMINE ERROR', stdout)
1412-
finally:
1413-
# restore the trusted file contents (modified by the GDB script in this test)
1414-
with open('fork_and_access_file_testfile', 'w') as f:
1415-
f.write('fork_and_access_file_testfile')
1416-
14171388
class TC_80_Socket(RegressionTestCase):
14181389
def test_000_getsockopt(self):
14191390
stdout, _ = self.run_binary(['getsockopt'])

libos/test/regression/tests.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ manifests = [
8383
"munmap",
8484
"open_opath",
8585
"openmp",
86-
"pf_rollback",
8786
"pipe",
8887
"pipe_nonblocking",
8988
"pipe_ocloexec",

libos/test/regression/tests_musl.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ manifests = [
8585
"munmap",
8686
"open_opath",
8787
"openmp",
88-
"pf_rollback",
8988
"pipe",
9089
"pipe_nonblocking",
9190
"pipe_ocloexec",

0 commit comments

Comments
 (0)