Message ID | 72d607dcade45c73c3f979d5f8ec1064c15a98b5.1592834304.git.szabolcs.nagy@arm.com |
---|---|
State | Committed |
Commit | fddbd7c0ef4960fc0a17712a95a146dd3f43de0a |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1AB5F388A81D; Mon, 22 Jun 2020 14:00:15 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60077.outbound.protection.outlook.com [40.107.6.77]) by sourceware.org (Postfix) with ESMTPS id 20EAD3840C0E for <libc-alpha@sourceware.org>; Mon, 22 Jun 2020 14:00:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 20EAD3840C0E 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=C+NK1G19nY/YOo52NcCJ+4Nsqz2cr67Bwt4lwbA15UGOvLMm6BWf4vMoWeGj9+DdaiyB8hqkBnOBrVNQ3Tt/GlSQbhfYbSTMK8GKygHFdkbAZwIhjBeMLiZJDEfYA63fm6UdX1QMFLa2tdPelHyOfbFUyceH1Rx6TJVDfSq2pJo= Received: from AM6P191CA0052.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::29) by DBBPR08MB4806.eurprd08.prod.outlook.com (2603:10a6:10:db::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.23; Mon, 22 Jun 2020 14:00:10 +0000 Received: from VE1EUR03FT038.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:7f:cafe::e9) by AM6P191CA0052.outlook.office365.com (2603:10a6:209:7f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Mon, 22 Jun 2020 14:00:10 +0000 X-MS-Exchange-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 VE1EUR03FT038.mail.protection.outlook.com (10.152.19.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Mon, 22 Jun 2020 14:00:10 +0000 Received: ("Tessian outbound 8fb20e43acb7:v59"); Mon, 22 Jun 2020 14:00:10 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: bcff2522097c7f06 X-CR-MTA-TID: 64aa7808 Received: from 65e7793ae293.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 6BDE2E6E-7411-4AA6-B00B-DD155984CA48.1; Mon, 22 Jun 2020 14:00:04 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 65e7793ae293.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 22 Jun 2020 14:00:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JbECc5rk9A7uIConvQw+sKLpQr3NqEmToO00J32pFqdfhwMPwmqSEoJJb92b4Bxmvt+i1QHIXU1h7AiTqdJx81mbIRl30IpgJFA2E/G8Sldsmr9ecl5eQ3W5sZyE2XKd+5UbBz7+ZTWKVvIMTTWHZJPW8SiVMcFeLJqkKrpsBlhgZjEAmg+PEIGFaqmeNdvZH63WdtmQ0sfxjRbxQMAnfIeH1/EMd2FHJTZ84nopQaQlbBk8MXYMHAVIoK4NCGuHASOgYPyB/x4+S0PAIpeaESj2Kz58Kh5Xk/TLsFlGlZ/8MRt1kPAs0tsMpt8keEDjy0EqWbYk77tuIFxzsVwtzA== 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=Xprn0NBeOEMgIw42vqUNSMU2/RsD4b9fMOZZlx7hv9elK/9sHqhdq+pIkXpQxT8QWeBlgoqaxCFm0N/BZPWEoQCC+HqKoIbK6vyqPJjpngRkEsFi19lj5s538P98bKunDOZInWrkBriqMdXJ2USIwRXMSExF2ZAg5Y9JRZyuuFycpO8M+clWIsFcBgYGD9n4rDRo+ym8M4T812+pyCI00OUTf2UEcoeHvuyJ7yf203NGJIr1BAvkKVjt2Os5XFLAmisquu8rfytmITwOKJeN+YWTorRMyZDLj33x7Of9ab8faH3yx+kIxKd7qpl6TaX9rLXHMM6l2Yms6RJeLVRS7g== 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=C+NK1G19nY/YOo52NcCJ+4Nsqz2cr67Bwt4lwbA15UGOvLMm6BWf4vMoWeGj9+DdaiyB8hqkBnOBrVNQ3Tt/GlSQbhfYbSTMK8GKygHFdkbAZwIhjBeMLiZJDEfYA63fm6UdX1QMFLa2tdPelHyOfbFUyceH1Rx6TJVDfSq2pJo= 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 AM6PR08MB4341.eurprd08.prod.outlook.com (2603:10a6:20b:b9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21; Mon, 22 Jun 2020 14:00:03 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c%6]) with mapi id 15.20.3109.027; Mon, 22 Jun 2020 14:00:03 +0000 From: Szabolcs Nagy <szabolcs.nagy@arm.com> To: libc-alpha@sourceware.org Subject: [PATCH v5 05/14] aarch64: fix swapcontext for BTI Date: Mon, 22 Jun 2020 14:59:57 +0100 Message-Id: <72d607dcade45c73c3f979d5f8ec1064c15a98b5.1592834304.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <cover.1592834304.git.szabolcs.nagy@arm.com> References: <cover.1592834304.git.szabolcs.nagy@arm.com> Content-Type: text/plain X-ClientProxiedBy: LO2P265CA0156.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::24) 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.53) by LO2P265CA0156.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.24 via Frontend Transport; Mon, 22 Jun 2020 14:00:03 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.53] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 63fd3a6f-fa01-41e5-6fed-08d816b493e6 X-MS-TrafficTypeDiagnostic: AM6PR08MB4341:|DBBPR08MB4806: X-Microsoft-Antispam-PRVS: <DBBPR08MB48061682955209E9AA4C5DE8ED970@DBBPR08MB4806.eurprd08.prod.outlook.com> x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-Forefront-PRVS: 0442E569BC X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: T2Yc4yEf5XyfcLV69EvbAw9hAbKGpRq92xOSXrKjSVBXAl7jB/HR4SQmUrI2fHsxq5ZW3dRB9MpuIneN92JTUuHmFE3+azlW1G/d2NrqjlTVb5nnOgZ2o1G9qmM7I8pZvoNiQf+KvvLGVDl/blfBjOG0MQ/Mzf1aTKvUJ2r9UGHHBHVe7fwX4PFn2IZkNsRqJO5SQ2qlBEeYooO29fMa5FCkV5Hcz9JsEXus6lQAegyLfMrk5mliFal16dHatCuFRV2m6SdXdka04pco7axhHTmq2lI6gYvhKmWOa/HONNaOVzWIU/ivASYSMsl13AgGv0BWeMbc2Vsp2J9vYwom28pirp4yvNLuhc1aKKnoxW/kC1a9gQvKYy4pkUS5QFdDQbvg8spNH7jfsc+3e2hlwqlm/ATn6jxPXhFPWE+M3+g= 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)(346002)(39860400002)(136003)(376002)(366004)(396003)(16526019)(186003)(66476007)(66556008)(2906002)(36756003)(6486002)(2616005)(44832011)(956004)(6512007)(316002)(66946007)(6666004)(478600001)(6506007)(69590400007)(52116002)(5660300002)(8936002)(8676002)(26005)(83380400001)(86362001)(6916009)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 3dIYAWb/Shmg/kgnMofhcbXic96iYrMgL/tZo/3NFBtu+fLFBFiPBlfIfjTLKQU7qPVpJJB9UxL+Vj4z9kEFyDKaC/YDxPMDFT7A8oHJLd3vKnlQA5whQyufeM+Jweelc/GYg7Q1t1PUM2lu1y5Qeu9w18YxlMhsrijPZcZlp0q3J53ZcOo26hTjM0g+LSlAYSK3lBV4L8afnqpyXOZuiy6bt+SJZiQkIthI0+bpN9UriTca+byfYN9oJZLKvQjLTz0yJm+OaU0Ee3bzN2TpOWSs7HDhw+POk8oZjZawc2PY/FolivkX8Cz7NHxyD+J8tTMB4gGKMXiPIkUC1RivuqbNLSt72Bhrd36iTaaoLlXdUj7mw33rfmiPp59wW2EF6J8CUrxVHGh8uMvMa1tRIFn65rqT8cWccaT997J2Qtwq2Z5O1CNkT2A8omW3Z3aI5vzcbyloZhzZwMLD+4xSkMRD0cNrucfTkZkZ1yUKlUVo8Am4F1asV7hCGS5hcpSs X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4341 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: VE1EUR03FT038.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)(396003)(346002)(39860400002)(376002)(46966005)(5660300002)(356005)(44832011)(81166007)(6666004)(6486002)(82310400002)(2616005)(956004)(8676002)(6916009)(6512007)(336012)(316002)(82740400003)(69590400007)(36906005)(8936002)(47076004)(6506007)(70206006)(70586007)(186003)(26005)(16526019)(2906002)(36756003)(86362001)(478600001)(83380400001)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: e0dc098d-1bbc-4654-e230-08d816b48fa7 X-Forefront-PRVS: 0442E569BC X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u7K3m2fVuqpX3o33P6Z8LCO8D6OkO7ZwBRPblEuYM+/2iu/IYfyhWHT2f62FiDYslpNHxaPmzgjfimJQ810ML4ZxN6ZQAtP8XwvEDxh33l15q+C1oQlF1sJuti1g8GQX0L6PR2Kejdw7nYiqkMmNssLPglqiWpCuehawjT8hWWZOkYfPYfNdur7QatsibVhEIBhwkhf0Oar1m8S5kHobW6RiDJYWnr1VIu411nsyCG4mQD10MQS6jjcGiAn81LRWppX+4fT4stG6//16fE/+auDtqKuzno+umVZXd2g1RyjaJkP2PmxHKtU+g1kP1/yBGBMJXcqQdshkJ2cFMlx/ZlZwQNm8v1/YWpjq8ljq/2xOA8Aex83iaitWDSGCFhUoeC7iT1wvC/AOqhg4GFd2yGjXlzs8EKWaE5PClqRbW0Z9RJ5pPrO+vkcnDfzjdae6IuP1pQ3Sdbb/rIvReNFyKw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2020 14:00:10.3112 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63fd3a6f-fa01-41e5-6fed-08d816b493e6 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: DBBPR08MB4806 X-Spam-Status: No, score=-16.1 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
|
|
Commit Message
Szabolcs Nagy
June 22, 2020, 1:59 p.m. UTC
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(-)
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)