2016-02-26 18:38:15 +01:00
|
|
|
hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow)
|
|
|
|
hardeningFlags+=("${hardeningEnable[@]}")
|
|
|
|
hardeningCFlags=()
|
|
|
|
hardeningLDFlags=()
|
|
|
|
|
|
|
|
if [[ ! $hardeningDisable == "all" ]]; then
|
|
|
|
for flag in "${hardeningFlags[@]}"
|
|
|
|
do
|
|
|
|
if [[ ! "$hardeningDisable" =~ "$flag" ]]; then
|
|
|
|
case $flag in
|
|
|
|
fortify)
|
|
|
|
hardeningCFlags+=('-O2' '-D_FORTIFY_SOURCE=2')
|
|
|
|
;;
|
|
|
|
stackprotector)
|
2016-03-07 01:29:11 +01:00
|
|
|
hardeningCFlags+=('-fstack-protector-strong' '--param ssp-buffer-size=4')
|
2016-02-26 18:38:15 +01:00
|
|
|
;;
|
|
|
|
pie)
|
2016-03-06 00:14:55 +01:00
|
|
|
hardeningCFlags+=('-fPIE')
|
2016-03-06 18:03:57 +01:00
|
|
|
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then
|
2016-03-06 15:27:41 +01:00
|
|
|
hardeningLDFlags+=('-pie')
|
|
|
|
fi
|
2016-02-26 18:38:15 +01:00
|
|
|
;;
|
|
|
|
pic)
|
|
|
|
hardeningCFlags+=('-fPIC')
|
|
|
|
;;
|
|
|
|
strictoverflow)
|
|
|
|
hardeningCFlags+=('-fno-strict-overflow')
|
|
|
|
;;
|
|
|
|
format)
|
|
|
|
hardeningCFlags+=('-Wformat' '-Wformat-security' '-Werror=format-security')
|
|
|
|
;;
|
|
|
|
relro)
|
|
|
|
hardeningLDFlags+=('-z relro')
|
|
|
|
;;
|
|
|
|
bindnow)
|
|
|
|
hardeningLDFlags+=('-z now')
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Hardening flag unknown: $flag"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|