Merge "Remove dead code related to downloadable TA" into tizen
authorPiotr Sawicki <p.sawicki2@partner.samsung.com>
Thu, 23 Nov 2017 14:42:26 +0000 (14:42 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 23 Nov 2017 14:42:26 +0000 (14:42 +0000)
TEECLib/src/teec_api.c
log/log.c
log/log.h
packaging/tef-simulator.spec
simulatordaemon/inc/TEEContext.h
simulatordaemon/src/ConnectionSession.cpp
simulatordaemon/src/TEEContext.cpp

index a3c0c71..d1f68c8 100644 (file)
@@ -267,6 +267,42 @@ static uint32_t checkContext(TEEC_Context *context)
        return found;
 }
 
+TEEC_Result tempSharedMemAllocate(TEEC_SharedMemory** tmpSharedMem, uint32_t type,
+                                                                 TEEC_Context* context, TEEC_Parameter param)
+{
+       TEEC_Result result;
+       *tmpSharedMem = (TEEC_SharedMemory *)OsaMalloc(sizeof(TEEC_SharedMemory));
+       (*tmpSharedMem)->size = param.tmpref.size;
+       (*tmpSharedMem)->buffer = param.tmpref.buffer;
+
+       (*tmpSharedMem)->flags = type & (TEEC_MEM_INPUT | TEEC_MEM_OUTPUT);
+
+       result = TEEC_RegisterSharedMemory(context, *tmpSharedMem);
+
+       if (result != TEEC_SUCCESS) {
+               if (*tmpSharedMem) {
+                       OsaFree(*tmpSharedMem);
+                       *tmpSharedMem = NULL;
+               }
+               return result;
+       }
+
+       if (type & TEEC_MEMREF_TEMP_INPUT) {
+               memcpy(((TEEC_SharedMemoryImp *)(*tmpSharedMem)->imp)->allocPtr,
+               (*tmpSharedMem)->buffer, (*tmpSharedMem)->size);
+       }
+       return result;
+}
+
+void tempSharedMemoryDeallocate(TEEC_SharedMemory** tmpSharedMem)
+{
+       if (*tmpSharedMem) {
+               TEEC_ReleaseSharedMemory(*tmpSharedMem);
+               OsaFree(*tmpSharedMem);
+               *tmpSharedMem = NULL;
+       }
+}
+
 /*
  * ===  FUNCTION  ======================================================================
  *         Name:  preProcessOperation
@@ -339,38 +375,10 @@ static TEEC_Result preProcessOperation(TEEC_Session *session,
                        op->paramTypes |= type << (8 * i);
 
                        if (!tmpSharedMem[i]) {
-                               tmpSharedMem[i] = (TEEC_SharedMemory *)OsaMalloc(
-                                                                         sizeof(TEEC_SharedMemory));
-                               tmpSharedMem[i]->size = operation->params[i].tmpref.size;
-                               tmpSharedMem[i]->buffer = operation->params[i].tmpref.buffer;
-
-                               if (type == TEEC_MEMREF_TEMP_INPUT)
-                                       tmpSharedMem[i]->flags = TEEC_MEM_INPUT;
-
-                               else if (type == TEEC_MEMREF_TEMP_OUTPUT)
-                                       tmpSharedMem[i]->flags = TEEC_MEM_OUTPUT;
-
-                               else if (type == TEEC_MEMREF_TEMP_INOUT)
-                                       tmpSharedMem[i]->flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
-
-                               result = TEEC_RegisterSharedMemory(
-                                                        ((TEEC_SessionImp *)session->imp)->context, tmpSharedMem[i]);
-
-                               if (result != TEEC_SUCCESS) {
-                                       for (i = 0; i < 4; i++) {
-                                               if (tmpSharedMem[i]) {
-                                                       OsaFree(tmpSharedMem[i]);
-                                                       tmpSharedMem[i] = NULL;
-                                               }
-                                       }
-
-                                       return result;
-                               }
-
-                               if (type & TEEC_MEMREF_TEMP_INPUT) {
-                                       memcpy(((TEEC_SharedMemoryImp *)tmpSharedMem[i]->imp)->allocPtr,
-                                                  tmpSharedMem[i]->buffer, tmpSharedMem[i]->size);
-                               }
+                               result = tempSharedMemAllocate(&tmpSharedMem[i], type,
+                                       ((TEEC_SessionImp *)session->imp)->context, operation->params[i]);
+                               if (result != TEEC_SUCCESS)
+                                       goto cleanup;
                        }
 
                        op->params[i].mem.size = tmpSharedMem[i]->size;
@@ -380,25 +388,19 @@ static TEEC_Result preProcessOperation(TEEC_Session *session,
                        break;
 
                case TEEC_MEMREF_WHOLE:
-                       op->paramTypes |= TEE_PARAM_TYPE_MEMREF_INOUT << (8 * i);
                        memref = &operation->params[i].memref;
 
                        if ((NULL == memref) || (NULL == memref->parent)
                                        || (((TEEC_SharedMemoryImp *)memref->parent->imp)->context->imp
                                                != context->imp)) {
-                               for (i = 0; i < 4; i++) {
-                                       if (tmpSharedMem[i]) {
-                                               TEEC_ReleaseSharedMemory(tmpSharedMem[i]);
-                                               OsaFree(tmpSharedMem[i]);
-                                               tmpSharedMem[i] = NULL;
-                                       }
-                               }
-
                                LOGE(TEEC_LIB, "Bad parameters");
-                               return TEEC_ERROR_BAD_PARAMETERS;
+                               result = TEEC_ERROR_BAD_PARAMETERS;
+                               goto cleanup;
                        }
 
                        memref_imp = (TEEC_SharedMemoryImp *)memref->parent->imp;
+                       op->paramTypes |= (operation->params[i].memref.parent->flags |
+                                                               (TEE_PARAM_TYPE_MEMREF_INPUT & TEE_PARAM_TYPE_MEMREF_OUTPUT)) << (8 * i);
                        op->params[i].mem.offset = 0;
                        op->params[i].mem.size = memref->parent->size;
                        op->params[i].mem.shmKey = memref_imp->shmKey;
@@ -411,23 +413,16 @@ static TEEC_Result preProcessOperation(TEEC_Session *session,
                case TEEC_MEMREF_PARTIAL_INPUT:
                case TEEC_MEMREF_PARTIAL_OUTPUT:
                case TEEC_MEMREF_PARTIAL_INOUT:
-                       op->paramTypes |= (type + TEE_PARAM_TYPE_MEMREF_INPUT
-                                                          - TEEC_MEMREF_PARTIAL_INPUT) << (8 * i);
+                       op->paramTypes |= ((operation->params[i].memref.parent->flags & type) |
+                                                               (TEE_PARAM_TYPE_MEMREF_INPUT & TEE_PARAM_TYPE_MEMREF_OUTPUT)) << (8 * i);
                        memref = &operation->params[i].memref;
 
                        if ((NULL == memref) || (NULL == memref->parent)
                                        || (((TEEC_SharedMemoryImp *)memref->parent->imp)->context->imp
                                                != context->imp)) {
-                               for (i = 0; i < 4; i++) {
-                                       if (tmpSharedMem[i]) {
-                                               TEEC_ReleaseSharedMemory(tmpSharedMem[i]);
-                                               OsaFree(tmpSharedMem[i]);
-                                               tmpSharedMem[i] = NULL;
-                                       }
-                               }
-
                                LOGE(TEEC_LIB, "Bad parameters");
-                               return TEEC_ERROR_BAD_PARAMETERS;
+                               result = TEEC_ERROR_BAD_PARAMETERS;
+                               goto cleanup;
                        }
 
                        memref_imp = (TEEC_SharedMemoryImp *)memref->parent->imp;
@@ -446,19 +441,18 @@ static TEEC_Result preProcessOperation(TEEC_Session *session,
                        break;
 
                default:
-                       for (i = 0; i < 4; i++) {
-                               if (tmpSharedMem[i]) {
-                                       TEEC_ReleaseSharedMemory(tmpSharedMem[i]);
-                                       OsaFree(tmpSharedMem[i]);
-                                       tmpSharedMem[i] = NULL;
-                               }
-                       }
-
-                       return TEEC_ERROR_BAD_PARAMETERS;
+                       result = TEEC_ERROR_BAD_PARAMETERS;
+                       goto cleanup;
                }
        }
 
-       return TEEC_SUCCESS;
+       return result;
+
+cleanup:
+       for (i = 0; i < 4; i++) {
+               tempSharedMemoryDeallocate(&tmpSharedMem[i]);
+       }
+       return result;
 }
 
 /*
index cfc55c6..afe0f81 100644 (file)
--- a/log/log.c
+++ b/log/log.c
@@ -150,6 +150,9 @@ const char *GetModuleLevel(IN int32_t module_level)
  *
  * @return  void
  */
