nixos/tests/hardened: test hardened malloc

This commit is contained in:
Joachim Fasting 2019-04-23 22:24:16 +02:00
parent 48ff4f1197
commit 10d3a0e10b
No known key found for this signature in database
GPG Key ID: 5C204DF675C90294

View File

@ -27,6 +27,20 @@ import ./make-test.nix ({ pkgs, ...} : {
}; };
testScript = testScript =
let
hardened-malloc-tests = pkgs.stdenv.mkDerivation rec {
name = "hardened-malloc-tests-${pkgs.graphene-hardened-malloc.version}";
src = pkgs.graphene-hardened-malloc.src;
buildPhase = ''
cd test/simple-memory-corruption
make -j4
'';
installPhase = ''
find . -type f -executable -exec install -Dt $out/bin '{}' +
'';
};
in
'' ''
$machine->waitForUnit("multi-user.target"); $machine->waitForUnit("multi-user.target");
@ -83,5 +97,18 @@ import ./make-test.nix ({ pkgs, ...} : {
$machine->fail("systemctl hibernate"); $machine->fail("systemctl hibernate");
$machine->fail("systemctl kexec"); $machine->fail("systemctl kexec");
}; };
# Test hardened memory allocator
sub runMallocTestProg {
my ($progName, $errorText) = @_;
my $text = "fatal allocator error: " . $errorText;
$machine->fail("${hardened-malloc-tests}/bin/" . $progName) =~ $text;
};
subtest "hardenedmalloc", sub {
runMallocTestProg("double_free_large", "invalid free");
runMallocTestProg("unaligned_free_small", "invalid unaligned free");
runMallocTestProg("write_after_free_small", "detected write after free");
};
''; '';
}) })