From patchwork Wed Jun 30 22:33:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12352871 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 ED5A1C11F66 for ; Wed, 30 Jun 2021 22:35:59 +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 A74B360FF1 for ; Wed, 30 Jun 2021 22:35:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A74B360FF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+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.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aEEpu9B9yOmVakgxejeQN+i2BRP+6g8h5X8tfRgZn5g=; b=RUX4Tk0W/7bPLV c3xZ58stnXeII76Yn5+pI4jVcMcXRiBhnkXOYRUiPPsIIAo+MXbtHAR1J8o/fv8/xCqbwQONdgwUt hVHZAmBY/6kChkROJbGwV44cAzLhQfgb6ha5zs2YHng4EBlM+79Ut2jq8pPJ6lEH6PMqzGCZDDMWb GHUsnMHLSCAd/jZ9boqgTkS3GM5ND+4pKLMuEc7YX8sE/jlTTMrOtP73EkertlJFU62EVvs6hjAMA mbZafKVIml0A07Z531XC/EEPQixWDC5Q4NqBHlQc47j6wElMzFqzlhcZM/R6uBkI3Acrgf1lKeai8 p63jJrCF5xFm+dOvbtMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyima-00FOF4-FX; Wed, 30 Jun 2021 22:34:12 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyimW-00FOE8-Q9 for linux-arm-kernel@lists.infradead.org; Wed, 30 Jun 2021 22:34:10 +0000 Received: from x64host.home (unknown [47.187.214.213]) by linux.microsoft.com (Postfix) with ESMTPSA id 5D74320B6C50; Wed, 30 Jun 2021 15:34:07 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5D74320B6C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1625092448; bh=vvpqMQAHDttXStCeHW5CJ8/Wc5hwp1u/fuylw90c96k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=a1psfSJyxoBli1dd32NGtI32qMUWrmrp6sTy1CCHLu3gX2KXBWDcwHBarGoSXhPay F+euBIEVzUjv2Wdl2YQrdq9wowl2DistAvqba19L4lMYnGInhahOspvRZy+/8DhNLR g08JtM77Z5Z2+YPzM4f/psmtIaqv9oSeU31QxZxI= From: madvenka@linux.microsoft.com To: broonie@kernel.org, mark.rutland@arm.com, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, pasha.tatashin@soleen.com, jthierry@redhat.com, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [RFC PATCH v6 2/3] arm64: Introduce stack trace reliability checks in the unwinder Date: Wed, 30 Jun 2021 17:33:55 -0500 Message-Id: <20210630223356.58714-3-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210630223356.58714-1-madvenka@linux.microsoft.com> References: <3f2aab69a35c243c5e97f47c4ad84046355f5b90> <20210630223356.58714-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_153408_945507_6E61F45D X-CRM114-Status: GOOD ( 16.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" The unwinder should check for the presence of various features and conditions that can render the stack trace unreliable. Introduce a function unwind_check_frame() for this purpose. Introduce the first reliability check in unwind_check_frame() - If a return PC is not a valid kernel text address, consider the stack trace unreliable. It could be some generated code. Other reliability checks will be added in the future. If a reliability check fails, it is a non-fatal error. Introduce a new return code, UNWIND_CONTINUE_WITH_RISK, for non-fatal errors. Call unwind_check_frame() from unwind_frame(). Also, call it from start_backtrace() to remove the current assumption that the starting frame is reliable. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/include/asm/stacktrace.h | 4 +++- arch/arm64/kernel/stacktrace.c | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h index 6fcd58553fb1..d1625d55b980 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -32,6 +32,7 @@ struct stack_info { enum unwind_rc { UNWIND_CONTINUE, /* No errors encountered */ + UNWIND_CONTINUE_WITH_RISK, /* Non-fatal errors encountered */ UNWIND_ABORT, /* Fatal errors encountered */ UNWIND_FINISH, /* End of stack reached successfully */ }; @@ -73,6 +74,7 @@ extern void walk_stackframe(struct task_struct *tsk, struct stackframe *frame, bool (*fn)(void *, unsigned long), void *data); extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, const char *loglvl); +extern enum unwind_rc unwind_check_frame(struct stackframe *frame); DECLARE_PER_CPU(unsigned long *, irq_stack_ptr); @@ -176,7 +178,7 @@ static inline enum unwind_rc start_backtrace(struct stackframe *frame, bitmap_zero(frame->stacks_done, __NR_STACK_TYPES); frame->prev_fp = 0; frame->prev_type = STACK_TYPE_UNKNOWN; - return UNWIND_CONTINUE; + return unwind_check_frame(frame); } #endif /* __ASM_STACKTRACE_H */ diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index e9c2c1fa9dde..ba7b97b119e4 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -18,6 +18,21 @@ #include #include +/* + * Check the stack frame for conditions that make unwinding unreliable. + */ +enum unwind_rc unwind_check_frame(struct stackframe *frame) +{ + /* + * If the PC is not a known kernel text address, then we cannot + * be sure that a subsequent unwind will be reliable, as we + * don't know that the code follows our unwind requirements. + */ + if (!__kernel_text_address(frame->pc)) + return UNWIND_CONTINUE_WITH_RISK; + return UNWIND_CONTINUE; +} + /* * AArch64 PCS assigns the frame pointer to x29. * @@ -109,7 +124,7 @@ enum unwind_rc notrace unwind_frame(struct task_struct *tsk, frame->pc = ptrauth_strip_insn_pac(frame->pc); - return UNWIND_CONTINUE; + return unwind_check_frame(frame); } NOKPROBE_SYMBOL(unwind_frame);