Skip to content
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

Fix memory corruption bug #164

Merged
merged 1 commit into from
Oct 18, 2023
Merged

Fix memory corruption bug #164

merged 1 commit into from
Oct 18, 2023

Conversation

alrvid
Copy link
Contributor

@alrvid alrvid commented Oct 18, 2023

A problem occurs when get_new_address() returns address 5, and that number ends up at this line as dev_addr:

_hcd.ep[dev_addr - 1][dir_in][epn - 1] = num;

in hcd_edpt_open() in hcd_rusb2.c(). It becomes 4 and is then used to index the ep array. There's an assert that checks that the address is below 6, so it passes the assert:

TU_ASSERT(dev_addr < 6);

Then the 4 is used as the first index of the ep array, which is defined like so:

uint8_t ep[4][2][15];

This index may only be 0 to 3, so the array is now indexed outside its bounds. And then num is written to that location, which corrupts memory at random locations.

It can be worked around by lowering the value of CFG_TUH_DEVICE_MAX in the configuration file by one. I've also created an issue for TinyUSB.

A problem occurs when get_new_address() returns address 5, and that number ends up at this line as dev_addr:

_hcd.ep[dev_addr - 1][dir_in][epn - 1] = num;

in hcd_edpt_open() in hcd_rusb2.c(). It becomes 4 and is then used to index the ep array. There's an assert that checks that the address is below 6, so it passes the assert:

TU_ASSERT(dev_addr < 6);

Then the 4 is used as the first index of the ep array, which is defined like so:

uint8_t ep[4][2][15];

This index may only be 0 to 3, so the array is now indexed outside its bounds. And then num is written to that location, which corrupts memory at random locations.

It can be worked around by lowering the value of CFG_TUH_DEVICE_MAX in the configuration file by one. I've also created an issue for TinyUSB.
@alrvid alrvid requested a review from facchinm October 18, 2023 08:43
@facchinm facchinm merged commit 87db445 into arduino:main Oct 18, 2023
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants