[PATCH v3 2/2] tty: sysrq: reset the per-device key state when reparsing reset_seq

From: Zhan Xusheng

Date: Tue Oct 20 2026 - 22:24:04 EST


From: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>

sysrq_parse_reset_sequence() clears reset_seq_cnt, but reset_keybit is
only ever __set_bit() and reset_seq_len only ever incremented. struct
sysrq_state is allocated once per input device in sysrq_connect() and
lives until the device goes away, so both accumulate every time the
sequence is reparsed, which happens whenever the mode 0644 reset_seq
parameter is written.

After writing 56,29,111 and then 59,60 a device keeps all five keys in
reset_keybit with reset_seq_len 5, so the effective combination is the
union of the old and the new sequence. Holding just 59 and 60 counts two
of five and does nothing, while releasing a stale key drives
reset_seq_cnt below zero.

Clear both along with reset_seq_cnt. Also delete keyreset_timer: with
sysrq_downtime_ms set, holding a full sequence arms it, and it is only
deleted on a press outside the sequence or a release inside it. Dropping
the old keys from reset_keybit removes both of those cancellations, so an
already armed reset would survive into orderly_reboot().

Fixes: 154b7a489a5b ("Input: sysrq - allow specifying alternate reset sequence")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
---
drivers/tty/sysrq.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 4fd5b3ace9c40..bb202fc1ccf0b 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -691,6 +691,15 @@ static void sysrq_parse_reset_sequence(struct sysrq_state *state)
int i;
unsigned short key;

+ /*
+ * An armed reset belongs to the sequence being replaced: once the
+ * old keys are gone from reset_keybit their release no longer
+ * cancels it.
+ */
+ timer_delete(&state->keyreset_timer);
+
+ bitmap_zero(state->reset_keybit, KEY_CNT);
+ state->reset_seq_len = 0;
state->reset_seq_cnt = 0;

for (i = 0; i < len; i++) {
--
2.43.0