diff options
| author | Reepca Russelstein <reepca@russelstein.xyz> | 2024-10-20 15:39:02 -0500 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2024-10-21 00:09:24 +0200 |
| commit | 5ab3c4c1e43ebb637551223791db0ea3519986e1 (patch) | |
| tree | eed91396837697f77deff12e8c50a54ed01c4cb2 /nix | |
| parent | 558224140dab669cabdaebabff18504a066c48d4 (diff) | |
daemon: Sanitize successful build outputs prior to exposing them.
There is currently a window of time between when the build outputs are exposed
and when their metadata is canonicalized.
* nix/libstore/build.cc (DerivationGoal::registerOutputs): wait until after
metadata canonicalization to move successful build outputs to the store.
Change-Id: Ia995136f3f965eaf7b0e1d92af964b816f3fb276
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/libstore/build.cc | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index 67ebfe2f146..43a8a371846 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc | |||
| @@ -2369,15 +2369,6 @@ void DerivationGoal::registerOutputs() | |||
| 2369 | Path actualPath = path; | 2369 | Path actualPath = path; |
| 2370 | if (useChroot) { | 2370 | if (useChroot) { |
| 2371 | actualPath = chrootRootDir + path; | 2371 | actualPath = chrootRootDir + path; |
| 2372 | if (pathExists(actualPath)) { | ||
| 2373 | /* Move output paths from the chroot to the store. */ | ||
| 2374 | if (buildMode == bmRepair) | ||
| 2375 | replaceValidPath(path, actualPath); | ||
| 2376 | else | ||
| 2377 | if (buildMode != bmCheck && rename(actualPath.c_str(), path.c_str()) == -1) | ||
| 2378 | throw SysError(format("moving build output `%1%' from the chroot to the store") % path); | ||
| 2379 | } | ||
| 2380 | if (buildMode != bmCheck) actualPath = path; | ||
| 2381 | } else { | 2372 | } else { |
| 2382 | Path redirected = redirectedOutputs[path]; | 2373 | Path redirected = redirectedOutputs[path]; |
| 2383 | if (buildMode == bmRepair | 2374 | if (buildMode == bmRepair |
| @@ -2463,6 +2454,20 @@ void DerivationGoal::registerOutputs() | |||
| 2463 | canonicalisePathMetaData(actualPath, | 2454 | canonicalisePathMetaData(actualPath, |
| 2464 | buildUser.enabled() && !rewritten ? buildUser.getUID() : -1, inodesSeen); | 2455 | buildUser.enabled() && !rewritten ? buildUser.getUID() : -1, inodesSeen); |
| 2465 | 2456 | ||
| 2457 | if (useChroot) { | ||
| 2458 | if (pathExists(actualPath)) { | ||
| 2459 | /* Now that output paths have been canonicalized (in particular | ||
| 2460 | there are no setuid files left), move them outside of the | ||
| 2461 | chroot and to the store. */ | ||
| 2462 | if (buildMode == bmRepair) | ||
| 2463 | replaceValidPath(path, actualPath); | ||
| 2464 | else | ||
| 2465 | if (buildMode != bmCheck && rename(actualPath.c_str(), path.c_str()) == -1) | ||
| 2466 | throw SysError(format("moving build output `%1%' from the chroot to the store") % path); | ||
| 2467 | } | ||
| 2468 | if (buildMode != bmCheck) actualPath = path; | ||
| 2469 | } | ||
| 2470 | |||
| 2466 | /* For this output path, find the references to other paths | 2471 | /* For this output path, find the references to other paths |
| 2467 | contained in it. Compute the SHA-256 NAR hash at the same | 2472 | contained in it. Compute the SHA-256 NAR hash at the same |
| 2468 | time. The hash is stored in the database so that we can | 2473 | time. The hash is stored in the database so that we can |
