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
70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
//===-- scudo_new_delete.cpp ------------------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// Interceptors for operators new and delete.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "scudo_allocator.h"
|
|
|
|
#include "interception/interception.h"
|
|
|
|
#include <cstddef>
|
|
|
|
using namespace __scudo;
|
|
|
|
#define CXX_OPERATOR_ATTRIBUTE INTERCEPTOR_ATTRIBUTE
|
|
|
|
// Fake std::nothrow_t to avoid including <new>.
|
|
namespace std {
|
|
struct nothrow_t {};
|
|
} // namespace std
|
|
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void *operator new(size_t size) {
|
|
return scudoMalloc(size, FromNew);
|
|
}
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void *operator new[](size_t size) {
|
|
return scudoMalloc(size, FromNewArray);
|
|
}
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void *operator new(size_t size, std::nothrow_t const&) {
|
|
return scudoMalloc(size, FromNew);
|
|
}
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void *operator new[](size_t size, std::nothrow_t const&) {
|
|
return scudoMalloc(size, FromNewArray);
|
|
}
|
|
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void operator delete(void *ptr) NOEXCEPT {
|
|
return scudoFree(ptr, FromNew);
|
|
}
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void operator delete[](void *ptr) NOEXCEPT {
|
|
return scudoFree(ptr, FromNewArray);
|
|
}
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void operator delete(void *ptr, std::nothrow_t const&) NOEXCEPT {
|
|
return scudoFree(ptr, FromNew);
|
|
}
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void operator delete[](void *ptr, std::nothrow_t const&) NOEXCEPT {
|
|
return scudoFree(ptr, FromNewArray);
|
|
}
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void operator delete(void *ptr, size_t size) NOEXCEPT {
|
|
scudoSizedFree(ptr, size, FromNew);
|
|
}
|
|
CXX_OPERATOR_ATTRIBUTE
|
|
void operator delete[](void *ptr, size_t size) NOEXCEPT {
|
|
scudoSizedFree(ptr, size, FromNewArray);
|
|
}
|