Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc-wrapper: Remove redundant hardening #28555

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkgs/build-support/cc-wrapper/add-hardening.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if [[ -z "${hardeningDisableMap[all]:-}" ]]; then
hardeningCFlags+=('-fPIE')
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling LDFlags -pie >&2; fi
hardeningCFlags+=('-pie')
hardeningLDFlags+=('-pie')
fi
;;
Expand All @@ -67,7 +68,8 @@ if [[ -z "${hardeningDisableMap[all]:-}" ]]; then
hardeningLDFlags+=('-z' 'now')
;;
*)
echo "Hardening flag unknown: $flag" >&2
# Ignore unsupported. Checked in Nix that at least *some*
# tool supports each flag.
;;
esac
fi
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/cc-wrapper/cc-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ if [ "$dontLink" != 1 ]; then

# Add the flags that should only be passed to the compiler when
# linking.
extraAfter+=($NIX_@infixSalt@_CFLAGS_LINK "${hardeningLDFlags[@]}")
extraAfter+=($NIX_@infixSalt@_CFLAGS_LINK)

# Add the flags that should be passed to the linker (and prevent
# `ld-wrapper' from adding NIX_@infixSalt@_LDFLAGS again).
Expand Down
3 changes: 2 additions & 1 deletion pkgs/os-specific/linux/devmem2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ stdenv.mkDerivation rec {
sha256 = "14f1k7v6i1yaxg4xcaaf5i4aqn0yabba857zjnbg9wiymy82qf7c";
};

hardeningDisable = [ "format" ]; # fix compile error

buildCommand = ''
export hardeningDisable=format # fix compile error
cc "$src" -o devmem2
install -D devmem2 "$out/bin/devmem2"
'';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/firmware/fwupdate/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let version = "8"; in
buildInputs = [ gnu-efi libsmbios popt pkgconfig gettext ];
propagatedBuildInputs = [ efivar ];
# TODO: Just apply the disable to the efi subdir
hardeningDisable = "all";
hardeningDisable = [ "all" ];
patchPhase = ''
sed -i 's|/usr/include/smbios_c/token.h|smbios_c/token.h|' \
linux/libfwup.c
Expand Down
13 changes: 13 additions & 0 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ rec {
, __propagatedImpureHostDeps ? []
, sandboxProfile ? ""
, propagatedSandboxProfile ? ""

, hardeningEnable ? []
, hardeningDisable ? []
, ... } @ 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
dependencies = map lib.chooseDevOutputs [
(map (drv: drv.nativeDrv or drv) nativeBuildInputs
Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/networking/envoy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ stdenv.mkDerivation rec {

patches = [ ./nixos.patch ];

hardeningDisable = "all";
hardeningDisable = [ "all" ];
dontPatchELF = true;
dontStrip = true;

Expand Down