diff options
Diffstat (limited to 'nix/libstore')
| -rw-r--r-- | nix/libstore/build.cc | 25 | ||||
| -rw-r--r-- | nix/libstore/globals.cc | 1 | ||||
| -rw-r--r-- | nix/libstore/globals.hh | 4 |
3 files changed, 28 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 | ||
diff --git a/nix/libstore/globals.cc b/nix/libstore/globals.cc index eb7e7dac413..aa808186bd0 100644 --- a/nix/libstore/globals.cc +++ b/nix/libstore/globals.cc | |||
| @@ -53,6 +53,7 @@ Settings::Settings() | |||
| 53 | showTrace = false; | 53 | showTrace = false; |
| 54 | useHostLoopback = true; | 54 | useHostLoopback = true; |
| 55 | slirp4netns = SLIRP4NETNS; | 55 | slirp4netns = SLIRP4NETNS; |
| 56 | allowASLR = false; | ||
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | 59 | ||
diff --git a/nix/libstore/globals.hh b/nix/libstore/globals.hh index 8ce8aa665a8..f6b856091fc 100644 --- a/nix/libstore/globals.hh +++ b/nix/libstore/globals.hh | |||
| @@ -213,6 +213,10 @@ struct Settings { | |||
| 213 | /* The filename to use for executing slirp4netns when it is needed. */ | 213 | /* The filename to use for executing slirp4netns when it is needed. */ |
| 214 | Path slirp4netns; | 214 | Path slirp4netns; |
| 215 | 215 | ||
| 216 | /* Whether to proceed without the ADDR_NO_RANDOMIZE personality flag if | ||
| 217 | * its use is blocked. */ | ||
| 218 | bool allowASLR; | ||
| 219 | |||
| 216 | private: | 220 | private: |
| 217 | SettingsMap settings; | 221 | SettingsMap settings; |
| 218 | 222 | ||
