Skip to content

Commit 30532c1

Browse files
authored
[scudo] Fix secondary caching for mte (#150156)
The current code always unmaps a secondary allocation when MTE is enabled. Fix this to match the comment, namely only unmap if MTE was enabled and is no longer enabled after acquiring the lock. In addition, allow quaratine to work in the secondary even if MTE is not enabled.
1 parent b33f9f6 commit 30532c1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

compiler-rt/lib/scudo/standalone/secondary.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ class MapAllocatorCache {
269269
Entry.MemMap = MemMap;
270270
Entry.Time = UINT64_MAX;
271271

272-
if (useMemoryTagging<Config>(Options)) {
272+
bool MemoryTaggingEnabled = useMemoryTagging<Config>(Options);
273+
if (MemoryTaggingEnabled) {
273274
if (Interval == 0 && !SCUDO_FUCHSIA) {
274275
// Release the memory and make it inaccessible at the same time by
275276
// creating a new MAP_NOACCESS mapping on top of the existing mapping.
@@ -302,15 +303,16 @@ class MapAllocatorCache {
302303
if (Entry.Time != 0)
303304
Entry.Time = Time;
304305

305-
if (useMemoryTagging<Config>(Options) && QuarantinePos == -1U) {
306+
if (MemoryTaggingEnabled && !useMemoryTagging<Config>(Options)) {
306307
// If we get here then memory tagging was disabled in between when we
307308
// read Options and when we locked Mutex. We can't insert our entry into
308309
// the quarantine or the cache because the permissions would be wrong so
309310
// just unmap it.
310311
unmapCallBack(Entry.MemMap);
311312
break;
312313
}
313-
if (Config::getQuarantineSize() && useMemoryTagging<Config>(Options)) {
314+
315+
if (Config::getQuarantineSize()) {
314316
QuarantinePos =
315317
(QuarantinePos + 1) % Max(Config::getQuarantineSize(), 1u);
316318
if (!Quarantine[QuarantinePos].isValid()) {
@@ -513,9 +515,10 @@ class MapAllocatorCache {
513515
Quarantine[I].invalidate();
514516
}
515517
}
518+
QuarantinePos = -1U;
519+
516520
for (CachedBlock &Entry : LRUEntries)
517521
Entry.MemMap.setMemoryPermission(Entry.CommitBase, Entry.CommitSize, 0);
518-
QuarantinePos = -1U;
519522
}
520523

521524
void disable() NO_THREAD_SAFETY_ANALYSIS { Mutex.lock(); }

0 commit comments

Comments
 (0)