[PATCH] tty: sysrq: serialize sysrq_toggle_support()
From: Rahul Priolkar
Date: Wed Dec 02 2026 - 04:23:13 EST
Hi,
Thanks for the response. Here's the patch.
-- >8 --
Concurrent enable-mask updates in sysrq_toggle_support() can both
register the static SysRq input handler, corrupting input_handler_list.
Serialize the mask update and the corresponding handler registration or
unregistration with a mutex. Both callers run in process context.
Fixes: 97f5f0cd8cd0 ("Input: implement SysRq as a separate input handler")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Rahul Priolkar <rahul.priolkar@xxxxxxx>
---
drivers/tty/sysrq.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index f4571d05b..882d7ae43 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -1100,11 +1100,17 @@ static inline void sysrq_unregister_handler(void)
#endif /* CONFIG_INPUT */
+/* Serializes enable-mask updates with the handler (un)registration they imply. */
+static DEFINE_MUTEX(sysrq_toggle_mutex);
+
int sysrq_toggle_support(int enable_mask)
{
- bool was_enabled = sysrq_on();
+ bool was_enabled;
- sysrq_enabled = enable_mask;
+ guard(mutex)(&sysrq_toggle_mutex);
+
+ was_enabled = sysrq_on();
+ WRITE_ONCE(sysrq_enabled, enable_mask);
if (was_enabled != sysrq_on()) {
if (sysrq_on())
--
2.56.0