Skip to content

Fix a few issues detected with static code analysis - #131

Closed
tsautereau-anssi wants to merge 3 commits into
GrapheneOS:masterfrom
tsautereau-anssi:tsautereau/fixes
Closed

tsautereau-anssi wants to merge 3 commits into
GrapheneOS:masterfrom
tsautereau-anssi:tsautereau/fixes

Conversation

@tsautereau-anssi

Copy link
Copy Markdown
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.
Comment thread h_malloc.c
}
}

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

Copy link
Copy Markdown
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

thestinger commented Feb 10, 2021 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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