c03856c58e
GWP-ASan + heapprofd don't currently play nice together in some circumstances. heapprofd thinks it's still an only child, and refuses to accept the existence of its little brother, GWP-ASan. If GWP-ASan is installed before heapprofd, then heapprofd is *required* to respect that libc has a favourite child. If an allocation/free is passed to heapprofd, then heapprofd *must* (eventually) pass that allocation/free to GWP-ASan. If heapprofd doesn't do this, then a free() of a GWP-ASan allocation can be passed to the system allocator. This can happen in two places right now: 1. The heapprofd hooks simply clobber any trace of what was previously in the default_dispatch_table when enabled through the heapprofd signal. 2. Heapprofd can die when the system is under significant pressure. Some pipes can timeout, which ends up in the client calling ShutdownLazy() -> mallopt(M_RESET_HOOKS) -> DispatchReset(). This also clobbers any trace of the previous default_dispatch_table. To fix both these problems, we fix heapprofd to restore the previous default_dispatch_table whenever either circumstance happens. We do some tricky copying to avoid race conditions on the malloc_dispatch_table in fixing #1. Bug: 135634846 Test: Run HeapprofdEndToEnd.NativeProfilingActiveAtProcessExit/ForkMode a significant number of times with large amounts of system pressure (I just run bionic-unit-tests-scudo in parallel). You will see some test failures where heapprofd died due to system pressure, but never a death from the allocator. Tests should never fail when the system isn't under immense pressure. Change-Id: I20ab340d4bdc35d6d1012da5ee1a25634428d097
44 lines
2 KiB
C
44 lines
2 KiB
C
/*
|
|
* Copyright (C) 2020 The Android Open Source Project
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* * Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in
|
|
* the documentation and/or other materials provided with the
|
|
* distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <private/bionic_globals.h>
|
|
#include <private/bionic_malloc_dispatch.h>
|
|
#include <stddef.h>
|
|
|
|
// Hooks for libc to possibly install GWP-ASan.
|
|
bool MaybeInitGwpAsanFromLibc(libc_globals* globals);
|
|
|
|
// Maybe initialize GWP-ASan. Set force_init to true to bypass process sampling.
|
|
bool MaybeInitGwpAsan(libc_globals* globals, bool force_init = false);
|
|
|
|
// Returns whether GWP-ASan is the provided dispatch table pointer. Used in
|
|
// heapprofd's signal-initialization sequence to determine the intermediate
|
|
// dispatch pointer to use when initing.
|
|
bool DispatchIsGwpAsan(const MallocDispatch* dispatch);
|