-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Remove MAX_CTRL_BUFFER_LENGTH Limitation From Linux Build #1359
base: master
Are you sure you want to change the base?
Conversation
Reference existing issue: |
Refer to mailing list answer from Alan Stern, one of the leading Linux USB developer. +++++++++++++++ At least part of the reason for this is that some of the Linux host Alan Stern |
As libusb is widely used and we do not now the user base well enough, for example, some embedded Linux distro may still have the same limitation. Therefore I do not think we can take this PR. |
For Windows, the size limit is documented by Microsoft. libusb dropped the support of Windows XP, but Windows Vista/7/8/8.1 are still supported (not so sure if anyone still cares about Windows Vista though). 64K for SuperSpeed and high speed (xHCI) |
I think we can close this PR. |
What happens if you send more data than the OS / controller supports? Wouldn't you receive an error from the backend anyway, even without this check in libusb itself? |
even you device support more than 4K you'r application shall never assume what it can get you can't assume what is Host or hub bus speed capability you end up pluged into . Anyway control transfer are bad they're meant for system control not application data exchange it's a waste of bus bandwidth and it is jeopardizing ep0 usage on composite device. |
I agree. We should probably close this. 4k is plenty for control transfers. |
To me, I don't think it's about "how much you need" but rather about erroring too early and in a platform-specific way. It's something I ran into before as well - if I don't know how much data to expect, I'm happy to just give the OS a larger buffer, all the way up to 64K bytes (uint16 max, maximum possible for But, libusb errors out early due to If libusb knows that the OS doesn't support buffers larger than 4096 bytes, I think a better developer experience would be to clamp the transfer length to those 4096 bytes rather than return an error. If the device ever returns more data, then user will get the actual "babble" status, but if not - and, as you noted, usually it should be enough - then passing larger buffers won't be an error but the buffer simply won't be filled to its full capacity, like with any other transfers. This would allow to better abstract out OS-specific limits from the high-level libusb API. |
TL;DR instead of just removing this condition altogether, I'd clamp the transfer length for "in" transfers to the OS-specific limit. This way you still get errors if the device genuinely happens to return more data than the OS allows, and no errors otherwise. |
@mcuee, @hjelmn what if we make this limitation a runtime variable? @RReverser has a point that sometime one simply wants to laverage a platform-specific behavior. |
It seems to be a good improvement. @hjelmn and @tormodvolden How do you like this idea from @Youw? |
FWIW for me the more important part is clamping instead of erroring as mentioned above. Without it, code using libusb is not really platform-agnostic as it needs to know on which platform it's running and hardcode those limits at the application level. That is, re: "has a point that sometime one simply wants to laverage a platform-specific behavior" for me it's kinda the opposite, I want to avoid platform-specific behaviour to leak into apps. Custom limits alone don't help with this particular issue much. |
Both the Linux and Windows versions of LibUSB have a limitation placed on the size of Control Transfers that can be sent using LibUSB, returning a LIBUSB_ERROR_INVALID_PARAM error if the size of the buffer exceeds 4096 bytes. This is an artificial limitation, as most modern hardware is capable of handling control transfer buffers up to the 65535 byte limit, and in Linux specifically there is nothing in the Kernel to reject larger buffers. I have created this patch specifically for Linux, however it would likely also be viable for Windows.
The presence of this limitation means that users who wish to use LibUSB to identify vulnerabilities in USB devices, or communicate with devices which permit buffer sizes of greater than 4096 bytes, will be presented with an error message that they would have to manually remove from the library. This patch simply removes the limitation, preventing the library from throwing a LIBUSB_ERROR_INVALID_PARAM error when >4096 bytes are used in control transfers on Linux builds.