2022-03-20 22:56:25 -04:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Daniel Micay <danielmicay@gmail.com>
|
|
|
|
Date: Thu, 28 May 2020 20:19:14 -0400
|
|
|
|
Subject: [PATCH] workaround for audio service sorting bug
|
|
|
|
|
|
|
|
---
|
2024-05-06 16:49:46 -04:00
|
|
|
h_malloc.c | 10 +++++++++-
|
|
|
|
1 file changed, 9 insertions(+), 1 deletion(-)
|
2022-03-20 22:56:25 -04:00
|
|
|
|
|
|
|
diff --git a/h_malloc.c b/h_malloc.c
|
2024-05-06 16:49:46 -04:00
|
|
|
index 6c3b148..4090b0c 100644
|
2022-03-20 22:56:25 -04:00
|
|
|
--- a/h_malloc.c
|
|
|
|
+++ b/h_malloc.c
|
2024-05-06 16:49:46 -04:00
|
|
|
@@ -83,6 +83,7 @@ static union {
|
2022-03-20 22:56:25 -04:00
|
|
|
bool zero_on_free;
|
|
|
|
bool purge_slabs;
|
|
|
|
bool region_quarantine_protect;
|
|
|
|
+ bool slot_randomize;
|
|
|
|
};
|
|
|
|
char padding[PAGE_SIZE];
|
|
|
|
} ro __attribute__((aligned(PAGE_SIZE)));
|
2024-05-06 16:49:46 -04:00
|
|
|
@@ -386,7 +387,7 @@ static u64 get_mask(size_t slots) {
|
2022-03-20 22:56:25 -04:00
|
|
|
}
|
|
|
|
|
2024-05-06 16:49:46 -04:00
|
|
|
static size_t get_free_slot(struct random_state *rng, size_t slots, const struct slab_metadata *metadata) {
|
2022-03-20 22:56:25 -04:00
|
|
|
- if (SLOT_RANDOMIZE) {
|
|
|
|
+ if (ro.slot_randomize) {
|
|
|
|
// randomize start location for linear search (uniform random choice is too slow)
|
2024-05-06 16:49:46 -04:00
|
|
|
size_t random_index = get_random_u16_uniform(rng, slots);
|
|
|
|
size_t first_bitmap = random_index / U64_WIDTH;
|
|
|
|
@@ -1218,6 +1219,12 @@ COLD static void handle_bugs(void) {
|
2022-03-20 22:56:25 -04:00
|
|
|
ro.purge_slabs = false;
|
|
|
|
ro.region_quarantine_protect = false;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // DeviceDescriptor sorting wrongly relies on malloc addresses
|
|
|
|
+ const char audio_service[] = "/system/bin/audioserver";
|
|
|
|
+ if (strcmp(audio_service, path) == 0) {
|
|
|
|
+ ro.slot_randomize = false;
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
2024-05-06 16:49:46 -04:00
|
|
|
static struct mutex init_lock = MUTEX_INITIALIZER;
|
|
|
|
@@ -1238,6 +1245,7 @@ COLD static void init_slow_path(void) {
|
2022-03-20 22:56:25 -04:00
|
|
|
ro.purge_slabs = true;
|
|
|
|
ro.zero_on_free = ZERO_ON_FREE;
|
|
|
|
ro.region_quarantine_protect = true;
|
|
|
|
+ ro.slot_randomize = SLOT_RANDOMIZE;
|
2024-05-06 16:49:46 -04:00
|
|
|
handle_bugs();
|
2022-03-20 22:56:25 -04:00
|
|
|
|
2024-05-06 16:49:46 -04:00
|
|
|
if (unlikely(sysconf(_SC_PAGESIZE) != PAGE_SIZE)) {
|