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

[staging] {cc,binutils}-wrapper: fixes for PIE hardening #135619

Merged
merged 5 commits into from
Sep 24, 2021
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
6 changes: 5 additions & 1 deletion pkgs/build-support/bintools-wrapper/add-hardening.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ fi
for flag in "${!hardeningEnableMap[@]}"; do
case $flag in
pie)
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static " || "$*" =~ " -r " || "$*" =~ " -Ur " || "$*" =~ " -i ") ]]; then
if [[ ! (" $* " =~ " -shared " \
|| " $* " =~ " -static " \
|| " $* " =~ " -r " \
|| " $* " =~ " -Ur " \
|| " $* " =~ " -i ") ]]; then
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling LDFlags -pie >&2; fi
hardeningLDFlags+=('-pie')
fi
Expand Down
7 changes: 4 additions & 3 deletions pkgs/build-support/cc-wrapper/add-hardening.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ for flag in "${!hardeningEnableMap[@]}"; do
hardeningCFlags+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4')
;;
pie)
# NB: we do not use `+=` here, because PIE flags must occur before any PIC flags
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling CFlags -fPIE >&2; fi
hardeningCFlags+=('-fPIE')
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then
hardeningCFlags=('-fPIE' "${hardeningCFlags[@]}")
if [[ ! (" $* " =~ " -shared " || " $* " =~ " -static ") ]]; then
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling LDFlags -pie >&2; fi
hardeningCFlags+=('-pie')
hardeningCFlags=('-pie' "${hardeningCFlags[@]}")
fi
;;
pic)
Expand Down
4 changes: 1 addition & 3 deletions pkgs/development/interpreters/python/cpython/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
# enableLTO is a subset of the enableOptimizations flag that doesn't harm reproducibility.
# enabling LTO on 32bit arch causes downstream packages to fail when linking
# enabling LTO on *-darwin causes python3 to fail when linking.
# enabling LTO with musl and dynamic linking fails with a linker error although it should
# be possible as alpine is doing it: https://github.com/alpinelinux/aports/blob/a8ccb04668c7729e0f0db6c6ff5f25d7519e779b/main/python3/APKBUILD#L82
, enableLTO ? stdenv.is64bit && stdenv.isLinux && !(stdenv.hostPlatform.isMusl && !stdenv.hostPlatform.isStatic)
, enableLTO ? stdenv.is64bit && stdenv.isLinux
, reproducibleBuild ? false
, pythonAttr ? "python${sourceVersion.major}${sourceVersion.minor}"
}:
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/libraries/glib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ stdenv.mkDerivation rec {
"-DG_DISABLE_CAST_CHECKS"
];

hardeningDisable = [ "pie" ];

postPatch = ''
chmod +x gio/tests/gengiotypefuncs.py
patchShebangs gio/tests/gengiotypefuncs.py
Expand Down
4 changes: 0 additions & 4 deletions pkgs/development/libraries/libiscsi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ stdenv.mkDerivation rec {

nativeBuildInputs = [ autoreconfHook ];

# This can be removed after >=1.20.0, or if the build suceeds with
# pie enabled (default on Musl).
hardeningDisable = [ "pie" ];

# This problem is gone on libiscsi master.
NIX_CFLAGS_COMPILE =
lib.optional stdenv.hostPlatform.is32bit "-Wno-error=sign-compare";
Expand Down