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 a few issues detected with static code analysis #131

Closed

Conversation

tsautereau-anssi
Copy link
Contributor

Static code analysis of hardened_malloc flagged some small issues. This pull request proposes fixes for three of them, and I'll open an issue to discuss the remaining ones, if that's OK for you.

All other calls to memory_map_fixed() are checked, and this one may also
theoretically fail.
It's the region pointer that can be NULL here, and p was checked at the
beginning of the function. Also fix the test accordingly.
It's the region pointer that can be NULL here, and p was checked at the
beginning of the function.
@@ -903,7 +903,10 @@ static int regions_grow(void) {
}
}

memory_map_fixed(ra->regions, ra->total * sizeof(struct region_metadata));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call shouldn't be checked because failure doesn't impact whether the function succeeded. It doesn't really matter if it succeeds. The point of doing this is to free memory.

@thestinger
Copy link
Member

thestinger commented Feb 10, 2021

I've cherry-picked the other 2 commits. I reworded the commit messages to explain what was wrong in both cases.

The malloc_usable_size fix makes it abort as intended rather than getting a guaranteed access fault.

The malloc_object_size fix is more important since it's needed for that function to work as intended as it's not supposed to abort when passing in an invalid pointer. The object size functions still need more work and testing before we can start using them. GrapheneOS used to have an implementation that was being actively used for the previous allocator but we haven't yet reimplemented the features using this.

@thestinger
Copy link
Member

The memory_map_fixed call you're changing is for freeing memory when possible. If it fails, that means the memory wasn't freed. That shouldn't lead to a memory allocation failure. There's nothing that can or should be done about that kind of thing failing.

@thestinger thestinger closed this Feb 10, 2021
@tsautereau-anssi
Copy link
Contributor Author

The memory_map_fixed call you're changing is for freeing memory when possible. If it fails, that means the memory wasn't freed. That shouldn't lead to a memory allocation failure. There's nothing that can or should be done about that kind of thing failing.

Alright, maybe a comment would help clarify this for future source code reviews/analyses, but thanks for the explanation!

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