Skip to content

Commit 3458472

Browse files
committed
[libpas] Enable MTE Retag-on-Scavenge in privileged processes
https://bugs.webkit.org/show_bug.cgi?id=300151 rdar://156723433 Reviewed by Mark Lam. This is an MTE hardening feature which helps catch use-after-frees by retagging objects as we scavenge them. It has a significant performance cost, but as long as we only enable it for privileged processes that cost disappears. Canonical link: https://commits.webkit.org/300987@main
1 parent a53c1df commit 3458472

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Source/bmalloc/libpas/src/libpas/pas_mte.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,17 @@ PAS_IGNORE_WARNINGS_END
522522

523523
#define PAS_MTE_TAG_REGION_FROM_OTHER_ALLOCATION(ptr, size, mode, is_allocator_homogeneous, is_known_medium) do { \
524524
if (!PAS_MTE_FEATURE_ENABLED(PAS_MTE_FEATURE_RETAG_ON_FREE)) { \
525-
PAS_MTE_TAG_REGION(ptr, size, mode, is_allocator_homogeneous, is_known_medium); \
525+
uintptr_t tag = ptr; \
526+
PAS_MTE_GET_TAG(tag); \
527+
/* libpas ensures that all allocations which reside in pages with \
528+
* backing tag memory are tagged with a non-zero tag at all points \
529+
* in time after they've been allocated, so we can use this to see \
530+
* whether the allocation should be retagged or not. \
531+
* In the future it would be better to pipe the information through \
532+
* so that we can save the LDG, but that will require moving the \
533+
* source-of-truth out of the local allocator. */ \
534+
if (tag) \
535+
PAS_MTE_TAG_REGION(ptr, size, mode, is_allocator_homogeneous, is_known_medium); \
526536
break; \
527537
} \
528538
uint8_t* pas_mte_begin = (uint8_t*)(ptr); \

Source/bmalloc/libpas/src/libpas/pas_mte_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ extern Slot g_config[];
121121
#define PAS_MTE_FEATURE_ASSERT_ADJACENT_TAGS_ARE_DISJOINT 6
122122

123123
#define PAS_MTE_FEATURE_FORCED(feature) (0)
124-
#define PAS_MTE_FEATURE_PRIVILEGED_FORCED(feature) (feature == PAS_MTE_FEATURE_ADJACENT_TAG_EXCLUSION)
124+
#define PAS_MTE_FEATURE_PRIVILEGED_FORCED(feature) (feature == PAS_MTE_FEATURE_ADJACENT_TAG_EXCLUSION || feature == PAS_MTE_FEATURE_RETAG_ON_FREE)
125125
#define PAS_MTE_FEATURE_WCP_FORCED(feature) (0)
126126
#define PAS_MTE_FEATURE_DEBUG_FORCED(feature) (feature == PAS_MTE_FEATURE_ASSERT_ADJACENT_TAGS_ARE_DISJOINT)
127127

0 commit comments

Comments
 (0)