[sanitizer] Initial implementation of a Hardened Allocator
Summary:
This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator.
It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast.
The following were implemented:
- additional consistency checks on the allocation function parameters and on the heap chunks;
- use of checksum protected chunk header, to detect corruption;
- randomness to the allocator base;
- delayed freelist (quarantine), to mitigate use after free and overall determinism.
Additional mitigations are in the works.
Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc
Subscribers: kubabrecka, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D20084
llvm-svn: 271968
2016-06-07 09:20:26 +08:00
|
|
|
//===-- scudo_flags.cpp -----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// Hardened Allocator flag parsing logic.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "scudo_flags.h"
|
|
|
|
#include "scudo_utils.h"
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
|
|
|
#include "sanitizer_common/sanitizer_flag_parser.h"
|
|
|
|
|
2016-08-03 06:25:38 +08:00
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
const char* __scudo_default_options();
|
|
|
|
|
[sanitizer] Initial implementation of a Hardened Allocator
Summary:
This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator.
It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast.
The following were implemented:
- additional consistency checks on the allocation function parameters and on the heap chunks;
- use of checksum protected chunk header, to detect corruption;
- randomness to the allocator base;
- delayed freelist (quarantine), to mitigate use after free and overall determinism.
Additional mitigations are in the works.
Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc
Subscribers: kubabrecka, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D20084
llvm-svn: 271968
2016-06-07 09:20:26 +08:00
|
|
|
namespace __scudo {
|
|
|
|
|
2016-08-03 06:25:38 +08:00
|
|
|
Flags ScudoFlags; // Use via getFlags().
|
[sanitizer] Initial implementation of a Hardened Allocator
Summary:
This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator.
It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast.
The following were implemented:
- additional consistency checks on the allocation function parameters and on the heap chunks;
- use of checksum protected chunk header, to detect corruption;
- randomness to the allocator base;
- delayed freelist (quarantine), to mitigate use after free and overall determinism.
Additional mitigations are in the works.
Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc
Subscribers: kubabrecka, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D20084
llvm-svn: 271968
2016-06-07 09:20:26 +08:00
|
|
|
|
|
|
|
void Flags::setDefaults() {
|
|
|
|
#define SCUDO_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
|
|
|
|
#include "scudo_flags.inc"
|
|
|
|
#undef SCUDO_FLAG
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RegisterScudoFlags(FlagParser *parser, Flags *f) {
|
|
|
|
#define SCUDO_FLAG(Type, Name, DefaultValue, Description) \
|
|
|
|
RegisterFlag(parser, #Name, Description, &f->Name);
|
|
|
|
#include "scudo_flags.inc"
|
|
|
|
#undef SCUDO_FLAG
|
|
|
|
}
|
|
|
|
|
2016-08-03 06:25:38 +08:00
|
|
|
static const char *callGetScudoDefaultOptions() {
|
|
|
|
return (&__scudo_default_options) ? __scudo_default_options() : "";
|
|
|
|
}
|
|
|
|
|
[sanitizer] Initial implementation of a Hardened Allocator
Summary:
This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator.
It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast.
The following were implemented:
- additional consistency checks on the allocation function parameters and on the heap chunks;
- use of checksum protected chunk header, to detect corruption;
- randomness to the allocator base;
- delayed freelist (quarantine), to mitigate use after free and overall determinism.
Additional mitigations are in the works.
Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc
Subscribers: kubabrecka, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D20084
llvm-svn: 271968
2016-06-07 09:20:26 +08:00
|
|
|
void initFlags() {
|
|
|
|
SetCommonFlagsDefaults();
|
|
|
|
{
|
|
|
|
CommonFlags cf;
|
|
|
|
cf.CopyFrom(*common_flags());
|
|
|
|
cf.exitcode = 1;
|
|
|
|
OverrideCommonFlags(cf);
|
|
|
|
}
|
|
|
|
Flags *f = getFlags();
|
|
|
|
f->setDefaults();
|
|
|
|
|
2016-08-03 06:25:38 +08:00
|
|
|
FlagParser ScudoParser;
|
|
|
|
RegisterScudoFlags(&ScudoParser, f);
|
|
|
|
RegisterCommonFlags(&ScudoParser);
|
|
|
|
|
|
|
|
// Override from user-specified string.
|
|
|
|
const char *ScudoDefaultOptions = callGetScudoDefaultOptions();
|
|
|
|
ScudoParser.ParseString(ScudoDefaultOptions);
|
[sanitizer] Initial implementation of a Hardened Allocator
Summary:
This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator.
It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast.
The following were implemented:
- additional consistency checks on the allocation function parameters and on the heap chunks;
- use of checksum protected chunk header, to detect corruption;
- randomness to the allocator base;
- delayed freelist (quarantine), to mitigate use after free and overall determinism.
Additional mitigations are in the works.
Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc
Subscribers: kubabrecka, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D20084
llvm-svn: 271968
2016-06-07 09:20:26 +08:00
|
|
|
|
2016-08-03 06:25:38 +08:00
|
|
|
// Override from environment.
|
|
|
|
ScudoParser.ParseString(GetEnv("SCUDO_OPTIONS"));
|
[sanitizer] Initial implementation of a Hardened Allocator
Summary:
This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator.
It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast.
The following were implemented:
- additional consistency checks on the allocation function parameters and on the heap chunks;
- use of checksum protected chunk header, to detect corruption;
- randomness to the allocator base;
- delayed freelist (quarantine), to mitigate use after free and overall determinism.
Additional mitigations are in the works.
Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc
Subscribers: kubabrecka, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D20084
llvm-svn: 271968
2016-06-07 09:20:26 +08:00
|
|
|
|
|
|
|
InitializeCommonFlags();
|
|
|
|
|
|
|
|
// Sanity checks and default settings for the Quarantine parameters.
|
|
|
|
|
|
|
|
if (f->QuarantineSizeMb < 0) {
|
|
|
|
const int DefaultQuarantineSizeMb = 64;
|
|
|
|
f->QuarantineSizeMb = DefaultQuarantineSizeMb;
|
|
|
|
}
|
|
|
|
// We enforce an upper limit for the quarantine size of 4Gb.
|
|
|
|
if (f->QuarantineSizeMb > (4 * 1024)) {
|
|
|
|
dieWithMessage("ERROR: the quarantine size is too large\n");
|
|
|
|
}
|
|
|
|
if (f->ThreadLocalQuarantineSizeKb < 0) {
|
|
|
|
const int DefaultThreadLocalQuarantineSizeKb = 1024;
|
|
|
|
f->ThreadLocalQuarantineSizeKb = DefaultThreadLocalQuarantineSizeKb;
|
|
|
|
}
|
|
|
|
// And an upper limit of 128Mb for the thread quarantine cache.
|
|
|
|
if (f->ThreadLocalQuarantineSizeKb > (128 * 1024)) {
|
|
|
|
dieWithMessage("ERROR: the per thread quarantine cache size is too "
|
|
|
|
"large\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Flags *getFlags() {
|
2016-08-03 06:25:38 +08:00
|
|
|
return &ScudoFlags;
|
[sanitizer] Initial implementation of a Hardened Allocator
Summary:
This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator.
It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast.
The following were implemented:
- additional consistency checks on the allocation function parameters and on the heap chunks;
- use of checksum protected chunk header, to detect corruption;
- randomness to the allocator base;
- delayed freelist (quarantine), to mitigate use after free and overall determinism.
Additional mitigations are in the works.
Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc
Subscribers: kubabrecka, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D20084
llvm-svn: 271968
2016-06-07 09:20:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|