Skip to content

Commit

Permalink
mkDerivation: fix hardening flags check
Browse files Browse the repository at this point in the history
- allow "all" in hardeningDisable
- fix busybox flags
- print detailed error message

Discussed at #28555 (comment)
  • Loading branch information
orivej committed Sep 1, 2017
1 parent 46d6fec commit d70006c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/busybox/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ stdenv.mkDerivation rec {
sha256 = "1pv3vs2w4l2wnw5qb0rkbpvjjdd1fwjv87miavqq0r0ynqbfajwx";
};

hardeningDisable = [ "format" ] ++ lib.optional enableStatic [ "fortify" ];
hardeningDisable = [ "format" ] ++ lib.optionals enableStatic [ "fortify" ];

patches = [ ./busybox-in-store.patch ];

Expand Down
15 changes: 7 additions & 8 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ rec {
, ... } @ attrs:

# TODO(@Ericson2314): Make this more modular, and not O(n^2).
let allHardeningFlags = [
"fortify" "stackprotector" "pie" "pic" "strictoverflow" "format" "relro"
"bindnow"
];
in assert lib.all
(flag: lib.elem flag allHardeningFlags)
(hardeningEnable ++ hardeningDisable);

let
supportedHardeningFlags = [ "fortify" "stackprotector" "pie" "pic" "strictoverflow" "format" "relro" "bindnow" ];
erroneousHardeningFlags = lib.subtractLists supportedHardeningFlags (hardeningEnable ++ lib.remove "all" hardeningDisable);
in if builtins.length erroneousHardeningFlags != 0
then abort ("mkDerivation was called with unsupported hardening flags: " + lib.generators.toPretty {} {
inherit erroneousHardeningFlags hardeningDisable hardeningEnable supportedHardeningFlags;
})
else let
dependencies = map lib.chooseDevOutputs [
(map (drv: drv.nativeDrv or drv) nativeBuildInputs
++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh
Expand Down

0 comments on commit d70006c

Please sign in to comment.