Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp614341rwd; Sat, 20 May 2023 03:49:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6tFC6KYzzYvgBvRpRTF6nh7EufAXxmduCgrICaZuE8ElW7dGFqVTiMm63uCwFbvw/0bG9J X-Received: by 2002:a05:6a20:9f99:b0:103:946d:8a4c with SMTP id mm25-20020a056a209f9900b00103946d8a4cmr4757152pzb.5.1684579780900; Sat, 20 May 2023 03:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684579780; cv=none; d=google.com; s=arc-20160816; b=ktmprW4JIgLgxXnLWY3HU8FkTQK4ZDLAmb+FQT/cvitzoRYic/YS08CqyYG9viqVtK Of5pzzVxANwT7C6cM+ma3vDrCFrGdKifoxIhZ835cpo2DzMwxMrYHtYWOQrWA+gtmwRp RAkTwLUBLhx0UFz9a8atI3jqRq/CEJdknadi2U0JHgsF8Q4+/Q2yEhK2Qk/AaM6vs9Sb RW4cVv1Vp0hiHOqfj1w+1vrckpJOOmkk2q6Mgku7/pPRWt86PHGB38n2VIV09b18d82C COWvGqaI4uZSpt+UlDW9e4IFBa30Dw8oFuProeVFcLwWPhxl7Nk/dBthrxls4tD5RLd7 dESA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:dkim-signature:from; bh=dQ8hI0gn44tNx4CCUQO7NEKJU7+EOHcXqdxEUea7pNo=; b=gBiIHSG/kQlUfZYhmwH+jc0I3+BgymbtLS2Y/5VZJO7mICDiGtAuBoQFQCjn0G5Fdj z+fdC8BBZv521yYermeuL8690s6UtHyjwHAoS/g/N7kHxrMuR95K7nWbYSM2atqqRGaL 4ksvy3gfJZbyjUZnFonihis9YubSN8OLvXvNoQakAh+72wfpL3pT6hDQihhexqDngUxl cDjA/SQxXChirIqZQbrTcRfihy9gsCJVdYq4kQEj0htxst4/wFhEFngezc6VO0LhcfK9 6oDX+nWzC+XoMpIfj47mbpqSf8vtKzY0yghEsz8aw6cwkIMnmZi3k0xrZ5aC2tRt3wwj Q8Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=YdfF2wHQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q21-20020a656a95000000b005303c3dedc2si1383772pgu.419.2023.05.20.03.49.25; Sat, 20 May 2023 03:49:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=YdfF2wHQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231154AbjETJxn (ORCPT + 99 others); Sat, 20 May 2023 05:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230113AbjETJxl (ORCPT ); Sat, 20 May 2023 05:53:41 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A253FE46; Sat, 20 May 2023 02:53:39 -0700 (PDT) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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?Thomas_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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) 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 \ --- base-commit: 6a1f732e0d753a691e9e787615b9a0dd92e1f3f4 change-id: 20230520-nolibc-stackprotector-riscv-160cb957fcd5 Best regards, -- Thomas Weißschuh