All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add support for stack-protector
@ 2021-01-10 15:39 Joel Peshkin
  2021-01-10 16:18 ` Heinrich Schuchardt
                   ` (9 more replies)
  0 siblings, 10 replies; 29+ messages in thread
From: Joel Peshkin @ 2021-01-10 15:39 UTC (permalink / raw)
  To: u-boot

Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Jagan Teki <jagan@amarulasolutions.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Usama Arif <usama.arif@arm.com>
Cc: Sam Protsenko <joe.skb7@gmail.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Philippe Reynes <philippe.reynes@softathome.com>
Cc: Eugeniu Rosca <roscaeugeniu@gmail.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>

Signed-off-by: Joel Peshkin <joel.peshkin@broadcom.com>

---

 Makefile             |  4 ++++
 common/Kconfig       | 15 +++++++++++++++
 common/Makefile      |  2 ++
 common/stackprot.c   | 17 +++++++++++++++++
 scripts/Makefile.spl |  6 ++++++
 5 files changed, 44 insertions(+)
 create mode 100644 common/stackprot.c

diff --git a/Makefile b/Makefile
index 3ee4cc00dd..6e7a81ec7d 100644
--- a/Makefile
+++ b/Makefile
@@ -677,7 +677,11 @@ else
 KBUILD_CFLAGS	+= -O2
 endif
 
+ifeq ($(CONFIG_STACKPROTECTOR),y)
+KBUILD_CFLAGS += $(call cc-option,-fstack-protector-strong)
+else
 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
+endif
 KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks)
 
 # disable stringop warnings in gcc 8+
diff --git a/common/Kconfig b/common/Kconfig
index 2bce8c9ba1..e30c3c4ab8 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -595,6 +595,21 @@ config TPL_HASH
 	  and the algorithms it supports are defined in common/hash.c. See
 	  also CMD_HASH for command-line access.
 
+config STACKPROTECTOR
+	bool "Stack Protector buffer overflow detection"
+	default n
+	help
+	  Enable stack smash detection through gcc built-in stack-protector
+	  canary logic
+
+config SPL_STACKPROTECTOR
+	bool "Stack Protector buffer overflow detection for SPL"
+	default n
+
+config TPL_STACKPROTECTOR
+	bool "Stack Protector buffer overflow detection for SPL"
+	default n
+
 endmenu
 
 menu "Update support"
diff --git a/common/Makefile b/common/Makefile
index bcf352d016..fe71e18317 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -138,3 +138,5 @@ obj-$(CONFIG_CMD_LOADB) += xyzModem.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
 
 obj-$(CONFIG_AVB_VERIFY) += avb_verify.o
+obj-$(CONFIG_$(SPL_TPL_)STACKPROTECTOR) += stackprot.o
+
diff --git a/common/stackprot.c b/common/stackprot.c
new file mode 100644
index 0000000000..7c95b8544f
--- /dev/null
+++ b/common/stackprot.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  Copyright 2021 Broadcom
+ */
+
+#include <common.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+unsigned long __stack_chk_guard = 0xfeedf00ddeadbeef;
+
+void __stack_chk_fail(void)
+{
+	panic("Stack smashing detected in function: %p relocated from %p",
+	      __builtin_return_address(0),
+	      __builtin_return_address(0) - gd->reloc_off);
+}
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 9f1f7445d7..1505e4e851 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -63,6 +63,12 @@ include $(srctree)/scripts/Makefile.lib
 KBUILD_CFLAGS += -ffunction-sections -fdata-sections
 LDFLAGS_FINAL += --gc-sections
 
+ifeq ($(CONFIG_$(SPL_TPL_)STACKPROTECTOR),y)
+KBUILD_CFLAGS += -fstack-protector-strong
+else
+KBUILD_CFLAGS += -fno-stack-protector
+endif
+
 # FIX ME
 cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
 							$(NOSTDINC_FLAGS)
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2021-04-10 11:17 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-10 15:39 [PATCH] Add support for stack-protector Joel Peshkin
2021-01-10 16:18 ` Heinrich Schuchardt
2021-01-10 19:44   ` Joel Peshkin
2021-01-10 22:20     ` Heinrich Schuchardt
2021-01-10 22:40 ` Alex Sadovsky
2021-01-11  0:23   ` Joel Peshkin
2021-01-11  3:10 ` [PATCH v2] " Joel Peshkin
2021-01-11  9:59   ` Heinrich Schuchardt
2021-01-11 16:20 ` [PATCH v3] " Joel Peshkin
2021-01-11 18:12   ` Heinrich Schuchardt
2021-01-11 22:49 ` [PATCH v4] " Joel Peshkin
2021-01-12 15:48   ` Heinrich Schuchardt
2021-01-11 23:55 ` [PATCH v5] " Joel Peshkin
2021-01-12 16:51 ` [PATCH v6] " Joel Peshkin
2021-01-12 20:01   ` Heinrich Schuchardt
2021-01-14 13:59 ` [PATCH v7] " Joel Peshkin
2021-01-14 14:59   ` Alex Sadovsky
2021-01-14 20:35 ` [PATCH v8] " Joel Peshkin
2021-01-15 18:53   ` Heinrich Schuchardt
2021-01-28  0:57   ` Tom Rini
2021-01-28  8:20     ` Heinrich Schuchardt
2021-01-28 11:00       ` Heinrich Schuchardt
2021-01-28 14:33         ` Heinrich Schuchardt
2021-02-09  3:36 ` [PATCH v9] " Joel Peshkin
     [not found]   ` <794783f5-da5c-65b4-82a4-0f62d1f6a8b0@gmx.de>
2021-02-09 20:39     ` Heinrich Schuchardt
2021-03-22 17:37   ` Heinrich Schuchardt
2021-04-09 22:27     ` Joel Peshkin
2021-04-10 10:11       ` Heinrich Schuchardt
2021-04-10 11:17         ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.