vt: fix post-boot keyboard attachment

With absolutely no keyboards attached and no kbdmux in kernel, we descend
down this error path. 0 is a valid keyboard index, so leaving
vd->vd_keyboard at 0 when there's no keyboard found is objectively wrong as
later attachment of a keyboard will fail -- it gets index 0, and vt thinks
it's already using that keyboard.

This is decidedly the corniest of corner cases, but it's easy enough to get
correct that we should do so.

Tested in a kernel without atkbdc, atkbd, psm, kbdmux, ukbd, hyperv then
loading ukbd post-boot and attaching a usb keyboard.
This commit is contained in:
Kyle Evans 2019-12-20 16:20:38 +00:00
parent 2dfc696ef1
commit 4eac76656e

View File

@ -1039,6 +1039,13 @@ vt_allocate_keyboard(struct vt_device *vd)
DPRINTF(20, "%s: no kbdmux allocated\n", __func__);
idx0 = kbd_allocate("*", -1, vd, vt_kbdevent, vd);
if (idx0 < 0) {
/*
* We don't have a keyboard yet, so we must invalidate
* vd->vd_keyboard so that later keyboard attachment can
* succeed. Any value >= 0 can accidentally match a
* keyboard.
*/
vd->vd_keyboard = -1;
DPRINTF(10, "%s: No keyboard found.\n", __func__);
return (-1);
}