Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp138705ybc; Mon, 18 Nov 2019 22:01:23 -0800 (PST) X-Google-Smtp-Source: APXvYqwmu5EXnE0softFPtuuZFb8WBSBnOW5s/v1ben14YxoKnm5QNivMrfi5px8SpMq12KRVq50 X-Received: by 2002:a1c:7215:: with SMTP id n21mr3512587wmc.129.1574143283279; Mon, 18 Nov 2019 22:01:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574143283; cv=none; d=google.com; s=arc-20160816; b=kdavg7HaoVK1F5roo088rN8pr635YzAndyNtNpcObh/UWnPQFq7QgCpZSEqObaPwPS z/IrDpc0FzfzIpyb3WwfXl6nICc5M6c2UF2E7GkeqbBeMY7SofZJro7w3HkyDHqP+8Xo KdCO8UVDyjWzBoX2Z9mHr3igfjuMZWe+7EXgNH/xYYHa5WXMdgBhioWJ3C8dPjE29Eou dQTjb6la8UvnDLvwJsIS3A4U4ZJj2PBXeE84L+oB7d/JOEz+2o2ZEFdYS2OV2S/34Y+T 0MzM6IM2CjL8dfemg+KaRQvZC+x3q/IkME6CPhIDabItAeNvkw5y041QjWEirLR+INXx 18WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Tanc7GF3v7UARB/e2vi4fwROEPb9OmnhjWjo87AIDiQ=; b=v/Gbpq3s04+x5mi5+3/wIXeWI+tYy/ToLTLaqFeL8766ETJTaO9v06irzvni05A2AC FM/AEZ7eP/eM3zbRToiT7eOoJqpReWGXniVFQGUjUgQrF6wDM4ANRprrv0Cef84TqIHx ErIAv7f6ogT3d+yNYr8DAR9DlWMugu/wQr8cnWxGwJEM9lkSNQ7C3fGESGuIZ4/ojlkA TqdAUQTtZm15skK4ddWxy2waw6sUpXx2HhRbjNypIQRNZZU9b77gl0S5dc6oGAA0a/pd 8sH7BephwIL/iDlwNJ7RFtKsrFsdN8PGUpKlDfhzwsKpnTnc8u662P+JLG2wQiENTx8X /OCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=in8DGZx7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x95si9760345ede.192.2019.11.18.22.00.57; Mon, 18 Nov 2019 22:01:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=in8DGZx7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731716AbfKSF6q (ORCPT + 99 others); Tue, 19 Nov 2019 00:58:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:45616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731414AbfKSFtB (ORCPT ); Tue, 19 Nov 2019 00:49:01 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 216AA20862; Tue, 19 Nov 2019 05:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574142540; bh=fyEovHonIi28L8n/cm3MK/odCyRSRZIyQ7OjuLbLtdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=in8DGZx7cCrl1yDixAK9lWA9kAe95AUIKFbRDvQLMcUXAUMvuJareo94QR9kht/HL ZGegzzea5jdrNzttVU/bBuUZEyJjZeiGrbI3oiJqvjkvwP6pCq20A+QNdkYfv5f0/o DlusjFy7qfF0YC/5N/UlAYEEKs9BKFTmJ3a7aMeA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Modra , Reza Arbab , Paul Mackerras , Sasha Levin Subject: [PATCH 4.14 115/239] powerpc/vdso: Correct call frame information Date: Tue, 19 Nov 2019 06:18:35 +0100 Message-Id: <20191119051328.957111578@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191119051255.850204959@linuxfoundation.org> References: <20191119051255.850204959@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Modra [ Upstream commit 56d20861c027498b5a1112b4f9f05b56d906fdda ] Call Frame Information is used by gdb for back-traces and inserting breakpoints on function return for the "finish" command. This failed when inside __kernel_clock_gettime. More concerning than difficulty debugging is that CFI is also used by stack frame unwinding code to implement exceptions. If you have an app that needs to handle asynchronous exceptions for some reason, and you are unlucky enough to get one inside the VDSO time functions, your app will crash. What's wrong: There is control flow in __kernel_clock_gettime that reaches label 99 without saving lr in r12. CFI info however is interpreted by the unwinder without reference to control flow: It's a simple matter of "Execute all the CFI opcodes up to the current address". That means the unwinder thinks r12 contains the return address at label 99. Disabuse it of that notion by resetting CFI for the return address at label 99. Note that the ".cfi_restore lr" could have gone anywhere from the "mtlr r12" a few instructions earlier to the instruction at label 99. I put the CFI as late as possible, because in general that's best practice (and if possible grouped with other CFI in order to reduce the number of CFI opcodes executed when unwinding). Using r12 as the return address is perfectly fine after the "mtlr r12" since r12 on that code path still contains the return address. __get_datapage also has a CFI error. That function temporarily saves lr in r0, and reflects that fact with ".cfi_register lr,r0". A later use of r0 means the CFI at that point isn't correct, as r0 no longer contains the return address. Fix that too. Signed-off-by: Alan Modra Tested-by: Reza Arbab Signed-off-by: Paul Mackerras Signed-off-by: Sasha Levin --- arch/powerpc/kernel/vdso32/datapage.S | 1 + arch/powerpc/kernel/vdso32/gettimeofday.S | 1 + arch/powerpc/kernel/vdso64/datapage.S | 1 + arch/powerpc/kernel/vdso64/gettimeofday.S | 1 + 4 files changed, 4 insertions(+) diff --git a/arch/powerpc/kernel/vdso32/datapage.S b/arch/powerpc/kernel/vdso32/datapage.S index 3745113fcc652..2a7eb5452aba7 100644 --- a/arch/powerpc/kernel/vdso32/datapage.S +++ b/arch/powerpc/kernel/vdso32/datapage.S @@ -37,6 +37,7 @@ data_page_branch: mtlr r0 addi r3, r3, __kernel_datapage_offset-data_page_branch lwz r0,0(r3) + .cfi_restore lr add r3,r0,r3 blr .cfi_endproc diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S b/arch/powerpc/kernel/vdso32/gettimeofday.S index 769c2624e0a6b..1e0bc5955a400 100644 --- a/arch/powerpc/kernel/vdso32/gettimeofday.S +++ b/arch/powerpc/kernel/vdso32/gettimeofday.S @@ -139,6 +139,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime) */ 99: li r0,__NR_clock_gettime + .cfi_restore lr sc blr .cfi_endproc diff --git a/arch/powerpc/kernel/vdso64/datapage.S b/arch/powerpc/kernel/vdso64/datapage.S index abf17feffe404..bf96686915116 100644 --- a/arch/powerpc/kernel/vdso64/datapage.S +++ b/arch/powerpc/kernel/vdso64/datapage.S @@ -37,6 +37,7 @@ data_page_branch: mtlr r0 addi r3, r3, __kernel_datapage_offset-data_page_branch lwz r0,0(r3) + .cfi_restore lr add r3,r0,r3 blr .cfi_endproc diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/kernel/vdso64/gettimeofday.S index 3820213248836..09b2a49f6dd53 100644 --- a/arch/powerpc/kernel/vdso64/gettimeofday.S +++ b/arch/powerpc/kernel/vdso64/gettimeofday.S @@ -124,6 +124,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime) */ 99: li r0,__NR_clock_gettime + .cfi_restore lr sc blr .cfi_endproc -- 2.20.1