This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Fix missing pushing 1 block to BatchClassId
ClosedPublic

Authored by Chia-hungDuan on Apr 25 2023, 2:57 AM.

Details

Summary

This may happen when thread is teared down and it only has 1 block of BatchClass left and the freelist of BatchClass is empty. The side effect is that it leaks 1 block of BatchClass

Diff Detail

Event Timeline

Chia-hungDuan created this revision.Apr 25 2023, 2:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 2:57 AM
Herald added subscribers: yaneury, Enna1. · View Herald Transcript
Chia-hungDuan requested review of this revision.Apr 25 2023, 2:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 2:57 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
Chia-hungDuan edited the summary of this revision. (Show Details)Apr 25 2023, 3:42 AM
Chia-hungDuan updated this revision to Diff 516739.EditedApr 25 2023, 4:04 AM

Please ignore this revision, uploaded to the wrong revision number

Revise the logic

Chia-hungDuan edited the summary of this revision. (Show Details)Apr 25 2023, 4:07 AM
cferris requested changes to this revision.Apr 25 2023, 3:08 PM

Are there already tests for this corner case?

compiler-rt/lib/scudo/standalone/primary64.h
217–218

Is this comment not true any more? Otherwise, you are holding the lock while getStats could be called.

This revision now requires changes to proceed.Apr 25 2023, 3:08 PM

Release lock before calling getStats().

Oops, uploaded wrong version

Release lock before calling getStats().

Oops, uploaded wrong version

One thing to add, the problem is not in primary32.

cferris requested changes to this revision.Apr 25 2023, 5:51 PM
cferris added inline comments.
compiler-rt/lib/scudo/standalone/primary64.h
210

Shouldn't this be:

PrintStats = Region->Exhausted;

Since you only print the stats when it wasn't previously exhausted and the region is now exhausted?

This revision now requires changes to proceed.Apr 25 2023, 5:51 PM
Chia-hungDuan marked an inline comment as done.

Rebase and amend missing code which was supposed to be included in last patch

compiler-rt/lib/scudo/standalone/primary64.h
210

Per discussion, even though only region exhaustion will return false from populateFreeList(), any failure from populateFreeList() should be viewed as critical in BatchClass region.

BTW, I thought I added a DCHECK(!Region->Exhausted) but it seems that I didn't include it...

cferris accepted this revision.Apr 26 2023, 4:15 PM

LGTM

This revision is now accepted and ready to land.Apr 26 2023, 4:15 PM
This revision was landed with ongoing or failed builds.Apr 26 2023, 5:05 PM
This revision was automatically updated to reflect the committed changes.