Compare commits
11 Commits
d3152b8e8f
...
2d302f7d85
Author | SHA1 | Date | |
---|---|---|---|
|
2d302f7d85 | ||
|
d5f9909eca | ||
|
5e1901e85d | ||
|
462c2c5293 | ||
|
8f3281ed6a | ||
|
7d75acc62a | ||
|
af866a7faa | ||
|
64dad0a69f | ||
|
95c4b40caf | ||
|
cc70583beb | ||
|
62a98efb13 |
@ -1,2 +1,2 @@
|
|||||||
Checks: 'bugprone-*,-bugprone-easily-swappable-parameters,-bugprone-macro-parentheses,-bugprone-too-small-loop-variable,cert-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-clang-diagnostic-constant-logical-operand,readability-*,-readability-function-cognitive-complexity,-readability-identifier-length,-readability-inconsistent-declaration-parameter-name,-readability-magic-numbers,-readability-named-parameter,llvm-include-order,misc-*'
|
Checks: 'bugprone-*,-bugprone-easily-swappable-parameters,-bugprone-macro-parentheses,-bugprone-too-small-loop-variable,cert-*,-cert-err33-c,clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-clang-diagnostic-constant-logical-operand,readability-*,-readability-function-cognitive-complexity,-readability-identifier-length,-readability-inconsistent-declaration-parameter-name,-readability-magic-numbers,-readability-named-parameter,llvm-include-order,misc-*'
|
||||||
WarningsAsErrors: '*'
|
WarningsAsErrors: '*'
|
||||||
|
7
Makefile
7
Makefile
@ -14,13 +14,14 @@ endif
|
|||||||
OUT := out$(SUFFIX)
|
OUT := out$(SUFFIX)
|
||||||
|
|
||||||
define safe_flag
|
define safe_flag
|
||||||
$(shell $(CC) $(if $(filter clang,$(CC)),-Werror=unknown-warning-option) -E $1 - </dev/null >/dev/null 2>&1 && echo $1 || echo $2)
|
$(shell $(CC) $(if $(filter clang%,$(CC)),-Werror=unknown-warning-option) -E $1 - </dev/null >/dev/null 2>&1 && echo $1 || echo $2)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
CPPFLAGS := $(CPPFLAGS) -D_GNU_SOURCE -I include
|
CPPFLAGS := $(CPPFLAGS) -D_GNU_SOURCE -I include
|
||||||
SHARED_FLAGS := -pipe -O3 -flto -fPIC -fvisibility=hidden -fno-plt \
|
SHARED_FLAGS := -pipe -O3 -flto -fPIC -fvisibility=hidden -fno-plt \
|
||||||
-fstack-clash-protection $(call safe_flag,-fcf-protection) -fstack-protector-strong \
|
-fstack-clash-protection $(call safe_flag,-fcf-protection) -fstack-protector-strong \
|
||||||
-Wall -Wextra $(call safe_flag,-Wcast-align=strict,-Wcast-align) -Wcast-qual -Wwrite-strings
|
-Wall -Wextra $(call safe_flag,-Wcast-align=strict,-Wcast-align) -Wcast-qual -Wwrite-strings \
|
||||||
|
-Wundef
|
||||||
|
|
||||||
ifeq ($(CONFIG_WERROR),true)
|
ifeq ($(CONFIG_WERROR),true)
|
||||||
SHARED_FLAGS += -Werror
|
SHARED_FLAGS += -Werror
|
||||||
@ -34,7 +35,7 @@ ifeq ($(CONFIG_UBSAN),true)
|
|||||||
SHARED_FLAGS += -fsanitize=undefined -fno-sanitize-recover=undefined
|
SHARED_FLAGS += -fsanitize=undefined -fno-sanitize-recover=undefined
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS := $(CFLAGS) -std=c17 $(SHARED_FLAGS) -Wmissing-prototypes
|
CFLAGS := $(CFLAGS) -std=c17 $(SHARED_FLAGS) -Wmissing-prototypes -Wstrict-prototypes
|
||||||
CXXFLAGS := $(CXXFLAGS) -std=c++17 -fsized-deallocation $(SHARED_FLAGS)
|
CXXFLAGS := $(CXXFLAGS) -std=c++17 -fsized-deallocation $(SHARED_FLAGS)
|
||||||
LDFLAGS := $(LDFLAGS) -Wl,-O1,--as-needed,-z,defs,-z,relro,-z,now,-z,nodlopen,-z,text
|
LDFLAGS := $(LDFLAGS) -Wl,-O1,--as-needed,-z,defs,-z,relro,-z,now,-z,nodlopen,-z,text
|
||||||
|
|
||||||
|
21
README.md
21
README.md
@ -65,12 +65,14 @@ used instead as this allocator fundamentally doesn't support that environment.
|
|||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
Debian stable (currently Debian 11) determines the most ancient set of
|
Debian stable (currently Debian 12) determines the most ancient set of
|
||||||
supported dependencies:
|
supported dependencies:
|
||||||
|
|
||||||
* glibc 2.31
|
* glibc 2.36
|
||||||
* Linux 5.10
|
* Linux 6.1
|
||||||
* Clang 11.0.1 or GCC 10.2.1
|
* Clang 14.0.6 or GCC 12.2.0
|
||||||
|
|
||||||
|
For Android, the Linux GKI 5.10, 5.15 and 6.1 branches are supported.
|
||||||
|
|
||||||
However, using more recent releases is highly recommended. Older versions of
|
However, using more recent releases is highly recommended. Older versions of
|
||||||
the dependencies may be compatible at the moment but are not tested and will
|
the dependencies may be compatible at the moment but are not tested and will
|
||||||
@ -81,16 +83,7 @@ there will be custom integration offering better performance in the future
|
|||||||
along with other hardening for the C standard library implementation.
|
along with other hardening for the C standard library implementation.
|
||||||
|
|
||||||
For Android, only the current generation, actively developed maintenance branch of the Android
|
For Android, only the current generation, actively developed maintenance branch of the Android
|
||||||
Open Source Project will be supported, which currently means `android13-release`. The `12.1`
|
Open Source Project will be supported, which currently means `android13-qpr2-release`.
|
||||||
branch is temporarily supported while we finish migrating to Android 13. If you want us to
|
|
||||||
continue supporting it you'll need to provide GrapheneOS with developers and funding.
|
|
||||||
|
|
||||||
The Linux kernel's implementation of Memory Protection Keys was severely broken
|
|
||||||
before Linux 5.0. The `CONFIG_SEAL_METADATA` feature should only be enabled for
|
|
||||||
use on kernels newer than 5.0 or longterm branches with a backport of the [fix
|
|
||||||
for the
|
|
||||||
issue](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a31e184e4f69965c99c04cc5eb8a4920e0c63737).
|
|
||||||
This issue was discovered and reported by the hardened\_malloc project.
|
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
|
16
h_malloc.c
16
h_malloc.c
@ -80,7 +80,7 @@ static union {
|
|||||||
char padding[PAGE_SIZE];
|
char padding[PAGE_SIZE];
|
||||||
} ro __attribute__((aligned(PAGE_SIZE)));
|
} ro __attribute__((aligned(PAGE_SIZE)));
|
||||||
|
|
||||||
static inline void *get_slab_region_end() {
|
static inline void *get_slab_region_end(void) {
|
||||||
return atomic_load_explicit(&ro.slab_region_end, memory_order_acquire);
|
return atomic_load_explicit(&ro.slab_region_end, memory_order_acquire);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1808,24 +1808,18 @@ EXPORT int h_malloc_trim(UNUSED size_t pad) {
|
|||||||
|
|
||||||
EXPORT void h_malloc_stats(void) {}
|
EXPORT void h_malloc_stats(void) {}
|
||||||
|
|
||||||
|
#if defined(__GLIBC__) || defined(__ANDROID__)
|
||||||
// glibc mallinfo is broken and replaced with mallinfo2
|
// glibc mallinfo is broken and replaced with mallinfo2
|
||||||
#if defined(__GLIBC__)
|
#if defined(__GLIBC__)
|
||||||
EXPORT struct mallinfo h_mallinfo(void) {
|
EXPORT struct mallinfo h_mallinfo(void) {
|
||||||
return (struct mallinfo){0};
|
return (struct mallinfo){0};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __GLIBC_PREREQ(2, 33)
|
|
||||||
#define HAVE_MALLINFO2
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_MALLINFO2) || defined(__ANDROID__)
|
|
||||||
#ifndef __GLIBC__
|
|
||||||
EXPORT struct mallinfo h_mallinfo(void) {
|
|
||||||
struct mallinfo info = {0};
|
|
||||||
#else
|
|
||||||
EXPORT struct mallinfo2 h_mallinfo2(void) {
|
EXPORT struct mallinfo2 h_mallinfo2(void) {
|
||||||
struct mallinfo2 info = {0};
|
struct mallinfo2 info = {0};
|
||||||
|
#else
|
||||||
|
EXPORT struct mallinfo h_mallinfo(void) {
|
||||||
|
struct mallinfo info = {0};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_STATS
|
#if CONFIG_STATS
|
||||||
|
4
new.cc
4
new.cc
@ -1,4 +1,8 @@
|
|||||||
|
// needed with libstdc++ but not libc++
|
||||||
|
#if __has_include(<bits/functexcept.h>)
|
||||||
#include <bits/functexcept.h>
|
#include <bits/functexcept.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include "h_malloc.h"
|
#include "h_malloc.h"
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
static void print_mallinfo2(void) {
|
static void print_mallinfo2(void) {
|
||||||
#if defined(__GLIBC__)
|
#if defined(__GLIBC__)
|
||||||
#if __GLIBC_PREREQ(2, 33)
|
|
||||||
struct mallinfo2 info = mallinfo2();
|
struct mallinfo2 info = mallinfo2();
|
||||||
printf("mallinfo2:\n");
|
printf("mallinfo2:\n");
|
||||||
printf("arena: %zu\n", (size_t)info.arena);
|
printf("arena: %zu\n", (size_t)info.arena);
|
||||||
@ -23,7 +22,6 @@ static void print_mallinfo2(void) {
|
|||||||
printf("fordblks: %zu\n", (size_t)info.fordblks);
|
printf("fordblks: %zu\n", (size_t)info.fordblks);
|
||||||
printf("keepcost: %zu\n", (size_t)info.keepcost);
|
printf("keepcost: %zu\n", (size_t)info.keepcost);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTNONE int main(void) {
|
OPTNONE int main(void) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user