Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Dec 2019 16:20:38 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r355935 - head/sys/dev/vt
Message-ID:  <201912201620.xBKGKciY014687@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912201620.xBKGKciY014687>