tty/vt/keyboard: fix OOB access in do_compute_shiftstate()
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 27 Jun 2016 21:12:34 +0000 (14:12 -0700)
committerSasha Levin <alexander.levin@verizon.com>
Sat, 6 Aug 2016 17:01:07 +0000 (13:01 -0400)
commit9524cc41374df87b9c8d200e3561ad408bfa5844
tree978de002ce1ce268a642aea4899c93c3169ec004
parente77df443966296efb726712e064ee34b9ce42737
tty/vt/keyboard: fix OOB access in do_compute_shiftstate()

[ Upstream commit 510cccb5b0c8868a2b302a0ab524da7912da648b ]

The size of individual keymap in drivers/tty/vt/keyboard.c is NR_KEYS,
which is currently 256, whereas number of keys/buttons in input device (and
therefor in key_down) is much larger - KEY_CNT - 768, and that can cause
out-of-bound access when we do

sym = U(key_maps[0][k]);

with large 'k'.

To fix it we should not attempt iterating beyond smaller of NR_KEYS and
KEY_CNT.

Also while at it let's switch to for_each_set_bit() instead of open-coding
it.

Reported-by: Sasha Levin <sasha.levin@oracle.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
drivers/tty/vt/keyboard.c