[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
//===-- guarded_pool_allocator.cpp ------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "gwp_asan/guarded_pool_allocator.h"
|
|
|
|
|
|
|
|
#include "gwp_asan/options.h"
|
|
|
|
|
2019-07-12 02:07:03 +08:00
|
|
|
// RHEL creates the PRIu64 format macro (for printing uint64_t's) only when this
|
|
|
|
// macro is defined before including <inttypes.h>.
|
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
2019-08-21 04:16:11 +08:00
|
|
|
#define __STDC_FORMAT_MACROS 1
|
2019-07-12 02:07:03 +08:00
|
|
|
#endif
|
|
|
|
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
#include <assert.h>
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
using AllocationMetadata = gwp_asan::GuardedPoolAllocator::AllocationMetadata;
|
|
|
|
using Error = gwp_asan::GuardedPoolAllocator::Error;
|
|
|
|
|
|
|
|
namespace gwp_asan {
|
|
|
|
namespace {
|
|
|
|
// Forward declare the pointer to the singleton version of this class.
|
|
|
|
// Instantiated during initialisation, this allows the signal handler
|
|
|
|
// to find this class in order to deduce the root cause of failures. Must not be
|
|
|
|
// referenced by users outside this translation unit, in order to avoid
|
|
|
|
// init-order-fiasco.
|
|
|
|
GuardedPoolAllocator *SingletonPtr = nullptr;
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
|
|
|
|
class ScopedBoolean {
|
|
|
|
public:
|
|
|
|
ScopedBoolean(bool &B) : Bool(B) { Bool = true; }
|
|
|
|
~ScopedBoolean() { Bool = false; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool &Bool;
|
|
|
|
};
|
|
|
|
|
2019-08-13 05:36:44 +08:00
|
|
|
void defaultPrintStackTrace(uintptr_t *Trace, size_t TraceLength,
|
|
|
|
options::Printf_t Printf) {
|
|
|
|
if (TraceLength == 0)
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
Printf(" <unknown (does your allocator support backtracing?)>\n");
|
|
|
|
|
2019-08-13 05:36:44 +08:00
|
|
|
for (size_t i = 0; i < TraceLength; ++i) {
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
Printf(" #%zu 0x%zx in <unknown>\n", i, Trace[i]);
|
|
|
|
}
|
|
|
|
Printf("\n");
|
|
|
|
}
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// Gets the singleton implementation of this class. Thread-compatible until
|
|
|
|
// init() is called, thread-safe afterwards.
|
2020-01-11 08:01:01 +08:00
|
|
|
GuardedPoolAllocator *GuardedPoolAllocator::getSingleton() {
|
|
|
|
return SingletonPtr;
|
|
|
|
}
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
|
|
|
void GuardedPoolAllocator::AllocationMetadata::RecordAllocation(
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
uintptr_t AllocAddr, size_t AllocSize, options::Backtrace_t Backtrace) {
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
Addr = AllocAddr;
|
|
|
|
Size = AllocSize;
|
|
|
|
IsDeallocated = false;
|
|
|
|
|
|
|
|
// TODO(hctim): Ask the caller to provide the thread ID, so we don't waste
|
|
|
|
// other thread's time getting the thread ID under lock.
|
|
|
|
AllocationTrace.ThreadID = getThreadID();
|
2019-08-16 05:09:09 +08:00
|
|
|
AllocationTrace.TraceSize = 0;
|
|
|
|
DeallocationTrace.TraceSize = 0;
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
DeallocationTrace.ThreadID = kInvalidThreadID;
|
2019-08-16 05:09:09 +08:00
|
|
|
|
|
|
|
if (Backtrace) {
|
|
|
|
uintptr_t UncompressedBuffer[kMaxTraceLengthToCollect];
|
|
|
|
size_t BacktraceLength =
|
|
|
|
Backtrace(UncompressedBuffer, kMaxTraceLengthToCollect);
|
|
|
|
AllocationTrace.TraceSize = compression::pack(
|
|
|
|
UncompressedBuffer, BacktraceLength, AllocationTrace.CompressedTrace,
|
|
|
|
kStackFrameStorageBytes);
|
|
|
|
}
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
void GuardedPoolAllocator::AllocationMetadata::RecordDeallocation(
|
|
|
|
options::Backtrace_t Backtrace) {
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
IsDeallocated = true;
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
// Ensure that the unwinder is not called if the recursive flag is set,
|
|
|
|
// otherwise non-reentrant unwinders may deadlock.
|
2019-08-16 05:09:09 +08:00
|
|
|
DeallocationTrace.TraceSize = 0;
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
if (Backtrace && !ThreadLocals.RecursiveGuard) {
|
|
|
|
ScopedBoolean B(ThreadLocals.RecursiveGuard);
|
2019-08-16 05:09:09 +08:00
|
|
|
|
|
|
|
uintptr_t UncompressedBuffer[kMaxTraceLengthToCollect];
|
|
|
|
size_t BacktraceLength =
|
|
|
|
Backtrace(UncompressedBuffer, kMaxTraceLengthToCollect);
|
|
|
|
DeallocationTrace.TraceSize = compression::pack(
|
|
|
|
UncompressedBuffer, BacktraceLength, DeallocationTrace.CompressedTrace,
|
|
|
|
kStackFrameStorageBytes);
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
}
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
DeallocationTrace.ThreadID = getThreadID();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuardedPoolAllocator::init(const options::Options &Opts) {
|
|
|
|
// Note: We return from the constructor here if GWP-ASan is not available.
|
|
|
|
// This will stop heap-allocation of class members, as well as mmap() of the
|
|
|
|
// guarded slots.
|
|
|
|
if (!Opts.Enabled || Opts.SampleRate == 0 ||
|
|
|
|
Opts.MaxSimultaneousAllocations == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Opts.SampleRate < 0) {
|
|
|
|
Opts.Printf("GWP-ASan Error: SampleRate is < 0.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Opts.SampleRate > INT32_MAX) {
|
|
|
|
Opts.Printf("GWP-ASan Error: SampleRate is > 2^31.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Opts.MaxSimultaneousAllocations < 0) {
|
|
|
|
Opts.Printf("GWP-ASan Error: MaxSimultaneousAllocations is < 0.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
SingletonPtr = this;
|
|
|
|
|
|
|
|
MaxSimultaneousAllocations = Opts.MaxSimultaneousAllocations;
|
|
|
|
|
|
|
|
PageSize = getPlatformPageSize();
|
|
|
|
|
|
|
|
PerfectlyRightAlign = Opts.PerfectlyRightAlign;
|
|
|
|
Printf = Opts.Printf;
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
Backtrace = Opts.Backtrace;
|
|
|
|
if (Opts.PrintBacktrace)
|
|
|
|
PrintBacktrace = Opts.PrintBacktrace;
|
|
|
|
else
|
|
|
|
PrintBacktrace = defaultPrintStackTrace;
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
|
|
|
size_t PoolBytesRequired =
|
|
|
|
PageSize * (1 + MaxSimultaneousAllocations) +
|
|
|
|
MaxSimultaneousAllocations * maximumAllocationSize();
|
2020-01-25 07:01:47 +08:00
|
|
|
void *GuardedPoolMemory = mapMemory(PoolBytesRequired, kGwpAsanGuardPageName);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
|
|
|
size_t BytesRequired = MaxSimultaneousAllocations * sizeof(*Metadata);
|
2020-01-25 07:01:47 +08:00
|
|
|
Metadata = reinterpret_cast<AllocationMetadata *>(
|
|
|
|
mapMemory(BytesRequired, kGwpAsanMetadataName));
|
|
|
|
markReadWrite(Metadata, BytesRequired, kGwpAsanMetadataName);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
|
|
|
// Allocate memory and set up the free pages queue.
|
|
|
|
BytesRequired = MaxSimultaneousAllocations * sizeof(*FreeSlots);
|
2020-01-25 07:01:47 +08:00
|
|
|
FreeSlots = reinterpret_cast<size_t *>(
|
|
|
|
mapMemory(BytesRequired, kGwpAsanFreeSlotsName));
|
|
|
|
markReadWrite(FreeSlots, BytesRequired, kGwpAsanFreeSlotsName);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
|
|
|
// Multiply the sample rate by 2 to give a good, fast approximation for (1 /
|
|
|
|
// SampleRate) chance of sampling.
|
|
|
|
if (Opts.SampleRate != 1)
|
2020-01-11 08:01:01 +08:00
|
|
|
AdjustedSampleRatePlusOne = static_cast<uint32_t>(Opts.SampleRate) * 2 + 1;
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
else
|
2020-01-11 08:01:01 +08:00
|
|
|
AdjustedSampleRatePlusOne = 2;
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
[GWP-ASan] Allow late initialisation if single-threaded.
Summary:
This patch allows for late initialisation of the GWP-ASan allocator. Previously, if late initialisation occurred, the sample counter was never updated, meaning we would end up having to wait for 2^32 allocations before getting a sampled allocation.
Now, we initialise the sampling mechanism in init() as well. We require init() to be called single-threaded, so this isn't a problem.
Reviewers: eugenis
Reviewed By: eugenis
Subscribers: merge_guards_bot, mgorny, #sanitizers, llvm-commits, cferris
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D73896
2020-02-04 04:25:51 +08:00
|
|
|
ThreadLocals.NextSampleCounter =
|
|
|
|
(getRandomUnsigned32() % (AdjustedSampleRatePlusOne - 1)) + 1;
|
|
|
|
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
GuardedPagePool = reinterpret_cast<uintptr_t>(GuardedPoolMemory);
|
|
|
|
GuardedPagePoolEnd =
|
|
|
|
reinterpret_cast<uintptr_t>(GuardedPoolMemory) + PoolBytesRequired;
|
|
|
|
|
|
|
|
// Ensure that signal handlers are installed as late as possible, as the class
|
|
|
|
// is not thread-safe until init() is finished, and thus a SIGSEGV may cause a
|
2019-08-21 04:16:11 +08:00
|
|
|
// race to members if received during init().
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
if (Opts.InstallSignalHandlers)
|
|
|
|
installSignalHandlers();
|
2020-01-11 08:01:01 +08:00
|
|
|
|
|
|
|
if (Opts.InstallForkHandlers)
|
|
|
|
installAtFork();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuardedPoolAllocator::disable() { PoolMutex.lock(); }
|
|
|
|
|
|
|
|
void GuardedPoolAllocator::enable() { PoolMutex.unlock(); }
|
|
|
|
|
2020-01-24 08:12:15 +08:00
|
|
|
void GuardedPoolAllocator::iterate(void *Base, size_t Size, iterate_callback Cb,
|
|
|
|
void *Arg) {
|
|
|
|
uintptr_t Start = reinterpret_cast<uintptr_t>(Base);
|
|
|
|
for (size_t i = 0; i < MaxSimultaneousAllocations; ++i) {
|
|
|
|
const AllocationMetadata &Meta = Metadata[i];
|
|
|
|
if (Meta.Addr && !Meta.IsDeallocated && Meta.Addr >= Start &&
|
|
|
|
Meta.Addr < Start + Size)
|
|
|
|
Cb(Meta.Addr, Meta.Size, Arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-11 08:01:01 +08:00
|
|
|
void GuardedPoolAllocator::uninitTestOnly() {
|
|
|
|
if (GuardedPagePool) {
|
|
|
|
unmapMemory(reinterpret_cast<void *>(GuardedPagePool),
|
2020-01-25 07:01:47 +08:00
|
|
|
GuardedPagePoolEnd - GuardedPagePool, kGwpAsanGuardPageName);
|
2020-01-11 08:01:01 +08:00
|
|
|
GuardedPagePool = 0;
|
|
|
|
GuardedPagePoolEnd = 0;
|
|
|
|
}
|
|
|
|
if (Metadata) {
|
2020-01-25 07:01:47 +08:00
|
|
|
unmapMemory(Metadata, MaxSimultaneousAllocations * sizeof(*Metadata),
|
|
|
|
kGwpAsanMetadataName);
|
2020-01-11 08:01:01 +08:00
|
|
|
Metadata = nullptr;
|
|
|
|
}
|
|
|
|
if (FreeSlots) {
|
2020-01-25 07:01:47 +08:00
|
|
|
unmapMemory(FreeSlots, MaxSimultaneousAllocations * sizeof(*FreeSlots),
|
|
|
|
kGwpAsanFreeSlotsName);
|
2020-01-11 08:01:01 +08:00
|
|
|
FreeSlots = nullptr;
|
|
|
|
}
|
|
|
|
uninstallSignalHandlers();
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *GuardedPoolAllocator::allocate(size_t Size) {
|
[GWP-ASan] Guard against recursive allocs. Pack TLS for perf.
Summary:
Add a recursivity guard for GPA::allocate(). This means that any
recursive allocations will fall back to the supporting allocator. In future
patches, we will introduce stack trace collection support. The unwinder will be
provided by the supporting allocator, and we can't guarantee they don't call
malloc() (e.g. backtrace() on posix may call dlopen(), which may call malloc().
Furthermore, this patch packs the new TLS recursivity guard into a thread local
struct, so that TLS variables should be hopefully not fall across cache lines.
Reviewers: vlad.tsyrklevich, morehouse, eugenis
Reviewed By: eugenis
Subscribers: kubamracek, #sanitizers, llvm-commits, eugenis
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63736
llvm-svn: 364356
2019-06-26 06:29:05 +08:00
|
|
|
// GuardedPagePoolEnd == 0 when GWP-ASan is disabled. If we are disabled, fall
|
|
|
|
// back to the supporting allocator.
|
|
|
|
if (GuardedPagePoolEnd == 0)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Protect against recursivity.
|
|
|
|
if (ThreadLocals.RecursiveGuard)
|
|
|
|
return nullptr;
|
|
|
|
ScopedBoolean SB(ThreadLocals.RecursiveGuard);
|
|
|
|
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
if (Size == 0 || Size > maximumAllocationSize())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
size_t Index;
|
|
|
|
{
|
|
|
|
ScopedLock L(PoolMutex);
|
|
|
|
Index = reserveSlot();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Index == kInvalidSlotID)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
uintptr_t Ptr = slotToAddr(Index);
|
|
|
|
Ptr += allocationSlotOffset(Size);
|
|
|
|
AllocationMetadata *Meta = addrToMetadata(Ptr);
|
|
|
|
|
|
|
|
// If a slot is multiple pages in size, and the allocation takes up a single
|
|
|
|
// page, we can improve overflow detection by leaving the unused pages as
|
|
|
|
// unmapped.
|
2020-01-25 07:01:47 +08:00
|
|
|
markReadWrite(reinterpret_cast<void *>(getPageAddr(Ptr)), Size,
|
|
|
|
kGwpAsanAliveSlotName);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
Meta->RecordAllocation(Ptr, Size, Backtrace);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
|
|
|
return reinterpret_cast<void *>(Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuardedPoolAllocator::deallocate(void *Ptr) {
|
|
|
|
assert(pointerIsMine(Ptr) && "Pointer is not mine!");
|
|
|
|
uintptr_t UPtr = reinterpret_cast<uintptr_t>(Ptr);
|
|
|
|
uintptr_t SlotStart = slotToAddr(addrToSlot(UPtr));
|
|
|
|
AllocationMetadata *Meta = addrToMetadata(UPtr);
|
|
|
|
if (Meta->Addr != UPtr) {
|
|
|
|
reportError(UPtr, Error::INVALID_FREE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intentionally scope the mutex here, so that other threads can access the
|
|
|
|
// pool during the expensive markInaccessible() call.
|
|
|
|
{
|
|
|
|
ScopedLock L(PoolMutex);
|
|
|
|
if (Meta->IsDeallocated) {
|
|
|
|
reportError(UPtr, Error::DOUBLE_FREE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that the deallocation is recorded before marking the page as
|
|
|
|
// inaccessible. Otherwise, a racy use-after-free will have inconsistent
|
|
|
|
// metadata.
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
Meta->RecordDeallocation(Backtrace);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
|
|
|
|
2020-01-25 07:01:47 +08:00
|
|
|
markInaccessible(reinterpret_cast<void *>(SlotStart), maximumAllocationSize(),
|
|
|
|
kGwpAsanGuardPageName);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
|
|
|
// And finally, lock again to release the slot back into the pool.
|
|
|
|
ScopedLock L(PoolMutex);
|
|
|
|
freeSlot(addrToSlot(UPtr));
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GuardedPoolAllocator::getSize(const void *Ptr) {
|
|
|
|
assert(pointerIsMine(Ptr));
|
|
|
|
ScopedLock L(PoolMutex);
|
|
|
|
AllocationMetadata *Meta = addrToMetadata(reinterpret_cast<uintptr_t>(Ptr));
|
|
|
|
assert(Meta->Addr == reinterpret_cast<uintptr_t>(Ptr));
|
|
|
|
return Meta->Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GuardedPoolAllocator::maximumAllocationSize() const { return PageSize; }
|
|
|
|
|
|
|
|
AllocationMetadata *GuardedPoolAllocator::addrToMetadata(uintptr_t Ptr) const {
|
|
|
|
return &Metadata[addrToSlot(Ptr)];
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GuardedPoolAllocator::addrToSlot(uintptr_t Ptr) const {
|
|
|
|
assert(pointerIsMine(reinterpret_cast<void *>(Ptr)));
|
|
|
|
size_t ByteOffsetFromPoolStart = Ptr - GuardedPagePool;
|
|
|
|
return ByteOffsetFromPoolStart / (maximumAllocationSize() + PageSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t GuardedPoolAllocator::slotToAddr(size_t N) const {
|
|
|
|
return GuardedPagePool + (PageSize * (1 + N)) + (maximumAllocationSize() * N);
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t GuardedPoolAllocator::getPageAddr(uintptr_t Ptr) const {
|
|
|
|
assert(pointerIsMine(reinterpret_cast<void *>(Ptr)));
|
|
|
|
return Ptr & ~(static_cast<uintptr_t>(PageSize) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GuardedPoolAllocator::isGuardPage(uintptr_t Ptr) const {
|
|
|
|
assert(pointerIsMine(reinterpret_cast<void *>(Ptr)));
|
|
|
|
size_t PageOffsetFromPoolStart = (Ptr - GuardedPagePool) / PageSize;
|
|
|
|
size_t PagesPerSlot = maximumAllocationSize() / PageSize;
|
|
|
|
return (PageOffsetFromPoolStart % (PagesPerSlot + 1)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GuardedPoolAllocator::reserveSlot() {
|
|
|
|
// Avoid potential reuse of a slot before we have made at least a single
|
|
|
|
// allocation in each slot. Helps with our use-after-free detection.
|
|
|
|
if (NumSampledAllocations < MaxSimultaneousAllocations)
|
|
|
|
return NumSampledAllocations++;
|
|
|
|
|
|
|
|
if (FreeSlotsLength == 0)
|
|
|
|
return kInvalidSlotID;
|
|
|
|
|
|
|
|
size_t ReservedIndex = getRandomUnsigned32() % FreeSlotsLength;
|
|
|
|
size_t SlotIndex = FreeSlots[ReservedIndex];
|
|
|
|
FreeSlots[ReservedIndex] = FreeSlots[--FreeSlotsLength];
|
|
|
|
return SlotIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuardedPoolAllocator::freeSlot(size_t SlotIndex) {
|
|
|
|
assert(FreeSlotsLength < MaxSimultaneousAllocations);
|
|
|
|
FreeSlots[FreeSlotsLength++] = SlotIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t GuardedPoolAllocator::allocationSlotOffset(size_t Size) const {
|
|
|
|
assert(Size > 0);
|
|
|
|
|
|
|
|
bool ShouldRightAlign = getRandomUnsigned32() % 2 == 0;
|
|
|
|
if (!ShouldRightAlign)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
uintptr_t Offset = maximumAllocationSize();
|
|
|
|
if (!PerfectlyRightAlign) {
|
|
|
|
if (Size == 3)
|
|
|
|
Size = 4;
|
|
|
|
else if (Size > 4 && Size <= 8)
|
|
|
|
Size = 8;
|
|
|
|
else if (Size > 8 && (Size % 16) != 0)
|
|
|
|
Size += 16 - (Size % 16);
|
|
|
|
}
|
|
|
|
Offset -= Size;
|
|
|
|
return Offset;
|
|
|
|
}
|
|
|
|
|
2019-06-06 16:04:33 +08:00
|
|
|
void GuardedPoolAllocator::reportError(uintptr_t AccessPtr, Error E) {
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
if (SingletonPtr)
|
2019-06-06 16:04:33 +08:00
|
|
|
SingletonPtr->reportErrorInternal(AccessPtr, E);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t GuardedPoolAllocator::getNearestSlot(uintptr_t Ptr) const {
|
|
|
|
if (Ptr <= GuardedPagePool + PageSize)
|
|
|
|
return 0;
|
|
|
|
if (Ptr > GuardedPagePoolEnd - PageSize)
|
|
|
|
return MaxSimultaneousAllocations - 1;
|
|
|
|
|
|
|
|
if (!isGuardPage(Ptr))
|
|
|
|
return addrToSlot(Ptr);
|
|
|
|
|
|
|
|
if (Ptr % PageSize <= PageSize / 2)
|
|
|
|
return addrToSlot(Ptr - PageSize); // Round down.
|
|
|
|
return addrToSlot(Ptr + PageSize); // Round up.
|
|
|
|
}
|
|
|
|
|
|
|
|
Error GuardedPoolAllocator::diagnoseUnknownError(uintptr_t AccessPtr,
|
|
|
|
AllocationMetadata **Meta) {
|
|
|
|
// Let's try and figure out what the source of this error is.
|
|
|
|
if (isGuardPage(AccessPtr)) {
|
|
|
|
size_t Slot = getNearestSlot(AccessPtr);
|
|
|
|
AllocationMetadata *SlotMeta = addrToMetadata(slotToAddr(Slot));
|
|
|
|
|
|
|
|
// Ensure that this slot was allocated once upon a time.
|
|
|
|
if (!SlotMeta->Addr)
|
|
|
|
return Error::UNKNOWN;
|
|
|
|
*Meta = SlotMeta;
|
|
|
|
|
|
|
|
if (SlotMeta->Addr < AccessPtr)
|
|
|
|
return Error::BUFFER_OVERFLOW;
|
|
|
|
return Error::BUFFER_UNDERFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Access wasn't a guard page, check for use-after-free.
|
|
|
|
AllocationMetadata *SlotMeta = addrToMetadata(AccessPtr);
|
|
|
|
if (SlotMeta->IsDeallocated) {
|
|
|
|
*Meta = SlotMeta;
|
|
|
|
return Error::USE_AFTER_FREE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have reached here, the error is still unknown. There is no metadata
|
|
|
|
// available.
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
*Meta = nullptr;
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
return Error::UNKNOWN;
|
|
|
|
}
|
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
namespace {
|
|
|
|
// Prints the provided error and metadata information.
|
|
|
|
void printErrorType(Error E, uintptr_t AccessPtr, AllocationMetadata *Meta,
|
|
|
|
options::Printf_t Printf, uint64_t ThreadID) {
|
|
|
|
// Print using intermediate strings. Platforms like Android don't like when
|
|
|
|
// you print multiple times to the same line, as there may be a newline
|
|
|
|
// appended to a log file automatically per Printf() call.
|
|
|
|
const char *ErrorString;
|
2019-06-06 16:04:33 +08:00
|
|
|
switch (E) {
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
case Error::UNKNOWN:
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
ErrorString = "GWP-ASan couldn't automatically determine the source of "
|
|
|
|
"the memory error. It was likely caused by a wild memory "
|
2019-08-21 04:16:11 +08:00
|
|
|
"access into the GWP-ASan pool. The error occurred";
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
break;
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
case Error::USE_AFTER_FREE:
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
ErrorString = "Use after free";
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
break;
|
|
|
|
case Error::DOUBLE_FREE:
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
ErrorString = "Double free";
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
break;
|
|
|
|
case Error::INVALID_FREE:
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
ErrorString = "Invalid (wild) free";
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
break;
|
|
|
|
case Error::BUFFER_OVERFLOW:
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
ErrorString = "Buffer overflow";
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
break;
|
|
|
|
case Error::BUFFER_UNDERFLOW:
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
ErrorString = "Buffer underflow";
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
constexpr size_t kDescriptionBufferLen = 128;
|
|
|
|
char DescriptionBuffer[kDescriptionBufferLen];
|
|
|
|
if (Meta) {
|
|
|
|
if (E == Error::USE_AFTER_FREE) {
|
|
|
|
snprintf(DescriptionBuffer, kDescriptionBufferLen,
|
|
|
|
"(%zu byte%s into a %zu-byte allocation at 0x%zx)",
|
|
|
|
AccessPtr - Meta->Addr, (AccessPtr - Meta->Addr == 1) ? "" : "s",
|
|
|
|
Meta->Size, Meta->Addr);
|
|
|
|
} else if (AccessPtr < Meta->Addr) {
|
|
|
|
snprintf(DescriptionBuffer, kDescriptionBufferLen,
|
|
|
|
"(%zu byte%s to the left of a %zu-byte allocation at 0x%zx)",
|
|
|
|
Meta->Addr - AccessPtr, (Meta->Addr - AccessPtr == 1) ? "" : "s",
|
|
|
|
Meta->Size, Meta->Addr);
|
|
|
|
} else if (AccessPtr > Meta->Addr) {
|
|
|
|
snprintf(DescriptionBuffer, kDescriptionBufferLen,
|
|
|
|
"(%zu byte%s to the right of a %zu-byte allocation at 0x%zx)",
|
|
|
|
AccessPtr - Meta->Addr, (AccessPtr - Meta->Addr == 1) ? "" : "s",
|
|
|
|
Meta->Size, Meta->Addr);
|
|
|
|
} else {
|
|
|
|
snprintf(DescriptionBuffer, kDescriptionBufferLen,
|
|
|
|
"(a %zu-byte allocation)", Meta->Size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Possible number of digits of a 64-bit number: ceil(log10(2^64)) == 20. Add
|
|
|
|
// a null terminator, and round to the nearest 8-byte boundary.
|
|
|
|
constexpr size_t kThreadBufferLen = 24;
|
|
|
|
char ThreadBuffer[kThreadBufferLen];
|
|
|
|
if (ThreadID == GuardedPoolAllocator::kInvalidThreadID)
|
|
|
|
snprintf(ThreadBuffer, kThreadBufferLen, "<unknown>");
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
else
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
snprintf(ThreadBuffer, kThreadBufferLen, "%" PRIu64, ThreadID);
|
|
|
|
|
|
|
|
Printf("%s at 0x%zx %s by thread %s here:\n", ErrorString, AccessPtr,
|
|
|
|
DescriptionBuffer, ThreadBuffer);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
void printAllocDeallocTraces(uintptr_t AccessPtr, AllocationMetadata *Meta,
|
|
|
|
options::Printf_t Printf,
|
|
|
|
options::PrintBacktrace_t PrintBacktrace) {
|
|
|
|
assert(Meta != nullptr && "Metadata is non-null for printAllocDeallocTraces");
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
if (Meta->IsDeallocated) {
|
|
|
|
if (Meta->DeallocationTrace.ThreadID ==
|
|
|
|
GuardedPoolAllocator::kInvalidThreadID)
|
|
|
|
Printf("0x%zx was deallocated by thread <unknown> here:\n", AccessPtr);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
else
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
Printf("0x%zx was deallocated by thread %zu here:\n", AccessPtr,
|
|
|
|
Meta->DeallocationTrace.ThreadID);
|
|
|
|
|
2019-08-16 05:09:09 +08:00
|
|
|
uintptr_t UncompressedTrace[AllocationMetadata::kMaxTraceLengthToCollect];
|
|
|
|
size_t UncompressedLength = compression::unpack(
|
|
|
|
Meta->DeallocationTrace.CompressedTrace,
|
|
|
|
Meta->DeallocationTrace.TraceSize, UncompressedTrace,
|
|
|
|
AllocationMetadata::kMaxTraceLengthToCollect);
|
|
|
|
|
|
|
|
PrintBacktrace(UncompressedTrace, UncompressedLength, Printf);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
|
|
|
|
if (Meta->AllocationTrace.ThreadID == GuardedPoolAllocator::kInvalidThreadID)
|
|
|
|
Printf("0x%zx was allocated by thread <unknown> here:\n", Meta->Addr);
|
|
|
|
else
|
|
|
|
Printf("0x%zx was allocated by thread %zu here:\n", Meta->Addr,
|
|
|
|
Meta->AllocationTrace.ThreadID);
|
|
|
|
|
2019-08-16 05:09:09 +08:00
|
|
|
uintptr_t UncompressedTrace[AllocationMetadata::kMaxTraceLengthToCollect];
|
|
|
|
size_t UncompressedLength = compression::unpack(
|
|
|
|
Meta->AllocationTrace.CompressedTrace, Meta->AllocationTrace.TraceSize,
|
|
|
|
UncompressedTrace, AllocationMetadata::kMaxTraceLengthToCollect);
|
|
|
|
|
|
|
|
PrintBacktrace(UncompressedTrace, UncompressedLength, Printf);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ScopedEndOfReportDecorator {
|
|
|
|
ScopedEndOfReportDecorator(options::Printf_t Printf) : Printf(Printf) {}
|
|
|
|
~ScopedEndOfReportDecorator() { Printf("*** End GWP-ASan report ***\n"); }
|
|
|
|
options::Printf_t Printf;
|
|
|
|
};
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
} // anonymous namespace
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
[GWP-ASan] Guard against recursive allocs. Pack TLS for perf.
Summary:
Add a recursivity guard for GPA::allocate(). This means that any
recursive allocations will fall back to the supporting allocator. In future
patches, we will introduce stack trace collection support. The unwinder will be
provided by the supporting allocator, and we can't guarantee they don't call
malloc() (e.g. backtrace() on posix may call dlopen(), which may call malloc().
Furthermore, this patch packs the new TLS recursivity guard into a thread local
struct, so that TLS variables should be hopefully not fall across cache lines.
Reviewers: vlad.tsyrklevich, morehouse, eugenis
Reviewed By: eugenis
Subscribers: kubamracek, #sanitizers, llvm-commits, eugenis
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63736
llvm-svn: 364356
2019-06-26 06:29:05 +08:00
|
|
|
void GuardedPoolAllocator::reportErrorInternal(uintptr_t AccessPtr, Error E) {
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
if (!pointerIsMine(reinterpret_cast<void *>(AccessPtr))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to prevent races to re-use the same slot that triggered this error.
|
|
|
|
// This does not guarantee that there are no races, because another thread can
|
|
|
|
// take the locks during the time that the signal handler is being called.
|
|
|
|
PoolMutex.tryLock();
|
[GWP-ASan] Guard against recursive allocs. Pack TLS for perf.
Summary:
Add a recursivity guard for GPA::allocate(). This means that any
recursive allocations will fall back to the supporting allocator. In future
patches, we will introduce stack trace collection support. The unwinder will be
provided by the supporting allocator, and we can't guarantee they don't call
malloc() (e.g. backtrace() on posix may call dlopen(), which may call malloc().
Furthermore, this patch packs the new TLS recursivity guard into a thread local
struct, so that TLS variables should be hopefully not fall across cache lines.
Reviewers: vlad.tsyrklevich, morehouse, eugenis
Reviewed By: eugenis
Subscribers: kubamracek, #sanitizers, llvm-commits, eugenis
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63736
llvm-svn: 364356
2019-06-26 06:29:05 +08:00
|
|
|
ThreadLocals.RecursiveGuard = true;
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
|
|
|
Printf("*** GWP-ASan detected a memory error ***\n");
|
|
|
|
ScopedEndOfReportDecorator Decorator(Printf);
|
|
|
|
|
|
|
|
AllocationMetadata *Meta = nullptr;
|
|
|
|
|
2019-06-06 16:04:33 +08:00
|
|
|
if (E == Error::UNKNOWN) {
|
|
|
|
E = diagnoseUnknownError(AccessPtr, &Meta);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
} else {
|
|
|
|
size_t Slot = getNearestSlot(AccessPtr);
|
|
|
|
Meta = addrToMetadata(slotToAddr(Slot));
|
|
|
|
// Ensure that this slot has been previously allocated.
|
|
|
|
if (!Meta->Addr)
|
|
|
|
Meta = nullptr;
|
|
|
|
}
|
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
// Print the error information.
|
|
|
|
uint64_t ThreadID = getThreadID();
|
|
|
|
printErrorType(E, AccessPtr, Meta, Printf, ThreadID);
|
|
|
|
if (Backtrace) {
|
2019-08-13 05:36:44 +08:00
|
|
|
static constexpr unsigned kMaximumStackFramesForCrashTrace = 512;
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
uintptr_t Trace[kMaximumStackFramesForCrashTrace];
|
2019-08-13 05:36:44 +08:00
|
|
|
size_t TraceLength = Backtrace(Trace, kMaximumStackFramesForCrashTrace);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
|
2019-08-13 05:36:44 +08:00
|
|
|
PrintBacktrace(Trace, TraceLength, Printf);
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
} else {
|
|
|
|
Printf(" <unknown (does your allocator support backtracing?)>\n\n");
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
if (Meta)
|
|
|
|
printAllocDeallocTraces(AccessPtr, Meta, Printf, PrintBacktrace);
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
}
|
|
|
|
|
2019-11-26 04:25:43 +08:00
|
|
|
GWP_ASAN_TLS_INITIAL_EXEC
|
[GWP-ASan] Guard against recursive allocs. Pack TLS for perf.
Summary:
Add a recursivity guard for GPA::allocate(). This means that any
recursive allocations will fall back to the supporting allocator. In future
patches, we will introduce stack trace collection support. The unwinder will be
provided by the supporting allocator, and we can't guarantee they don't call
malloc() (e.g. backtrace() on posix may call dlopen(), which may call malloc().
Furthermore, this patch packs the new TLS recursivity guard into a thread local
struct, so that TLS variables should be hopefully not fall across cache lines.
Reviewers: vlad.tsyrklevich, morehouse, eugenis
Reviewed By: eugenis
Subscribers: kubamracek, #sanitizers, llvm-commits, eugenis
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63736
llvm-svn: 364356
2019-06-26 06:29:05 +08:00
|
|
|
GuardedPoolAllocator::ThreadLocalPackedVariables
|
|
|
|
GuardedPoolAllocator::ThreadLocals;
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
} // namespace gwp_asan
|