Input: add safety guards to input_set_keycode()
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 13 Dec 2019 22:56:16 +0000 (14:56 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Jan 2020 19:07:01 +0000 (20:07 +0100)
commitf5b9bfbe94a042a2e3806efa4c6e1b6ddb4292c4
tree2f2b123db44c792243b341402d07ae27a9064565
parent64c8b76e69acdecab62b035e72b12775d6d35a3b
Input: add safety guards to input_set_keycode()

commit cb222aed03d798fc074be55e59d9a112338ee784 upstream.

If we happen to have a garbage in input device's keycode table with values
too big we'll end up doing clear_bit() with offset way outside of our
bitmaps, damaging other objects within an input device or even outside of
it. Let's add sanity checks to the returned old keycodes.

Reported-by: syzbot+c769968809f9359b07aa@syzkaller.appspotmail.com
Reported-by: syzbot+76f3a30e88d256644c78@syzkaller.appspotmail.com
Link: https://lore.kernel.org/r/20191207212757.GA245964@dtor-ws
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/input/input.c