mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
libstore: ensure that passAsFile
is created in the original temp dir
This ensures that `passAsFile` data is created inside the expected temporary build directory by `openat()` from the parent directory file descriptor. This avoids a TOCTOU which is part of the attack chain of CVE-????. Change-Id: Ie5273446c4a19403088d0389ae8e3f473af8879a Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
parent
034f59bbb9
commit
4e59d3fdb2
1 changed files with 5 additions and 2 deletions
|
@ -1070,8 +1070,11 @@ void DerivationBuilderImpl::initEnv()
|
|||
auto hash = hashString(HashAlgorithm::SHA256, i.first);
|
||||
std::string fn = ".attr-" + hash.to_string(HashFormat::Nix32, false);
|
||||
Path p = tmpDir + "/" + fn;
|
||||
writeFile(p, rewriteStrings(i.second, inputRewrites));
|
||||
chownToBuilder(p);
|
||||
AutoCloseFD passAsFileFd{openat(tmpDirFd.get(), fn.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC | O_EXCL | O_NOFOLLOW, 0666)};
|
||||
if (!passAsFileFd)
|
||||
throw SysError("opening `passAsFile` file in the sandbox '%1%'", p);
|
||||
writeFile(passAsFileFd, rewriteStrings(i.second, inputRewrites));
|
||||
chownToBuilder(passAsFileFd);
|
||||
env[i.first + "Path"] = tmpDirInSandbox() + "/" + fn;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue