[Bug 247498] vd_kbstate not getting reset after keyboard detach/attach?
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Tue Jun 23 11:50:55 UTC 2020
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247498
Bug ID: 247498
Summary: vd_kbstate not getting reset after keyboard
detach/attach?
Product: Base System
Version: 12.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: kern
Assignee: bugs at FreeBSD.org
Reporter: billblake2018 at gmail.com
I have discovered a condition under which pressing a key results in an input of
the ESC character followed by the key WITHOUT my holding down any ALT key.
(See VT_ALT_TO_ESC_HACK.) This is using the vt driver on 12.1-RELEASE with no
relevant changes to the GENERIC kernel config. The bug is NOT reliably
reproducible.
I discovered the bug while putting together a script to secure my laptop and
power down the screen when I close my laptop's lid. The script (invoked via
devd), switches to the X console, uses DPMS to turn off my display, disables
the mouse, and detaches the keyboard with "kbdcontrol -A atkbd0". (Why, you
ask? Because when using vt, only X can turn off my display, but keyboard
locking is worthless when running X. This was the only way I found to save
power *and* secure my system when the lid is closed.) When the lid is opened,
a program is called to switch to an unused virtual console, reattach the
keyboard (with the KBADDKB ioctl), and read a password (with console switching
disabled).
Most of the time, this worked as expected. Every once in awhile, however, the
program would not accept my password. After some debugging, I discovered that
the reason was that the kernel was returning my keyboard input with an ESC
character before every character I typed. Looking around, I found that there
is exactly one place where that could be happening, in sys/dev/vt/vt_core.c,
line 961, and that it would do this only if ALKED is set in vd->vd_kbstate, a
field that *should* only be set while one of my ALT keys is pressed. I
confirmed that this was the likely culprit by pressing my left ALT key while
the bug manifested--the kernel immediately stopped adding the ESC characters.
I no longer have the kernel knowledge (or the time) track this bug to its lair,
but it seems fairly obvious that vd_kbstate is not getting properly initialized
when the keyboard is reattached. This is relatively harmless; that field
controls only the one thing, and the problem is remedied by merely hitting an
ALT key. Of greater concern is the possibility that some *other* field is not
getting reinitialized after a keyboard detach/attach sequence, which suggests
that a review of the keyboard attach code is in order.
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-bugs
mailing list