2024-05-28 19:43:04 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2011-07-20 15:15:40 +03:00
|
|
|
# Test that users cannot register specially-crafted derivations that
|
|
|
|
# produce output paths belonging to other derivations. This could be
|
|
|
|
# used to inject malware into the store.
|
|
|
|
|
|
|
|
source common.sh
|
|
|
|
|
2024-06-16 13:51:46 +03:00
|
|
|
TODO_NixOS
|
|
|
|
|
2011-07-20 15:15:40 +03:00
|
|
|
clearStore
|
|
|
|
|
|
|
|
startDaemon
|
|
|
|
|
|
|
|
# Determine the output path of the "good" derivation.
|
2011-10-11 00:32:34 +03:00
|
|
|
goodOut=$(nix-store -q $(nix-instantiate ./secure-drv-outputs.nix -A good))
|
2011-07-20 15:15:40 +03:00
|
|
|
|
|
|
|
# Instantiate the "bad" derivation.
|
2011-10-11 00:32:34 +03:00
|
|
|
badDrv=$(nix-instantiate ./secure-drv-outputs.nix -A bad)
|
|
|
|
badOut=$(nix-store -q $badDrv)
|
2011-07-20 15:15:40 +03:00
|
|
|
|
|
|
|
# Rewrite the bad derivation to produce the output path of the good
|
|
|
|
# derivation.
|
|
|
|
rm -f $TEST_ROOT/bad.drv
|
|
|
|
sed -e "s|$badOut|$goodOut|g" < $badDrv > $TEST_ROOT/bad.drv
|
|
|
|
|
|
|
|
# Add the manipulated derivation to the store and build it. This
|
|
|
|
# should fail.
|
2011-10-11 00:32:34 +03:00
|
|
|
if badDrv2=$(nix-store --add $TEST_ROOT/bad.drv); then
|
|
|
|
nix-store -r "$badDrv2"
|
2011-07-20 15:15:40 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Now build the good derivation.
|
2012-09-12 02:14:15 +03:00
|
|
|
goodOut2=$(nix-build ./secure-drv-outputs.nix -A good --no-out-link)
|
2011-07-20 15:15:40 +03:00
|
|
|
test "$goodOut" = "$goodOut2"
|
|
|
|
|
|
|
|
if ! test -e "$goodOut"/good; then
|
|
|
|
echo "Bad derivation stole the output path of the good derivation!"
|
|
|
|
exit 1
|
|
|
|
fi
|