msm: hdcp: protect encryption enable with a mutex

Enable/disable encryption API can be called by multiple
threads. Protect this API with a mutex to avoid any
possible memory violation due to invalid calls to the API.

Change-Id: I190cdf24880645ac20ec17934d76498d71b2802a
Signed-off-by: Ajay Singh Parmar <aparmar@codeaurora.org>
This commit is contained in:
Ajay Singh Parmar 2017-01-06 19:22:46 -08:00 committed by Gerrit - the friendly Code Review server
parent 4eaf19c57a
commit ed104f71b6

View file

@ -559,6 +559,7 @@ static int hdcp_lib_txmtr_init_legacy(struct hdcp_lib_handle *handle);
static struct qseecom_handle *hdcp1_handle; static struct qseecom_handle *hdcp1_handle;
static bool hdcp1_supported = true; static bool hdcp1_supported = true;
static bool hdcp1_enc_enabled; static bool hdcp1_enc_enabled;
static struct mutex hdcp1_ta_cmd_lock;
static const char *hdcp_lib_message_name(int msg_id) static const char *hdcp_lib_message_name(int msg_id)
{ {
@ -2217,6 +2218,8 @@ bool hdcp1_check_if_supported_load_app(void)
if (rc) { if (rc) {
pr_err("qseecom_start_app failed %d\n", rc); pr_err("qseecom_start_app failed %d\n", rc);
hdcp1_supported = false; hdcp1_supported = false;
} else {
mutex_init(&hdcp1_ta_cmd_lock);
} }
} }
@ -2281,12 +2284,16 @@ int hdcp1_set_enc(bool enable)
struct hdcp1_set_enc_req *set_enc_req; struct hdcp1_set_enc_req *set_enc_req;
struct hdcp1_set_enc_rsp *set_enc_rsp; struct hdcp1_set_enc_rsp *set_enc_rsp;
if (!hdcp1_supported || !hdcp1_handle) mutex_lock(&hdcp1_ta_cmd_lock);
return -EINVAL;
if (!hdcp1_supported || !hdcp1_handle) {
rc = -EINVAL;
goto end;
}
if (hdcp1_enc_enabled == enable) { if (hdcp1_enc_enabled == enable) {
pr_debug("already %s\n", enable ? "enabled" : "disabled"); pr_debug("already %s\n", enable ? "enabled" : "disabled");
return rc; goto end;
} }
/* set keys and request aksv */ /* set keys and request aksv */
@ -2304,18 +2311,21 @@ int hdcp1_set_enc(bool enable)
if (rc < 0) { if (rc < 0) {
pr_err("qseecom cmd failed err=%d\n", rc); pr_err("qseecom cmd failed err=%d\n", rc);
return -EINVAL; goto end;
} }
rc = set_enc_rsp->ret; rc = set_enc_rsp->ret;
if (rc) { if (rc) {
pr_err("enc cmd failed, rsp=%d\n", set_enc_rsp->ret); pr_err("enc cmd failed, rsp=%d\n", set_enc_rsp->ret);
return -EINVAL; rc = -EINVAL;
goto end;
} }
hdcp1_enc_enabled = enable; hdcp1_enc_enabled = enable;
pr_debug("%s success\n", enable ? "enable" : "disable"); pr_debug("%s success\n", enable ? "enable" : "disable");
return 0; end:
mutex_unlock(&hdcp1_ta_cmd_lock);
return rc;
} }
int hdcp_library_register(struct hdcp_register_data *data) int hdcp_library_register(struct hdcp_register_data *data)