Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e45e3a6 authored by Mohit Aggarwal's avatar Mohit Aggarwal
Browse files

diag: Synchronize command registration table access



Currently, command registration table is being read
in debugfs without any protection which may lead to
access of stale entries. The patch takes care of the
issue by adding proper protection.

CRs-Fixed: 2032672
Change-Id: I6ae058c16873f9ed52ae6516a1a70fd6d2d0da80
Signed-off-by: default avatarMohit Aggarwal <maggarwa@codeaurora.org>
parent 60be7160
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -273,8 +273,10 @@ static ssize_t diag_dbgfs_read_table(struct file *file, char __user *ubuf,
	struct list_head *temp;
	struct diag_cmd_reg_t *item = NULL;

	mutex_lock(&driver->cmd_reg_mutex);
	if (diag_dbgfs_table_index == driver->cmd_reg_count) {
		diag_dbgfs_table_index = 0;
		mutex_unlock(&driver->cmd_reg_mutex);
		return 0;
	}

@@ -283,6 +285,7 @@ static ssize_t diag_dbgfs_read_table(struct file *file, char __user *ubuf,
	buf = kzalloc(sizeof(char) * buf_size, GFP_KERNEL);
	if (ZERO_OR_NULL_PTR(buf)) {
		pr_err("diag: %s, Error allocating memory\n", __func__);
		mutex_unlock(&driver->cmd_reg_mutex);
		return -ENOMEM;
	}
	buf_size = ksize(buf);
@@ -327,6 +330,7 @@ static ssize_t diag_dbgfs_read_table(struct file *file, char __user *ubuf,
			break;
	}
	diag_dbgfs_table_index = i;
	mutex_unlock(&driver->cmd_reg_mutex);

	*ppos = 0;
	ret = simple_read_from_buffer(ubuf, count, ppos, buf, bytes_in_buffer);