security: tlk_driver: vrr authentication
sujeet baranwal [Wed, 28 Oct 2015 20:08:13 +0000 (13:08 -0700)]
Upon hpd, vrr authentication protocol is initated and tz
calls are made to validate the connection.

bug 1647060

Change-Id: I3755facc05f81f0aa6cc264847d5ab6a72a7cc17
Signed-off-by: sujeet baranwal <sbaranwal@nvidia.com>
Reviewed-on: http://git-master/r/819008
Reviewed-by: Daniel Solomon <daniels@nvidia.com>
Tested-by: Daniel Solomon <daniels@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Mitch Luban <mluban@nvidia.com>

security/tlk_driver/ote_comms.c
security/tlk_driver/ote_device.c

index de59bf1..15babae 100644 (file)
@@ -34,6 +34,7 @@
 bool verbose_smc;
 core_param(verbose_smc, verbose_smc, bool, 0644);
 
+#define VR_AUTH_UUID   {0x0179ED96, 0x45A81ADB, 0x089DC68D, 0xBB520279}
 #define SET_RESULT(req, r, ro) { req->result = r; req->result_origin = ro; }
 
 static int te_pin_user_pages(void *buffer, size_t size,
@@ -595,3 +596,82 @@ void te_launch_operation(struct te_launchop *cmd,
 
        te_release_mem_buffers(&session->temp_shmem_list);
 }
+
+void te_authenticate_vrr(u8 *buf_ptr, u32 buflen)
+{
+       u32 i, no_of_params = 1;
+       struct te_request *request;
+       struct te_oper_param user_param;
+       struct te_oper_param *param_array;
+       struct te_oper_param *params = NULL;
+       struct te_cmd_req_desc *cmd_desc = NULL;
+       u32 session_id, vrr_auth_uuid[4] = VR_AUTH_UUID;
+
+       mutex_lock(&smc_lock);
+
+       /* Open & submit the work to SMC */
+       cmd_desc = NULL;
+       params = NULL;
+       no_of_params =  1;
+
+       cmd_desc = te_get_free_cmd_desc(&tlk_dev);
+       params = te_get_free_params(&tlk_dev, no_of_params);
+
+       if (!cmd_desc || !params) {
+               pr_err("failed to get cmd_desc/params\n");
+               goto error;
+       }
+
+       /* Request and parameter are prepared for VRR authenticaiton */
+       request = cmd_desc->req_addr;
+       memset(request, 0, sizeof(struct te_request));
+       request->params = (uintptr_t)params;
+       request->params_size = no_of_params;
+       request->type = TE_SMC_OPEN_SESSION;
+
+       user_param.index = 0;
+       user_param.u.Mem.len = buflen;
+       user_param.type = TE_PARAM_TYPE_MEM_RW;
+       user_param.u.Mem.type = TE_MEM_TYPE_NS_KERNEL;
+       user_param.u.Mem.base = (uint64_t)(uintptr_t)buf_ptr;
+       memcpy(request->dest_uuid, vrr_auth_uuid, sizeof(vrr_auth_uuid));
+
+       param_array = (struct te_oper_param *)(uintptr_t)request->params;
+
+       for (i = 0; i < no_of_params; i++)
+               memcpy(param_array + i, &user_param, sizeof(struct te_oper_param));
+
+       do_smc(request, &tlk_dev);
+       session_id = request->session_id;
+
+       if (request->result) {
+               pr_err("%s: error opening session: 0x%08x\n",
+                       __func__, request->result);
+               goto error;
+       }
+
+       /* Close the session */
+       request = cmd_desc->req_addr;
+       memset(request, 0, sizeof(struct te_request));
+
+       request->type = TE_SMC_CLOSE_SESSION;
+       request->session_id = session_id;
+       memcpy(request->dest_uuid, vrr_auth_uuid, sizeof(vrr_auth_uuid));
+
+       do_smc(request, &tlk_dev);
+
+       if (request->result) {
+               pr_err("%s: error closing session: 0x%08x\n",
+                       __func__, request->result);
+       }
+
+error:
+       if (cmd_desc)
+               te_put_used_cmd_desc(&tlk_dev, cmd_desc);
+
+       if (params)
+               te_put_free_params(&tlk_dev, params, no_of_params);
+
+       mutex_unlock(&smc_lock);
+}
+EXPORT_SYMBOL(te_authenticate_vrr);
index 2cc78f8..daed225 100644 (file)
@@ -104,7 +104,7 @@ error:
        return ret;
 }
 
-static struct te_oper_param *te_get_free_params(struct tlk_device *dev,
+struct te_oper_param *te_get_free_params(struct tlk_device *dev,
        unsigned int nparams)
 {
        struct te_oper_param *params = NULL;
@@ -120,7 +120,7 @@ static struct te_oper_param *te_get_free_params(struct tlk_device *dev,
        return params;
 }
 
-static void te_put_free_params(struct tlk_device *dev,
+void te_put_free_params(struct tlk_device *dev,
        struct te_oper_param *params, uint32_t nparams)
 {
        int idx, nbits;
@@ -130,7 +130,7 @@ static void te_put_free_params(struct tlk_device *dev,
        bitmap_release_region(dev->param_bitmap, idx, nbits);
 }
 
-static struct te_cmd_req_desc *te_get_free_cmd_desc(struct tlk_device *dev)
+struct te_cmd_req_desc *te_get_free_cmd_desc(struct tlk_device *dev)
 {
        struct te_cmd_req_desc *cmd_desc = NULL;
 
@@ -143,7 +143,7 @@ static struct te_cmd_req_desc *te_get_free_cmd_desc(struct tlk_device *dev)
        return cmd_desc;
 }
 
-static void te_put_used_cmd_desc(struct tlk_device *dev,
+void te_put_used_cmd_desc(struct tlk_device *dev,
        struct te_cmd_req_desc *cmd_desc)
 {
        struct te_cmd_req_desc *param_desc, *tmp_param_desc;