Skip to content

Commit 753231e

Browse files
committed
add more synchronization to h_malloc_disable_memory_tagging
This avoids concurrent reads/writes of ro.is_memtag_disabled which is technically undefined without using atomic operations.
1 parent 212947c commit 753231e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

h_malloc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,19 +2220,21 @@ COLD EXPORT void h_malloc_disable_memory_tagging(void) {
22202220
mutex_lock(&init_lock);
22212221
}
22222222

2223-
if (!ro.is_memtag_disabled) {
2224-
if (is_init()) {
2223+
if (is_init()) {
2224+
full_lock();
2225+
if (!ro.is_memtag_disabled) {
22252226
if (unlikely(memory_protect_rw(&ro, sizeof(ro)))) {
22262227
fatal_error("failed to unprotect allocator data");
22272228
}
22282229
ro.is_memtag_disabled = true;
22292230
if (unlikely(memory_protect_ro(&ro, sizeof(ro)))) {
22302231
fatal_error("failed to protect allocator data");
22312232
}
2232-
} else {
2233-
// bionic calls this function very early in some cases
2234-
ro.is_memtag_disabled = true;
22352233
}
2234+
full_unlock();
2235+
} else {
2236+
// bionic calls this function very early in some cases
2237+
ro.is_memtag_disabled = true;
22362238
}
22372239

22382240
if (need_init_lock) {

0 commit comments

Comments
 (0)