From owner-freebsd-bugs@freebsd.org Tue Jun 23 11:50:55 2020 Return-Path: Delivered-To: freebsd-bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 85BC1352B5C for ; Tue, 23 Jun 2020 11:50:55 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 49rl3M2zpNz4QMf for ; Tue, 23 Jun 2020 11:50:55 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id 64AD2352B5B; Tue, 23 Jun 2020 11:50:55 +0000 (UTC) Delivered-To: bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 647A6352D17 for ; Tue, 23 Jun 2020 11:50:55 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49rl3M266Tz4Q8V for ; Tue, 23 Jun 2020 11:50:55 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 43CE71FA74 for ; Tue, 23 Jun 2020 11:50:55 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 05NBotYS017406 for ; Tue, 23 Jun 2020 11:50:55 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 05NBotkI017405 for bugs@FreeBSD.org; Tue, 23 Jun 2020 11:50:55 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 247498] vd_kbstate not getting reset after keyboard detach/attach? Date: Tue, 23 Jun 2020 11:50:54 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 12.1-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: billblake2018@gmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2020 11:50:55 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D247498 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@FreeBSD.org Reporter: billblake2018@gmail.com I have discovered a condition under which pressing a key results in an inpu= t of the ESC character followed by the key WITHOUT my holding down any ALT key.= =20 (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 open= ed, a program is called to switch to an unused virtual console, reattach the keyboard (with the KBADDKB ioctl), and read a password (with console switch= ing 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 t= hat 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 the= re 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 character= s. I no longer have the kernel knowledge (or the time) track this bug to its l= air, but it seems fairly obvious that vd_kbstate is not getting properly initial= ized 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 sugges= ts that a review of the keyboard attach code is in order. --=20 You are receiving this mail because: You are the assignee for the bug.=