Skip to content

Commit bf0f874

Browse files
ahomescumarcone
andauthored
[scudo] Avoid splitting aligned allocations on Trusty (#69281)
Don't use multiple tagged pages at the beginning of an allocation, since it prevents using such allocations for memrefs, and mappings aren't reused anyway since Trusty uses MapAllocatorNoCache. Upstreamed from https://r.android.com/2537251. Co-authored-by: Marco Nelissen <[email protected]>
1 parent 71eead5 commit bf0f874

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,29 @@ bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,
122122
Flags |= MAP_RESIZABLE;
123123
Flags |= MAP_ALLOWNOMEM;
124124

125-
const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * getPageSizeCached();
125+
const uptr PageSize = getPageSizeCached();
126+
if (SCUDO_TRUSTY) {
127+
/*
128+
* On Trusty we need AllocPos to be usable for shared memory, which cannot
129+
* cross multiple mappings. This means we need to split around AllocPos
130+
* and not over it. We can only do this if the address is page-aligned.
131+
*/
132+
const uptr TaggedSize = AllocPos - CommitBase;
133+
if (useMemoryTagging<Config>(Options) && isAligned(TaggedSize, PageSize)) {
134+
DCHECK_GT(TaggedSize, 0);
135+
return MemMap.remap(CommitBase, TaggedSize, "scudo:secondary",
136+
MAP_MEMTAG | Flags) &&
137+
MemMap.remap(AllocPos, CommitSize - TaggedSize, "scudo:secondary",
138+
Flags);
139+
} else {
140+
const uptr RemapFlags =
141+
(useMemoryTagging<Config>(Options) ? MAP_MEMTAG : 0) | Flags;
142+
return MemMap.remap(CommitBase, CommitSize, "scudo:secondary",
143+
RemapFlags);
144+
}
145+
}
146+
147+
const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * PageSize;
126148
if (useMemoryTagging<Config>(Options) && CommitSize > MaxUnusedCacheBytes) {
127149
const uptr UntaggedPos = Max(AllocPos, CommitBase + MaxUnusedCacheBytes);
128150
return MemMap.remap(CommitBase, UntaggedPos - CommitBase, "scudo:secondary",

0 commit comments

Comments
 (0)