-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[bugfix] Restore overflowed memory copy #661
Conversation
I think the issue is line 68-69:
The 4 bytes pointed by the pbUsrBuf will be overwritten, pdwVal is a 32 bit pointer. I think the best solution would be to add a dummy byte to the usb_cdcacm_line_coding struct (between lines 154-155) so that the memory allocation will always reserve 8 bytes, this way the speed advantage is kept.
|
Hm, having a closer look at the function PMAToUserBufferCopy, it seems to me that it will copy twice as much data as needed.
Result: n x 4 bytes will be copied. Or do I miss something? |
I was missing that the packet buffer memory, as well as all USB registers, are aligned to 32-bit word boundaries although they are 16-bit wide only, see RM0008, chapter 23.5.
Can you please check if this solves the issue? |
yeah, dummy reserved byte can solve my problem, But in fact, the parameters
can only be even number, cann't be odd number |
It looks okay. |
Yea, it looks okay, but it is not fast.
The difference to the original is that the number of times to copy data in word (16-bit) format will not be rounded up. |
I merged my variant as it seems to be a more effective solution than yours. |
Arduino_STM32/STM32F1/system/libmaple/include/libmaple/usb_cdcacm.h
Line 155 in a3a5686
This structure takes up 7 bytes of RAM, under some memory-aligned compilation rules, it takes up 8bytes
This structural variable is passed into the
PMAToUserBufferCopy
function as au8 * pbUsrBuf
parameter in hereArduino_STM32/STM32F1/cores/maple/libmaple/usb/usb_lib/usb_mem.c
Line 60 in a3a5686
If the length of the
pbUsrBuf
parameter is odd, it will tamper with the last byte of the address.If the compiler is single-byte aligned, the structure
line_coding
takes up 7bytes, At this point, the value of the variable that followsline_coding
will be tampered byPMAToUserBufferCopy
.for example:
The normal value of the
test
variable is 0. When thefunction has been executed
The value of the
test
variable will be tampered, not equal 0.thie PR restored tampered data.