1
0

hardening.mk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2015-2020 OpenWrt.org
  4. PKG_CHECK_FORMAT_SECURITY ?= 1
  5. PKG_ASLR_PIE ?= 1
  6. PKG_ASLR_PIE_REGULAR ?= 0
  7. PKG_SSP ?= 1
  8. PKG_FORTIFY_SOURCE ?= 1
  9. PKG_RELRO ?= 1
  10. ifdef CONFIG_PKG_CHECK_FORMAT_SECURITY
  11. ifeq ($(strip $(PKG_CHECK_FORMAT_SECURITY)),1)
  12. TARGET_CFLAGS += -Wformat -Werror=format-security
  13. endif
  14. endif
  15. ifdef CONFIG_PKG_ASLR_PIE_ALL
  16. ifeq ($(strip $(PKG_ASLR_PIE)),1)
  17. TARGET_CFLAGS += $(FPIC)
  18. TARGET_LDFLAGS += $(FPIC) -specs=$(INCLUDE_DIR)/hardened-ld-pie.specs
  19. endif
  20. endif
  21. ifdef CONFIG_PKG_ASLR_PIE_REGULAR
  22. ifeq ($(strip $(PKG_ASLR_PIE_REGULAR)),1)
  23. TARGET_CFLAGS += $(FPIC)
  24. TARGET_LDFLAGS += $(FPIC) -specs=$(INCLUDE_DIR)/hardened-ld-pie.specs
  25. endif
  26. endif
  27. ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR
  28. ifeq ($(strip $(PKG_SSP)),1)
  29. TARGET_CFLAGS += -fstack-protector
  30. endif
  31. endif
  32. ifdef CONFIG_PKG_CC_STACKPROTECTOR_STRONG
  33. ifeq ($(strip $(PKG_SSP)),1)
  34. TARGET_CFLAGS += -fstack-protector-strong
  35. endif
  36. endif
  37. ifdef CONFIG_PKG_FORTIFY_SOURCE_1
  38. ifeq ($(strip $(PKG_FORTIFY_SOURCE)),1)
  39. TARGET_CFLAGS += -D_FORTIFY_SOURCE=1
  40. endif
  41. endif
  42. ifdef CONFIG_PKG_FORTIFY_SOURCE_2
  43. ifeq ($(strip $(PKG_FORTIFY_SOURCE)),1)
  44. TARGET_CFLAGS += -D_FORTIFY_SOURCE=2
  45. endif
  46. endif
  47. ifdef CONFIG_PKG_RELRO_PARTIAL
  48. ifeq ($(strip $(PKG_RELRO)),1)
  49. TARGET_CFLAGS += -Wl,-z,relro
  50. TARGET_LDFLAGS += -zrelro
  51. endif
  52. endif
  53. ifdef CONFIG_PKG_RELRO_FULL
  54. ifeq ($(strip $(PKG_RELRO)),1)
  55. TARGET_CFLAGS += -Wl,-z,now -Wl,-z,relro
  56. TARGET_LDFLAGS += -znow -zrelro
  57. endif
  58. endif