Commit 07fa7e8
Fix race condition in libusb hotplug: protect devs with mutex in process_hotplug_event
In process_hotplug_event(), the devs list was modified without holding
hid_hotplug_context.mutex. Meanwhile, hid_hotplug_register_callback()
iterates devs under that mutex during HID_API_HOTPLUG_ENUMERATE. A device
disconnect processed by callback_thread could free a devs entry while
the ENUMERATE loop was still traversing it, causing a use-after-free.
Fix by wrapping process_hotplug_event() with hid_hotplug_context.mutex.
The mutex is recursive, so hid_internal_invoke_callbacks() (which also
acquires it) works correctly. This aligns with how the linux backend
handles the same scenario.
Agent-Logs-Url: https://github.com/libusb/hidapi/sessions/cb1dc652-1f96-457d-8319-55e4a6f6e6f3
Co-authored-by: Youw <5939659+Youw@users.noreply.github.com>1 parent e43174a commit 07fa7e8
1 file changed
+9
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
177 | | - | |
| 176 | + | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| |||
1165 | 1165 | | |
1166 | 1166 | | |
1167 | 1167 | | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
1168 | 1173 | | |
1169 | 1174 | | |
1170 | 1175 | | |
| |||
1205 | 1210 | | |
1206 | 1211 | | |
1207 | 1212 | | |
| 1213 | + | |
| 1214 | + | |
1208 | 1215 | | |
1209 | 1216 | | |
1210 | 1217 | | |
| |||
0 commit comments