You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2020/06/04 02:45:20 UTC

[incubator-teaclave] branch master updated: [protected_fs] Fix rename_meta and get_current_meta_gmac, add mutex synchronization (#336)

This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git


The following commit(s) were added to refs/heads/master by this push:
     new ea2df91  [protected_fs] Fix rename_meta and get_current_meta_gmac, add mutex synchronization (#336)
ea2df91 is described below

commit ea2df9140945f8a5f81f3c6f7572f262960e0562
Author: volcano <vo...@163.com>
AuthorDate: Thu Jun 4 10:45:12 2020 +0800

    [protected_fs] Fix rename_meta and get_current_meta_gmac, add mutex synchronization (#336)
---
 .../protected_fs_c/sgx_tprotected_fs/file_other.cpp   | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/common/protected_fs_rs/protected_fs_c/sgx_tprotected_fs/file_other.cpp b/common/protected_fs_rs/protected_fs_c/sgx_tprotected_fs/file_other.cpp
index c0b1b80..62b240b 100644
--- a/common/protected_fs_rs/protected_fs_c/sgx_tprotected_fs/file_other.cpp
+++ b/common/protected_fs_rs/protected_fs_c/sgx_tprotected_fs/file_other.cpp
@@ -391,40 +391,50 @@ int32_t protected_fs_file::clear_cache()
 }
 
 
-int32_t protected_fs_file::get_current_meta_gmac(sgx_aes_gcm_128bit_tag_t out_gmac) {
+int32_t protected_fs_file::get_current_meta_gmac(sgx_aes_gcm_128bit_tag_t out_gmac)
+{
+	sgx_thread_mutex_lock(&mutex);
+
 	if (out_gmac == NULL) {
 		last_error = EINVAL;
+		sgx_thread_mutex_unlock(&mutex);
 		return -1;
 	}
 
-	sgx_thread_mutex_lock(&mutex);
 	memcpy(out_gmac, file_meta_data.plain_part.meta_data_gmac, sizeof(sgx_aes_gcm_128bit_tag_t));
 	sgx_thread_mutex_unlock(&mutex);
 	return 0;
 }
 
 
-int32_t protected_fs_file::rename_meta(const char* old_name, const char* new_name) {
+int32_t protected_fs_file::rename_meta(const char* old_name, const char* new_name)
+{
+	sgx_thread_mutex_lock(&mutex);
+
 	if ((old_name == NULL) || (new_name == NULL)) {
 		last_error = EINVAL;
+		sgx_thread_mutex_unlock(&mutex);
 		return -1;
 	}
 
 	if (strnlen(old_name, FILENAME_MAX_LEN) >= FILENAME_MAX_LEN-1)
 	{
 		last_error = ENAMETOOLONG;
+		sgx_thread_mutex_unlock(&mutex);
 		return -1;
 	}
 
 	if (strnlen(new_name, FILENAME_MAX_LEN) >= FILENAME_MAX_LEN-1)
 	{
 		last_error = ENAMETOOLONG;
+		sgx_thread_mutex_unlock(&mutex);
 		return -1;
 	}
 
 	if (strncmp(old_name, encrypted_part_plain.clean_filename, FILENAME_MAX_LEN) != 0)
 	{
 		last_error = SGX_ERROR_FILE_NAME_MISMATCH;
+		sgx_thread_mutex_unlock(&mutex);
 		return -1;
 	}
 
@@ -434,7 +444,10 @@ int32_t protected_fs_file::rename_meta(const char* old_name, const char* new_nam
 	bool success = internal_flush(true);
 	if (success == false) {
 		last_error = SGX_ERROR_FILE_FLUSH_FAILED;
+		sgx_thread_mutex_unlock(&mutex);
 		return -1;
 	}
+
+	sgx_thread_mutex_unlock(&mutex);
 	return 0;
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org