From e84f8c878dc6dfe42b7bc1ad3971623aa591ed8a Mon Sep 17 00:00:00 2001 From: Jacob Bramley Date: Tue, 12 Dec 2023 16:45:20 +0000 Subject: [PATCH] Check for mallocx alignment bug. https://github.com/CTSRD-CHERI/cheribsd/issues/1964 This was fixed, but the assertions here might be useful in case someone tries to run this on an affected CheriBSD. --- Source/WTF/wtf/ContinuousArenaMalloc.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/WTF/wtf/ContinuousArenaMalloc.cpp b/Source/WTF/wtf/ContinuousArenaMalloc.cpp index e11edbaba6f..98d789baf5c 100644 --- a/Source/WTF/wtf/ContinuousArenaMalloc.cpp +++ b/Source/WTF/wtf/ContinuousArenaMalloc.cpp @@ -111,13 +111,25 @@ void *ContinuousArenaMalloc::internalAllocateAligned(size_t alignment, ASSERT((alignment & (alignment - 1)) == 0); ASSERT(s_Initialized); - return mallocx(size, MALLOCX_ALIGN(alignment) | MALLOCX_TCACHE_NONE | MALLOCX_ARENA(s_arenaIndex)); + void * result = mallocx(size, MALLOCX_ALIGN(alignment) | MALLOCX_TCACHE_NONE | MALLOCX_ARENA(s_arenaIndex)); +#if __has_feature(capabilities) + // If this happens, try disabling capability revocation. + // See: https://github.com/CTSRD-CHERI/cheribsd/issues/1964 + ASSERT(cheri_is_aligned(result, size)); +#endif + return result; } void *ContinuousArenaMalloc::internalReallocate(void *ptr, size_t size) { ASSERT(s_Initialized); - return rallocx(ptr, size, MALLOCX_TCACHE_NONE | MALLOCX_ARENA(s_arenaIndex)); + void * result = rallocx(ptr, size, MALLOCX_TCACHE_NONE | MALLOCX_ARENA(s_arenaIndex)); +#if __has_feature(capabilities) + // If this happens, try disabling capability revocation. + // See: https://github.com/CTSRD-CHERI/cheribsd/issues/1964 + ASSERT(cheri_is_aligned(result, size)); +#endif + return result; } void ContinuousArenaMalloc::internalFree(void *ptr)