public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Patch "platform/x86: xiaomi-wmi: Fix race condition when reporting key events" has been added to the 6.6-stable tree
       [not found] <20240526194314.3503546-1-sashal@kernel.org>
@ 2024-05-26 22:59 ` Armin Wolf
  2024-06-12 12:40   ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Armin Wolf @ 2024-05-26 22:59 UTC (permalink / raw)
  To: stable, stable-commits; +Cc: Hans de Goede, Ilpo Järvinen

Am 26.05.24 um 21:43 schrieb Sasha Levin:

> This is a note to let you know that I've just added the patch titled
>
>      platform/x86: xiaomi-wmi: Fix race condition when reporting key events
>
> to the 6.6-stable tree which can be found at:
>      http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
>
> The filename of the patch is:
>       platform-x86-xiaomi-wmi-fix-race-condition-when-repo.patch
> and it can be found in the queue-6.6 subdirectory.
>
> If you, or anyone else, feels it should not be added to the stable tree,
> please let <stable@vger.kernel.org> know about it.
>
Hi,

the underlying race condition can only be triggered since
commit e2ffcda16290 ("ACPI: OSL: Allow Notify () handlers to run on all CPUs"), which
afaik was introduced with kernel 6.8.

Because of this, i do not think that we have to backport this commit to kernels before 6.8.

Thanks,
Armin Wolf

>
> commit 831f943a69833152081ec7393af598f0c8b415fa
> Author: Armin Wolf <W_Armin@gmx.de>
> Date:   Tue Apr 2 16:30:57 2024 +0200
>
>      platform/x86: xiaomi-wmi: Fix race condition when reporting key events
>
>      [ Upstream commit 290680c2da8061e410bcaec4b21584ed951479af ]
>
>      Multiple WMI events can be received concurrently, so multiple instances
>      of xiaomi_wmi_notify() can be active at the same time. Since the input
>      device is shared between those handlers, the key input sequence can be
>      disturbed.
>
>      Fix this by protecting the key input sequence with a mutex.
>
>      Compile-tested only.
>
>      Fixes: edb73f4f0247 ("platform/x86: wmi: add Xiaomi WMI key driver")
>      Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>      Link: https://lore.kernel.org/r/20240402143059.8456-2-W_Armin@gmx.de
>      Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
>      Reviewed-by: Hans de Goede <hdegoede@redhat.com>
>      Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>      Signed-off-by: Sasha Levin <sashal@kernel.org>
>
> diff --git a/drivers/platform/x86/xiaomi-wmi.c b/drivers/platform/x86/xiaomi-wmi.c
> index 54a2546bb93bf..be80f0bda9484 100644
> --- a/drivers/platform/x86/xiaomi-wmi.c
> +++ b/drivers/platform/x86/xiaomi-wmi.c
> @@ -2,8 +2,10 @@
>   /* WMI driver for Xiaomi Laptops */
>
>   #include <linux/acpi.h>
> +#include <linux/device.h>
>   #include <linux/input.h>
>   #include <linux/module.h>
> +#include <linux/mutex.h>
>   #include <linux/wmi.h>
>
>   #include <uapi/linux/input-event-codes.h>
> @@ -20,12 +22,21 @@
>
>   struct xiaomi_wmi {
>   	struct input_dev *input_dev;
> +	struct mutex key_lock;	/* Protects the key event sequence */
>   	unsigned int key_code;
>   };
>
> +static void xiaomi_mutex_destroy(void *data)
> +{
> +	struct mutex *lock = data;
> +
> +	mutex_destroy(lock);
> +}
> +
>   static int xiaomi_wmi_probe(struct wmi_device *wdev, const void *context)
>   {
>   	struct xiaomi_wmi *data;
> +	int ret;
>
>   	if (wdev == NULL || context == NULL)
>   		return -EINVAL;
> @@ -35,6 +46,11 @@ static int xiaomi_wmi_probe(struct wmi_device *wdev, const void *context)
>   		return -ENOMEM;
>   	dev_set_drvdata(&wdev->dev, data);
>
> +	mutex_init(&data->key_lock);
> +	ret = devm_add_action_or_reset(&wdev->dev, xiaomi_mutex_destroy, &data->key_lock);
> +	if (ret < 0)
> +		return ret;
> +
>   	data->input_dev = devm_input_allocate_device(&wdev->dev);
>   	if (data->input_dev == NULL)
>   		return -ENOMEM;
> @@ -59,10 +75,12 @@ static void xiaomi_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy)
>   	if (data == NULL)
>   		return;
>
> +	mutex_lock(&data->key_lock);
>   	input_report_key(data->input_dev, data->key_code, 1);
>   	input_sync(data->input_dev);
>   	input_report_key(data->input_dev, data->key_code, 0);
>   	input_sync(data->input_dev);
> +	mutex_unlock(&data->key_lock);
>   }
>
>   static const struct wmi_device_id xiaomi_wmi_id_table[] = {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Patch "platform/x86: xiaomi-wmi: Fix race condition when reporting key events" has been added to the 6.6-stable tree
  2024-05-26 22:59 ` Patch "platform/x86: xiaomi-wmi: Fix race condition when reporting key events" has been added to the 6.6-stable tree Armin Wolf
@ 2024-06-12 12:40   ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2024-06-12 12:40 UTC (permalink / raw)
  To: Armin Wolf; +Cc: stable, stable-commits, Hans de Goede, Ilpo Järvinen

On Mon, May 27, 2024 at 12:59:49AM +0200, Armin Wolf wrote:
> Am 26.05.24 um 21:43 schrieb Sasha Levin:
> 
> > This is a note to let you know that I've just added the patch titled
> > 
> >      platform/x86: xiaomi-wmi: Fix race condition when reporting key events
> > 
> > to the 6.6-stable tree which can be found at:
> >      http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > 
> > The filename of the patch is:
> >       platform-x86-xiaomi-wmi-fix-race-condition-when-repo.patch
> > and it can be found in the queue-6.6 subdirectory.
> > 
> > If you, or anyone else, feels it should not be added to the stable tree,
> > please let <stable@vger.kernel.org> know about it.
> > 
> Hi,
> 
> the underlying race condition can only be triggered since
> commit e2ffcda16290 ("ACPI: OSL: Allow Notify () handlers to run on all CPUs"), which
> afaik was introduced with kernel 6.8.
> 
> Because of this, i do not think that we have to backport this commit to kernels before 6.8.

Thanks for looking into this and letting us know!

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-12 12:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20240526194314.3503546-1-sashal@kernel.org>
2024-05-26 22:59 ` Patch "platform/x86: xiaomi-wmi: Fix race condition when reporting key events" has been added to the 6.6-stable tree Armin Wolf
2024-06-12 12:40   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox