Commit d72cf01f authored by Dan Carpenter's avatar Dan Carpenter Committed by Noralf Trønnes

drm/mipi-dbi: fix a loop in debugfs code

This code will likely crash if we try to do a zero byte write.  The code
looks like this:

        /* strip trailing whitespace */
        for (i = count - 1; i > 0; i--)
                if (isspace(buf[i]))
			...

We're writing zero bytes so count = 0.  You would think that "count - 1"
would be negative one, but because "i" is unsigned it is a large
positive numer instead.  The "i > 0" condition is true and the "buf[i]"
access will be out of bounds.

The fix is to make "i" signed and now everything works as expected.  The
upper bound of "count" is capped in __kernel_write() at MAX_RW_COUNT so
we don't have to worry about it being higher than INT_MAX.

Fixes: 02dd95fe ("drm/tinydrm: Add MIPI DBI support")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
[noralf: Adjust title]
Signed-off-by: default avatarNoralf Trønnes <noralf@tronnes.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190821072456.GJ26957@mwanda
parent 6dbe0c4b
...@@ -1187,8 +1187,7 @@ static ssize_t mipi_dbi_debugfs_command_write(struct file *file, ...@@ -1187,8 +1187,7 @@ static ssize_t mipi_dbi_debugfs_command_write(struct file *file,
struct mipi_dbi_dev *dbidev = m->private; struct mipi_dbi_dev *dbidev = m->private;
u8 val, cmd = 0, parameters[64]; u8 val, cmd = 0, parameters[64];
char *buf, *pos, *token; char *buf, *pos, *token;
unsigned int i; int i, ret, idx;
int ret, idx;
if (!drm_dev_enter(&dbidev->drm, &idx)) if (!drm_dev_enter(&dbidev->drm, &idx))
return -ENODEV; return -ENODEV;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment