From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
stable@vger.kernel.org, linux-serial@vger.kernel.org,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Zhan Xusheng <zhanxusheng@xiaomi.com>
Subject: [PATCH v2] tty: sysrq: reset the per-device key state when reparsing reset_seq
Date: Fri, 16 Oct 2026 15:06:36 +0800 [thread overview]
Message-ID: <20261016070636.2559899-1-zhanxusheng@xiaomi.com> (raw)
sysrq_parse_reset_sequence() clears reset_seq_cnt, but reset_keybit is
only ever __set_bit() and reset_seq_len only ever incremented, and
nothing else clears either. 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 reset_seq module parameter is written:
# echo 56,29,111 > /sys/module/sysrq/parameters/reset_seq
# echo 59,60 > /sys/module/sysrq/parameters/reset_seq
After the second write reset_keybit holds all five keys and reset_seq_len
is 5, so the combination that resets the machine is the union of the old
and the new one. Holding just 59+60 counts 2 of 5 and does nothing.
Releasing one of the stale keys decrements reset_seq_cnt below zero.
Clear both along with reset_seq_cnt.
Doing only that would drop a cancellation the stale bits were providing
by accident: with sysrq_downtime_ms set, holding a full sequence arms
keyreset_timer, and the timer is only deleted on a press outside the
sequence or a release inside it. With the old keys gone from
reset_keybit their release matches neither, and the armed reset survives
into orderly_reboot(). Delete the timer as well, since it belongs to the
sequence being replaced.
The boot paths are unaffected: the command line and
sysrq_of_get_keyreset_config() leave sysrq_reset_seq_version at 1, so a
freshly kzalloc'd state parses once with both fields already zero.
Fixes: 154b7a489a5b ("Input: sysrq - allow specifying alternate reset sequence")
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
v1: https://lore.kernel.org/all/20261016032732.2328852-1-zhanxusheng@xiaomi.com/
v1 -> v2:
- Retitle from "Input:" to "tty: sysrq:" and add Cc: stable, per Greg KH.
- Delete keyreset_timer when the sequence is redefined. Clearing
reset_keybit removes a cancellation the stale bits were providing by
accident, so without this an armed reset would survive the release of
the old keys. Reported by the Sashiko bot.
- Fix the description of the breakage. reset_seq_cnt does reach
reset_seq_len once every accumulated key is held, so the reset
combination becomes the union of the old and the new sequence rather
than stopping working.
drivers/tty/sysrq.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index c2e4b31b699aa..013ad3a500703 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -689,6 +689,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 < sysrq_reset_seq_len; i++) {
base-commit: 2f2f7eeef8b0a1a9b9ca998231419873ccae8d4e
--
2.43.0
next reply other threads:[~2026-10-16 7:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 7:06 Zhan Xusheng [this message]
2026-10-16 7:19 ` [PATCH v2] tty: sysrq: reset the per-device key state when reparsing reset_seq sashiko-bot
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=20261016070636.2559899-1-zhanxusheng@xiaomi.com \
--to=zhanxusheng1024@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=stable@vger.kernel.org \
--cc=zhanxusheng@xiaomi.com \
/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