Skip to content

Commit ff14daf

Browse files
committed
Input: uinput - take event lock when submitting FF request "event"
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Cc: [email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 4cda78d commit ff14daf

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

drivers/input/misc/uinput.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
#include <linux/module.h>
2626
#include <linux/init.h>
2727
#include <linux/fs.h>
28+
#include <linux/lockdep.h>
2829
#include <linux/miscdevice.h>
2930
#include <linux/overflow.h>
31+
#include <linux/spinlock.h>
3032
#include <linux/input/mt.h>
3133
#include "../input-compat.h"
3234

@@ -76,6 +78,8 @@ static int uinput_dev_event(struct input_dev *dev,
7678
struct uinput_device *udev = input_get_drvdata(dev);
7779
struct timespec64 ts;
7880

81+
lockdep_assert_held(&dev->event_lock);
82+
7983
ktime_get_ts64(&ts);
8084

8185
udev->buff[udev->head] = (struct input_event) {
@@ -147,6 +151,7 @@ static void uinput_request_release_slot(struct uinput_device *udev,
147151
static int uinput_request_send(struct uinput_device *udev,
148152
struct uinput_request *request)
149153
{
154+
unsigned long flags;
150155
int retval = 0;
151156

152157
spin_lock(&udev->state_lock);
@@ -160,7 +165,9 @@ static int uinput_request_send(struct uinput_device *udev,
160165
* Tell our userspace application about this new request
161166
* by queueing an input event.
162167
*/
168+
spin_lock_irqsave(&udev->dev->event_lock, flags);
163169
uinput_dev_event(udev->dev, EV_UINPUT, request->code, request->id);
170+
spin_unlock_irqrestore(&udev->dev->event_lock, flags);
164171

165172
out:
166173
spin_unlock(&udev->state_lock);

0 commit comments

Comments
 (0)