From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F863C10F25 for ; Mon, 9 Mar 2020 19:04:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C321215A4 for ; Mon, 9 Mar 2020 19:04:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PduT3iQj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C321215A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aB7ibKP9MgOkVvch8Dibpg9U44+2aiz9hkuF2/g+ESA=; b=PduT3iQjt+rY+S nkt6SmHAJv5mmcD0OoEFdi0l982azx8KVAaH7ppQ6o1tTGxrLnP+0MIvYQfXYsPlTEyWT94UzAslB r67SjagnCBLzr6f2DT+d7/2iZ6rMXrxBLLyWZDENGTShuLSHtfvx09hpBBdJqsPNTTO472z++Ntxo q69cVOjcYwSkdQ1pdhKD0a5x1iTETuU1/FDaw9XYQlkcQyoeQ41wv6WetSWjiXN+N29KZT/7gD4cw jkHqaMJZhxZTB1kKpdOOWBvBKwq2hBCWEY46sKU8kE0P/5N3zQp4NB75OA5XPgelNAvPR1NiKo0oZ dG6ugEmM5aaWskMpV3Bg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jBNh3-0006X3-Jw; Mon, 09 Mar 2020 19:04:01 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jBNgz-0006NV-U6 for linux-arm-kernel@lists.infradead.org; Mon, 09 Mar 2020 19:03:59 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DA5431FB; Mon, 9 Mar 2020 12:03:56 -0700 (PDT) Received: from [10.1.196.105] (eglon.cambridge.arm.com [10.1.196.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 120E63F67D; Mon, 9 Mar 2020 12:03:54 -0700 (PDT) Subject: Re: [PATCH v6 13/18] arm64: unwind: strip PAC from kernel addresses To: Amit Daniel Kachhap References: <1583476525-13505-1-git-send-email-amit.kachhap@arm.com> <1583476525-13505-14-git-send-email-amit.kachhap@arm.com> From: James Morse Message-ID: Date: Mon, 9 Mar 2020 19:03:53 +0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <1583476525-13505-14-git-send-email-amit.kachhap@arm.com> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200309_120358_059712_B5D86D47 X-CRM114-Status: GOOD ( 15.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Kees Cook , Suzuki K Poulose , Catalin Marinas , Kristina Martsenko , Dave Martin , Mark Brown , Ramana Radhakrishnan , Vincenzo Frascino , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Amit, On 06/03/2020 06:35, Amit Daniel Kachhap wrote: > From: Mark Rutland > > When we enable pointer authentication in the kernel, LR values saved to > the stack will have a PAC which we must strip in order to retrieve the > real return address. > > Strip PACs when unwinding the stack in order to account for this. This patch had me looking at the wider pointer-auth + ftrace interaction... > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index a336cb1..b479df7 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -14,6 +14,7 @@ > #include > > #include > +#include > #include > #include > > @@ -101,6 +102,8 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) There is an earlier reader of frame->pc: | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | if (tsk->ret_stack && | (frame->pc == (unsigned long)return_to_handler)) { Which leads down the rat-hole of: does this need ptrauth_strip_insn_pac()? The version of GCC on my desktop supports patchable-function-entry, the function pre-amble has two nops for use by ftrace[0]. This means if prepare_ftrace_return() re-writes the saved LR, it does it before the caller paciasp's it. I think that means if you stack-trace from a function that had been hooked by the function_graph_tracer, you will see the LR with a PAC, meaning the above == won't match. The version of LLVM on my desktop however doesn't support patchable-function-entry, it uses _mcount() to do the ftrace stuff[1]. Here prepare_ftrace_return() overwrites a paciasp'd LR with one that isn't, which will fail. Could the ptrauth_strip_insn_pac() call move above the CONFIG_FUNCTION_GRAPH_TRACER block, and could we add something like: | depends on (!FTRACE || HAVE_DYNAMIC_FTRACE_WITH_REGS) to the Kconfig to prevent both FTRACE and PTR_AUTH being enabled unless the compiler has support for patchable-function-entry? > } > #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ > > + frame->pc = ptrauth_strip_insn_pac(frame->pc); > + > /* > * Frames created upon entry from EL0 have NULL FP and PC values, so > * don't bother reporting these. Frames created by __noreturn functions Thanks, James [0] gcc (Debian 9.2.1-28) 9.2.1 20200203 0000000000000048 : 48: d503201f nop 4c: d503201f nop 50: 90000002 adrp x2, 0 <__icache_flags> 54: d503233f paciasp 58: a9bf7bfd stp x29, x30, [sp, #-16]! 5c: 910003fd mov x29, sp 60: f9400044 ldr x4, [x2] 64: 36000124 tbz w4, #0, 88 : 0: d503233f paciasp 4: a9be4ff4 stp x20, x19, [sp, #-32]! 8: a9017bfd stp x29, x30, [sp, #16] c: 910043fd add x29, sp, #0x10 10: aa0103f4 mov x20, x1 14: aa0003f3 mov x19, x0 18: 94000000 bl 0 <_mcount> 1c: 90000008 adrp x8, 0 <__icache_flags> 20: f9400108 ldr x8, [x8] 24: 370000a8 tbnz w8, #0, 38 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel