OSDN Git Service

diag: Add missing protection while accessing session's info
authorHardik Arya <harya@codeaurora.org>
Mon, 9 Apr 2018 09:19:40 +0000 (14:49 +0530)
committerHardik Arya <harya@codeaurora.org>
Tue, 7 Aug 2018 12:24:41 +0000 (17:54 +0530)
Currently, mutex protection is missing while accessing md session's
info via macro. The patch adds proper protection before accessing
the same.

Change-Id: I17b18183407279447229783fd0165337bd173423
Signed-off-by: Hardik Arya <harya@codeaurora.org>
drivers/char/diag/diag_masks.c

index ad68055..94613a4 100644 (file)
 
 #define DIAG_SET_FEATURE_MASK(x) (feature_bytes[(x)/8] |= (1 << (x & 0x7)))
 
-#define diag_check_update(x)   \
-       (!info || (info && (info->peripheral_mask & MD_PERIPHERAL_MASK(x))) \
-       || (info && (info->peripheral_mask & MD_PERIPHERAL_PD_MASK(x)))) \
-
 struct diag_mask_info msg_mask;
 struct diag_mask_info msg_bt_mask;
 struct diag_mask_info log_mask;
@@ -65,6 +61,22 @@ static const struct diag_ssid_range_t msg_mask_tbl[] = {
        { .ssid_first = MSG_SSID_25, .ssid_last = MSG_SSID_25_LAST }
 };
 
+static int diag_check_update(int md_peripheral, int pid)
+{
+       int ret;
+       struct diag_md_session_t *info = NULL;
+
+       mutex_lock(&driver->md_session_lock);
+       info = diag_md_session_get_pid(pid);
+       ret = (!info || (info &&
+               (info->peripheral_mask & MD_PERIPHERAL_MASK(md_peripheral))) ||
+               (info && (info->peripheral_mask &
+               MD_PERIPHERAL_PD_MASK(md_peripheral))));
+       mutex_unlock(&driver->md_session_lock);
+
+       return ret;
+}
+
 static int diag_apps_responds(void)
 {
        /*
@@ -838,7 +850,7 @@ static int diag_cmd_set_msg_mask(unsigned char *src_buf, int src_len,
        mutex_unlock(&driver->msg_mask_lock);
        mutex_unlock(&mask_info->lock);
        mutex_unlock(&driver->md_session_lock);
-       if (diag_check_update(APPS_DATA))
+       if (diag_check_update(APPS_DATA, pid))
                diag_update_userspace_clients(MSG_MASKS_TYPE);
 
        /*
@@ -860,7 +872,7 @@ static int diag_cmd_set_msg_mask(unsigned char *src_buf, int src_len,
        memcpy(dest_buf + write_len, src_buf + header_len, mask_size);
        write_len += mask_size;
        for (i = 0; i < NUM_PERIPHERALS; i++) {
-               if (!diag_check_update(i))
+               if (!diag_check_update(i, pid))
                        continue;
                mutex_lock(&driver->md_session_lock);
                diag_send_msg_mask_update(i, req->ssid_first, req->ssid_last);
@@ -928,7 +940,7 @@ static int diag_cmd_set_all_msg_mask(unsigned char *src_buf, int src_len,
        mutex_unlock(&driver->msg_mask_lock);
        mutex_unlock(&mask_info->lock);
        mutex_unlock(&driver->md_session_lock);
-       if (diag_check_update(APPS_DATA))
+       if (diag_check_update(APPS_DATA, pid))
                diag_update_userspace_clients(MSG_MASKS_TYPE);
 
        /*
@@ -944,7 +956,7 @@ static int diag_cmd_set_all_msg_mask(unsigned char *src_buf, int src_len,
        write_len += header_len;
 
        for (i = 0; i < NUM_PERIPHERALS; i++) {
-               if (!diag_check_update(i))
+               if (!diag_check_update(i, pid))
                        continue;
                mutex_lock(&driver->md_session_lock);
                diag_send_msg_mask_update(i, ALL_SSID, ALL_SSID);
@@ -1032,7 +1044,7 @@ static int diag_cmd_update_event_mask(unsigned char *src_buf, int src_len,
        mask_info->status = DIAG_CTRL_MASK_VALID;
        mutex_unlock(&mask_info->lock);
        mutex_unlock(&driver->md_session_lock);
-       if (diag_check_update(APPS_DATA))
+       if (diag_check_update(APPS_DATA, pid))
                diag_update_userspace_clients(EVENT_MASKS_TYPE);
 
        /*
@@ -1049,7 +1061,7 @@ static int diag_cmd_update_event_mask(unsigned char *src_buf, int src_len,
        write_len += mask_len;
 
        for (i = 0; i < NUM_PERIPHERALS; i++) {
-               if (!diag_check_update(i))
+               if (!diag_check_update(i, pid))
                        continue;
                mutex_lock(&driver->md_session_lock);
                diag_send_event_mask_update(i);
@@ -1098,7 +1110,7 @@ static int diag_cmd_toggle_events(unsigned char *src_buf, int src_len,
        }
        mutex_unlock(&mask_info->lock);
        mutex_unlock(&driver->md_session_lock);
-       if (diag_check_update(APPS_DATA))
+       if (diag_check_update(APPS_DATA, pid))
                diag_update_userspace_clients(EVENT_MASKS_TYPE);
 
        /*
@@ -1108,7 +1120,7 @@ static int diag_cmd_toggle_events(unsigned char *src_buf, int src_len,
        header.cmd_code = DIAG_CMD_EVENT_TOGGLE;
        header.padding = 0;
        for (i = 0; i < NUM_PERIPHERALS; i++) {
-               if (!diag_check_update(i))
+               if (!diag_check_update(i, pid))
                        continue;
                mutex_lock(&driver->md_session_lock);
                diag_send_event_mask_update(i);
@@ -1371,7 +1383,7 @@ static int diag_cmd_set_log_mask(unsigned char *src_buf, int src_len,
        }
        mutex_unlock(&mask_info->lock);
        mutex_unlock(&driver->md_session_lock);
-       if (diag_check_update(APPS_DATA))
+       if (diag_check_update(APPS_DATA, pid))
                diag_update_userspace_clients(LOG_MASKS_TYPE);
 
        /*
@@ -1400,7 +1412,7 @@ static int diag_cmd_set_log_mask(unsigned char *src_buf, int src_len,
        write_len += payload_len;
 
        for (i = 0; i < NUM_PERIPHERALS; i++) {
-               if (!diag_check_update(i))
+               if (!diag_check_update(i, pid))
                        continue;
                mutex_lock(&driver->md_session_lock);
                diag_send_log_mask_update(i, req->equip_id);
@@ -1453,7 +1465,7 @@ static int diag_cmd_disable_log_mask(unsigned char *src_buf, int src_len,
        }
        mask_info->status = DIAG_CTRL_MASK_ALL_DISABLED;
        mutex_unlock(&driver->md_session_lock);
-       if (diag_check_update(APPS_DATA))
+       if (diag_check_update(APPS_DATA, pid))
                diag_update_userspace_clients(LOG_MASKS_TYPE);
 
        /*
@@ -1469,7 +1481,7 @@ static int diag_cmd_disable_log_mask(unsigned char *src_buf, int src_len,
        memcpy(dest_buf, &header, sizeof(struct diag_log_config_rsp_t));
        write_len += sizeof(struct diag_log_config_rsp_t);
        for (i = 0; i < NUM_PERIPHERALS; i++) {
-               if (!diag_check_update(i))
+               if (!diag_check_update(i, pid))
                        continue;
                mutex_lock(&driver->md_session_lock);
                diag_send_log_mask_update(i, ALL_EQUIP_ID);