+
+#ifdef _LOGGING
+
 __attribute__((visibility("default")))
 void PrintLog(IN const char *function_name, IN const int32_t line_no,
                          IN int32_t module_level, IN int32_t debug_level, IN const char *message,
@@ -236,3 +239,15 @@ void PrintLog(IN const char *function_name, IN const int32_t line_no,
        va_end(variable_list);
        return;
 }
+
+#else // ifdef _LOGGING
+
+__attribute__((visibility("default")))
+void PrintLog(IN const char *function_name, IN const int32_t line_no,
+                         IN int32_t module_level, IN int32_t debug_level, IN const char *message,
+                         ...)
+{
+       // stub function
+}
+
+#endif // ifdef _LOGGING
index 11b2fd4..8c31f2d 100644 (file)
--- a/log/log.h
+++ b/log/log.h
@@ -102,8 +102,6 @@ typedef enum {
        #endif
 #endif // __TIZEN__
 
-#ifdef _LOGGING
-
 #define _LOG(module_level, debug_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, debug_level, ##__VA_ARGS__)
 
 #define LOGE(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, ERROR_LEVEL_LOG, ##__VA_ARGS__)
@@ -113,17 +111,6 @@ typedef enum {
 #define LOGS(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, INFO_LEVEL_LOG, ##__VA_ARGS__)
 #define LOGP(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, PACKET_LEVEL_LOG, ##__VA_ARGS__)
 
-#else //ifdef _LOGGING
-
-#define LOGE(module_level, ...)
-#define LOGV(module_level, ...)
-#define LOGD(module_level, ...)
-#define LOGI(module_level, ...)
-#define LOGS(module_level, ...)
-#define LOGP(module_level, ...)
-
-#endif //ifdef _LOGGING
-
 #if defined(__cplusplus)
 extern "C" {
 #endif
index e9696c5..81f67c7 100644 (file)
@@ -5,6 +5,7 @@ Release:    1
 Group:      Security
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
+Source1:    %{name}.manifest
 ExcludeArch: armv6l armv7hl armv7l aarch64
 BuildRequires: cmake
 BuildRequires: boost-devel
@@ -67,6 +68,7 @@ with TEF Simulator.
 
 %prep
 %setup -q
+cp %{SOURCE1} .
 
 %build
 # cannot call cmake rpmbuild macro because of scripts removing libTEEStub.a, which is a part of devkit
@@ -105,6 +107,7 @@ if [ $1 = 0 ] ; then
 fi
 
 %files -n %{name}
+%manifest tef-simulator.manifest
 %attr(111,security_fw,security_fw) %{bin_dir}/tef-simulator-daemon
 %{lib_dir}/libtef-simulator-ssflib.so
 %attr(770,root,security_fw) %{tastore_dir}
@@ -112,7 +115,6 @@ fi
 %attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.socket
 %attr(755,security_fw,security_fw) %{lib_dir}/tef/simulator/libteec.so
 
-
 %files -n %{name}-devkit
 %{bin_dir}/TA_PackageBuilder.sh
 %{bin_dir}/TAPackageMaker
index 4db8506..ab68665 100644 (file)
@@ -61,6 +61,7 @@ public:
        uint32_t mContextID;
        /* Security context wich stores info about low-level connection data*/
        SecurityContext secContext;
+       bool cynara_check_result;
 
        /* For TA internal APIs support, dummy Context is created and for recognizing
         * the context as dummy isInternal member variable is used
index 31fb181..8fadf2f 100644 (file)
@@ -48,22 +48,23 @@ void ConnectionSession::start() {
        // init SecurityContext of current session after initializing socket
        this->secContext = SecurityContext(clientSocket.native());
 
+       // Create a new Context
+       pthread_rwlock_wrlock(&ctxIDLock);
+       TEECtx = new TEEContext(ctxID, this);
+       // Increment the Context ID to be assigned to next Context
+       ctxID++;
+       if (ctxID == 0) ctxID++;
+       pthread_rwlock_unlock(&ctxIDLock);
+
 #ifdef _CYNARA_INTEGRATION
        /* Check if client has cynara permission */
        const string privilege("http://tizen.org/privilege/tee.client");
        if (!secContext.clientHasCynaraPermission(privilege)) {
                LOGE(SIM_DAEMON, "Client has no permission to use TEE");
-               return;
+               TEECtx->cynara_check_result = false;
        }
 #endif /* _CYNARA_INTEGRATION */
 
-       // Create a new Context
-       pthread_rwlock_wrlock(&ctxIDLock);
-       TEECtx = new TEEContext(ctxID, this);
-       // Increment the Context ID to be assigned to next Context
-       ctxID++;
-       if (ctxID == 0) ctxID++;
-       pthread_rwlock_unlock(&ctxIDLock);
        currentState = CMD_READ;
 
        // read exactly 1 byte to identify the command and execute callback when
index f85729c..189f918 100644 (file)
@@ -57,6 +57,8 @@ TEEContext::TEEContext(uint32_t contextID, IConnectionSession* connSession):
        /* Clear the shared memory list (mShmList) and Session map (mSessionMap) */
        mSessionMap.clear();
        mShmList.clear();
+
+       cynara_check_result = true;
 }
 
 /**
@@ -75,6 +77,17 @@ TEEC_Result TEEContext::initContext(InitContextData* data) {
         */
        isInternal = false;
 
+       if (!cynara_check_result) {
+               result = TEEC_ERROR_ACCESS_DENIED;
+               data->returnValue = result;
+               result = mConnSess->write(INITIALIZE_CONTEXT, (char*)data,
+                   sizeof(InitContextData));
+               if (result != TEEC_SUCCESS) {
+                       LOGE(SIM_DAEMON, "Initialize Context response write to CA FAILED");
+               }
+               return result;
+       }
+
        /* Check if the TEEName is proper or not */
        if (data->nameLength != 0) {
                string TName(data->TEEName);
@@ -167,6 +180,7 @@ TEEC_Result TEEContext::openSession(OpenSessionData data) {
        LOGD(SIM_DAEMON, "Entry");
        data.returnOrigin = TEEC_ORIGIN_TEE;
        data.returnValue = TEEC_ERROR_GENERIC;
+
        pthread_rwlock_wrlock(&sessIDLock);
        data.sessionID = sessID;
        sessID++;