From patchwork Sat May 20 09:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13249143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35A78C77B7A for ; Sat, 20 May 2023 09:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Va1Bx1RD1Gij5bgiAyXkSruSJS4aag4eJ4uA2TOVq+s=; b=zkN8kYsK5aitUc SPMW/bymEe0ECalUhKUUnal8b5VEZR8yO2ztF+pfbg2SyVLnVuovwA76AlXvPi8PC6w6oDf8lJpHj oGJxLb/4DLozhqa1xHHbgJOF6mUCuKnscPpUfUIs4McNgbUUbMS/cO//F408Cry95mlc6z9qIihH0 qvMQ1PUNREq/gn9Si8YFX9h+3FkQgrAe4ntxtS+qxYIv0AXcavXD9j7iE5Lf38PquHsqrIfE42Q6f jWuBpSRIsDuWXP3E2qtmAy+nZ0o6khQ4RThlU0BMiPj78PKh8CA7lHC+Ri07pLm6vSgsbFB/LKgGb 0ihk5auVr940+05H+DPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q0JHW-001Ber-2B; Sat, 20 May 2023 09:53:46 +0000 Received: from todd.t-8ch.de ([159.69.126.157]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q0JHS-001BdX-2K for linux-riscv@lists.infradead.org; Sat, 20 May 2023 09:53:44 +0000 From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1684576417; bh=4DgNOA9MxUdAC/1KBzMGa1BMYIwEibXuZWjLGIR+M4Y=; h=From:Date:Subject:To:Cc:From; b=YdfF2wHQeAHvxYdN3D90MRXKyn0mgq3yjtd06cnIPS30c+UHNOpY0Lj6zZCG2aRXE R3QCC5C3DuZP8v/hq++VOyLpswTKYYc9s3tHXxLOevzairZCj9bJW3LQdXD9XaENgI qhXdmBA7ft2J/LwOQV2IfASy1Mv/MaELdY/A94OY= Date: Sat, 20 May 2023 11:53:35 +0200 Subject: [PATCH] tools/nolibc: riscv: add stackprotector support MIME-Version: 1.0 Message-Id: <20230520-nolibc-stackprotector-riscv-v1-1-d8912012a034@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAJ6YaGQC/x2NQQrCMBAAv1L27EIaiaJfEQ/JdmsXQ1J2YxFK/ 27wOHOY2cFYhQ3uww7Km5jU0mE8DUBLLC9GmTqDd/7sgndYapZEaC3Se9XamFpVVDHacLw4Srd wnWkK0AspGmPSWGjpjfLJuctVeZbvf/l4HscP8js5B4IAAAA= To: Willy Tarreau , Paul Walmsley , Palmer Dabbelt , Albert Ou , Shuah Khan Cc: Zhangjin Wu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?T?= =?utf-8?q?homas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684576416; l=2523; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=4DgNOA9MxUdAC/1KBzMGa1BMYIwEibXuZWjLGIR+M4Y=; b=AQlACYthYxoszOZiNGyDJMnuc12eS8SCPgKc8+mKUU7vddLmVS/v0wGmHcxVJhTuTp1cUe+dP BrnOmwubpxDBV9w9hmNLbAtIpQb+KGH8KbEZLwivhPgdcHNYJRXZvp4 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230520_025342_913595_822CD139 X-CRM114-Status: UNSURE ( 7.84 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Signed-off-by: Thomas Weißschuh --- This was split out from the general stackprotector series[0] to be rebased on the nolibc rv32 work from Zhangjin. This was only tested for rv64 as the nolibc rv32 port is not yet functional. Based on the nolibc/20230520-nolibc-rv32+stkp branch. [0] https://lore.kernel.org/lkml/20230408-nolibc-stackprotector-archs-v1-0-271f5c859c71@weissschuh.net/ --- tools/include/nolibc/arch-riscv.h | 7 ++++++- tools/testing/selftests/nolibc/Makefile | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) --- base-commit: 6a1f732e0d753a691e9e787615b9a0dd92e1f3f4 change-id: 20230520-nolibc-stackprotector-riscv-160cb957fcd5 Best regards, diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index 992a1739dd9c..d0439249c9c9 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -177,14 +177,19 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); +#define __ARCH_SUPPORTS_STACK_PROTECTOR + /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_protector)) _start(void) { __asm__ volatile ( ".option push\n" ".option norelax\n" "lla gp, __global_pointer$\n" ".option pop\n" +#ifdef NOLIBC_STACKPROTECTOR + "call __stack_chk_init\n" /* initialize stack protector */ +#endif REG_L" a0, 0(sp)\n" /* argc (a0) was in the stack */ "add a1, sp, "SZREG"\n" /* argv (a1) = sp */ "slli a2, a0, "PTRLOG"\n" /* envp (a2) = SZREG*argc ... */ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 6d660d922240..bd41102ea299 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -85,6 +85,7 @@ CFLAGS_STKP_x86 = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm64 = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_mips = $(CFLAGS_STACKPROTECTOR) +CFLAGS_STKP_riscv = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_loongarch = $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 = -m64 CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \