-
-
Notifications
You must be signed in to change notification settings - Fork 14k
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
hardening flags: add FORTIFY_SOURCE=3
support
#212498
Changes from all commits
3d453e2
00aadf0
74ea4fe
c09e1fa
6360298
4e49c5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,17 @@ done | |
# Remove unsupported flags. | ||
for flag in @hardening_unsupported_flags@; do | ||
unset -v "hardeningEnableMap[$flag]" | ||
# fortify being unsupported implies fortify3 is unsupported | ||
if [[ "$flag" = 'fortify' ]] ; then | ||
unset -v "hardeningEnableMap['fortify3']" | ||
fi | ||
done | ||
|
||
# make fortify and fortify3 mutually exclusive | ||
if [[ -z "${hardeningEnableMap[fortify3]-}" ]]; then | ||
unset -v "hardeningEnableMap['fortify']" | ||
fi | ||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I read it correctly it unsets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Snap. See #217394 |
||
|
||
if (( "${NIX_DEBUG:-0}" >= 1 )); then | ||
declare -a allHardeningFlags=(fortify stackprotector pie pic strictoverflow format) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes probably I think the first time I scanned this I assumed it was another default setting, not just debugging output. |
||
declare -A hardeningDisableMap=() | ||
|
@@ -36,11 +45,23 @@ fi | |
|
||
for flag in "${!hardeningEnableMap[@]}"; do | ||
case $flag in | ||
fortify) | ||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling fortify >&2; fi | ||
fortify | fortify3) | ||
# Use -U_FORTIFY_SOURCE to avoid warnings on toolchains that explicitly | ||
# set -D_FORTIFY_SOURCE=0 (like 'clang -fsanitize=address'). | ||
hardeningCFlags+=('-O2' '-U_FORTIFY_SOURCE' '-D_FORTIFY_SOURCE=2') | ||
hardeningCFlags+=('-O2' '-U_FORTIFY_SOURCE') | ||
case $flag in | ||
fortify) | ||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling fortify >&2; fi | ||
hardeningCFlags+=('-D_FORTIFY_SOURCE=2') | ||
;; | ||
fortify3) | ||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling fortify3 >&2; fi | ||
hardeningCFlags+=('-D_FORTIFY_SOURCE=3') | ||
;; | ||
*) | ||
# Ignore unsupported. | ||
;; | ||
esac | ||
;; | ||
stackprotector) | ||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling stackprotector >&2; fi | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've got the sense of this flipped. This should be
-n
shouldn't it?