Re: [PATCH] tty: sysrq: serialize sysrq_toggle_support()

From: Greg Kroah-Hartman

Date: Wed Dec 02 2026 - 04:48:04 EST


On Wed, Dec 02, 2026 at 01:23:06AM -0800, Rahul Priolkar wrote:
> 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);

Why WRITE_ONCE if you have a mutex?

And you have a mutex that only works for writing?

what exactly is the "bug" here you are trying to fix?

confused,

greg k-h