summaryrefslogtreecommitdiff
path: root/nix/libstore/build.cc
diff options
context:
space:
mode:
Diffstat (limited to 'nix/libstore/build.cc')
-rw-r--r--nix/libstore/build.cc25
1 files changed, 23 insertions, 2 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 7dd630cc5d8..e72a0165987 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2526,8 +2526,29 @@ void DerivationGoal::startBuilder()
2526 ctx.persona |= 0x0020000; /* == UNAME26 */ 2526 ctx.persona |= 0x0020000; /* == UNAME26 */
2527 } 2527 }
2528 2528
2529 /* Disable address space randomization for improved determinism. */ 2529 /* Check whether we can set ADDR_NO_RANDOMIZE, some container seccomp
2530 ctx.persona |= ADDR_NO_RANDOMIZE; 2530 policies block it. */
2531 int currentPersonality = personality(0xffffffff);
2532 if (currentPersonality == -1)
2533 throw SysError("unable to get current personality");
2534
2535 if (personality(currentPersonality | ADDR_NO_RANDOMIZE) == -1) {
2536 if (errno == EINVAL)
2537 throw SysError("unexpectedly unable to add ADDR_NO_RANDOMIZE to personality");
2538
2539 /* Some other, unexpected errno; seccomp is probably behind it. */
2540 if (!settings.allowASLR)
2541 throw SysError("ADDR_NO_RANDOMIZE appears blocked and `--allow-aslr' was not passed, refusing to weaken reproducibility by default");
2542
2543 printMsg(lvlInfo, "the ADDR_NO_RANDOMIZE personality flag appears to be blocked, not using it");
2544 }
2545 else {
2546 /* It worked, now first restore the original personality. */
2547 if (personality(currentPersonality) == -1)
2548 throw SysError("unable to restore personality after testing for availability of ADDR_NO_RANDOMIZE");
2549 /* Disable address space randomization for improved determinism. */
2550 ctx.persona |= ADDR_NO_RANDOMIZE;
2551 }
2531 2552
2532#endif 2553#endif
2533 2554