From patchwork Wed Aug 7 12:35:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 33988 Received: (qmail 126247 invoked by alias); 7 Aug 2019 12:35:52 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 125263 invoked by uid 89); 7 Aug 2019 12:35:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=45011 X-HELO: EUR04-DB3-obe.outbound.protection.outlook.com Received: from mail-eopbgr60072.outbound.protection.outlook.com (HELO EUR04-DB3-obe.outbound.protection.outlook.com) (40.107.6.72) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Aug 2019 12:35:47 +0000 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=C6B2or6XE5tG5PQSSaF7MXAp6PMr33BqpkE5TfKLPxI=; b=bf0Wwqp5fymguq7phjMDsUfq2QLTcNd/3c9gqvldic3Y+vEsV4fZpkjDPdkjFfvejmLF7rTOgPAt9BFp/SU62xB3PtxpmMvOO1lHMresKwrtpqBEKjhbZnNcy2cavbhOBxqnio1z3E7y6SQMLbgmmZ0MyfOfKJCp8wNcBgYePkU= Received: from VI1PR08CA0204.eurprd08.prod.outlook.com (2603:10a6:800:d2::34) by AM0PR08MB4948.eurprd08.prod.outlook.com (2603:10a6:208:163::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.15; Wed, 7 Aug 2019 12:35:42 +0000 Received: from AM5EUR03FT028.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::202) by VI1PR08CA0204.outlook.office365.com (2603:10a6:800:d2::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2157.15 via Frontend Transport; Wed, 7 Aug 2019 12:35:42 +0000 Authentication-Results: spf=temperror (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=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT028.mail.protection.outlook.com (10.152.16.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2052.18 via Frontend Transport; Wed, 7 Aug 2019 12:35:40 +0000 Received: ("Tessian outbound 1e6e633a5b56:v26"); Wed, 07 Aug 2019 12:35:40 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 6220151c99118587 X-CR-MTA-TID: 64aa7808 Received: from 89ddbeaad2a8.1 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.1.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id F81B6C9E-6FC1-43C5-885E-551CA9E34588.1; Wed, 07 Aug 2019 12:35:34 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp2054.outbound.protection.outlook.com [104.47.1.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 89ddbeaad2a8.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 07 Aug 2019 12:35:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IHtBa+x+8/K2owWkyFnJY/6fwBv6dz50g6Ro3TbBvG+SYLPxDw2M9ruT1dJEzz2tul2tgsiOdT4pyuRBEIW0/8rYvt8mi1H4/jnf3mU8/YtjzTNxKmHeQ8/oDsvS6KfXcY7irZdru/97kLOX+cOgTxRbgfnabARvEOwkOaWA62qVF9jgySoGJgQVHZUn28oky6XuHFV8RfEXZibVRvcBim/0giCHrQLlJKMb35AdU7SHQvyduMBWhcW/6EQbWWUw/HsFMQ5mGegXbHTtxHmqNbG6MoG/jpCWM+EmsTY1ojK/L67X/s6o1LhFzc8s/stlIbPFfNd9oBb+o+TiPrKvlQ== 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=C6B2or6XE5tG5PQSSaF7MXAp6PMr33BqpkE5TfKLPxI=; b=CmK5TJRAhE3obtxHH3uLASOA8YRaVilq1VvlxPgLeFjCyCiFVh56roM2kIPgvZVPRCYMP5+lIwx1KG+Q5k7UMwcf+RW438lwGVKc8ceINviffMwZ3HMYl35isK7Amk6IXegPA0jmiL7gOB4tX9tsieinmx95lpS/jLSyqcHM9UWDGvvVwjBw3Hgb8y1eRLnXrfqRNt1YsMMlN29XM120us9PWLdjOGXmCOZi0H9plt1gHNNGiaBPh4e80onW0SqIqPhJk8fkTVQzxeNQeDWXB9lzd533jJs3KetW6/iFXEo/tAOspnw9xgs1xfR6R2sfoM0Zgkl0RvMsPfW0vTbvNQ== 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=C6B2or6XE5tG5PQSSaF7MXAp6PMr33BqpkE5TfKLPxI=; b=bf0Wwqp5fymguq7phjMDsUfq2QLTcNd/3c9gqvldic3Y+vEsV4fZpkjDPdkjFfvejmLF7rTOgPAt9BFp/SU62xB3PtxpmMvOO1lHMresKwrtpqBEKjhbZnNcy2cavbhOBxqnio1z3E7y6SQMLbgmmZ0MyfOfKJCp8wNcBgYePkU= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.227.22) by DB6PR0802MB2392.eurprd08.prod.outlook.com (10.172.251.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2136.20; Wed, 7 Aug 2019 12:35:33 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::5ce5:cf42:42dd:eda1]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::5ce5:cf42:42dd:eda1%6]) with mapi id 15.20.2136.018; Wed, 7 Aug 2019 12:35:33 +0000 From: Alan Hayward To: Tom Tromey CC: "gdb-patches@sourceware.org" , nd Subject: Re: [PATCH V2] AArch64 pauth: Indicate unmasked addresses in backtrace Date: Wed, 7 Aug 2019 12:35:33 +0000 Message-ID: References: <20190730144123.11135-1-alan.hayward@arm.com> <87imra9snt.fsf@tromey.com> In-Reply-To: <87imra9snt.fsf@tromey.com> Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; X-Microsoft-Antispam-Untrusted: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:DB6PR0802MB2392; x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:2449;OLM:2449; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(346002)(396003)(136003)(366004)(376002)(39860400002)(54534003)(51914003)(199004)(189003)(4326008)(476003)(2616005)(6506007)(86362001)(486006)(102836004)(5660300002)(57306001)(305945005)(11346002)(66446008)(14454004)(7736002)(446003)(66476007)(76116006)(66556008)(64756008)(66946007)(71190400001)(6246003)(14444005)(256004)(53546011)(91956017)(71200400001)(76176011)(53936002)(81156014)(99286004)(478600001)(316002)(6116002)(33656002)(81166006)(3846002)(66066001)(8936002)(50226002)(6916009)(8676002)(26005)(6486002)(54906003)(68736007)(229853002)(36756003)(186003)(25786009)(2906002)(6436002)(6512007); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0802MB2392; H:DB6PR0802MB2133.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info-Original: i0P5Gox3s0P4yjBp6ED7Ax6jPYN0vQDbtx8ER4a1WVklVfpAWkDUVigyyAWNoj5gLscJgL+05rxDJ51HUp7xjIVNPoX9bALrudFm4qXcDAdbzZp5zF3lUV4IiV5ZfAb6M9tW4jXuSZpJrUm3XwQv28fklt5UIvA4DGkwuWhhu49a8bOyo96AqfLy9tehvQAqYlqF6o5PlfkSQYF18Edtm6vqfuv4Nrp2kUQy0OD5aUh3LbRV9AgHFNzGVTs2zpDAsHpiVQJLbL3oE8FFuM3rH5DUJbxrzxPlPn+yeO15a1CedbPecP4i28AVkicyCT2jZ4igCdp1mWD4/vIv0nD+rL/Dk/jk9Z7+kSMiKRuVVSWWywnuXIUqLl5rbBnN7oYxqAqpXEfIXSdW4NsyHZZ53q5Ix8hNx7r1Fsl1p9NFYNM= Content-ID: <6642634E4CC72F49AA4A7233C6B3136D@eurprd08.prod.outlook.com> MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Return-Path: Alan.Hayward@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: bb95688f-29b4-41bf-701d-08d71b33bd6f X-IsSubscribed: yes > On 6 Aug 2019, at 17:15, Tom Tromey wrote: > >>>>>> "Alan" == Alan Hayward writes: > > Alan> Armv8.3-a Pointer Authentication causes the function return address to be > Alan> obfuscated on entry to some functions. GDB must unmask the link register in > Alan> order to produce a backtrace. > > Alan> The following patch adds markers of [PAC] to the bracktrace, to indicate > Alan> which addresses needed unmasking. This includes the backtrace when using MI. > > Thanks for the patch. I don't think this was re-reviewed? It hadn’t been - so thanks! > > Alan> --- a/gdb/frame.c > Alan> +++ b/gdb/frame.c > Alan> @@ -124,6 +124,8 @@ struct frame_info > Alan> struct { > Alan> enum cached_copy_status status; > Alan> CORE_ADDR value; > Alan> + /* Did VALUE require unmasking when being read. */ > Alan> + bool masked; > Alan> } prev_pc; > > I think putting the new field between "status" and "value" will pack the > structure a bit better. It doesn’t look as nice when switched, but agreed and done. > > Alan> +bool > Alan> +get_frame_pc_masked (struct frame_info *frame) > > Maybe make the parameter "const"? I see there isn't much use of const > in frame.h, but on the other hand, that's probably just historical and > not required. > Done. > Otherwise the patch looks fine to me. It is ok. I'd prefer those > changes but if you'd prefer not, a note to that effect is fine. > > thanks, > Tom Patch pushed and posted below for reference. Alan. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 82e0819c13..bacf5d7636 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2019-08-07 Alan Hayward + + * NEWS: Expand the Pointer Authentication entry. + * aarch64-tdep.c (aarch64_frame_unmask_address): Rename from this. + (aarch64_frame_unmask_lr): ... to this. + (aarch64_prologue_prev_register, aarch64_dwarf2_prev_register): + Call aarch64_frame_unmask_lr. + * frame.c (struct frame_info): Add "masked" variable. + (frame_set_previous_pc_masked) (frame_get_pc_masked): New functions. + (fprint_frame): Check for masked pc. + * frame.h (frame_set_previous_pc_masked) (frame_get_pc_masked): New + declarations. + * python/py-framefilter.c (py_print_frame): Check for masked pc. + * stack.c (print_frame): Check for masked pc. + 2019-08-06 Tom Tromey * stabsread.c (patch_block_stabs, read_one_struct_field) diff --git a/gdb/NEWS b/gdb/NEWS index b4c59e4410..fa01adf6e8 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -16,7 +16,9 @@ architectures require kernel changes. TLS is not yet supported for amd64 and i386 process core dumps. -* Support for Pointer Authentication on AArch64 Linux. +* Support for Pointer Authentication (PAC) on AArch64 Linux. Return + addresses that required unmasking are shown in the backtrace with the + postfix [PAC]. * Two new convenience functions $_cimag and $_creal that extract the imaginary and real parts respectively from complex numbers. diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index e23cc3f956..9b6324f0fc 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -250,13 +250,13 @@ class instruction_reader : public abstract_instruction_reader } // namespace -/* If address signing is enabled, mask off the signature bits from ADDR, using - the register values in THIS_FRAME. */ +/* If address signing is enabled, mask off the signature bits from the link + register, which is passed by value in ADDR, using the register values in + THIS_FRAME. */ static CORE_ADDR -aarch64_frame_unmask_address (struct gdbarch_tdep *tdep, - struct frame_info *this_frame, - CORE_ADDR addr) +aarch64_frame_unmask_lr (struct gdbarch_tdep *tdep, + struct frame_info *this_frame, CORE_ADDR addr) { if (tdep->has_pauth () && frame_unwind_register_unsigned (this_frame, @@ -265,6 +265,9 @@ aarch64_frame_unmask_address (struct gdbarch_tdep *tdep, int cmask_num = AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base); CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame, cmask_num); addr = addr & ~cmask; + + /* Record in the frame that the link register required unmasking. */ + set_frame_previous_pc_masked (this_frame); } return addr; @@ -952,7 +955,7 @@ aarch64_prologue_prev_register (struct frame_info *this_frame, if (tdep->has_pauth () && trad_frame_value_p (cache->saved_regs, tdep->pauth_ra_state_regnum)) - lr = aarch64_frame_unmask_address (tdep, this_frame, lr); + lr = aarch64_frame_unmask_lr (tdep, this_frame, lr); return frame_unwind_got_constant (this_frame, prev_regnum, lr); } @@ -1119,7 +1122,7 @@ aarch64_dwarf2_prev_register (struct frame_info *this_frame, { case AARCH64_PC_REGNUM: lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM); - lr = aarch64_frame_unmask_address (tdep, this_frame, lr); + lr = aarch64_frame_unmask_lr (tdep, this_frame, lr); return frame_unwind_got_constant (this_frame, regnum, lr); default: diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 6faf5f359d..702bb7c7a0 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2019-08-07 Alan Hayward + + * gdb.texinfo (AArch64 Pointer Authentication): New subsection. + 2019-08-05 Christian Biesinger * python.texi (Blocks In Python): Document dictionary access on blocks. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 89b1eda2c1..7f8c0aff1c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -24390,6 +24390,14 @@ but the lengths of the @code{z} and @code{p} registers will not change. This is a known limitation of @value{GDBN} and does not affect the execution of the target process. +@subsubsection AArch64 Pointer Authentication. +@cindex AArch64 Pointer Authentication. + +When @value{GDBN} is debugging the AArch64 architecture, and the program is +using the v8.3-A feature Pointer Authentication (PAC), then whenever the link +register @code{$lr} is pointing to an PAC function it's value will be masked. +When GDB prints a backtrace, any addresses that required unmasking will be +postfixed with the marker [PAC]. @node i386 @subsection x86 Architecture-specific Issues diff --git a/gdb/frame.c b/gdb/frame.c index adac24f68c..b62fd5cd85 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -123,6 +123,8 @@ struct frame_info /* Cached copy of the previous frame's resume address. */ struct { enum cached_copy_status status; + /* Did VALUE require unmasking when being read. */ + bool masked; CORE_ADDR value; } prev_pc; @@ -161,6 +163,25 @@ struct frame_info const char *stop_string; }; +/* See frame.h. */ + +void +set_frame_previous_pc_masked (struct frame_info *frame) +{ + frame->prev_pc.masked = true; +} + +/* See frame.h. */ + +bool +get_frame_pc_masked (const struct frame_info *frame) +{ + gdb_assert (frame->next != nullptr); + gdb_assert (frame->next->prev_pc.status == CC_VALUE); + + return frame->next->prev_pc.masked; +} + /* A frame stash used to speed up frame lookups. Create a hash table to stash frames previously accessed from the frame cache for quicker subsequent retrieval. The hash table is emptied whenever @@ -429,8 +450,11 @@ fprint_frame (struct ui_file *file, struct frame_info *fi) if (fi->next == NULL || fi->next->prev_pc.status == CC_UNKNOWN) fprintf_unfiltered (file, ""); else if (fi->next->prev_pc.status == CC_VALUE) - fprintf_unfiltered (file, "%s", - hex_string (fi->next->prev_pc.value)); + { + fprintf_unfiltered (file, "%s", hex_string (fi->next->prev_pc.value)); + if (fi->next->prev_pc.masked) + fprintf_unfiltered (file, "[PAC]"); + } else if (fi->next->prev_pc.status == CC_NOT_SAVED) val_print_not_saved (file); else if (fi->next->prev_pc.status == CC_UNAVAILABLE) diff --git a/gdb/frame.h b/gdb/frame.h index ccc285005a..fdb401d84f 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -949,4 +949,13 @@ extern const gdb::option::option_def set_backtrace_option_defs[2]; /* The values behind the global "set backtrace ..." settings. */ extern set_backtrace_options user_set_backtrace_options; +/* Mark that the PC value is masked for the previous frame. */ + +extern void set_frame_previous_pc_masked (struct frame_info *frame); + +/* Get whether the PC value is masked for the given frame. */ + +extern bool get_frame_pc_masked (const struct frame_info *frame); + + #endif /* !defined (FRAME_H) */ diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index a2a96ac0d3..d805ec68f2 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -901,6 +901,8 @@ py_print_frame (PyObject *filter, frame_filter_flags flags, { annotate_frame_address (); out->field_core_addr ("addr", gdbarch, address); + if (get_frame_pc_masked (frame)) + out->field_string ("pac", " [PAC]"); annotate_frame_address_end (); out->text (" in "); } diff --git a/gdb/stack.c b/gdb/stack.c index c68b3876d3..0859815baf 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1298,7 +1298,11 @@ print_frame (const frame_print_options &fp_opts, { annotate_frame_address (); if (pc_p) - uiout->field_core_addr ("addr", gdbarch, pc); + { + uiout->field_core_addr ("addr", gdbarch, pc); + if (get_frame_pc_masked (frame)) + uiout->field_string ("pac", " [PAC]"); + } else uiout->field_string ("addr", "", ui_out_style_kind::ADDRESS);