Skip to content

Commit 5673e8e

Browse files
committed
[scudo] Compute the default aligned pointer without tag
#83493 slightly changed the order of computation of block addresses and pointers, causing the value of DefaultAlignedPtr to include the MTE tag. Move this computation earlier so it matches the old behavior. This fixes a UBSan failure in Trusty: secure os: UBSan: (overflow:-) external/scudo/standalone/combined.h:1070:35 secure os: Details: unsigned integer overflow: 8988807738704 - 144124176883594576 cannot be represented in type 'uptr'
1 parent 97025bd commit 5673e8e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ class Allocator {
10521052
void *Block, const uptr UserPtr,
10531053
const uptr SizeOrUnusedBytes,
10541054
const FillContentsMode FillContents) {
1055+
// Compute the default pointer before adding the header tag
1056+
const uptr DefaultAlignedPtr =
1057+
reinterpret_cast<uptr>(Block) + Chunk::getHeaderSize();
1058+
10551059
Block = addHeaderTag(Block);
10561060
// Only do content fill when it's from primary allocator because secondary
10571061
// allocator has filled the content.
@@ -1064,8 +1068,6 @@ class Allocator {
10641068

10651069
Chunk::UnpackedHeader Header = {};
10661070

1067-
const uptr DefaultAlignedPtr =
1068-
reinterpret_cast<uptr>(Block) + Chunk::getHeaderSize();
10691071
if (UNLIKELY(DefaultAlignedPtr != UserPtr)) {
10701072
const uptr Offset = UserPtr - DefaultAlignedPtr;
10711073
DCHECK_GE(Offset, 2 * sizeof(u32));

0 commit comments

Comments
 (0)