Skip to content
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
3 changes: 3 additions & 0 deletions doc/redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@
"strictflexarrays3": [
"index.html#strictflexarrays3"
],
"glibcxxassertions": [
"index.html#glibcxxassertions"
],
"tester-shfmt": [
"index.html#tester-shfmt"
],
Expand Down
6 changes: 6 additions & 0 deletions doc/stdenv/stdenv.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,12 @@ This should be turned off or fixed for build errors such as:
sorry, unimplemented: __builtin_clear_padding not supported for variable length aggregates
```

#### `glibcxxassertions` {#glibcxxassertions}

Adds the `-D_GLIBCXX_ASSERTIONS` compiler flag. This flag only has an effect on libstdc++ targets, and when defined, enables extra error checking in the form of precondition assertions, such as bounds checking in c++ strings and null pointer checks when dereferencing c++ smart pointers.

These checks may have an impact on performance in some cases.

#### `pacret` {#pacret}

This flag adds the `-mbranch-protection=pac-ret` compiler option on aarch64-linux targets. This uses ARM v8.3's Pointer Authentication feature to sign function return pointers before adding them to the stack. The pointer's authenticity is then validated before returning to its destination. This dramatically increases the difficulty of ROP exploitation techniques.
Expand Down
6 changes: 5 additions & 1 deletion pkgs/build-support/cc-wrapper/add-hardening.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fi


if (( "${NIX_DEBUG:-0}" >= 1 )); then
declare -a allHardeningFlags=(fortify fortify3 shadowstack stackprotector stackclashprotection nostrictaliasing pacret strictflexarrays1 strictflexarrays3 pie pic strictoverflow format trivialautovarinit zerocallusedregs)
declare -a allHardeningFlags=(fortify fortify3 shadowstack stackprotector stackclashprotection nostrictaliasing pacret strictflexarrays1 strictflexarrays3 pie pic strictoverflow glibcxxassertions format trivialautovarinit zerocallusedregs)
declare -A hardeningDisableMap=()

# Determine which flags were effectively disabled so we can report below.
Expand Down Expand Up @@ -111,6 +111,10 @@ for flag in "${!hardeningEnableMap[@]}"; do
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling pacret >&2; fi
hardeningCFlagsBefore+=('-mbranch-protection=pac-ret')
;;
glibcxxassertions)
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling glibcxxassertions >&2; fi
hardeningCFlagsBefore+=('-D_GLIBCXX_ASSERTIONS')
;;
stackprotector)
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling stackprotector >&2; fi
hardeningCFlagsBefore+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4')
Expand Down
3 changes: 3 additions & 0 deletions pkgs/by-name/ar/arrow-cpp/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ stdenv.mkDerivation (finalAttrs: {
ZSTD_ROOT = zstd.dev;
};

# fails tests on glibc with this enabled
hardeningDisable = [ "glibcxxassertions" ];

preConfigure = ''
patchShebangs build-support/
substituteInPlace "src/arrow/vendored/datetime/tz.cpp" \
Expand Down
1 change: 1 addition & 0 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ let
"pie"
"relro"
"stackprotector"
"glibcxxassertions"
"stackclashprotection"
"strictoverflow"
"trivialautovarinit"
Expand Down
30 changes: 30 additions & 0 deletions pkgs/test/cc-wrapper/hardening.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
runCommand,
runCommandWith,
runCommandCC,
writeText,
bintools,
hello,
debian-devscripts,
Expand Down Expand Up @@ -40,6 +41,17 @@ let

flexArrF2ExampleWithStdEnv = writeCBinWithStdenv ./flex-arrays-fortify-example.c;

checkGlibcxxassertionsWithStdEnv =
expectDefined:
writeCBinWithStdenv (
writeText "main.cpp" ''
#if${if expectDefined then "n" else ""}def _GLIBCXX_ASSERTIONS
#error "Expected _GLIBCXX_ASSERTIONS to be ${if expectDefined then "" else "un"}defined"
#endif
int main() {}
''
);

# for when we need a slightly more complicated program
helloWithStdEnv =
stdenv': env:
Expand Down Expand Up @@ -502,6 +514,10 @@ nameDrvAfterAttrName (
hardeningEnable = [ "shadowstack" ];
}) false;

glibcxxassertionsExplicitEnabled = checkGlibcxxassertionsWithStdEnv true stdenv {
hardeningEnable = [ "glibcxxassertions" ];
};

bindNowExplicitDisabled =
checkTestBin
(f2exampleWithStdEnv stdenv {
Expand Down Expand Up @@ -697,6 +713,10 @@ nameDrvAfterAttrName (
hardeningDisable = [ "shadowstack" ];
}) true;

glibcxxassertionsExplicitDisabled = checkGlibcxxassertionsWithStdEnv false stdenv {
hardeningDisable = [ "glibcxxassertions" ];
};

# most flags can't be "unsupported" by compiler alone and
# binutils doesn't have an accessible hardeningUnsupportedFlags
# mechanism, so can only test a couple of flags through altered
Expand Down Expand Up @@ -897,6 +917,12 @@ nameDrvAfterAttrName (
expectFailure = true;
};

glibcxxassertionsStdenvUnsupp =
checkGlibcxxassertionsWithStdEnv false (stdenvUnsupport [ "glibcxxassertions" ])
{
hardeningEnable = [ "glibcxxassertions" ];
};

fortify3EnabledEnvEnablesFortify1 =
checkTestBin
(f1exampleWithStdEnv stdenv {
Expand Down Expand Up @@ -1107,6 +1133,10 @@ nameDrvAfterAttrName (
allExplicitDisabledShadowStack = shadowStackTest (f1exampleWithStdEnv stdenv {
hardeningDisable = [ "all" ];
}) true;

glibcxxassertionsExplicitDisabled = checkGlibcxxassertionsWithStdEnv false stdenv {
hardeningDisable = [ "all" ];
};
}
)
)
1 change: 1 addition & 0 deletions pkgs/top-level/variants.nix
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ self: super: {
"shadowstack"
"nostrictaliasing"
"pacret"
"glibcxxassertions"
"trivialautovarinit"
]
) super'.stdenv;
Expand Down
Loading