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

Add mechanism to check for invalid sized frees #13661

Open
ronawho opened this issue Aug 6, 2019 · 3 comments
Open

Add mechanism to check for invalid sized frees #13661

ronawho opened this issue Aug 6, 2019 · 3 comments
Assignees

Comments

@ronawho
Copy link
Contributor

ronawho commented Aug 6, 2019

Spawned off from #13611 (comment)

Our array allocation sub-interface requires the allocation size when free'ing:

void chpl_mem_array_free(void* p,
size_t nmemb, size_t eltSize,
int32_t lineno, int32_t filename) {

We do this so we can figure out if we've allocated memory through the comm layer, or through the normal memory interface. Passing in the wrong size to the free routine can result in mixed allocation calls, which is UB and can cause bugs like: #13611

We should add the ability to check if the free size matches the allocation size. Note that this requires storing the sizes of allocations, so we don't want to do this by default, but that's something we already track for --memTrack so we can probably add that as a sanity check there pretty easily.

@ronawho ronawho self-assigned this Aug 6, 2019
@ronawho
Copy link
Contributor Author

ronawho commented Aug 6, 2019

This ended being pretty straightforward. I have a prototype branch at https://github.com/ronawho/chapel/tree/check-sized-dealloc, and I'll try to PR that this week.

@ronawho
Copy link
Contributor Author

ronawho commented Jun 24, 2020

See #15918 (comment) for additional motivation.

@ronawho
Copy link
Contributor Author

ronawho commented Jul 16, 2021

We should do these checks for the realloc path too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant