svn commit: r355935 - head/sys/dev/vt

Kyle Evans kevans at FreeBSD.org
Fri Dec 20 16:20:39 UTC 2019


Author: kevans
Date: Fri Dec 20 16:20:38 2019
New Revision: 355935
URL: https://svnweb.freebsd.org/changeset/base/355935

Log:
  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.

Modified:
  head/sys/dev/vt/vt_core.c

Modified: head/sys/dev/vt/vt_core.c
==============================================================================
--- head/sys/dev/vt/vt_core.c	Fri Dec 20 16:05:29 2019	(r355934)
+++ head/sys/dev/vt/vt_core.c	Fri Dec 20 16:20:38 2019	(r355935)
@@ -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);
 		}


More information about the svn-src-head mailing list