Skip to content
This repository was archived by the owner on Sep 9, 2019. It is now read-only.

Commit 3d1e6af

Browse files
bisdashkdrag0n
authored andcommitted
touchscreen: sec_ts: Fix array OOB issues in the sec_ts touch driver.
sec_ts touch driver sysfs store callback had couple of userspace buffer copy operations where it was not checking for validity of length being copied from source buffer. This CL adds necessary boundary checks to make sure the destination kernel buffer is not overflown. Bug: 120211708 Bug: 120211415 Change-Id: I8bfe1ab9ae50d89ce12eeaf856204c20056a2061 Signed-off-by: Biswajit Dash <bisdash@google.com> Signed-off-by: Danny Lin <danny@kdrag0n.dev>
1 parent 9901181 commit 3d1e6af

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

drivers/input/touchscreen/sec_ts/sec_cmd.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,20 @@ static ssize_t sec_cmd_store(struct device *dev,
6161
struct sec_cmd_data *data = dev_get_drvdata(dev);
6262
char *cur, *start, *end;
6363
char buff[SEC_CMD_STR_LEN] = { 0 };
64-
int len, i;
64+
size_t len;
6565
struct sec_cmd *sec_cmd_ptr = NULL;
6666
char delim = ',';
6767
bool cmd_found = false;
68-
int param_cnt = 0;
68+
unsigned int i, param_cnt = 0;
6969

7070
if (!data) {
7171
pr_err("%s %s: No platform data found\n", SECLOG, __func__);
7272
return -EINVAL;
7373
}
7474

75-
if (strlen(buf) >= SEC_CMD_STR_LEN) {
76-
pr_err("%s %s: cmd length is over (%s,%d)!!\n", SECLOG, __func__, buf, (int)strlen(buf));
75+
if (count >= SEC_CMD_STR_LEN) {
76+
pr_err("%s %s: cmd length is over (%s,%d)!!\n",
77+
SECLOG, __func__, buf, (int)count);
7778
return -EINVAL;
7879
}
7980

@@ -91,7 +92,7 @@ static ssize_t sec_cmd_store(struct device *dev,
9192
for (i = 0; i < ARRAY_SIZE(data->cmd_param); i++)
9293
data->cmd_param[i] = 0;
9394

94-
len = (int)count;
95+
len = count;
9596
if (*(buf + len - 1) == '\n')
9697
len--;
9798

@@ -285,12 +286,13 @@ static ssize_t sec_cmd_store(struct device *dev, struct device_attribute *devatt
285286
return -EINVAL;
286287
}
287288

288-
if (strlen(buf) >= SEC_CMD_STR_LEN) {
289-
pr_err("%s %s: cmd length is over (%s,%d)!!\n", SECLOG, __func__, buf, (int)strlen(buf));
289+
if (count >= SEC_CMD_STR_LEN) {
290+
pr_err("%s %s: cmd length is over (%s,%d)!!\n", SECLOG,
291+
__func__, buf, (int)count);
290292
return -EINVAL;
291293
}
292294

293-
strncpy(cmd.cmd, buf, count);
295+
strlcpy(cmd.cmd, buf, sizeof(cmd.cmd));
294296

295297
mutex_lock(&data->fifo_lock);
296298
queue_size = (kfifo_len(&data->cmd_queue) / sizeof(struct command));

0 commit comments

Comments
 (0)