From patchwork Fri Aug 12 15:29:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Corallo X-Patchwork-Id: 56715 Return-Path: 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 0EC59385828A for ; Fri, 12 Aug 2022 15:30:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0EC59385828A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660318258; bh=5tCAZOhg7PY7j+opIRtabGB+kps1BjOEdxhhr6CDoGE=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=izk7Z8vagUjNCybDJfMbav+IniA+l4JQmMykQ00pCdjR29CWqsX3C4xzfXyWmdE4E 8NzvfHJ4uerEin5D9wfizsW6ZoMgrqQIXRt90702uIgM2JPHEHpTcP5uyMxfh2gRxr GExP6dEcY+UBl1FbrrYGbE6OgdCjPex705f1c2j4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70040.outbound.protection.outlook.com [40.107.7.40]) by sourceware.org (Postfix) with ESMTPS id 692E83856DE2 for ; Fri, 12 Aug 2022 15:30:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 692E83856DE2 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Cl+8aSppNKSK/+Uzla/tcKrBG3SoMd9rCYedyUwRpvE5MujrIWz/DaivFGOrtv9xmWNr6Jl9HTWxYZwPqwnn3S0buwN7yU55g4zZGJDHRMCOf8ad2uz4MuyKLKh6TIEbY+LSnrobVzGWGJrBXxQGBL0EejaDuNn5r4jZfXxMStzmbMBilfhJfIFXlag6DAv9AjnFBibPZ5Id9+omn75gQm2OVrOUS+HRtVipX8+/REbc9DEDYxeyTFzZMc9g+vDTdy998DGVq7yo49sSjGozShZugOcoby1HZLl/83oHnJr+/O3DsVb9RP9zG62/fV2hZqAebpOEZjxZf8B+lyh04A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5tCAZOhg7PY7j+opIRtabGB+kps1BjOEdxhhr6CDoGE=; b=OA+N7OD4j4inKCV4d90y6fF37Zqtnaf3nfxIu+xF5S+CT/4HlFAzZcca8INKHvMBzOFBqKXdm0dcJsb7qht4FgQS7IHWyDoUwgb5R4ZO5Zf0SScOFSuB0oC8Q2mL/+ec3fAK97o4LODTySDQJQGnFj/Ih9BbN2KAf1PZfzzXllM7HGyzUmqLqBdJvaeIad/4L0Fnyg+Rby4gtNCkHqdqNNONjhalTFfCC8W6F33CyT4ZWXqBQhwQUx/nu5fahdmy0vko7D/2ugHAf1g2L2Rl7c5i0GoPjzSKelps/ZT4GnmMCiQsA2nNy8DTMsheTKSuPy+JcOXsJvEgdRDDiGAehQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB6PR0202CA0037.eurprd02.prod.outlook.com (2603:10a6:4:a5::23) by DU0PR08MB8188.eurprd08.prod.outlook.com (2603:10a6:10:3ef::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.22; Fri, 12 Aug 2022 15:30:06 +0000 Received: from DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:a5:cafe::7e) by DB6PR0202CA0037.outlook.office365.com (2603:10a6:4:a5::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.14 via Frontend Transport; Fri, 12 Aug 2022 15:30:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass 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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT032.mail.protection.outlook.com (100.127.142.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11 via Frontend Transport; Fri, 12 Aug 2022 15:30:05 +0000 Received: ("Tessian outbound cc6a8ab50b6b:v123"); Fri, 12 Aug 2022 15:30:05 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: fe43483ec824cb73 X-CR-MTA-TID: 64aa7808 Received: from 9fd66949e87d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 28DC5B3D-AB5E-463F-BB79-1F5E7CEF8E7A.1; Fri, 12 Aug 2022 15:29:58 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9fd66949e87d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 12 Aug 2022 15:29:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=du52iERwLOlTk86wlA7usvgY4/iWx6xYVbr6a9mqZc75nPmmOcoYhOYhoLsv4q2UbRzddVIDD/r8v6kHpM8r7tjdBXdPbmEY9OQ3Xle9bEBJn4+VhQ3bcchLmRJWEsT5BsDu1mpmFw2OPLVf9dyD+dG95r38GsrBx1HhTw2RSKp45pK5yw4sgmZEovGmTr5Tk5uUrJ7+O/494ifl9Bj0b7ZiyaZioXYPqzb95E2Z0ek6ArytBjlT7ZmjSZYyHMeyp7DYqSORE7JySRwigrfJz5bw8+cftgup3lFbSXfdczTzLzYVc14mh6qwrUUISQTLfpoHSmkZCFjhHjse0mthiA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5tCAZOhg7PY7j+opIRtabGB+kps1BjOEdxhhr6CDoGE=; b=HIScHSvkbrTIk3HfmG54F2ws6KwGpa+bgHtixcCVJqWCYUgWCg60T+0yeZB3LmxPll/3WdQS3ARw5P9tBquPnhbw4xwPsiIKbBVAshAA4cYBnUkummBwfONUFOO0kXQvZ2UJ+HGXV2Kt2r+SzVsPQq+DBLXZvGhjf71rywTKN32vnq7dzDLXN/axTE6X4foiSf37tvRHkQ+HJXznlYJRuzh/cwyT6xsemYyE8wYFMpxhS5CBbYCtTMmmgyO3s607JBp+W8/f9XO9RQrehD407aCSRT2Ju15G/Nd/nHFBjqY+j4gDh0dk80bCVcgGB02ZCNpnSAiUEx3gGnwgcU1Kxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB6PR07CA0110.eurprd07.prod.outlook.com (2603:10a6:6:2c::24) by VE1PR08MB5119.eurprd08.prod.outlook.com (2603:10a6:803:114::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14; Fri, 12 Aug 2022 15:29:56 +0000 Received: from DBAEUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2c:cafe::8f) by DB6PR07CA0110.outlook.office365.com (2603:10a6:6:2c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.14 via Frontend Transport; Fri, 12 Aug 2022 15:29:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT059.mail.protection.outlook.com (100.127.142.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Fri, 12 Aug 2022 15:29:56 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2507.9; Fri, 12 Aug 2022 15:29:56 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.9; Fri, 12 Aug 2022 15:29:55 +0000 Received: from e124257 (10.34.105.24) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.9 via Frontend Transport; Fri, 12 Aug 2022 15:29:55 +0000 To: Andrea Corallo via Gcc-patches Subject: [PATCH 6/15] arm: Add pointer authentication for stack-unwinding runtime References: Date: Fri, 12 Aug 2022 17:29:55 +0200 In-Reply-To: (Andrea Corallo via Gcc-patches's message of "Fri, 12 Aug 2022 16:26:49 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1.50 (gnu/linux) MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: b3cd3562-d155-4792-548a-08da7c778886 X-MS-TrafficTypeDiagnostic: VE1PR08MB5119:EE_|DBAEUR03FT032:EE_|DU0PR08MB8188:EE_ x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: c41NLzZ5WkikYvBrS1OjJ0V94Crj/5tcMOuKepBf2z2Zv2FGog4YV56IdtCCQ5ewyEDElBzSqLSWxo9piVMvScgvoSubZsuWVvhJBrHwjb1lYCmq/7Jb9Av8KaNNmAr5cXR0FZ/GcAYU0QZiMl6icvVwWtr2AqzMwcFUNO2KzL+WrQlmgdn4Mn8ZbBCG1EEf5D/ztANMLV5v4sUf71XFwl2PG3IkeD4OaK8PGUPkgtr9V2FjXj4UtQXs7cyqX7pbdAOB457X1GmcaK8IllH7vNci37zupAo/kzB7x3WY82+m+fHC3oFw1ymKV++UJRDypgWT2bimWfhhXwcc7sLcO6S/tlj5+4Ismxdo4YRIttXEKtMcGcrbX+pQp7x5T29sBi90ioo57MHh7/yfZCjp4w9YnkrL4y8ie2GeSnxMRRsLx+rGusVaCQR95L54EZtpzErnXjV3lvvDSPhJWGzZ7TTncBmJ2gglDIPevWvS1ZH9UlB6cTA9vpg/bsTazElt7d3Bz7mZIfEhKuO4oiprLT0iEAjeX563I9dtUzq6xBt3w/QO2GF6c6LM8Ft45CHqmAPG13YgGGnu305N7zqXa/OSEFEy+WU0a+E1q7AKMX0wHPZWqhqfcflj7Y9vmjeC3PaMWvRG/DNgzYQMrjcfw7csgh0Sx5/RlyQqBeYtNuz9rKOQrb1fTCDXIh8ozAROdm3Nl2WJyKuzMKJV3x3DJ3tWs/eE2WA8b24crKk5vQTghO8SYnpjOhP9Hi3hfyy7CKl7hyBNPQL7LDjHMPE/ODahBd/21UWdAsUz8J8KoZLa3ejuHcxW7kYCPaBqTWKdrxHMR52m0fyLyhCWs/daC2Za5ZmLt0y6pkvqt1aBxDtkU1cf/7Xc7WyZhiVv8039 X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(376002)(39860400002)(396003)(136003)(346002)(46966006)(36840700001)(40470700004)(81166007)(86362001)(70206006)(82740400003)(316002)(82310400005)(47076005)(356005)(36860700001)(186003)(70586007)(83380400001)(426003)(336012)(40460700003)(41300700001)(2616005)(33964004)(40480700001)(8936002)(5660300002)(235185007)(26005)(478600001)(6916009)(8676002)(36756003)(4326008)(54906003)(2906002)(44832011)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: tEXJZO+uzMzCx1treU2to/2oCpzvlTZjQUFKxDtv4x+YeH8ey/3YRtgroOM9KHdKGFd8tsoJljKNuT+DTCaeqLwaNkaT+XXSC79TW2maESw1JaGuS0BRTsx2YdhM65A114GhyQxoBjaIZnTMQ6HEfEsBzQSzNiLC4cBYt+b+MyckDjDRHW8wnfB1SQewdgwohUIHh5iQX35aJkS4Vx+ua5U70mtxmSB6FY9gUeKBQJyNlu1A8ctgfvyrw37qIU+EC0IRp3XMI2ERbTV/ZT/DnLavEwOJJN6SnGiJnh6mjSBy7rkGDtVpZWkHFDixOadrBpg1yldrdYHgKi1p4E1RNmznWbfzeBjAvcMN/DNwel0FG3tDTVz7+X6LJ41L4Vw5neS3fp1eQHpyWZEeEtP3ppGN1rT41xDD0ne2C/qPMfZagRgwGmGAm+mtnj+6Jyobtd5FwANi/9WgRbo6Fs624JrBCkhjc/p6R9il6QvUO0sVyzUcH6HWpXxJ7yCpTMAhyYBSCIWqKRfHMCHXN3FqYLEK6MERnzjVHYoZkOghIcG9xQe8i68heNilbPOhNLVgevLUs0rf+BRQVWkKCI0M1xXT8MWAlSh5qQ/KVz9DLJPUewq/xYvgItK6SASpaY8wFdOPi+C3F3MzTNo5mNGWULSWVyA44izRxGh1anDlJf2MGKN1oDWmWHhAoVo68ENRDbcYvO9+qfT2aD2ZDerJVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5119 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 699e465f-01ee-49cc-4f81-08da7c7782e9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qwmECnG5RKA4XcTVXTig1Rpi5nXYEzJOgKnHVVpxc0nuyjk/YaZGJ6SY572QB/Fzk7JmWeMQ9TDs4rZECGX9NffWAafqNqH8rSIAoESk/DxDVLyy9V3QL6ZzcWe/gPyoRM6AI2Cw+FpGnRV4iQmdXex9N0MsomDTw/l3b5UnH5XsD9oa3QitcDVCoP3XNtvOUqzH/0swCZK348Lcn/Yy4FazqN3z5evHLqlMlFBGakk0SjxxEx3sP5BThewiUB3OBCfVSv6FeS9T0KQ4KT5/8QQFoY/ksF6ExYZaro7DX0pvQwliS1SvyvK30sRHFhevnkFeW95IueGN/EjhvG+vVGJa059uMd2lDIWAaDK9/Dp3AervCncldP1LUEXM1nj7HMqesAutfgmPtvEFRzu+bF//aeuBiyZmQ8b57TpPuynR7Fpm/D3iycxnacfch1kYerin4tQ/mGt5CjltQo+lI1VrAXbURdjrPcIYoYsal7sDeAUyYXJ6CtddxnckwfvAjZZ5m5QzVFE0FRuGXuLc2Fa/evkw4c0aaZ3xSL2yDUk+SavKhWFJpf5KnETvzSBDEkBo/lHMvU7f/hMWbFCg4RsD/DbqzP/8V1VPvkUoNwL+sRNFZ65O9Be/d8KbQr6VIjyCoJwtUybjojwXctPYu5yNdQ2CdNegp+wCDKVjJJEP8JomIzNdEh8hlh3Oae59OlIw5if7uXkoWQinlDOOD0AR5dTlFka/EZXAD1qRT4ubH5EuxbL0+KHYXAKSNtJvhPcwOOYm5XqPd9saQBormfaePfghIxFwn7YU6zGyqgqz3Ba4Yk1mHDsgAwwIAiWKX6vf8Tsj2UZUqqQYVRxPKQ== 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; SFS:(13230016)(4636009)(346002)(136003)(396003)(376002)(39860400002)(40470700004)(46966006)(36840700001)(86362001)(44832011)(8936002)(2906002)(235185007)(5660300002)(40460700003)(33964004)(8676002)(316002)(54906003)(70206006)(70586007)(82310400005)(36756003)(40480700001)(6916009)(81166007)(478600001)(82740400003)(4326008)(36860700001)(26005)(83380400001)(336012)(41300700001)(186003)(426003)(47076005)(2616005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2022 15:30:05.9803 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3cd3562-d155-4792-548a-08da7c778886 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-AuthSource: DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8188 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrea Corallo via Gcc-patches From: Andrea Corallo Reply-To: Andrea Corallo Cc: Richard Earnshaw , nd Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi all, this patch adds authentication for when the stack is unwound when an exception is taken. All the changes here are done to the runtime code in libgcc's unwinder code for Arm target. All the changes are guarded under defined (__ARM_FEATURE_PAC_DEFAULT) and activated only if the +pacbti feature is switched on for the architecture. This means that switching on the target feature via -march or -mcpu is sufficient and -mbranch-protection need not be enabled. This ensures that the unwinder is authenticated only if the PACBTI instructions are available in the non-NOP space as it uses AUTG. Just generating PAC/AUT instructions using -mbranch-protection will not enable authentication on the unwinder. Arroved here: gcc/ChangeLog: * ginclude/unwind-arm-common.h (_Unwind_VRS_RegClass): Introduce new pseudo register class _UVRSC_PAC. * libgcc/config/arm/pr-support.c (__gnu_unwind_execute): Decode exception opcode (0xb4) for saving RA_AUTH_CODE and authenticate with AUTG if found. * libgcc/config/arm/unwind-arm.c (struct pseudo_regs): New. (phase1_vrs): Introduce new field to store pseudo-reg state. (phase2_vrs): Likewise. (_Unwind_VRS_Get): Load pseudo register state from virtual reg set. (_Unwind_VRS_Set): Store pseudo register state to virtual reg set. (_Unwind_VRS_Pop): Load pseudo register value from stack into VRS. Co-Authored-By: Tejas Belagod diff --git a/gcc/ginclude/unwind-arm-common.h b/gcc/ginclude/unwind-arm-common.h index d3831f6c60a..f26702e8c6c 100644 --- a/gcc/ginclude/unwind-arm-common.h +++ b/gcc/ginclude/unwind-arm-common.h @@ -127,7 +127,8 @@ extern "C" { _UVRSC_VFP = 1, /* vfp */ _UVRSC_FPA = 2, /* fpa */ _UVRSC_WMMXD = 3, /* Intel WMMX data register */ - _UVRSC_WMMXC = 4 /* Intel WMMX control register */ + _UVRSC_WMMXC = 4, /* Intel WMMX control register */ + _UVRSC_PAC = 5 /* Armv8.1-M Mainline PAC/AUTH pseudo-register */ } _Unwind_VRS_RegClass; diff --git a/libgcc/config/arm/pr-support.c b/libgcc/config/arm/pr-support.c index 2de96c2a447..e48854587c6 100644 --- a/libgcc/config/arm/pr-support.c +++ b/libgcc/config/arm/pr-support.c @@ -106,6 +106,7 @@ __gnu_unwind_execute (_Unwind_Context * context, __gnu_unwind_state * uws) { _uw op; int set_pc; + int set_pac = 0; _uw reg; set_pc = 0; @@ -114,6 +115,27 @@ __gnu_unwind_execute (_Unwind_Context * context, __gnu_unwind_state * uws) op = next_unwind_byte (uws); if (op == CODE_FINISH) { + /* When we reach end, we have to authenticate R12 we just popped + earlier. + + Note: while the check provides additional security against a + corrupted unwind chain, it isn't essential for correct unwinding + of an uncorrupted chain. */ +#if defined(TARGET_HAVE_PACBTI) + if (set_pac) + { + _uw sp; + _uw lr; + _uw pac; + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &sp); + _Unwind_VRS_Get (context, _UVRSC_CORE, R_LR, _UVRSD_UINT32, &lr); + _Unwind_VRS_Get (context, _UVRSC_PAC, R_IP, + _UVRSD_UINT32, &pac); + __asm__ __volatile__ + ("autg %0, %1, %2" : : "r"(pac), "r"(lr), "r"(sp) :); + } +#endif + /* If we haven't already set pc then copy it from lr. */ if (!set_pc) { @@ -227,6 +249,16 @@ __gnu_unwind_execute (_Unwind_Context * context, __gnu_unwind_state * uws) return _URC_FAILURE; continue; } + /* Pop PAC off the stack into VRS pseudo.pac. */ + if (op == 0xb4) + { + if (_Unwind_VRS_Pop (context, _UVRSC_PAC, 0, _UVRSD_UINT32) + != _UVRSR_OK) + return _URC_FAILURE; + set_pac = 1; + continue; + } + if ((op & 0xfc) == 0xb4) /* Obsolete FPA. */ return _URC_FAILURE; diff --git a/libgcc/config/arm/unwind-arm.c b/libgcc/config/arm/unwind-arm.c index 386406564af..89f945d047e 100644 --- a/libgcc/config/arm/unwind-arm.c +++ b/libgcc/config/arm/unwind-arm.c @@ -64,6 +64,12 @@ struct wmmxc_regs _uw wc[4]; }; +/* Holds value of pseudo registers eg. PAC. */ +struct pseudo_regs +{ + _uw pac; +}; + /* The ABI specifies that the unwind routines may only use core registers, except when actually manipulating coprocessor state. This allows us to write one implementation that works on all platforms by @@ -78,6 +84,9 @@ typedef struct /* The first fields must be the same as a phase2_vrs. */ _uw demand_save_flags; struct core_regs core; + /* Armv8.1-M Mainline PAC/AUTH values. This field should be in the same field + order as phase2_vrs. */ + struct pseudo_regs pseudo; _uw prev_sp; /* Only valid during forced unwinding. */ struct vfp_regs vfp; struct vfpv3_regs vfp_regs_16_to_31; @@ -99,6 +108,7 @@ typedef struct { _uw demand_save_flags; struct core_regs core; + struct pseudo_regs pac; } phase2_vrs; /* Coprocessor register state manipulation functions. */ @@ -175,6 +185,10 @@ _Unwind_VRS_Result _Unwind_VRS_Get (_Unwind_Context *context, case _UVRSC_WMMXC: return _UVRSR_NOT_IMPLEMENTED; + case _UVRSC_PAC: + *(_uw *) valuep = vrs->pseudo.pac; + return _UVRSR_OK; + default: return _UVRSR_FAILED; } @@ -206,6 +220,10 @@ _Unwind_VRS_Result _Unwind_VRS_Set (_Unwind_Context *context, case _UVRSC_WMMXC: return _UVRSR_NOT_IMPLEMENTED; + case _UVRSC_PAC: + vrs->pseudo.pac = *(_uw *) valuep; + return _UVRSR_OK; + default: return _UVRSR_FAILED; } @@ -246,6 +264,14 @@ _Unwind_VRS_Result _Unwind_VRS_Pop (_Unwind_Context *context, } return _UVRSR_OK; + case _UVRSC_PAC: + { + if (discriminator != 0) + return _UVRSR_FAILED; + vrs->pseudo.pac = *(_uw *) vrs->core.r[R_SP]; + return _UVRSR_OK; + } + case _UVRSC_VFP: { _uw start = discriminator >> 16;