Skip to content

Commit f8f84af

Browse files
avlarkindtor
authored andcommitted
Input: joydev - prevent use of not validated data in JSIOCSBTNMAP ioctl
Even though we validate user-provided inputs we then traverse past validated data when applying the new map. The issue was originally discovered by Murray McAllister with this simple POC (if the following is executed by an unprivileged user it will instantly panic the system): int main(void) { int fd, ret; unsigned int buffer[10000]; fd = open("/dev/input/js0", O_RDONLY); if (fd == -1) printf("Error opening file\n"); ret = ioctl(fd, JSIOCSBTNMAP & ~IOCSIZE_MASK, &buffer); printf("%d\n", ret); } The solution is to traverse internal buffer which is guaranteed to only contain valid date when constructing the map. Fixes: 182d679 ("Input: joydev - prevent potential read overflow in ioctl") Fixes: 999b874 ("Input: joydev - validate axis/button maps before clobbering current ones") Reported-by: Murray McAllister <[email protected]> Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Alexander Larkin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent cac7100 commit f8f84af

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/input/joydev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev,
499499
memcpy(joydev->keypam, keypam, len);
500500

501501
for (i = 0; i < joydev->nkey; i++)
502-
joydev->keymap[keypam[i] - BTN_MISC] = i;
502+
joydev->keymap[joydev->keypam[i] - BTN_MISC] = i;
503503

504504
out:
505505
kfree(keypam);

0 commit comments

Comments
 (0)