Skip to content
Snippets Groups Projects
Commit 2ac5dc64 authored by Andrew Chant's avatar Andrew Chant Committed by Ariel Yin
Browse files

input: synaptics: put offset checks under mutex.


Place file offset validity checks under mutex.

BUG: 33555878
BUG: 33002026
Change-Id: I7eae42b9f69bf12114001e2edf752f219edfc56e
Signed-off-by: default avatarAndrew Chant <achant@google.com>
parent 3d63c530
Branches
Tags android-7.1.1_r0.41
No related merge requests found
...@@ -355,17 +355,24 @@ static ssize_t rmidev_read(struct file *filp, char __user *buf, ...@@ -355,17 +355,24 @@ static ssize_t rmidev_read(struct file *filp, char __user *buf,
return -EBADF; return -EBADF;
} }
if (count == 0) mutex_lock(&(dev_data->file_mutex));
return 0;
if (*f_pos > REG_ADDR_LIMIT) {
retval = -EFAULT;
goto unlock;
}
if (count > (REG_ADDR_LIMIT - *f_pos)) if (count > (REG_ADDR_LIMIT - *f_pos))
count = REG_ADDR_LIMIT - *f_pos; count = REG_ADDR_LIMIT - *f_pos;
if (count == 0) {
retval = 0;
goto unlock;
}
tmpbuf = kzalloc(count + 1, GFP_KERNEL); tmpbuf = kzalloc(count + 1, GFP_KERNEL);
if (!tmpbuf) if (!tmpbuf) {
return -ENOMEM; retval = -ENOMEM;
goto unlock;
mutex_lock(&(dev_data->file_mutex)); }
retval = synaptics_rmi4_reg_read(rmidev->rmi4_data, retval = synaptics_rmi4_reg_read(rmidev->rmi4_data,
*f_pos, *f_pos,
...@@ -380,9 +387,10 @@ static ssize_t rmidev_read(struct file *filp, char __user *buf, ...@@ -380,9 +387,10 @@ static ssize_t rmidev_read(struct file *filp, char __user *buf,
*f_pos += retval; *f_pos += retval;
clean_up: clean_up:
kfree(tmpbuf);
unlock:
mutex_unlock(&(dev_data->file_mutex)); mutex_unlock(&(dev_data->file_mutex));
kfree(tmpbuf);
return retval; return retval;
} }
...@@ -406,32 +414,40 @@ static ssize_t rmidev_write(struct file *filp, const char __user *buf, ...@@ -406,32 +414,40 @@ static ssize_t rmidev_write(struct file *filp, const char __user *buf,
return -EBADF; return -EBADF;
} }
if (count == 0) mutex_lock(&(dev_data->file_mutex));
return 0;
if (*f_pos > REG_ADDR_LIMIT) {
retval = -EFAULT;
goto unlock;
}
if (count > (REG_ADDR_LIMIT - *f_pos)) if (count > (REG_ADDR_LIMIT - *f_pos))
count = REG_ADDR_LIMIT - *f_pos; count = REG_ADDR_LIMIT - *f_pos;
if (count == 0) {
retval = 0;
goto unlock;
}
tmpbuf = kzalloc(count + 1, GFP_KERNEL); tmpbuf = kzalloc(count + 1, GFP_KERNEL);
if (!tmpbuf) if (!tmpbuf) {
return -ENOMEM; retval = -ENOMEM;
goto unlock;
}
if (copy_from_user(tmpbuf, buf, count)) { if (copy_from_user(tmpbuf, buf, count)) {
kfree(tmpbuf); retval = -EFAULT;
return -EFAULT; goto clean_up;
} }
mutex_lock(&(dev_data->file_mutex));
retval = synaptics_rmi4_reg_write(rmidev->rmi4_data, retval = synaptics_rmi4_reg_write(rmidev->rmi4_data,
*f_pos, *f_pos,
tmpbuf, tmpbuf,
count); count);
if (retval >= 0) if (retval >= 0)
*f_pos += retval; *f_pos += retval;
clean_up:
mutex_unlock(&(dev_data->file_mutex));
kfree(tmpbuf); kfree(tmpbuf);
unlock:
mutex_unlock(&(dev_data->file_mutex));
return retval; return retval;
} }
......
...@@ -299,13 +299,19 @@ static ssize_t rmidev_read(struct file *filp, char __user *buf, ...@@ -299,13 +299,19 @@ static ssize_t rmidev_read(struct file *filp, char __user *buf,
return -EBADF; return -EBADF;
} }
if (count == 0) mutex_lock(&(dev_data->file_mutex));
return 0;
if (*f_pos > REG_ADDR_LIMIT) {
retval = -EFAULT;
goto clean_up;
}
if (count > (REG_ADDR_LIMIT - *f_pos)) if (count > (REG_ADDR_LIMIT - *f_pos))
count = REG_ADDR_LIMIT - *f_pos; count = REG_ADDR_LIMIT - *f_pos;
if (count == 0) {
retval = 0;
goto clean_up;
}
mutex_lock(&(dev_data->file_mutex));
retval = rmidev->fn_ptr->read(rmidev->rmi4_data, retval = rmidev->fn_ptr->read(rmidev->rmi4_data,
*f_pos, *f_pos,
...@@ -345,16 +351,23 @@ static ssize_t rmidev_write(struct file *filp, const char __user *buf, ...@@ -345,16 +351,23 @@ static ssize_t rmidev_write(struct file *filp, const char __user *buf,
return -EBADF; return -EBADF;
} }
if (count == 0) mutex_lock(&(dev_data->file_mutex));
return 0;
if (*f_pos > REG_ADDR_LIMIT) {
retval = -EFAULT;
goto clean_up;
}
if (count > (REG_ADDR_LIMIT - *f_pos)) if (count > (REG_ADDR_LIMIT - *f_pos))
count = REG_ADDR_LIMIT - *f_pos; count = REG_ADDR_LIMIT - *f_pos;
if (count == 0) {
retval = 0;
goto clean_up;
}
if (copy_from_user(tmpbuf, buf, count)) if (copy_from_user(tmpbuf, buf, count)) {
return -EFAULT; retval = -EFAULT;
goto clean_up;
mutex_lock(&(dev_data->file_mutex)); }
retval = rmidev->fn_ptr->write(rmidev->rmi4_data, retval = rmidev->fn_ptr->write(rmidev->rmi4_data,
*f_pos, *f_pos,
...@@ -362,7 +375,7 @@ static ssize_t rmidev_write(struct file *filp, const char __user *buf, ...@@ -362,7 +375,7 @@ static ssize_t rmidev_write(struct file *filp, const char __user *buf,
count); count);
if (retval >= 0) if (retval >= 0)
*f_pos += retval; *f_pos += retval;
clean_up:
mutex_unlock(&(dev_data->file_mutex)); mutex_unlock(&(dev_data->file_mutex));
return retval; return retval;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment