Skip to content

Commit

Permalink
Input: joydev - prevent potential read overflow in ioctl
Browse files Browse the repository at this point in the history
The problem here is that "len" might be less than "joydev->nabs" so the
loops which verfy abspam[i] and keypam[] might read beyond the buffer.

Fixes: 999b874 ("Input: joydev - validate axis/button maps before clobbering current ones")
Signed-off-by: Dan Carpenter <[email protected]>
Link: https://lore.kernel.org/r/YCyzR8WvFRw4HWw6@mwanda
[dtor: additional check for len being even in joydev_handle_JSIOCSBTNMAP]
Cc: [email protected]
Signed-off-by: Dmitry Torokhov <[email protected]>
  • Loading branch information
Dan Carpenter authored and dtor committed Feb 19, 2021
1 parent 0958351 commit 182d679
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/input/joydev.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev,
if (IS_ERR(abspam))
return PTR_ERR(abspam);

for (i = 0; i < joydev->nabs; i++) {
for (i = 0; i < len && i < joydev->nabs; i++) {
if (abspam[i] > ABS_MAX) {
retval = -EINVAL;
goto out;
Expand All @@ -480,14 +480,17 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev,
int i;
int retval = 0;

if (len % sizeof(*keypam))
return -EINVAL;

len = min(len, sizeof(joydev->keypam));

/* Validate the map. */
keypam = memdup_user(argp, len);
if (IS_ERR(keypam))
return PTR_ERR(keypam);

for (i = 0; i < joydev->nkey; i++) {
for (i = 0; i < (len / 2) && i < joydev->nkey; i++) {
if (keypam[i] > KEY_MAX || keypam[i] < BTN_MISC) {
retval = -EINVAL;
goto out;
Expand Down

0 comments on commit 182d679

Please sign in to comment.