-
Notifications
You must be signed in to change notification settings - Fork 8k
usb: enhance verification of the class control requests #36694
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
usb: enhance verification of the class control requests #36694
Conversation
394e842
to
4401e94
Compare
4b2670d
to
f2172ef
Compare
CC @szymonh |
subsys/usb/usb_device.c
Outdated
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 would suggest changing /**
to /*
here just so it isn't picked up by doxygen.
subsys/usb/usb_device.c
Outdated
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 would suggest changing /**
to /*
here just so it isn't picked up by doxygen
@jfischer-no - do we have test coverage for most of these changes? |
No, there is no testbench for current USB device stack. I test such changes manually with testusb and USBCV3. For overhauled USB device stack I plan to implement test based on USBIP. |
Ah, ok. As long as you're testing ;-) Is there someone in particular you would like to review this? As an alternative to USBIP, there are a few other emulated peripheral drivers that are fairly invaluable to CI / automated testing.
USB would be great to have on that list. Kind of surprised it hasn't grown beyond that yet. UART would be an obvious candidate too. |
These are in the review list 😄
It is not that simple. It is not just the driver API (btw, there is simple CI test for USB driver API), it is also the stack that needs to be tested. However, it makes no sense to waste resources on current implementation. |
The emulated peripherals aren't simple per se - the intent is to use them to achieve 100% test coverage for driver APIs along with the stack. Would definitely be something worthwhile to consider if we ever do reimplement the USB stack ;-) |
@d3zd3z - can you please take a look at this? |
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.
NACK just because of missing -ENOTSUP
the rest are clarification questions rather than nack
@jfischer-no - could you address the comments by @emob-nordic ? |
4007f5d
to
88521bf
Compare
Set data stage length variable to zero as a precaution so that no trouble happens if control request handler does not check the request values sufficiently. Signed-off-by: Johann Fischer <[email protected]>
Rework CDC ACM class control request handling and check the control transfer direction. Signed-off-by: Johann Fischer <[email protected]>
Use internal buffer to store request data and not the data OUT stage buffer. Signed-off-by: Johann Fischer <[email protected]>
Control request handler from CDC ECM implementation does not care at all about returning errors when a request is not supported. Return EINVAL/ENOTSUP if request is incorrect/unsupported. Signed-off-by: Johann Fischer <[email protected]>
Return ENOTSUP if request is unsupported and pass on the error from encapsulated command/response functions. Signed-off-by: Johann Fischer <[email protected]>
Rework mute request handling and add checks for control request direction. Signed-off-by: Johann Fischer <[email protected]>
HCI commands are always directed to controller and should be host-to-device class control requests. Signed-off-by: Johann Fischer <[email protected]>
This class does not handle any vendor request, therefore just return -ENOTSUP on any vendor request. Signed-off-by: Johann Fischer <[email protected]>
Rework class control request handler and add control request direction check. Signed-off-by: Johann Fischer <[email protected]>
The sample only supports device-to-host control requests. Return -ENOTSUP on host-to-device control requests. Signed-off-by: Johann Fischer <[email protected]>
Control pipe in wpanusb is used only for host-to-device requests. Signed-off-by: Johann Fischer <[email protected]>
Check control request direction and split class request handler by request direction. Signed-off-by: Johann Fischer <[email protected]>
Halt endpoint on flash API error or block mismatch. Signed-off-by: Johann Fischer <[email protected]>
Obtain the requested length from wLength and assign the possible length to len argument. Signed-off-by: Johann Fischer <[email protected]>
Cleanup standard device request handler. Pass pointer to setup packet as argument where it is reasonable. Signed-off-by: Johann Fischer <[email protected]>
Cleanup standard endpoint request handler. Signed-off-by: Johann Fischer <[email protected]>
Cleanup standard device request handler. Pass pointer to setup packet as argument where it is reasonable. Signed-off-by: Johann Fischer <[email protected]>
Check request direction in standard device, interface, and endpoint request handlers. Signed-off-by: Johann Fischer <[email protected]>
88521bf
to
dbfd641
Compare
Set data stage length variable to zero as a precaution
so that no trouble happens if control request handler
does not check the request values sufficiently.
Check the control transfer direction in CDC classes, bluetooth, audio, and DFU.