blob: ab2062b78f5eb6cd479c7417ced30b4019df3522 [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"
9
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010# _FORTIFY_SOURCE requires -O1 or higher, so disable in debug builds as they use
11# -O0 which then results in a compiler warning.
12lcl_maybe_fortify = "${@base_conditional('DEBUG_BUILD','1','','-D_FORTIFY_SOURCE=2',d)}"
13
Patrick Williamsc0f7c042017-02-23 20:41:17 -060014# Error on use of format strings that represent possible security problems
15SECURITY_STRINGFORMAT ?= "-Wformat -Wformat-security -Werror=format-security"
16
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017# Inject pie flags into compiler flags if not configured with gcc itself
18# especially useful with external toolchains
19SECURITY_PIE_CFLAGS ?= "${@'' if '${GCCPIE}' else '-pie -fPIE'}"
20
21SECURITY_NOPIE_CFLAGS ?= "-no-pie -fno-PIE"
22
23SECURITY_CFLAGS ?= "-fstack-protector-strong ${SECURITY_PIE_CFLAGS} ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060024SECURITY_NO_PIE_CFLAGS ?= "-fstack-protector-strong ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050026SECURITY_LDFLAGS ?= "-fstack-protector-strong -Wl,-z,relro,-z,now"
27SECURITY_X_LDFLAGS ?= "-fstack-protector-strong -Wl,-z,relro"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028
29# powerpc does not get on with pie for reasons not looked into as yet
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030SECURITY_CFLAGS_powerpc = "-fstack-protector-strong ${lcl_maybe_fortify} ${SECURITY_NOPIE_CFLAGS}"
31SECURITY_CFLAGS_pn-libgcc_powerpc = ""
32GCCPIE_powerpc = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033
34# arm specific security flag issues
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035SECURITY_CFLAGS_pn-glibc = ""
36SECURITY_CFLAGS_pn-glibc-initial = ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050037SECURITY_CFLAGS_pn-gcc-runtime = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038SECURITY_CFLAGS_pn-grub = ""
39SECURITY_CFLAGS_pn-grub-efi = ""
40SECURITY_CFLAGS_pn-grub-efi-native = ""
41SECURITY_CFLAGS_pn-grub-efi-x86-native = ""
42SECURITY_CFLAGS_pn-grub-efi-i586-native = ""
43SECURITY_CFLAGS_pn-grub-efi-x86-64-native = ""
Brad Bishopd7bf8c12018-02-25 22:55:05 -050044
45SECURITY_CFLAGS_pn-mkelfimage_x86 = ""
46
47SECURITY_CFLAGS_pn-valgrind = "${SECURITY_NOPIE_CFLAGS}"
48SECURITY_LDFLAGS_pn-valgrind = ""
49SECURITY_CFLAGS_pn-sysklogd = "${SECURITY_NOPIE_CFLAGS}"
50SECURITY_LDFLAGS_pn-sysklogd = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052# Recipes which fail to compile when elevating -Wformat-security to an error
53SECURITY_STRINGFORMAT_pn-busybox = ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054SECURITY_STRINGFORMAT_pn-gcc = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055
Brad Bishopd7bf8c12018-02-25 22:55:05 -050056TARGET_CC_ARCH_append_class-target = " ${SECURITY_CFLAGS}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050059SECURITY_LDFLAGS_remove_pn-gcc-runtime = "-fstack-protector-strong"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050060SECURITY_LDFLAGS_remove_pn-glibc = "-fstack-protector-strong"
61SECURITY_LDFLAGS_remove_pn-glibc-initial = "-fstack-protector-strong"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062SECURITY_LDFLAGS_pn-xf86-video-fbdev = "${SECURITY_X_LDFLAGS}"
63SECURITY_LDFLAGS_pn-xf86-video-intel = "${SECURITY_X_LDFLAGS}"
64SECURITY_LDFLAGS_pn-xf86-video-omapfb = "${SECURITY_X_LDFLAGS}"
65SECURITY_LDFLAGS_pn-xf86-video-omap = "${SECURITY_X_LDFLAGS}"
66SECURITY_LDFLAGS_pn-xf86-video-vesa = "${SECURITY_X_LDFLAGS}"
67SECURITY_LDFLAGS_pn-xf86-video-vmware = "${SECURITY_X_LDFLAGS}"
68SECURITY_LDFLAGS_pn-xserver-xorg = "${SECURITY_X_LDFLAGS}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050069
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070TARGET_CC_ARCH_append_pn-binutils = " ${SELECTED_OPTIMIZATION}"
71TARGET_CC_ARCH_append_pn-gcc = " ${SELECTED_OPTIMIZATION}"
72TARGET_CC_ARCH_append_pn-gdb = " ${SELECTED_OPTIMIZATION}"
73TARGET_CC_ARCH_append_pn-perf = " ${SELECTED_OPTIMIZATION}"