From patchwork Fri Jun 12 13:29:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39583 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 A95A8395B0B5; Fri, 12 Jun 2020 13:30:09 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130085.outbound.protection.outlook.com [40.107.13.85]) by sourceware.org (Postfix) with ESMTPS id D2D79395B084 for ; Fri, 12 Jun 2020 13:30:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D2D79395B084 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=nUtjZ8MxE/HoT2ciyvCRhauxY1gID6XJ0NF2gGk+He8=; b=6SJZVlDCAL33rlOTqM+nYYZmj6ogPWe10nsyzhOFgkSVrXeFO8s0J8ejkhCchVmy/vHUKMfV9WldnlgRj1paU8gPq8XbQUB5/TvBnO+sfgj71qWzeW4YWAUdZtk4ryUR1XqH0d27EVNl+ZO25CE+YStMWF8gWbUzrC9jMqryxE8= Received: from AM6P194CA0006.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::19) by VI1PR08MB4160.eurprd08.prod.outlook.com (2603:10a6:803:ea::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18; Fri, 12 Jun 2020 13:30:01 +0000 Received: from AM5EUR03FT053.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:90:cafe::d5) by AM6P194CA0006.outlook.office365.com (2603:10a6:209:90::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18 via Frontend Transport; Fri, 12 Jun 2020 13:30:01 +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 AM5EUR03FT053.mail.protection.outlook.com (10.152.16.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18 via Frontend Transport; Fri, 12 Jun 2020 13:30:01 +0000 Received: ("Tessian outbound 3e82c366635e:v59"); Fri, 12 Jun 2020 13:30:01 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 268cbc71ec08505a X-CR-MTA-TID: 64aa7808 Received: from 39c482356b9e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 22BB592A-0ADF-4AD4-A72D-CB7CFFC4BDF6.1; Fri, 12 Jun 2020 13:29:55 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 39c482356b9e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 12 Jun 2020 13:29:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a19Isn0VaAC1iJN46b6AWtG8NeTLTxgKljqMXH+3Oda5tlaJPGlZ/Zc/RnQd6cQUDbyfiS9AiTueQXvVZpRdpn6xzY8X+UQBTQpiuWJxXkfOyHhzf0BR0886ANzfIUBfiuTcfDE6+xGAVDCW5PxlB8x46vpJ3uwSzr9nl2P4QM562Y6gHhY3WrFzM39R8Qsaxt+ArvB7+a0PyrqZ6ECbeSbAhw4vN7Pv7CBS437CsWpfGdR50s1nAaF/hrH6W7TYZLgnUWFXtM/o/r/WFX50w52AtKK/ee+Cs1WNNZAtaL//9g2E07q/NQ9X+H0SrFoY9sa+ZgBbSVB9LvNuQiLH8A== 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=nUtjZ8MxE/HoT2ciyvCRhauxY1gID6XJ0NF2gGk+He8=; b=VQF0iwQYhjEnYM6TFDP9Rl5dkc+h13xVMMN+xLHX3Zjjh08zeGDIxA5aXHYK/BwFd4yyDm5o1Nfv3MOwhN+3hyTuUpJPrmgZ5VtpZFTpigZPKgIEg0wpbZbhpC6SY1wgdczdQJZ10wPqFR9mhTMKjJ5PbdLQn4yDru0ovuIL6QPJiDKmGVY/IOPzfalXPh+sclD99C1fy6HsYqCgKJd7/S+2cqaKdkvarsRxb8T1/+rEErf47MHK2+h3YwLbGXdxaU1iiyw5vdBhkdEvTSqiSkuJHdOtKsXZdoAP4Xx3+Gr11tEuxRsNveSFnScnVS1Dh8AI0aB3TwytcLU9AyVxbA== 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=nUtjZ8MxE/HoT2ciyvCRhauxY1gID6XJ0NF2gGk+He8=; b=6SJZVlDCAL33rlOTqM+nYYZmj6ogPWe10nsyzhOFgkSVrXeFO8s0J8ejkhCchVmy/vHUKMfV9WldnlgRj1paU8gPq8XbQUB5/TvBnO+sfgj71qWzeW4YWAUdZtk4ryUR1XqH0d27EVNl+ZO25CE+YStMWF8gWbUzrC9jMqryxE8= 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 AM6PR08MB3912.eurprd08.prod.outlook.com (2603:10a6:20b:86::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.24; Fri, 12 Jun 2020 13:29:54 +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.3088.022; Fri, 12 Jun 2020 13:29:54 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v4 09/12] aarch64: Add pac-ret support to assembly files Date: Fri, 12 Jun 2020 14:29:27 +0100 Message-Id: <28395b80fdaf7a2394a3d8495d37dd1969acae39.1591899092.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR03CA0017.namprd03.prod.outlook.com (2603:10b6:806:20::22) 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 SA9PR03CA0017.namprd03.prod.outlook.com (2603:10b6:806:20::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Fri, 12 Jun 2020 13:29:53 +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: 00ee6655-bda1-4f69-40e6-08d80ed4b587 X-MS-TrafficTypeDiagnostic: AM6PR08MB3912:|VI1PR08MB4160: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-Forefront-PRVS: 0432A04947 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: B8q94akbc30YjyV2NWNWWmidvOk7ZP7/pj9RkZyQTFd6LYeumFj1uMKWEMj2mplwPTxmlWjX5SzgIpuQDdvxXtCo/8a1H8Ga2O1X403MBp/OXsfniaONwCQ5RP3l5Mu2yucE5BdQn+LldhILGVXaxjaltzrZk9Dokf0L2QcpndgIHlb5+Of3YreWblkY6GiebKsFcIE7Ieje6N0TMDFKl40N34urXRbSBSZ6FIdCXhoogwBjzMFuxmAxgPdpKKsnasgE84xZG7zxwm/PLLPyIto/6XHVAWzvUduumy1f40scHX/MVbsvRFt6BfUHTouhvmks0QLbJ737blpmNva2Ylm0Cidi9Qoz+sUs85rEDsDdqnZ/n7CTYc1M9Kb2836agapzFkkca1/S7gfhQu9mrTNqdlxZle4A6wyssC2LXAU= 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)(346002)(396003)(39860400002)(366004)(956004)(66476007)(66556008)(66946007)(6506007)(26005)(6512007)(5660300002)(6916009)(6666004)(2906002)(8676002)(6486002)(52116002)(8936002)(44832011)(186003)(16526019)(36756003)(2616005)(316002)(86362001)(83380400001)(69590400007)(478600001)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hwV2BPrEr3XWYbqvRngTVm7dycd9pMoAt9w94FXt3VQld0ktoHcqaFy3oMtoAhLmuq8hboQa9p/m2URWejecnso7IytQc4oPFiRswH6D+Rdqwxst2zBiHYEpUNGKflq3m1a/4ndZ7eoDxd9SlfH7UYLsKD+pbfe38+5ASQ2epAoivFwLdXuwuvVgF+LrD6MDyFEY9c9t5qOtnlhXY2tNv55rRwsgIoQZMooeeOQGq/XxLxQS5FsdzoljcTCl/dyU/qdKChKTLsOXzxzc9y1oVW21vFeAksohnA/Zi2xlBpbDKXiyuBQtNYw111qlxpq7GJKDc1kyfI/ZT6/v/pPSCagS3oIJqHHBEJEsg0bHIXnLQkexIWT5Br9pomzU5qjAelWpieD8JtIv69FRFpjrhQr1R8mON62vTui8tNJOsAEjEpFY9BZuL1boJe4WBn8MjcpULY+8QWIAwF+vCbHLp3dKGWTxJApLFbmf36v+HmI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3912 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: AM5EUR03FT053.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)(396003)(346002)(39860400002)(136003)(376002)(46966005)(316002)(6512007)(86362001)(8936002)(47076004)(336012)(69590400007)(44832011)(2616005)(6486002)(82740400003)(82310400002)(956004)(8676002)(16526019)(70206006)(186003)(36906005)(70586007)(5660300002)(6506007)(81166007)(83380400001)(6666004)(36756003)(2906002)(478600001)(6916009)(356005)(26005)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 4703be33-ebc2-4704-82e8-08d80ed4b0f1 X-Forefront-PRVS: 0432A04947 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: akPozwL9rlnXqj1EWHAH4XiDu3crF44CXXa5Dxe3uIpLw7XjafDv/LNGCYU5H1kulAKHRK9NeZwZe/SDyH9PDFzdJt+fEodji9b37/EWN+LGdHwW+rByn74LkApgES3wHv8T/dKUxsXrqBCIg8njwToii6rlz7NK+b4LIlUk48DuFK+xECQKX/h2J/tf3XIuHEX3peeYgyLCRuTSwyJ6sAnyQ7+TU6bxLn8B01Qoy1k9J611cpt/gzFrnwjLy8G0sPX9r4f339BcUJvUB9W4+bZ4H6JaLprHj4N7S/D5NQDIriY3TrZ36OVn+SOxqS7462FVd9GFCjHaLkouL3VSZJQknixcgLKTMY0RDJSXFinlZXQ3E9Hpn3GjWuSsXNJFvLHBTG/WM2wg8I9ymwaQa3BrY6+I44SFJqWrAayB6x6JIak8vF+1V5xAO2s56YnyK/slfPIP0zi9ja3uItwH5w== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2020 13:30:01.3761 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00ee6655-bda1-4f69-40e6-08d80ed4b587 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: VI1PR08MB4160 X-Spam-Status: No, score=-17.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Use return address signing in assembly files for functions that save LR when pac-ret is enabled in the compiler. The GNU property note for PAC-RET is not meaningful to the dynamic linker so it is not strictly required, but it may be used to track the security property of binaries. (The PAC-RET property is only set if BTI is set too because BTI implies working GNU property support.) Reviewed-by: Adhemerval Zanella --- sysdeps/aarch64/crti.S | 8 ++++++++ sysdeps/aarch64/crtn.S | 6 ++++++ sysdeps/aarch64/dl-tlsdesc.S | 8 ++++++++ sysdeps/aarch64/dl-trampoline.S | 18 ++++++++++++++++++ sysdeps/aarch64/sysdep.h | 8 +++++++- 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/sysdeps/aarch64/crti.S b/sysdeps/aarch64/crti.S index c346bcad72..c486e9ca44 100644 --- a/sysdeps/aarch64/crti.S +++ b/sysdeps/aarch64/crti.S @@ -75,7 +75,11 @@ call_weak_fn: .hidden _init .type _init, %function _init: +#if HAVE_AARCH64_PAC_RET + PACIASP +#else BTI_C +#endif stp x29, x30, [sp, -16]! mov x29, sp #if PREINIT_FUNCTION_WEAK @@ -90,6 +94,10 @@ _init: .hidden _fini .type _fini, %function _fini: +#if HAVE_AARCH64_PAC_RET + PACIASP +#else BTI_C +#endif stp x29, x30, [sp, -16]! mov x29, sp diff --git a/sysdeps/aarch64/crtn.S b/sysdeps/aarch64/crtn.S index 0c1ef112c2..d21c21c203 100644 --- a/sysdeps/aarch64/crtn.S +++ b/sysdeps/aarch64/crtn.S @@ -41,8 +41,14 @@ .section .init,"ax",%progbits ldp x29, x30, [sp], 16 +#if HAVE_AARCH64_PAC_RET + AUTIASP +#endif RET .section .fini,"ax",%progbits ldp x29, x30, [sp], 16 +#if HAVE_AARCH64_PAC_RET + AUTIASP +#endif RET diff --git a/sysdeps/aarch64/dl-tlsdesc.S b/sysdeps/aarch64/dl-tlsdesc.S index 9d96c8632a..db8a064322 100644 --- a/sysdeps/aarch64/dl-tlsdesc.S +++ b/sysdeps/aarch64/dl-tlsdesc.S @@ -183,6 +183,10 @@ _dl_tlsdesc_dynamic: callee will trash. */ /* Save the remaining registers that we must treat as caller save. */ +# if HAVE_AARCH64_PAC_RET + PACIASP + cfi_window_save +# endif # define NSAVEXREGPAIRS 8 stp x29, x30, [sp,#-16*NSAVEXREGPAIRS]! cfi_adjust_cfa_offset (16*NSAVEXREGPAIRS) @@ -233,6 +237,10 @@ _dl_tlsdesc_dynamic: cfi_adjust_cfa_offset (-16*NSAVEXREGPAIRS) cfi_restore (x29) cfi_restore (x30) +# if HAVE_AARCH64_PAC_RET + AUTIASP + cfi_window_save +# endif b 1b cfi_endproc .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic diff --git a/sysdeps/aarch64/dl-trampoline.S b/sysdeps/aarch64/dl-trampoline.S index 2cbfa81434..794876fffa 100644 --- a/sysdeps/aarch64/dl-trampoline.S +++ b/sysdeps/aarch64/dl-trampoline.S @@ -127,7 +127,12 @@ _dl_runtime_resolve: cfi_startproc .align 2 _dl_runtime_profile: +# if HAVE_AARCH64_PAC_RET + PACIASP + cfi_window_save +# else BTI_C +# endif /* AArch64 we get called with: ip0 &PLTGOT[2] ip1 temp(dl resolver entry point) @@ -239,8 +244,17 @@ _dl_runtime_profile: cfi_restore(x29) cfi_restore(x30) +# if HAVE_AARCH64_PAC_RET + add sp, sp, SF_SIZE + cfi_adjust_cfa_offset (-SF_SIZE) + AUTIASP + cfi_window_save + add sp, sp, 16 + cfi_adjust_cfa_offset (-16) +# else add sp, sp, SF_SIZE + 16 cfi_adjust_cfa_offset (- SF_SIZE - 16) +# endif /* Jump to the newly found address. */ br ip0 @@ -287,6 +301,10 @@ _dl_runtime_profile: /* LR from within La_aarch64_reg */ ldr lr, [x29, #OFFSET_RG + DL_OFFSET_RG_LR] cfi_restore(lr) +# if HAVE_AARCH64_PAC_RET + /* Note: LR restored from La_aarch64_reg has no PAC. */ + cfi_window_save +# endif mov sp, x29 cfi_def_cfa_register (sp) ldr x29, [x29, #0] diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h index 4664329d3a..500c272745 100644 --- a/sysdeps/aarch64/sysdep.h +++ b/sysdeps/aarch64/sysdep.h @@ -45,6 +45,10 @@ #define BTI_C hint 34 #define BTI_J hint 36 +/* Return address signing support (pac-ret). */ +#define PACIASP hint 25 +#define AUTIASP hint 29 + /* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ #define FEATURE_1_AND 0xc0000000 #define FEATURE_1_BTI 1 @@ -66,7 +70,9 @@ /* Add GNU property note with the supported features to all asm code where sysdep.h is included. */ -#if HAVE_AARCH64_BTI +#if HAVE_AARCH64_BTI && HAVE_AARCH64_PAC_RET +GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC) +#elif HAVE_AARCH64_BTI GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI) #endif