···
1
-
{ lib, stdenv, fetchurl }:
1
+
{ lib, stdenv, fetchurl, python3, runCommand, makeWrapper, stress-ng }:
3
-
stdenv.mkDerivation rec {
3
+
lib.fix (self: stdenv.mkDerivation rec {
pname = "graphene-hardened-malloc";
url = "https://github.com/GrapheneOS/hardened_malloc/archive/${version}.tar.gz";
9
-
sha256 = "0zsl4vl65ic6lw5rzcjzvcxg8makg683abnwvy60zfap8hvijvjb";
9
+
sha256 = "0lipyd2pb1bmghkyv9zmg25jwcglj7m281f01zlh3ghz3xlfh0ym";
13
+
checkInputs = [ python3 ];
14
+
# these tests cover use as a build-time-linked library
20
+
install -Dm444 -t $out/include include/*
install -Dm444 -t $out/lib libhardened_malloc.so
···
separateDebugInfo = true;
22
-
doInstallCheck = true;
23
-
installCheckPhase = ''
26
-
$out/bin/preload-hardened-malloc ./offset
31
+
ld-preload-tests = stdenv.mkDerivation {
32
+
name = "${self.name}-ld-preload-tests";
28
-
pushd simple-memory-corruption
35
+
nativeBuildInputs = [ makeWrapper ];
31
-
# these tests don't actually appear to generate overflows currently
32
-
rm read_after_free_small string_overflow eight_byte_overflow_large
37
+
# reuse the projects tests to cover use with LD_PRELOAD. we have
38
+
# to convince the test programs to build as though they're naive
39
+
# standalone executables. this includes disabling tests for
40
+
# malloc_object_size, which doesn't make sense to use via LD_PRELOAD.
42
+
pushd test/simple-memory-corruption
43
+
make LDLIBS= LDFLAGS=-Wl,--unresolved-symbols=ignore-all CXXFLAGS=-lstdc++
44
+
substituteInPlace test_smc.py \
45
+
--replace 'test_malloc_object_size' 'dont_test_malloc_object_size' \
46
+
--replace 'test_invalid_malloc_object_size' 'dont_test_invalid_malloc_object_size'
47
+
popd # test/simple-memory-corruption
34
-
for t in `find . -regex ".*/[a-z_]+"` ; do
35
-
echo "Running $t..."
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))
52
+
cp -r test/simple-memory-corruption $out/test/simple-memory-corruption
55
+
makeWrapper ${python3.interpreter} $out/bin/run-tests \
56
+
--add-flags "-I -m unittest discover --start-directory $out/test/simple-memory-corruption"
60
+
ld-preload = runCommand "ld-preload-test-run" {} ''
61
+
${self}/bin/preload-hardened-malloc ${self.ld-preload-tests}/bin/run-tests
64
+
# to compensate for the lack of tests of correct normal malloc operation
65
+
stress = runCommand "stress-test-run" {} ''
66
+
${self}/bin/preload-hardened-malloc ${stress-ng}/bin/stress-ng \
69
+
--malloc-ops 1000000 \
homepage = "https://github.com/GrapheneOS/hardened_malloc";
···
maintainers = with maintainers; [ ris ];
platforms = [ "x86_64-linux" "aarch64-linux" ];