This is an archive of the discontinued LLVM Phabricator instance.

[scudo] releaseToOSMaybe can fail if it can't allocate PageMap
ClosedPublic

Authored by Chia-hungDuan on May 24 2023, 3:01 PM.

Details

Summary

PageMap is allocated with MAP_ALLOWNOMEM if there's no static buffer
left. So it can be failed and return nullptr without any assertion
triggered. Instead of crashing in the releaseToOSMaybe in the middle,
just return and let the program handles the page failure.

Diff Detail

Event Timeline

Chia-hungDuan created this revision.May 24 2023, 3:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 3:01 PM
Herald added subscribers: yaneury, Enna1. · View Herald Transcript
Chia-hungDuan requested review of this revision.May 24 2023, 3:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 3:01 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Remove UNLIKELY attribute which was added by accident

cferris requested changes to this revision.May 24 2023, 6:25 PM

Just a few questions.

compiler-rt/lib/scudo/standalone/primary32.h
877

Is there a reason you don't make the ensurePageMapAllocated call before mark functions the same as in primary64.h?

It's not immediately obvious why that's not possible.

If you can pull it in front of these two calls, I would recommend removing the calls to ensurePageMapAllocated in both of the markXXX functions, replaced with a DCHECK(PageMap.isAllocated) call and leave the functions returning void.

This revision now requires changes to proceed.May 24 2023, 6:25 PM
Chia-hungDuan added inline comments.May 24 2023, 6:44 PM
compiler-rt/lib/scudo/standalone/primary32.h
877

In Primary64, we have determined which memory groups will release so that we can prepare the page map in advance.

In Primary32, we don't exam all the memory groups first to determine the groups to release, so we still have the chance of not releasing any group (i.e., don't need the page map).

The reason we haven't implemented this in primary32 is the logic is a little bit more complicated than primary64 because of multiple regions. Therefore, we didn't implement this in the same CL when we brought partial release in primary64

And yes, I agree that if both allocators apply the same strategy, we can remove theuse of ensurePageMapAllocated().

cferris accepted this revision.May 24 2023, 6:52 PM

LGTM

This revision is now accepted and ready to land.May 24 2023, 6:52 PM