Skip to contentSkip to conversation

HID: roccat: fix use-after-free in roccat_report_event

PATCH Applied FirstName LastName 3 participants 3 messages Mar 23 – Mar 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: roccat: fix use-after-free in roccat_report_event

From: Benoît Sevens <[email protected]>

roccat_report_event() iterates over the device->readers list without holding the readers_lock. This allows a concurrent roccat_release() to remove and free a reader while it's still being accessed, leading to a use-after-free.

Protect the readers list traversal with the readers_lock mutex.

---
 drivers/hid/hid-roccat.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hid/hid-roccat.c +2 -0
index fd0ea52f7cba..d6fff53d4ee7 100644
@@ -257,6 +257,7 @@ int roccat_report_event(int minor, u8 const *data)
 	if (!new_value)
 		return -ENOMEM;
 
+	mutex_lock(&device->readers_lock);
 	mutex_lock(&device->cbuf_lock);
 
 	report = &device->cbuf[device->cbuf_end];
@@ -279,6 +280,7 @@ int roccat_report_event(int minor, u8 const *data)
 	}
 
 	mutex_unlock(&device->cbuf_lock);
+	mutex_unlock(&device->readers_lock);
 
 	wake_up_interruptible(&device->wait);
 	return 0;
Signature · 1 line
2.53.0.959.g497ff81fa9-goog
Reviewed-by on v1 1/1
#1 lore raw

Hi

Thanks for the patch! One comment below.

Quoted 19 lines · FirstName LastName

From: Benoît Sevens <[email protected]>

roccat_report_event() iterates over the device->readers list without holding the readers_lock. This allows a concurrent roccat_release() to remove and free a reader while it's still being accessed, leading to a use-after-free.

Protect the readers list traversal with the readers_lock mutex.

---
 drivers/hid/hid-roccat.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hid/hid-roccat.c +0 -0
index fd0ea52f7cba..d6fff53d4ee7 100644

drivers/hid/hid-roccat.c int roccat_report_event(int minor, u8 const *data) · line 260

Quoted 4 lines
drivers/hid/hid-roccat.c +1 -0
@@ -257,6 +257,7 @@ int roccat_report_event(int minor, u8 const *data)
 	if (!new_value)
 		return -ENOMEM;
 
+	mutex_lock(&device->readers_lock);

As the readers are only accessed later, we could move the locking further down. Not sure if it's worth it in this case.

Other than that this LGTM!

Cheers,
Silvan

Quoted 11 lines
drivers/hid/hid-roccat.c +1 -0
 	mutex_lock(&device->cbuf_lock);
 
 	report = &device->cbuf[device->cbuf_end];
@@ -279,6 +280,7 @@ int roccat_report_event(int minor, u8 const *data)
 	}
 
 	mutex_unlock(&device->cbuf_lock);
+	mutex_unlock(&device->readers_lock);
 
 	wake_up_interruptible(&device->wait);
 	return 0;
maintainer Applied
#2 lore raw
In reply to FirstName LastName
Quoted 27 lines · FirstName LastName

From: Benoît Sevens <[email protected]>

roccat_report_event() iterates over the device->readers list without holding the readers_lock. This allows a concurrent roccat_release() to remove and free a reader while it's still being accessed, leading to a use-after-free.

Protect the readers list traversal with the readers_lock mutex.

---
 drivers/hid/hid-roccat.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hid/hid-roccat.c +1 -0
index fd0ea52f7cba..d6fff53d4ee7 100644
@@ -257,6 +257,7 @@ int roccat_report_event(int minor, u8 const *data)
 	if (!new_value)
 		return -ENOMEM;
 
+	mutex_lock(&device->readers_lock);
 	mutex_lock(&device->cbuf_lock);
 
 	report = &device->cbuf[device->cbuf_end];

drivers/hid/hid-roccat.c int roccat_report_event(int minor, u8 const *data) · line 283

Quoted 4 lines
drivers/hid/hid-roccat.c +1 -0
@@ -279,6 +280,7 @@ int roccat_report_event(int minor, u8 const *data)
 	}
 
 	mutex_unlock(&device->cbuf_lock);
+	mutex_unlock(&device->readers_lock);

Applied, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs