From patchwork Tue Jul 2 13:07:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 11027817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F337213B1 for ; Tue, 2 Jul 2019 13:07:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D81EA288D8 for ; Tue, 2 Jul 2019 13:07:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC29B2890B; Tue, 2 Jul 2019 13:07:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7343028901 for ; Tue, 2 Jul 2019 13:07:45 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=fPWdet+0xfYzx1OtlsETyXKmp1SS1fB8r4tLiJZMV7I=; b=JXB VslXU7OKd+FyDK4abLyNW1KzUsOJ7gkf67Z/0nmrdkXTJEtNinqgH2jgv5YyGVZZGHpAFY1Y0i60Q Dx5bgFHL0qqKv46ffyml2rs6VZNSD9FLicD8dSxwU4bM3djP7/su8i+VDIponr9rL5YXlrvSQZSd/ bkmTL+hselDVj6eoz7LK+3mPnBNWfaD1Omt9N7FdI3y8UcFoWqpCbD7T2D3lIUU4eYVyEZ98YUT48 RaIEO9kJ9yR6Wdqz1shVokxocQAndnDz+HGyLx3MWiyVnOhqkJ2H0ruS3+EnQlI4OcxHes2TFrhkS 1AqxMFVEx+jmyZply3XyNFdpZl57PQA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiIVY-0005Wu-Sk; Tue, 02 Jul 2019 13:07:40 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiIVU-0005W8-1u for linux-arm-kernel@lists.infradead.org; Tue, 02 Jul 2019 13:07:37 +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 B18B2344; Tue, 2 Jul 2019 06:07:34 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AB2F73F703; Tue, 2 Jul 2019 06:07:33 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Subject: [PATCHv3 0/3] arm64: stacktrace: improve robustness Date: Tue, 2 Jul 2019 14:07:26 +0100 Message-Id: <20190702130729.19615-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_060736_138859_22D8E0F5 X-CRM114-Status: UNSURE ( 9.36 ) X-CRM114-Notice: Please train this message. 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@arm.com, tengfeif@codeaurora.org, catalin.marinas@arm.com, will.deacon@arm.com, james.morse@arm.com, dave.martin@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The arm64 stacktrace code is careful to only access valid stack locations, but in the presence of a corrupted stack where frame records form a loop, it will never terminate. This series updates the stacktrace code to terminate in finite time even when a stack is corrupted. A stacktrace will be terminated if the next record is at a lower (or equal) address on the current stack, or when the next record is on a stack we've already completed unwinding. The first couple of patches come from Dave's prior attempt to fix this [1], with the final patch relying on infrastructure which has been introduced in the mean time. I've given this a quick spin with magic-sysrq L in a KVM guest, and things look fine, but further testing would be appreciated. This series (based on v5.2-rc1) can also be found in my arm64/robust-stracktrace branch on kernel.org [2]. Since v1 [3]: * Use start_backtrace() consistently * Don't use tsk in start_backtrace() * Track the previous FP and type explicitly Since v2 [4]: * Move graph to end of stuct stackframe * Remove prev_info, fix stacks_done * Accumulate acks * Add comments Thanks, Mark. [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-April/572685.html [2] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arm64/robust-stacktrace [3] https://lore.kernel.org/linux-arm-kernel/20190606125402.10229-1-mark.rutland@arm.com/ [4] https://lore.kernel.org/linux-arm-kernel/20190628154639.5308-1-mark.rutland@arm.com/ Dave Martin (2): arm64: stacktrace: Constify stacktrace.h functions arm64: stacktrace: Factor out backtrace initialisation Mark Rutland (1): arm64: stacktrace: better handle corrupted stacks arch/arm64/include/asm/stacktrace.h | 78 ++++++++++++++++++++++++++++++------- arch/arm64/kernel/perf_callchain.c | 7 +--- arch/arm64/kernel/process.c | 7 +--- arch/arm64/kernel/return_address.c | 9 ++--- arch/arm64/kernel/stacktrace.c | 59 +++++++++++++++++++++------- arch/arm64/kernel/time.c | 7 +--- arch/arm64/kernel/traps.c | 13 +++---- 7 files changed, 124 insertions(+), 56 deletions(-) Acked-by: Catalin Marinas