File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -698,6 +698,18 @@ static void handleChildException(bool sendException)
698
698
}
699
699
}
700
700
701
+ static bool checkNotWorldWritable (std::filesystem::path path)
702
+ {
703
+ while (true ) {
704
+ auto st = lstat (path);
705
+ if (st.st_mode & S_IWOTH)
706
+ return false ;
707
+ if (path == path.parent_path ()) break ;
708
+ path = path.parent_path ();
709
+ }
710
+ return true ;
711
+ }
712
+
701
713
void DerivationBuilderImpl::startBuilder ()
702
714
{
703
715
/* Make sure that no other processes are executing under the
@@ -729,6 +741,9 @@ void DerivationBuilderImpl::startBuilder()
729
741
730
742
createDirs (buildDir);
731
743
744
+ if (buildUser && !checkNotWorldWritable (buildDir))
745
+ throw Error (" Path %s or a parent directory is world-writable or a symlink. That's not allowed for security." , buildDir);
746
+
732
747
/* Create a temporary directory where the build will take
733
748
place. */
734
749
topTmpDir = createTempDir (buildDir, " nix-build-" + std::string (drvPath.name ()), 0700 );
Original file line number Diff line number Diff line change 41
41
42
42
# Test that /nix/store is available via an overlayfs mount.
43
43
machine.succeed("nix shell --store /tmp/nix ${ pkgA } --command cowsay foo >&2")
44
+
45
+ # Building in /tmp should fail for security reasons.
46
+ err = machine.fail("nix build --offline --store /tmp/nix --expr 'builtins.derivation { name = \"foo\"; system = \"x86_64-linux\"; builder = \"/foo\"; }' 2>&1")
47
+ assert "is world-writable" in err
44
48
'' ;
45
49
}
You can’t perform that action at this time.
0 commit comments