cc-wrapper: add trivialautovarinit hardening flag support

this equates to -ftrivial-auto-var-init=pattern

clang has removed support for -ftrivial-auto-var-init=zero and
are unlikely to re-add it, so use -ftrivial-auto-var-init=pattern
on both compilers if only to make behaviour more consistent
between the two.

add to pkgsExtraHardening's defaultHardeningFlags.

+12 -4
+2
nixos/doc/manual/release-notes/rl-2405.section.md
··· 310 311 - A new hardening flag, `zerocallusedregs` was made available, corresponding to the gcc/clang option `-fzero-call-used-regs=used-gpr`. 312 313 - New options were added to the dnsdist module to enable and configure a DNSCrypt endpoint (see `services.dnsdist.dnscrypt.enable`, etc.). 314 The module can generate the DNSCrypt provider key pair, certificates and also performs their rotation automatically with no downtime. 315
··· 310 311 - A new hardening flag, `zerocallusedregs` was made available, corresponding to the gcc/clang option `-fzero-call-used-regs=used-gpr`. 312 313 + - A new hardening flag, `trivialautovarinit` was made available, corresponding to the gcc/clang option `-ftrivial-auto-var-init=pattern`. 314 + 315 - New options were added to the dnsdist module to enable and configure a DNSCrypt endpoint (see `services.dnsdist.dnscrypt.enable`, etc.). 316 The module can generate the DNSCrypt provider key pair, certificates and also performs their rotation automatically with no downtime. 317
+5 -1
pkgs/build-support/cc-wrapper/add-hardening.sh
··· 32 fi 33 34 if (( "${NIX_DEBUG:-0}" >= 1 )); then 35 - declare -a allHardeningFlags=(fortify fortify3 stackprotector pie pic strictoverflow format zerocallusedregs) 36 declare -A hardeningDisableMap=() 37 38 # Determine which flags were effectively disabled so we can report below. ··· 105 else 106 hardeningCFlagsBefore+=('-fno-strict-overflow') 107 fi 108 ;; 109 format) 110 if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling format >&2; fi
··· 32 fi 33 34 if (( "${NIX_DEBUG:-0}" >= 1 )); then 35 + declare -a allHardeningFlags=(fortify fortify3 stackprotector pie pic strictoverflow format trivialautovarinit zerocallusedregs) 36 declare -A hardeningDisableMap=() 37 38 # Determine which flags were effectively disabled so we can report below. ··· 105 else 106 hardeningCFlagsBefore+=('-fno-strict-overflow') 107 fi 108 + ;; 109 + trivialautovarinit) 110 + if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling trivialautovarinit >&2; fi 111 + hardeningCFlagsBefore+=('-ftrivial-auto-var-init=pattern') 112 ;; 113 format) 114 if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling format >&2; fi
+1 -1
pkgs/development/compilers/gcc/default.nix
··· 408 isGNU = true; 409 hardeningUnsupportedFlags = lib.optional is48 "stackprotector" 410 ++ lib.optional (!atLeast11) "zerocallusedregs" 411 - ++ lib.optional (!atLeast12) "fortify3" 412 ++ lib.optionals (langFortran) [ "fortify" "format" ]; 413 }; 414
··· 408 isGNU = true; 409 hardeningUnsupportedFlags = lib.optional is48 "stackprotector" 410 ++ lib.optional (!atLeast11) "zerocallusedregs" 411 + ++ lib.optionals (!atLeast12) [ "fortify3" "trivialautovarinit" ] 412 ++ lib.optionals (langFortran) [ "fortify" "format" ]; 413 }; 414
+1
pkgs/stdenv/generic/make-derivation.nix
··· 249 "relro" 250 "stackprotector" 251 "strictoverflow" 252 "zerocallusedregs" 253 ]; 254 defaultHardeningFlags =
··· 249 "relro" 250 "stackprotector" 251 "strictoverflow" 252 + "trivialautovarinit" 253 "zerocallusedregs" 254 ]; 255 defaultHardeningFlags =
+1 -1
pkgs/stdenv/linux/bootstrap-tools-musl/default.nix
··· 15 langC = true; 16 langCC = true; 17 isGNU = true; 18 - hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ]; 19 } // extraAttrs)
··· 15 langC = true; 16 langCC = true; 17 isGNU = true; 18 + hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" "trivialautovarinit" ]; 19 } // extraAttrs)
+1 -1
pkgs/stdenv/linux/bootstrap-tools/default.nix
··· 15 langC = true; 16 langCC = true; 17 isGNU = true; 18 - hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ]; 19 } // extraAttrs)
··· 15 langC = true; 16 langCC = true; 17 isGNU = true; 18 + hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" "trivialautovarinit" ]; 19 } // extraAttrs)
+1
pkgs/top-level/stage.nix
··· 284 stdenv = super'.withDefaultHardeningFlags ( 285 super'.stdenv.cc.defaultHardeningFlags ++ [ 286 "zerocallusedregs" 287 ] 288 ) super'.stdenv; 289 })
··· 284 stdenv = super'.withDefaultHardeningFlags ( 285 super'.stdenv.cc.defaultHardeningFlags ++ [ 286 "zerocallusedregs" 287 + "trivialautovarinit" 288 ] 289 ) super'.stdenv; 290 })