2019-08-02 01:53:25 +08:00
|
|
|
//===-- basic.cpp -----------------------------------------------*- C++ -*-===//
|
[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
|
|
|
//
|
|
|
|
// 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/tests/harness.h"
|
|
|
|
|
|
|
|
TEST_F(CustomGuardedPoolAllocator, BasicAllocation) {
|
|
|
|
InitNumSlots(1);
|
|
|
|
void *Ptr = GPA.allocate(1);
|
|
|
|
EXPECT_NE(nullptr, Ptr);
|
|
|
|
EXPECT_TRUE(GPA.pointerIsMine(Ptr));
|
|
|
|
EXPECT_EQ(1u, GPA.getSize(Ptr));
|
|
|
|
GPA.deallocate(Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DefaultGuardedPoolAllocator, NullptrIsNotMine) {
|
|
|
|
EXPECT_FALSE(GPA.pointerIsMine(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CustomGuardedPoolAllocator, SizedAllocations) {
|
|
|
|
InitNumSlots(1);
|
|
|
|
|
[GWP-ASan] Crash Handler API.
Summary:
Forewarning: This patch looks big in #LOC changed. I promise it's not that bad, it just moves a lot of content from one file to another. I've gone ahead and left inline comments on Phabricator for sections where this has happened.
This patch:
1. Introduces the crash handler API (crash_handler_api.h).
2. Moves information required for out-of-process crash handling into an AllocatorState. This is a trivially-copied POD struct that designed to be recovered from a deceased process, and used by the crash handler to create a GWP-ASan report (along with the other trivially-copied Metadata struct).
3. Implements the crash handler API using the AllocatorState and Metadata.
4. Adds tests for the crash handler.
5. Reimplements the (now optionally linked by the supporting allocator) in-process crash handler (i.e. the segv handler) using the new crash handler API.
6. Minor updates Scudo & Scudo Standalone to fix compatibility.
7. Changed capitalisation of errors (e.g. /s/Use after free/Use After Free).
Reviewers: cryptoad, eugenis, jfb
Reviewed By: eugenis
Subscribers: merge_guards_bot, pcc, jfb, dexonsmith, mgorny, cryptoad, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D73557
2020-02-06 07:39:03 +08:00
|
|
|
std::size_t MaxAllocSize = GPA.getAllocatorState()->maximumAllocationSize();
|
[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
|
|
|
EXPECT_TRUE(MaxAllocSize > 0);
|
|
|
|
|
|
|
|
for (unsigned AllocSize = 1; AllocSize <= MaxAllocSize; AllocSize <<= 1) {
|
|
|
|
void *Ptr = GPA.allocate(AllocSize);
|
|
|
|
EXPECT_NE(nullptr, Ptr);
|
|
|
|
EXPECT_TRUE(GPA.pointerIsMine(Ptr));
|
|
|
|
EXPECT_EQ(AllocSize, GPA.getSize(Ptr));
|
|
|
|
GPA.deallocate(Ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DefaultGuardedPoolAllocator, TooLargeAllocation) {
|
[GWP-ASan] Crash Handler API.
Summary:
Forewarning: This patch looks big in #LOC changed. I promise it's not that bad, it just moves a lot of content from one file to another. I've gone ahead and left inline comments on Phabricator for sections where this has happened.
This patch:
1. Introduces the crash handler API (crash_handler_api.h).
2. Moves information required for out-of-process crash handling into an AllocatorState. This is a trivially-copied POD struct that designed to be recovered from a deceased process, and used by the crash handler to create a GWP-ASan report (along with the other trivially-copied Metadata struct).
3. Implements the crash handler API using the AllocatorState and Metadata.
4. Adds tests for the crash handler.
5. Reimplements the (now optionally linked by the supporting allocator) in-process crash handler (i.e. the segv handler) using the new crash handler API.
6. Minor updates Scudo & Scudo Standalone to fix compatibility.
7. Changed capitalisation of errors (e.g. /s/Use after free/Use After Free).
Reviewers: cryptoad, eugenis, jfb
Reviewed By: eugenis
Subscribers: merge_guards_bot, pcc, jfb, dexonsmith, mgorny, cryptoad, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D73557
2020-02-06 07:39:03 +08:00
|
|
|
EXPECT_EQ(nullptr,
|
|
|
|
GPA.allocate(GPA.getAllocatorState()->maximumAllocationSize() + 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
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CustomGuardedPoolAllocator, AllocAllSlots) {
|
|
|
|
constexpr unsigned kNumSlots = 128;
|
|
|
|
InitNumSlots(kNumSlots);
|
|
|
|
void *Ptrs[kNumSlots];
|
|
|
|
for (unsigned i = 0; i < kNumSlots; ++i) {
|
|
|
|
Ptrs[i] = GPA.allocate(1);
|
|
|
|
EXPECT_NE(nullptr, Ptrs[i]);
|
|
|
|
EXPECT_TRUE(GPA.pointerIsMine(Ptrs[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
// This allocation should fail as all the slots are used.
|
|
|
|
void *Ptr = GPA.allocate(1);
|
|
|
|
EXPECT_EQ(nullptr, Ptr);
|
|
|
|
EXPECT_FALSE(GPA.pointerIsMine(nullptr));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < kNumSlots; ++i)
|
|
|
|
GPA.deallocate(Ptrs[i]);
|
|
|
|
}
|