-
Notifications
You must be signed in to change notification settings - Fork 0
Allow for tcb migration of sealed files #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1088,7 +1088,7 @@ Encrypted files | |||||
| :: | ||||||
|
|
||||||
| fs.mounts = [ | ||||||
| { type = "encrypted", path = "[PATH]", uri = "[URI]", key_name = "[KEY_NAME]", enable_recovery = [true|false] }, | ||||||
| { type = "encrypted", path = "[PATH]", uri = "[URI]", key_name = "[KEY_NAME]", enable_recovery = [true|false], allow_tcb_migration = [true|false] }, | ||||||
| ] | ||||||
|
|
||||||
| fs.insecure__keys.[KEY_NAME] = "[32-character hex value]" | ||||||
|
|
@@ -1160,6 +1160,14 @@ or disabling of recovery for different mounted files or directories. Note that | |||||
| enabling this feature can negatively impact performance, as it writes to a | ||||||
| second shadow file for later recovery purposes on each flush. | ||||||
|
|
||||||
| The ``allow_tcb_migration`` mount parameter (default: ``false``) determines whether | ||||||
| the TCB migration feature is enabled for the mount. This feature allows sealed files to | ||||||
| be migrated to latest CPU SVN version after applying microcode updates. This feature | ||||||
| is only valid for ``key_name`` of ``"_sgx_mrenclave"``. Enabling this feature can | ||||||
| negatively impact security, as it allow the enclave to unseal files that were created | ||||||
|
||||||
| negatively impact security, as it allow the enclave to unseal files that were created | |
| negatively impact security, as it allows the enclave to unseal files that were created |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting issue: There are trailing spaces at the end of the line. These should be removed to conform to documentation standards.
| with an old potentially vulnerable CPU SVN version. It is the responsibility of the | |
| with an old potentially vulnerable CPU SVN version. It is the responsibility of the |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -364,6 +364,15 @@ random bits, to obtain an attestation report and quote, etc. | |||||||||||||||
| .. doxygenfunction:: PalGetSpecialKey | ||||||||||||||||
| :project: pal | ||||||||||||||||
|
|
||||||||||||||||
| .. doxygenfunction:: PalGetSpecialKeyForSVN | ||||||||||||||||
| :project: pal | ||||||||||||||||
|
|
||||||||||||||||
|
||||||||||||||||
| .. doxygenfunction:: PalGetCPUSVN | ||||||||||||||||
| :project: pal | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+369
to
+372
|
||||||||||||||||
| .. doxygenfunction:: PalGetCPUSVN | |
| :project: pal | |
| .. doxygenfunction:: PalGetCPUSVN | |
| :project: pal |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "api.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "hex.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "libos_fs_encrypted.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "libos_fs_pseudo.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "pal.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -84,6 +85,21 @@ static int user_report_data_save(struct libos_dentry* dent, const char* data, si | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef DEBUG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int cpu_svn_save(struct libos_dentry* dent, const char* data, size_t size) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_debug("cpu_svn_save: saving %zu bytes", size); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __UNUSED(dent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cpu_svn_t cpu_svn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (size != sizeof(cpu_svn)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_warning("CPU SVN must be exactly %zu bytes, got %zu", sizeof(cpu_svn), size); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return -EINVAL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| memcpy(&cpu_svn, data, sizeof(cpu_svn)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return set_cpu_svn(&cpu_svn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif /* DEBUG */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /*! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * \brief Modify target info used in `report` pseudo-file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -239,6 +255,32 @@ static int quote_load(struct libos_dentry* dent, char** out_data, size_t* out_si | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /*! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * \brief Get CPU SVN of the platform. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int cpu_svn_load(struct libos_dentry* dent, char** out_data, size_t* out_size) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __UNUSED(dent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cpu_svn_t cpu_svn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size_t cpu_svn_size = sizeof(cpu_svn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int ret = PalGetCPUSVN(&cpu_svn, &cpu_svn_size); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ret < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_warning("PalGetCPUSVN failed: %s", pal_strerror(ret)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pal_to_unix_errno(ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| char* str = calloc(1, cpu_svn_size); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return -ENOMEM; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| memcpy(str, &cpu_svn, sizeof(cpu_svn)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *out_data = str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *out_size = cpu_svn_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /*! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * \brief Get remote attestation type used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -264,6 +306,22 @@ static bool key_name_exists(struct libos_dentry* parent, const char* name) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return key != NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static bool key_name_exists_svn(struct libos_dentry* parent, const char* name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __UNUSED(parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (strlen(name) != 2 * sizeof(cpu_svn_t)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_warning("key_name_exists_svn: invalid key name length %zu of %s, expected %zu", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| strlen(name), name, 2 * sizeof(cpu_svn_t)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cpu_svn_t cpu_svn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!hex2bytes((char*)name, strlen(name), &cpu_svn, sizeof(cpu_svn_t))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_warning("key_name_exists_svn: invalid key name format"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct key_list_names_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readdir_callback_t callback; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void* arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -284,6 +342,13 @@ static int key_list_names(struct libos_dentry* parent, readdir_callback_t callba | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return list_encrypted_files_keys(&key_list_names_callback, &data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int key_list_names_svn(struct libos_dentry* parent, readdir_callback_t callback, void* arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __UNUSED(parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __UNUSED(callback); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __UNUSED(arg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int key_load(struct libos_dentry* dent, char** out_data, size_t* out_size) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct libos_encrypted_files_key* key = get_encrypted_files_key(dent->name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!key) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -307,6 +372,58 @@ static int key_load(struct libos_dentry* dent, char** out_data, size_t* out_size | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int key_load_svn(struct libos_dentry* dent, char** out_data, size_t* out_size) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (strlen(dent->name) != 2 * sizeof(cpu_svn_t)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_warning("key_name_exists_svn: invalid key name length"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cpu_svn_t cpu_svn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!hex2bytes((char*)dent->name, strlen(dent->name), &cpu_svn, sizeof(cpu_svn_t))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_warning("key_name_exists_svn: invalid key name format"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+378
to
+384
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | |
| } | |
| cpu_svn_t cpu_svn; | |
| if (!hex2bytes((char*)dent->name, strlen(dent->name), &cpu_svn, sizeof(cpu_svn_t))) { | |
| log_warning("key_name_exists_svn: invalid key name format"); | |
| return false; | |
| return -EINVAL; | |
| } | |
| cpu_svn_t cpu_svn; | |
| if (!hex2bytes((char*)dent->name, strlen(dent->name), &cpu_svn, sizeof(cpu_svn_t))) { | |
| log_warning("key_name_exists_svn: invalid key name format"); | |
| return -EINVAL; |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function returns false (boolean) but the return type is int. The function should return an appropriate integer error code such as -EINVAL instead of false.
| return false; | |
| } | |
| cpu_svn_t cpu_svn; | |
| if (!hex2bytes((char*)dent->name, strlen(dent->name), &cpu_svn, sizeof(cpu_svn_t))) { | |
| log_warning("key_name_exists_svn: invalid key name format"); | |
| return false; | |
| return -EINVAL; | |
| } | |
| cpu_svn_t cpu_svn; | |
| if (!hex2bytes((char*)dent->name, strlen(dent->name), &cpu_svn, sizeof(cpu_svn_t))) { | |
| log_warning("key_name_exists_svn: invalid key name format"); | |
| return -EINVAL; |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after asterisk in pointer declaration. Should be char* key_name = dent->parent->name; instead of char * key_name = dent->parent->name; to be consistent with the codebase style.
| char * key_name = dent->parent->name; | |
| char* key_name = dent->parent->name; |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory allocation redundancy: The key is allocated on line 391, but then the pointer is overwritten by create_encrypted_files_key_for_svn on line 397. This first allocation is unnecessary and causes a memory leak. Remove the initial calloc since create_encrypted_files_key_for_svn creates and returns a new key.
| key = calloc(1, sizeof(*key)); | |
| if (!key) { | |
| log_error("Cannot allocate memory for key"); | |
| ret = -ENOMEM; | |
| goto out; | |
| } |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: if malloc on line 406 fails, the function returns without freeing the previously allocated key structure and its key->name field. The error path cleanup should be reached via goto out instead of an early return.
| if (!buf) | |
| return -ENOMEM; | |
| if (!buf) { | |
| ret = -ENOMEM; | |
| goto out; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting issue: There are two spaces between sentences instead of one. Should be "microcode updates. This feature" with only one space after the period.