Skip to content

Commit 601bbbe

Browse files
committed
Input: uinput - fix crash when mixing old and new init style
If user tries to initialize uinput device mixing old and new style initialization (i.e. using old UI_SET_ABSBIT instead of UI_ABS_SETUP, we forget to allocate input->absinfo and will crash when trying to send absolute events: ioctl(ui, UI_DEV_SETUP, &us); ioctl(ui, UI_SET_PHYS, "Test"); ioctl(ui, UI_SET_EVBIT, EV_ABS); ioctl(ui, UI_SET_ABSBIT, ABS_X); ioctl(ui, UI_SET_ABSBIT, ABS_Y); ioctl(ui, UI_DEV_CREATE, 0); Reported-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=191811 Fixes: fbae10d ("Input: uinput - rework ABS validation") Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 05e0be7 commit 601bbbe

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎drivers/input/misc/uinput.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,21 @@ static int uinput_create_device(struct uinput_device *udev)
263263
return -EINVAL;
264264
}
265265

266-
if (test_bit(ABS_MT_SLOT, dev->absbit)) {
267-
nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
268-
error = input_mt_init_slots(dev, nslot, 0);
269-
if (error)
266+
if (test_bit(EV_ABS, dev->evbit)) {
267+
input_alloc_absinfo(dev);
268+
if (!dev->absinfo) {
269+
error = -EINVAL;
270270
goto fail1;
271-
} else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
272-
input_set_events_per_packet(dev, 60);
271+
}
272+
273+
if (test_bit(ABS_MT_SLOT, dev->absbit)) {
274+
nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
275+
error = input_mt_init_slots(dev, nslot, 0);
276+
if (error)
277+
goto fail1;
278+
} else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
279+
input_set_events_per_packet(dev, 60);
280+
}
273281
}
274282

275283
if (test_bit(EV_FF, dev->evbit) && !udev->ff_effects_max) {

0 commit comments

Comments
 (0)