Skip to content

[scudo] Make report pointers const. #144624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler-rt/lib/scudo/standalone/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ inline void loadHeader(u32 Cookie, const void *Ptr,
*NewUnpackedHeader = bit_cast<UnpackedHeader>(NewPackedHeader);
if (UNLIKELY(NewUnpackedHeader->Checksum !=
computeHeaderChecksum(Cookie, Ptr, NewUnpackedHeader)))
reportHeaderCorruption(NewUnpackedHeader, const_cast<void *>(Ptr));
reportHeaderCorruption(NewUnpackedHeader, Ptr);
}

inline bool isValid(u32 Cookie, const void *Ptr,
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/scudo/standalone/combined.h
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ class Allocator {

// Getting the alloc size of a chunk only makes sense if it's allocated.
if (UNLIKELY(Header.State != Chunk::State::Allocated))
reportInvalidChunkState(AllocatorAction::Sizing, const_cast<void *>(Ptr));
reportInvalidChunkState(AllocatorAction::Sizing, Ptr);

return getSize(Ptr, &Header);
}
Expand Down
15 changes: 7 additions & 8 deletions compiler-rt/lib/scudo/standalone/report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,16 @@ void NORETURN reportInvalidFlag(const char *FlagType, const char *Value) {

// The checksum of a chunk header is invalid. This could be caused by an
// {over,under}write of the header, a pointer that is not an actual chunk.
void NORETURN reportHeaderCorruption(void *Header, void *Ptr) {
void NORETURN reportHeaderCorruption(void *Header, const void *Ptr) {
ScopedErrorReport Report;
Report.append("corrupted chunk header at address %p", Ptr);
if (*static_cast<Chunk::PackedHeader *>(Header) == 0U) {
// Header all zero, which could indicate that this might be a pointer that
// has been double freed but the memory has been released to the kernel.
Report.append(": chunk header is zero and might indicate memory corruption "
"or a double free\n",
Ptr);
"or a double free\n");
} else {
Report.append(": most likely due to memory corruption\n", Ptr);
Report.append(": most likely due to memory corruption\n");
}
}

Expand Down Expand Up @@ -131,21 +130,21 @@ static const char *stringifyAction(AllocatorAction Action) {

// The chunk is not in a state congruent with the operation we want to perform.
// This is usually the case with a double-free, a realloc of a freed pointer.
void NORETURN reportInvalidChunkState(AllocatorAction Action, void *Ptr) {
void NORETURN reportInvalidChunkState(AllocatorAction Action, const void *Ptr) {
ScopedErrorReport Report;
Report.append("invalid chunk state when %s address %p\n",
stringifyAction(Action), Ptr);
}

void NORETURN reportMisalignedPointer(AllocatorAction Action, void *Ptr) {
void NORETURN reportMisalignedPointer(AllocatorAction Action, const void *Ptr) {
ScopedErrorReport Report;
Report.append("misaligned pointer when %s address %p\n",
stringifyAction(Action), Ptr);
}

// The deallocation function used is at odds with the one used to allocate the
// chunk (eg: new[]/delete or malloc/delete, and so on).
void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, void *Ptr,
void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, const void *Ptr,
u8 TypeA, u8 TypeB) {
ScopedErrorReport Report;
Report.append("allocation type mismatch when %s address %p (%d vs %d)\n",
Expand All @@ -154,7 +153,7 @@ void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, void *Ptr,

// The size specified to the delete operator does not match the one that was
// passed to new when allocating the chunk.
void NORETURN reportDeleteSizeMismatch(void *Ptr, uptr Size,
void NORETURN reportDeleteSizeMismatch(const void *Ptr, uptr Size,
uptr ExpectedSize) {
ScopedErrorReport Report;
Report.append(
Expand Down
11 changes: 6 additions & 5 deletions compiler-rt/lib/scudo/standalone/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void NORETURN reportRawError(const char *Message);
void NORETURN reportInvalidFlag(const char *FlagType, const char *Value);

// Chunk header related errors.
void NORETURN reportHeaderCorruption(void *Header, void *Ptr);
void NORETURN reportHeaderCorruption(void *Header, const void *Ptr);

// Sanity checks related error.
void NORETURN reportSanityCheckError(const char *Field);
Expand All @@ -41,11 +41,12 @@ enum class AllocatorAction : u8 {
Reallocating,
Sizing,
};
void NORETURN reportInvalidChunkState(AllocatorAction Action, void *Ptr);
void NORETURN reportMisalignedPointer(AllocatorAction Action, void *Ptr);
void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, void *Ptr,
void NORETURN reportInvalidChunkState(AllocatorAction Action, const void *Ptr);
void NORETURN reportMisalignedPointer(AllocatorAction Action, const void *Ptr);
void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, const void *Ptr,
u8 TypeA, u8 TypeB);
void NORETURN reportDeleteSizeMismatch(void *Ptr, uptr Size, uptr ExpectedSize);
void NORETURN reportDeleteSizeMismatch(const void *Ptr, uptr Size,
uptr ExpectedSize);

// C wrappers errors.
void NORETURN reportAlignmentNotPowerOfTwo(uptr Alignment);
Expand Down
Loading