Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp9125pja; Fri, 22 Nov 2019 02:44:32 -0800 (PST) X-Google-Smtp-Source: APXvYqwDxkkQArRSOUpymlk01ocbdpQZgDZ2/bal0wcLQ+33RMhLyBupIpkUU6lkQJ/epytASd3s X-Received: by 2002:a17:906:a28d:: with SMTP id i13mr4934117ejz.154.1574419472515; Fri, 22 Nov 2019 02:44:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574419472; cv=none; d=google.com; s=arc-20160816; b=0Sl/xkteTZAnRX5ZbxQZUrGckKl5RWP6QmuATXhRY2iOkfO6VOwOqBcqOlCpLT9+Z9 p86WYRLgr3/5UzLuA94l5yJ4pj6jcR6e8eYQ1DUT5Cg5P+JzvwnqKIuRYM9jp6pOPyFY CrpngJzH/5+s46vcJ8yuN5N0q4RFoQ1CF8rc/XrX4qfESi2bcMXmsDg6HlcXD8rBTtvL FjjZdDX38uB5L24nhOjKrpgGQiaBIJE3FbS55ez/1AE/BK2H0Owiwtxvyym5u4ucpqOR ae2EbPCyO5kFRXtFJE6a4t52y2XQPGsc6Lw0t2nwLm+BdLlKxVOAaU5FWr/u1M2BlcYE YF1w== 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=iTtDnALs20V5vzKATFHMLk7xjksbvIAProJQ4acO/CU=; b=CwGv1oi9K5kmCs6JsuM/JCApO55b9//Z9tfuE7D5y/aQXspaU7dfp/wVnnZgaTq5kK 4O3ZiOuvBi87B4lRacvWt/L1th5uKdrTFO6Yx5RmDlyVgKbe1x0DkuP8CkJeHDhaEj+h 7kGgAKyPE7dtxXAWQGrh4cU4X1xjoU2AsPI2ruwAz9BD5NvHnejnbIH2o+/nYOz7tC5n F+wS7FuqLtsB5kpsDP6dp2QdzIVHEKzPy5VPWKRjRmOq4gXYRjKGuL3t/HqdqjJr3fPW dxHcDkLme7v94aT9FU7it1+a7nEgxh94rsaMOSCk0arhd8ULNRBRejo+VZNJawGIHzYI H7mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T7CfDjVD; 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 p38si1184379edc.163.2019.11.22.02.44.08; Fri, 22 Nov 2019 02:44:32 -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=T7CfDjVD; 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 S1729060AbfKVKl6 (ORCPT + 99 others); Fri, 22 Nov 2019 05:41:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:46726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729048AbfKVKl4 (ORCPT ); Fri, 22 Nov 2019 05:41:56 -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 B26D620707; Fri, 22 Nov 2019 10:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574419315; bh=fCHwIOGu3unDcLR2KdVSgi3LcxKQ2gDJuYvU66MMI3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T7CfDjVDyw7bICgMwTK1ZZ/FpLrLtsoh4Et8ak5tN8vtTH8L8mOCa6PdHwH7oDX1B SLtoMnNyvdwK8KLjxkYsEDKTWG/PkJR4jj/3x9tC/jc4rkRsvpVuNkJm+yF8rLIhIb z4CzAC0HX2+2lAR6kU5RzhlkzE0J9f9lu78Q6wuQ= 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.9 068/222] powerpc/vdso: Correct call frame information Date: Fri, 22 Nov 2019 11:26:48 +0100 Message-Id: <20191122100905.013915167@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100830.874290814@linuxfoundation.org> References: <20191122100830.874290814@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 6b2b69616e776..7b341b86216c2 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