blob: aaeca6991be82f38736749c39cf5ebd7024c8ec6 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001# Setup extra CFLAGS and LDFLAGS which have 'security' benefits. These
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002# don't work universally, there are recipes which can't use one, the other
3# or both so a blacklist is maintained here. The idea would be over
4# time to reduce this list to nothing.
5# From a Yocto Project perspective, this file is included and tested
6# in the DISTRO="poky-lsb" configuration.
7
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008GCCPIE ?= "--enable-default-pie"
Brad Bishop6ef32652018-10-09 18:59:25 +01009# If static PIE is known to work well, GLIBCPIE="--enable-static-pie" can be set
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011# _FORTIFY_SOURCE requires -O1 or higher, so disable in debug builds as they use
12# -O0 which then results in a compiler warning.
Brad Bishop316dfdd2018-06-25 12:45:53 -040013lcl_maybe_fortify = "${@oe.utils.conditional('DEBUG_BUILD','1','','-D_FORTIFY_SOURCE=2',d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015# Error on use of format strings that represent possible security problems
16SECURITY_STRINGFORMAT ?= "-Wformat -Wformat-security -Werror=format-security"
17
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018# Inject pie flags into compiler flags if not configured with gcc itself
19# especially useful with external toolchains
20SECURITY_PIE_CFLAGS ?= "${@'' if '${GCCPIE}' else '-pie -fPIE'}"
21
22SECURITY_NOPIE_CFLAGS ?= "-no-pie -fno-PIE"
23
24SECURITY_CFLAGS ?= "-fstack-protector-strong ${SECURITY_PIE_CFLAGS} ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060025SECURITY_NO_PIE_CFLAGS ?= "-fstack-protector-strong ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027SECURITY_LDFLAGS ?= "-fstack-protector-strong -Wl,-z,relro,-z,now"
28SECURITY_X_LDFLAGS ?= "-fstack-protector-strong -Wl,-z,relro"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029
30# powerpc does not get on with pie for reasons not looked into as yet
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031SECURITY_CFLAGS_powerpc = "-fstack-protector-strong ${lcl_maybe_fortify} ${SECURITY_NOPIE_CFLAGS}"
32SECURITY_CFLAGS_pn-libgcc_powerpc = ""
33GCCPIE_powerpc = ""
Brad Bishop316dfdd2018-06-25 12:45:53 -040034GLIBCPIE_powerpc = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035
36# arm specific security flag issues
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037SECURITY_CFLAGS_pn-glibc = ""
38SECURITY_CFLAGS_pn-glibc-initial = ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039SECURITY_CFLAGS_pn-gcc-runtime = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040SECURITY_CFLAGS_pn-grub = ""
41SECURITY_CFLAGS_pn-grub-efi = ""
42SECURITY_CFLAGS_pn-grub-efi-native = ""
43SECURITY_CFLAGS_pn-grub-efi-x86-native = ""
44SECURITY_CFLAGS_pn-grub-efi-i586-native = ""
45SECURITY_CFLAGS_pn-grub-efi-x86-64-native = ""
Brad Bishopd7bf8c12018-02-25 22:55:05 -050046
47SECURITY_CFLAGS_pn-mkelfimage_x86 = ""
48
49SECURITY_CFLAGS_pn-valgrind = "${SECURITY_NOPIE_CFLAGS}"
50SECURITY_LDFLAGS_pn-valgrind = ""
51SECURITY_CFLAGS_pn-sysklogd = "${SECURITY_NOPIE_CFLAGS}"
52SECURITY_LDFLAGS_pn-sysklogd = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054# Recipes which fail to compile when elevating -Wformat-security to an error
55SECURITY_STRINGFORMAT_pn-busybox = ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060056SECURITY_STRINGFORMAT_pn-gcc = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057
Brad Bishopd7bf8c12018-02-25 22:55:05 -050058TARGET_CC_ARCH_append_class-target = " ${SECURITY_CFLAGS}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050059TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050061SECURITY_LDFLAGS_remove_pn-gcc-runtime = "-fstack-protector-strong"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050062SECURITY_LDFLAGS_remove_pn-glibc = "-fstack-protector-strong"
63SECURITY_LDFLAGS_remove_pn-glibc-initial = "-fstack-protector-strong"
Brad Bishop316dfdd2018-06-25 12:45:53 -040064# All xorg module drivers need to be linked this way as well and are
65# handled in recipes-graphics/xorg-driver/xorg-driver-common.inc
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066SECURITY_LDFLAGS_pn-xserver-xorg = "${SECURITY_X_LDFLAGS}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067
Brad Bishopd7bf8c12018-02-25 22:55:05 -050068TARGET_CC_ARCH_append_pn-binutils = " ${SELECTED_OPTIMIZATION}"
69TARGET_CC_ARCH_append_pn-gcc = " ${SELECTED_OPTIMIZATION}"
70TARGET_CC_ARCH_append_pn-gdb = " ${SELECTED_OPTIMIZATION}"
71TARGET_CC_ARCH_append_pn-perf = " ${SELECTED_OPTIMIZATION}"