]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Input: uinput - take event lock when submitting FF request "event"
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 8 Apr 2026 05:16:27 +0000 (22:16 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Apr 2026 08:35:56 +0000 (10:35 +0200)
commit ff14dafde15c11403fac61367a34fea08926e9ee upstream.

To avoid racing with FF playback events and corrupting device's event
queue take event_lock spinlock when calling uinput_dev_event() when
submitting a FF upload or erase "event".

Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Link: https://patch.msgid.link/adXkf6MWzlB8LA_s@google.com
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/input/misc/uinput.c

index bd8be236af756b2dbbfb23083e8bd04a0930a927..449dbf90d2473a6e5628e7e281d31b2172d77281 100644 (file)
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/fs.h>
+#include <linux/lockdep.h>
 #include <linux/miscdevice.h>
 #include <linux/overflow.h>
+#include <linux/spinlock.h>
 #include <linux/input/mt.h>
 #include "../input-compat.h"
 
@@ -75,6 +77,8 @@ static int uinput_dev_event(struct input_dev *dev,
        struct uinput_device    *udev = input_get_drvdata(dev);
        struct timespec64       ts;
 
+       lockdep_assert_held(&dev->event_lock);
+
        ktime_get_ts64(&ts);
 
        udev->buff[udev->head] = (struct input_event) {
@@ -146,6 +150,7 @@ static void uinput_request_release_slot(struct uinput_device *udev,
 static int uinput_request_send(struct uinput_device *udev,
                               struct uinput_request *request)
 {
+       unsigned long flags;
        int retval = 0;
 
        spin_lock(&udev->state_lock);
@@ -159,7 +164,9 @@ static int uinput_request_send(struct uinput_device *udev,
         * Tell our userspace application about this new request
         * by queueing an input event.
         */
+       spin_lock_irqsave(&udev->dev->event_lock, flags);
        uinput_dev_event(udev->dev, EV_UINPUT, request->code, request->id);
+       spin_unlock_irqrestore(&udev->dev->event_lock, flags);
 
  out:
        spin_unlock(&udev->state_lock);