1 { lib, stdenv, fetchurl }:
3 stdenv.mkDerivation rec {
4 pname = "graphene-hardened-malloc";
8 url = "https://github.com/GrapheneOS/hardened_malloc/archive/${version}.tar.gz";
9 sha256 = "0zsl4vl65ic6lw5rzcjzvcxg8makg683abnwvy60zfap8hvijvjb";
13 install -Dm444 -t $out/lib libhardened_malloc.so
16 substitute preload.sh $out/bin/preload-hardened-malloc --replace "\$dir" $out/lib
17 chmod 0555 $out/bin/preload-hardened-malloc
20 separateDebugInfo = true;
22 doInstallCheck = true;
23 installCheckPhase = ''
26 $out/bin/preload-hardened-malloc ./offset
28 pushd simple-memory-corruption
31 # these tests don't actually appear to generate overflows currently
32 rm read_after_free_small string_overflow eight_byte_overflow_large
34 for t in `find . -regex ".*/[a-z_]+"` ; do
36 # the program being aborted (as it should be) would result in an exit code > 128
37 (($out/bin/preload-hardened-malloc $t) && false) \
38 || (test $? -gt 128 || (echo "$t was not aborted" && false))
46 homepage = "https://github.com/GrapheneOS/hardened_malloc";
47 description = "Hardened allocator designed for modern systems";
49 This is a security-focused general purpose memory allocator providing the malloc API
50 along with various extensions. It provides substantial hardening against heap
51 corruption vulnerabilities yet aims to provide decent overall performance.
53 license = licenses.mit;
54 maintainers = with maintainers; [ ris ];
55 platforms = [ "x86_64-linux" "aarch64-linux" ];