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

Aligned alloc/free might have bug #240

Closed
jibsen opened this issue Jun 22, 2018 · 0 comments
Closed

Aligned alloc/free might have bug #240

jibsen opened this issue Jun 22, 2018 · 0 comments

Comments

@jibsen
Copy link
Collaborator

jibsen commented Jun 22, 2018

I just took a quick look through squash-memory.c, and noticed:

size_t padding = alignment - (addr % alignment);
if (padding < sizeof(void*))
padding += alignment;
assert ((padding + size) <= ms);
memcpy ((void*) (addr + padding - sizeof(void*)), &ptr, sizeof(void*));

If, say, alignment is 2, then padding is <= 2, and padding + alignment is still less than the size of a void pointer, so the memcpy will write before the start of the allocated memory.

squash_memfns.free ((void*) (((uintptr_t) ptr) - sizeof(void*)));

As far as I can tell this attempts to free the address at which the original pointer is stored, rather than the actual original pointer. I think there should be a read using memcpy somewhere.

I don't have time to look into this further at the moment, I just wanted to create an issue while I remembered.

jibsen added a commit that referenced this issue Dec 9, 2018
The squash_aligned_free function was not reading back the original
pointer. Also make sure there is room for storing the original
pointer even with small alignment values.

Fixes #240
@jibsen jibsen closed this as completed in 9fbbce9 Dec 11, 2018
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

No branches or pull requests

1 participant