From: Cen Zhang <zzzccc427@gmail.com>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
baijiaju1990@gmail.com, Cen Zhang <zzzccc427@gmail.com>
Subject: [PATCH] vt: keyboard: serialize KDGETLED with keyboard_tasklet
Date: Sun, 10 May 2026 11:13:48 +0800 [thread overview]
Message-ID: <20260510031348.1922157-1-zzzccc427@gmail.com> (raw)
KDGETLED reaches getledstate() and samples ledstate without serializing
against keyboard_tasklet.
That is problematic because kbd_bh() temporarily stores ~leds into
ledstate during a VT switch to force LED propagation before committing
the final value. An unlocked KDGETLED can therefore observe that
internal sentinel instead of the last committed LED state.
Other ledstate readers in this file already quiesce keyboard_tasklet
before sampling the value. Do the same in getledstate() so the ioctl
only returns a stable snapshot.
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
drivers/tty/vt/keyboard.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 13bc048f45e86..671ad4a5cb64c 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -1127,7 +1127,13 @@ static void kbd_init_leds(void)
*/
static unsigned char getledstate(void)
{
- return ledstate & 0xff;
+ unsigned char leds;
+
+ tasklet_disable(&keyboard_tasklet);
+ leds = ledstate & 0xff;
+ tasklet_enable(&keyboard_tasklet);
+
+ return leds;
}
void setledstate(struct kbd_struct *kb, unsigned int led)
--
2.43.0
next reply other threads:[~2026-05-10 3:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-10 3:13 Cen Zhang [this message]
2026-05-10 16:21 ` [PATCH] vt: keyboard: serialize KDGETLED with keyboard_tasklet Greg KH
2026-05-10 16:43 ` Cen Zhang
2026-05-10 16:55 ` Greg KH
2026-05-10 17:01 ` Cen Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260510031348.1922157-1-zzzccc427@gmail.com \
--to=zzzccc427@gmail.com \
--cc=baijiaju1990@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox