Skip to contentSkip to conversation

tty: sysrq: clear the old reset sequence when reset_seq changes

PATCH New Zhan Xusheng 2 participants 2 messages Oct 30

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 tty: sysrq: clear the old reset sequence when reset_seq changes

From: Zhan Xusheng <[email protected]>

Changing reset_seq at runtime does not work on a keyboard that already used the old value, because each keyboard adds the new keys to its own copy instead of replacing it:

echo 56,29,111 > /sys/module/sysrq/parameters/reset_seq # Alt+Ctrl+Del (press any key)
echo 59,60 > /sys/module/sysrq/parameters/reset_seq # F1+F2

F1+F2 then does nothing; only all five keys together reset.

Clear the old keys when the copy is rebuilt. If sysrq_downtime_ms is set, also stop a reset the old keys already started, since releasing them no longer cancels it.

A key pressed while reset_seq is being written can see a partial sequence. With this change that can happen on any keyboard, not only on ones that never used a sequence, but the window is a few microseconds and not worth closing.

Fixes 154b7a489a5b ("Input: sysrq - allow specifying alternate reset sequence")
Assisted-by Kiro:claude-opus-5.5

---
v5: Dropped v4 1/2 and rewrote the changelog. Tested in QEMU with a uinput keyboard: the new sequence resets, while the old one and a reset armed before the rewrite do not.

v4: https://lore.kernel.org/all/[email protected]/

 drivers/tty/sysrq.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/tty/sysrq.c +5 -0
index f4571d05b496..a90e97a6d7aa 100644
@@ -689,6 +689,11 @@ static void sysrq_parse_reset_sequence(struct sysrq_state *state)
 	int i;
 	unsigned short key;
 
+	/* A reset armed by the old sequence must not outlive 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: c339f4010dea8b0d754f84ace70cd1b089878ef8

Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 21 lines

From: Zhan Xusheng <[email protected]>

Changing reset_seq at runtime does not work on a keyboard that already used the old value, because each keyboard adds the new keys to its own copy instead of replacing it:

echo 56,29,111 > /sys/module/sysrq/parameters/reset_seq # Alt+Ctrl+Del (press any key)
echo 59,60 > /sys/module/sysrq/parameters/reset_seq # F1+F2

F1+F2 then does nothing; only all five keys together reset.

Clear the old keys when the copy is rebuilt. If sysrq_downtime_ms is set, also stop a reset the old keys already started, since releasing them no longer cancels it.

A key pressed while reset_seq is being written can see a partial sequence. With this change that can happen on any keyboard, not only on ones that never used a sequence, but the window is a few microseconds and not worth closing.

Quoted 4 lines
Fixes 154b7a489a5b ("Input: sysrq - allow specifying alternate reset sequence")
Assisted-by Kiro:claude-opus-5.5

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1