The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] vt: keyboard: serialize KDGETLED with keyboard_tasklet
@ 2026-05-10  3:13 Cen Zhang
  2026-05-10 16:21 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Cen Zhang @ 2026-05-10  3:13 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-kernel, linux-serial, baijiaju1990, Cen Zhang

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-10 17:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-10  3:13 [PATCH] vt: keyboard: serialize KDGETLED with keyboard_tasklet Cen Zhang
2026-05-10 16:21 ` Greg KH
2026-05-10 16:43   ` Cen Zhang
2026-05-10 16:55     ` Greg KH
2026-05-10 17:01       ` Cen Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox