blob: abb1e8d31986f69c2c9a89aa6c44df614add1820 [file] [log] [blame]
Peter Collingbourne5d3aa862020-09-11 15:05:17 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include "memory_mitigation_state.h"
30
31#include <dirent.h>
32#include <pthread.h>
33#include <semaphore.h>
34#include <stdatomic.h>
35#include <stdlib.h>
36#include <sys/prctl.h>
37#include <sys/types.h>
38
Peter Collingbourne9eb85bf2020-11-02 13:35:28 -080039#include <bionic/malloc.h>
Peter Collingbourne5d3aa862020-09-11 15:05:17 -070040#include <bionic/mte.h>
Peter Collingbourne5d3aa862020-09-11 15:05:17 -070041
Peter Collingbourne9eb85bf2020-11-02 13:35:28 -080042#include "heap_tagging.h"
Peter Collingbourne5d3aa862020-09-11 15:05:17 -070043#include "private/ScopedRWLock.h"
44#include "pthread_internal.h"
45
46extern "C" void scudo_malloc_set_zero_contents(int zero_contents);
Peter Collingbourne5d3aa862020-09-11 15:05:17 -070047
48bool DisableMemoryMitigations(void* arg, size_t arg_size) {
49 if (arg || arg_size) {
50 return false;
51 }
52
53#ifdef USE_SCUDO
54 scudo_malloc_set_zero_contents(0);
Peter Collingbourne9eb85bf2020-11-02 13:35:28 -080055#endif
Peter Collingbourne5d3aa862020-09-11 15:05:17 -070056
Peter Collingbourne9eb85bf2020-11-02 13:35:28 -080057 HeapTaggingLevel level = M_HEAP_TAGGING_LEVEL_NONE;
58 SetHeapTaggingLevel(reinterpret_cast<void*>(&level), sizeof(level));
Peter Collingbourne5d3aa862020-09-11 15:05:17 -070059
60 return true;
61}