-
Notifications
You must be signed in to change notification settings - Fork 37
fix(usb_host_hid): Harden hid_host_device_close() against concurrent access [WIP] (IEC-434) #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…fer on large report descriptors - Made all the null checks before any dereference - Fixed the unlock path on usb_host_transfer_alloc() error - Clamped req->wLength to some sane maximum (2048 bytes)
tore-espressif
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider adding tests
| } else if ((hid_iface->state == HID_INTERFACE_STATE_WAIT_USER_DELETION || | ||
| hid_iface->user_cb == NULL) && | ||
| hid_iface->state != HID_INTERFACE_STATE_NOT_INITIALIZED) { | ||
| // Second close OR no user callback at all AND not already removed: remove from list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that the '2 calls to close' was present even before. Can you explain why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look! This is still Draft / [WIP]. I’m landing a minimal bug fix first and prepared a draft as we discussed yesterday; if needed, I’ll follow up with a separate refactor to simplify the close logic.
On the “two calls to close”: yes, that existed before. When the upper layer opens the interface, it owns a handle. The first call closes the interface; the second removes the interface from the list and invalidates the handle so the upper layer never holds a dangling reference.
I’m keeping that behavior unchanged here to keep the fix small and low-risk. If you see anything blocking for the bug-fix itself, please feel free to share; otherwise I’ll ping when it’s ready for full review.
038e245 to
e5e6f2d
Compare
1aafd73 to
81b37c9
Compare
Description
Fixed potential race condition in
hid_host_device_close()that could lead to double-free and list corruption under concurrent close/disconnect.Additional notes
hid_iface_tfor simplifying the refactoringRelated
Testing
Checklist
Before submitting a Pull Request, please ensure the following: