Message ID | 219501f1211e6956aa579911eb1f49c969c9bdd0.1589552054.git.szabolcs.nagy@arm.com |
---|---|
State | New |
Headers | show
Return-Path: <libc-alpha-bounces@sourceware.org> X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=<UNKNOWN>) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=9BO6fUHi; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=9BO6fUHi; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Nrj64Lv6z9sWp for <incoming@patchwork.ozlabs.org>; Sat, 16 May 2020 00:42:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C3AE3985834; Fri, 15 May 2020 14:41:28 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10042.outbound.protection.outlook.com [40.107.1.42]) by sourceware.org (Postfix) with ESMTPS id E8A91398580E for <libc-alpha@sourceware.org>; Fri, 15 May 2020 14:41:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E8A91398580E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1B/jWlnGw6SE/g7p1Ew3WX2EXXdb7IFvovtKhBA1zHE=; b=9BO6fUHiOVWioWgdjH7pfoyxLeEoTDcZoJWNwyMIKrT5CnYT1/PwG7wHBix7WVMU8Ja/vAXyzGCJ5oCJPwMKibNeLtIatvGjY5B/8B8941LiT3CbwrJ6XEIi54CvTOqIO2w9h8eyWai1jSzMYA3XD5QAi1CQJQxa05690iNaf54= Received: from DB6PR0601CA0009.eurprd06.prod.outlook.com (2603:10a6:4:7b::19) by AM5PR0802MB2481.eurprd08.prod.outlook.com (2603:10a6:203:a0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.27; Fri, 15 May 2020 14:41:12 +0000 Received: from DB5EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:7b:cafe::d) by DB6PR0601CA0009.outlook.office365.com (2603:10a6:4:7b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20 via Frontend Transport; Fri, 15 May 2020 14:41:12 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT043.mail.protection.outlook.com (10.152.20.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Fri, 15 May 2020 14:41:12 +0000 Received: ("Tessian outbound 567b75aed2b9:v54"); Fri, 15 May 2020 14:41:12 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 930e51733ab58232 X-CR-MTA-TID: 64aa7808 Received: from ceb467c05350.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A9C39871-DB8C-4846-B1F1-F6C6A74763F6.1; Fri, 15 May 2020 14:41:06 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ceb467c05350.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 15 May 2020 14:41:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lk9R5FgYBCVJYsXJtApmb+BPU/WBdLmAQxs5nCPOzLnN6XC9cEEdORsQ4AqlJHKvZCps4BqOpKJ/poDjy4xQE2dSjLwGQyazGVspu3gi2AfQCs/NlCVmxXwOKKeNFKJlyigOuFdxeQohlIlcyqGlgtrku6e21tNTryvcQRDLzxeoe3SXi82kGtLVnWc32A1WaF5Dm40cRdhMZFJP+2gOylF4ua1VYBmYsFbIX6lJR+zD8TW71vlCPw49D4hIKY01+rySmwpXN6mf6tBmiVrIxMkqQsxGkzuogKP1WCkO79zxw6sOBLQGPrXiTEHlGrc72GKS9DbfcLy+A1QjYq9oPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1B/jWlnGw6SE/g7p1Ew3WX2EXXdb7IFvovtKhBA1zHE=; b=ZUHLObRjvOxudPkhCF/TVNGsAwMQDs9I9DY7iM74mO3elsyY3T6SeEmJ6AdOy9YVErsKhvuG35Y5tEwRFzt+cYFipy80icq0fjJo3ELHHX0YfMKLgeCj5nVBAk0iQssVh2dRJdgeI3rggniWtt4Ye/ZfyV3U4HrD0dPatVAJ4Lf7SOilGBldZSVMI+8682Jx1Y+RqBcMQGcG635FccCSIdoKt0zfXh+faUR56QWjVbWNcJgFT91ytTRk3ilnbIaKK7wX/B8ns9K46Sa/aOKOsdcTJJf6+1RwG8L9G4iFYpWkDJd2NT6LtlNO+lbHbADiYqAYJPnt6OLD0DiNlupewQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1B/jWlnGw6SE/g7p1Ew3WX2EXXdb7IFvovtKhBA1zHE=; b=9BO6fUHiOVWioWgdjH7pfoyxLeEoTDcZoJWNwyMIKrT5CnYT1/PwG7wHBix7WVMU8Ja/vAXyzGCJ5oCJPwMKibNeLtIatvGjY5B/8B8941LiT3CbwrJ6XEIi54CvTOqIO2w9h8eyWai1jSzMYA3XD5QAi1CQJQxa05690iNaf54= Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM6PR08MB3528.eurprd08.prod.outlook.com (2603:10a6:20b:4b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.34; Fri, 15 May 2020 14:41:06 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862%7]) with mapi id 15.20.2979.033; Fri, 15 May 2020 14:41:06 +0000 From: Szabolcs Nagy <szabolcs.nagy@arm.com> To: libc-alpha@sourceware.org Subject: [PATCH v3 07/13] aarch64: fix swapcontext for BTI Date: Fri, 15 May 2020 15:40:51 +0100 Message-Id: <219501f1211e6956aa579911eb1f49c969c9bdd0.1589552054.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <cover.1589552054.git.szabolcs.nagy@arm.com> References: <cover.1589552054.git.szabolcs.nagy@arm.com> Content-Type: text/plain X-ClientProxiedBy: LO2P265CA0309.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::33) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO2P265CA0309.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24 via Frontend Transport; Fri, 15 May 2020 14:41:05 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 617f13ca-1176-487f-fbea-08d7f8de0399 X-MS-TrafficTypeDiagnostic: AM6PR08MB3528:|AM5PR0802MB2481: X-Microsoft-Antispam-PRVS: <AM5PR0802MB24818336611E392A75C85BC5EDBD0@AM5PR0802MB2481.eurprd08.prod.outlook.com> x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-Forefront-PRVS: 04041A2886 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: F9ig+2A/6JRRFCVd1H4uEq1yBO2WAMhjem85EGop+CIxGzc2PQJ2+QKTBE/KwEb7OuzEG+nALN/2fLTknYvzTiwYpFCTEuGz1FSz+Sj7JHo4AF5YkclkKVrVUmOJ01RIkGap7ThKs8QiNui7kH2F2HzyFOBYvqec4j9gmIHVuoRctFm1tfDVXTJ1TBanl/R1zw1F838bEEa6YoIlu38NR5DwhI5ldMvblaeKv2eKy7lIRHQEZerdDpYT8v4lRIcoFv+fmAPyO33iW2X2dPWvHFpj9qeeIM94B5sAwqvDrfLcEjMyecVnHedC+VMZJdxV2ICUeX/9CCrD/lN5y1SZOVaBn7JOdQe4BvdRBvbUQyM5UKL1+hqBvMTEabScHVqMsNt8d+6wfnXA0HfTNvQt7nuGyHsA/i9llzTvciDbJBrWW/SZYizdp00m1JjYEc3Gll2oHriG4QRgBiYbSQHdarmXumN9sIdw4qOFPlXGwCafye8UvHJyIftSmI+a9NVOu9QDBOKnSuQUormNlr2hFb04EqS/8YUOoyPksxNY/hM= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(376002)(39860400002)(346002)(366004)(396003)(86362001)(6506007)(69590400007)(52116002)(478600001)(316002)(6666004)(6916009)(6486002)(66556008)(44832011)(6512007)(5660300002)(2906002)(956004)(66476007)(8936002)(66946007)(36756003)(186003)(26005)(2616005)(8676002)(16526019)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: dLx90xIVPhErYPM/Kxdk8ShdOeOJRjuG35dNy9YHGK1gDb3E7FZyUzS4CZXqf25OVRMMYK81PQyFC/xxMcBAVLLopDZzuHDer7p/CJ/fljQxF7nVnL42NDEeNMWUdd9Rd9EH7V+622hFUgTM4e/Eygo0C+7TQIujpMDB+2E0Cv0jzyr0HDakf0MaGLcaipkuB+1nbp19gNMbG/87oaTMz2CxvwgoLzpBwt/qudLDk815SRBUgGQv1Zm+HTaDpX1/Rb/XDdZXiS46JzdDRjFDvY8r0rneLR9qiuOPiPkqTvRWcN7t9gGK+0K26UTIrsS+2BO952fCFx/FoXgKzfjG0JcT+yhaVVFZF12U7W5eLuEoDWcOTjPCyQ10mZJMNuzBkNA6p+95CMrnJu9RFcT9SRmIR7IFO9g6DT05NwEUOs4J2mMXMFvUJVyRtpFOh+S8zFkHyl2KCOy3rz8w0yNYrfmtclGb9wv5kqdEUpOxnq4zFt4CSM6Ll6EP2YwLD/f6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3528 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT043.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(136003)(39860400002)(396003)(346002)(376002)(46966005)(86362001)(6916009)(6486002)(69590400007)(47076004)(2906002)(36756003)(8936002)(356005)(82310400002)(70586007)(316002)(82740400003)(70206006)(81166007)(8676002)(956004)(44832011)(26005)(186003)(478600001)(336012)(16526019)(6506007)(5660300002)(6666004)(6512007)(2616005)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: a35e10c8-97ec-46b4-5f57-08d7f8ddffba X-Forefront-PRVS: 04041A2886 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XO+mByfW7473fIFLEhU2NQQhkiDw/cJs8ISG5G3NQZVb7bRTXIVuE3fE/jA9InHSW1R8+GaPdrNno43apEHIrGb/KNh5GB79VFKhlZlM5hqYdr4yiFNlE9W7l9zOVrKZhEaG/6RKluKifOzOEvpTArJYjm4mRdjzYn1xUAg2tdtAohIXGAIdfifExYxULYVY9emjtQPs1hzrxriCiikW/l//N8jAiT0WZh6cu3nm2wNxM0z+JsyLLEMH6NR8qdqrfLMt2VsmkDO55ApwMQNgzj4K9PDK0WScai52JUejZmkwi2S2aLLDXPArcqqlSVkYZAP5B9hAfHSLq3dwfrs1iz3KwT0HvAuLWevzi12ytC2DcpUhH5eaVoa3ZJ1Q7KrgCua8bjRtVu27isGjU6DsMeXa9htwlX0sJ0Y2haec1s53LiS2TJy5u/POCFubweg2SOqhf/LGeq6LJXbysk2VRhD1PwD9+o/Ak+oZzdpvDDJri5ccA6KVpV+q1TU2DNdnciysLyAyDT0z4Eok34AImZCTqOY7ZO7WnrNKIuOyWbxHTP1yBgwCObZCNWFgpOhNtLtrPbhBs6pjEhN4IHKzOg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2020 14:41:12.3005 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 617f13ca-1176-487f-fbea-08d7f8de0399 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2481 X-Spam-Status: No, score=-18.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_STOCKGEN, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <http://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <http://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
aarch64: branch protection support
|
expand
|
diff --git a/sysdeps/unix/sysv/linux/aarch64/swapcontext.S b/sysdeps/unix/sysv/linux/aarch64/swapcontext.S index d30c543e6f..f8c66f0ef0 100644 --- a/sysdeps/unix/sysv/linux/aarch64/swapcontext.S +++ b/sysdeps/unix/sysv/linux/aarch64/swapcontext.S @@ -28,8 +28,12 @@ .text ENTRY(__swapcontext) DELOUSE (0) - /* Set the value returned when swapcontext() returns in this context. */ - str xzr, [x0, oX0 + 0 * SZREG] + /* Set the value returned when swapcontext() returns in this context. + And set up x1 to become the return address of the caller, so we + can return there with a normal RET instead of an indirect jump. */ + stp xzr, x30, [x0, oX0 + 0 * SZREG] + /* Arrange the oucp context to return to 2f. */ + adr x30, 2f stp x18, x19, [x0, oX0 + 18 * SZREG] stp x20, x21, [x0, oX0 + 20 * SZREG] @@ -97,5 +101,11 @@ ENTRY(__swapcontext) 1: b C_SYMBOL_NAME(__syscall_error) +2: + /* The oucp context is restored here via an indirect branch, + x1 must be restored too which has the real return address. */ + BTI_J + mov x30, x1 + RET PSEUDO_END (__swapcontext) weak_alias (__swapcontext, swapcontext)
setcontext returns to the specified context via an indirect jump, so there should be a BTI j. In case of getcontext (and all other returns_twice functions) the compiler adds BTI j at the call site, but swapcontext is a normal c call that is currently not handled specially by the compiler. So we change swapcontext such that the saved context returns to a local address that has BTI j and then swapcontext returns to the caller via a normal RET. For this we save the original return address in the slot for x1 of the context because x1 need not be preserved by swapcontext but it is restored when the context saved by swapcontext is resumed. The alternative fix (which is done on x86) would make swapcontext special in the compiler so BTI j is emitted at call sites, on x86 there is an indirect_return attribute for this, on AArch64 we would have to use returns_twice. It was decided against because such fix may need user code updates: the attribute has to be added when swapcontext is called via a function pointer and it breaks always_inline functions with swapcontext. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> --- sysdeps/unix/sysv/linux/aarch64/swapcontext.S | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)