public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: linux@weissschuh.net, linux-kernel@vger.kernel.org,
	Willy Tarreau <w@1wt.eu>
Subject: [PATCH 8/8] tools/nolibc: x86_64: add stackprotector support
Date: Sat, 25 Mar 2023 16:45:16 +0100	[thread overview]
Message-ID: <20230325154516.7995-9-w@1wt.eu> (raw)
In-Reply-To: <20230325154516.7995-1-w@1wt.eu>

From: Thomas Weißschuh <linux@weissschuh.net>

Enable the new stackprotector support for x86_64.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 tools/include/nolibc/arch-x86_64.h      | 5 +++++
 tools/testing/selftests/nolibc/Makefile | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h
index 17f6751208e7..f7f2a11d4c3b 100644
--- a/tools/include/nolibc/arch-x86_64.h
+++ b/tools/include/nolibc/arch-x86_64.h
@@ -181,6 +181,8 @@ struct sys_stat_struct {
 char **environ __attribute__((weak));
 const unsigned long *_auxv __attribute__((weak));
 
+#define __ARCH_SUPPORTS_STACK_PROTECTOR
+
 /* startup code */
 /*
  * x86-64 System V ABI mandates:
@@ -191,6 +193,9 @@ const unsigned long *_auxv __attribute__((weak));
 void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
 {
 	__asm__ volatile (
+#ifdef NOLIBC_STACKPROTECTOR
+		"call __stack_chk_init\n"   // initialize stack protector
+#endif
 		"pop %rdi\n"                // argc   (first arg, %rdi)
 		"mov %rsp, %rsi\n"          // argv[] (second arg, %rsi)
 		"lea 8(%rsi,%rdi,8),%rdx\n" // then a NULL then envp (third arg, %rdx)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index ab99786c1e94..bbce57420465 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -80,6 +80,8 @@ CFLAGS_STACKPROTECTOR = -DNOLIBC_STACKPROTECTOR \
 			$(call cc-option,-mstack-protector-guard=global) \
 			$(call cc-option,-fstack-protector-all)
 CFLAGS_STKP_i386 = $(CFLAGS_STACKPROTECTOR)
+CFLAGS_STKP_x86_64 = $(CFLAGS_STACKPROTECTOR)
+CFLAGS_STKP_x86 = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_s390 = -m64
 CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables \
 		$(call cc-option,-fno-stack-protector) \
-- 
2.17.5


  parent reply	other threads:[~2023-03-25 15:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-25 15:45 [PATCH 0/8] tools/nolibc: add support for stack protector Willy Tarreau
2023-03-25 15:45 ` [PATCH 1/8] tools/nolibc: add definitions for standard fds Willy Tarreau
2023-03-25 15:45 ` [PATCH 2/8] tools/nolibc: add helpers for wait() signal exits Willy Tarreau
2023-03-25 15:45 ` [PATCH 3/8] tools/nolibc: tests: constify test_names Willy Tarreau
2023-03-25 15:45 ` [PATCH 4/8] tools/nolibc: add support for stack protector Willy Tarreau
2023-03-25 15:45 ` [PATCH 5/8] tools/nolibc: tests: fold in no-stack-protector cflags Willy Tarreau
2023-03-25 15:45 ` [PATCH 6/8] tools/nolibc: tests: add test for -fstack-protector Willy Tarreau
2023-03-25 15:45 ` [PATCH 7/8] tools/nolibc: i386: add stackprotector support Willy Tarreau
2023-03-25 15:45 ` Willy Tarreau [this message]
2023-03-26  4:36 ` [PATCH 0/8] tools/nolibc: add support for stack protector Paul E. McKenney
2023-03-26  6:20   ` Willy Tarreau
2023-03-26 15:13   ` Paul E. McKenney
2023-03-26 15:17     ` Willy Tarreau
2023-03-26 15:26       ` Paul E. McKenney
2023-03-26 15:28         ` Willy Tarreau
2023-03-26 15:45           ` Paul E. McKenney
2023-03-26 16:00             ` Willy Tarreau
2023-03-26 16:05               ` Willy Tarreau
2023-03-26 16:55                 ` Willy Tarreau
2023-03-26 18:00                   ` Paul E. McKenney
2023-03-27  3:41                     ` Paul E. McKenney
2023-03-27  4:04                       ` Willy Tarreau
2023-03-26 15:30         ` Paul E. McKenney
2023-03-26 15:42           ` Willy Tarreau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230325154516.7995-9-w@1wt.eu \
    --to=w@1wt.eu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=paulmck@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox