Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751909AbdCAPa5 (ORCPT ); Wed, 1 Mar 2017 10:30:57 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:18116 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750734AbdCAPa4 (ORCPT ); Wed, 1 Mar 2017 10:30:56 -0500 From: Matt Redfearn To: Ralf Baechle CC: , Matt Redfearn , Subject: [PATCH v2 4/5] MIPS: Stacktrace: Fix __usermode() of uninitialised regs Date: Wed, 1 Mar 2017 14:41:19 +0000 Message-ID: <1488379280-2954-5-git-send-email-matt.redfearn@imgtec.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488379280-2954-1-git-send-email-matt.redfearn@imgtec.com> References: <1488379280-2954-1-git-send-email-matt.redfearn@imgtec.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.150.130.83] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1639 Lines: 47 Commit 81a76d7119f6 ("MIPS: Avoid using unwind_stack() with usermode") added a check if the passed regs are from user mode, and perform a raw backtrace if so. When WARN() is invoked, __dump_stack calls show_stack() with NULL task and stack pointers. This leads show_stack to create a pt_regs struct on the stack, and initialise it via prepare_frametrace(). When show_backtrace() examines the regs, the value of the status register checked by user_mode() is unpredictable, depending on the uninitialised content of the stack. This leads to show_backtrace() sometimes showing raw backtraces instead of correctly walking the kernel stack. Fix this by initialising the contents of the saved status register in prepare_frametrace(). Fixes: 81a76d7119f6 ("MIPS: Avoid using unwind_stack() with usermode") Signed-off-by: Matt Redfearn --- Changes in v2: None arch/mips/include/asm/stacktrace.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/mips/include/asm/stacktrace.h b/arch/mips/include/asm/stacktrace.h index 780ee2c2a2ac..4845945d02a5 100644 --- a/arch/mips/include/asm/stacktrace.h +++ b/arch/mips/include/asm/stacktrace.h @@ -1,6 +1,7 @@ #ifndef _ASM_STACKTRACE_H #define _ASM_STACKTRACE_H +#include #include #ifdef CONFIG_KALLSYMS @@ -47,6 +48,8 @@ static __always_inline void prepare_frametrace(struct pt_regs *regs) : "=m" (regs->cp0_epc), "=m" (regs->regs[29]), "=m" (regs->regs[31]) : : "memory"); + /* show_backtrace behaviour depends on user_mode(regs) */ + regs->cp0_status = read_c0_status(); } #endif /* _ASM_STACKTRACE_H */ -- 2.7.4