GrapheneOS / hardened_malloc

Hardened allocator designed for modern systems. It has integration into Android's Bionic libc and can be used externally with musl and glibc as a dynamic library for use on other Linux-based platforms. It will gain more portability / integration over time.
https://grapheneos.org/
MIT License
1.29k stars 97 forks source link

OOM when running the sh6bench benchmark #154

Closed jvoisin closed 2 years ago

jvoisin commented 2 years ago

As my of my recent efforts to benchmark (security-oriented) memory allocators in [](), I ~recently added hardened_malloc to the mimalloc-bench party, and it's doing pretty well, kudos!

Unfortunately, I'm getting an OOM on the sh6bench bench.

$ git clone https://github.com/daanx/mimalloc-bench
$ cd mimalloc-bench
$ ./build-bench-env.sh hm bench
$ cd ./out/bench
$ LD_PRELOAD=/home/jvoisin/dev/mimalloc-bench/extern/hm/libhardened_malloc.so ./sh6bench 4
Out of memory
$

Is this working as intended?

ghost commented 2 years ago

Have you increased vm.max_map_count to a higher default value?

vm.max_map_count = 1048576

thestinger commented 2 years ago

The guard slab feature is what massively increases the amount of VMAs. The cost of the expensive optional hardening features dwarfs the cost of allocation. That's why it would be nice to test it in a lightweight configuration too, especially if you're measuring memory usage. It's meant to be configured for the use case. GrapheneOS doesn't use it in the configuration that you're testing, for example.

jvoisin commented 2 years ago

Would it then be possible to have the default configuration of hardened_malloc be a reasonable one that doesn't require tweaking for most of the programs?

thestinger commented 2 years ago

The default is the most security-focused configuration sensible for regular use. It heavily leans towards security rather than performance in that default configuration. The thinking behind that is if people need better performance and/or lower memory usage they can configure it but security isn't something they'll be able to see or measure.