Skip to content

tty: sysrq: fix the reset sequence kept per input device

Zhan Xusheng linux-input linux-serial lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 7 repliesIn review
  2. v32 patches 0 repliesSuperseded

Changes in v4 from the cover letter

- Dropped v3 1/2 and replaced it with the seqlock patch (Sashiko flagged the window on v3 1/2).
- Reject KEY_RESERVED in the parameter instead of storing it.
- Dropped the stable tags.
- Tested in QEMU rather than by inspection only.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2tty: sysrq: don't expose a partially written reset_seqdrivers/tty/sysrq.c+99 -347 replies
2/2tty: sysrq: reset the per-device key state when reparsing reset_seqdrivers/tty/sysrq.c+8 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/2] tty: sysrq: fix the reset sequence kept per input device

From: Zhan Xusheng <[email protected]>

v3 1/2 was wrong and is dropped. It stopped a truncated parse from being cached, but the parse still reached sysrq_detect_reset_sequence() in the same call and could complete a reset. param_array() publishes every intermediate sequence with a fresh version, so no reader-side check can tell them from the final one; 1/2 now parses the whole parameter in one callback and replaces it under a seqlock. 2/2 is the same fix adapted to the new 1/2, and depends on it.

Both fix bugs from the same 2013 commit and apply to every stable tree, but 1/2 is over the 100-line limit in stable-kernel-rules.rst, so I left the stable tags out. The two have to go together.

Tested in QEMU with a uinput keyboard, one device per scenario so the per-device state survives the parameter writes:

                                           before       after
  hold the full sequence                   reboots      reboots
  hold one key of two                      no           no
  hold the old sequence after a rewrite    no           no
  0x3b,0x3c                                reboots      reboots
  hold the new sequence after a rewrite    no           reboots
  release a stale key, then hold the new   no           reboots
  press key 1 while the write is mid-way   reboots      no

The last row needs a 500 ms delay to widen the window, in sysrq_reset_seq_param_set() before the series and inside the seqlock section after it. Without 2/2's timer_delete() the armed reset survives the replacement and fires. Rejected input is the same apart from the two cases listed in 1/2, and reset_seq reads back the same.

Changes in v4:
- Dropped v3 1/2 and replaced it with the seqlock patch (Sashiko flagged the window on v3 1/2).
- Reject KEY_RESERVED in the parameter instead of storing it.
- Dropped the stable tags.
- Tested in QEMU rather than by inspection only.

Changes in v3:
- Added a first patch so that a truncated parse no longer sticks (Sashiko).
- Added Fixes: to both patches.

Changes in v2:
- Retitled from "Input:" to "tty: sysrq:" (Greg Kroah-Hartman).
- Delete keyreset_timer, otherwise an already armed reset survives the reparse (Sashiko).

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Zhan Xusheng (2):
tty: sysrq: don't expose a partially written reset_seq
tty: sysrq: reset the per-device key state when reparsing reset_seq

 drivers/tty/sysrq.c | 142 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 107 insertions(+), 35 deletions(-)

base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8

Signature · 1 line
2.43.0