From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754032AbcHRNKz (ORCPT ); Thu, 18 Aug 2016 09:10:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49140 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754042AbcHRNIF (ORCPT ); Thu, 18 Aug 2016 09:08:05 -0400 From: Josh Poimboeuf To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Linus Torvalds , Steven Rostedt , Brian Gerst , Kees Cook , Peter Zijlstra , Frederic Weisbecker , Byungchul Park , Nilay Vaish Subject: [PATCH v4 49/57] x86/unwind: warn on kernel stack corruption Date: Thu, 18 Aug 2016 08:06:29 -0500 Message-Id: <26dff9c775956ee8b27dc72d9cd349ca7fa34782.1471525031.git.jpoimboe@redhat.com> In-Reply-To: References: X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 18 Aug 2016 13:08:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Detect situations in the unwinder where the frame pointer refers to a bad address, and print an appropriate warning. Use printk_deferred_once() because the unwinder can be called with the console lock by lockdep via save_stack_trace(). Signed-off-by: Josh Poimboeuf --- arch/x86/kernel/unwind_frame.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c index 2e729bf..65c5e416 100644 --- a/arch/x86/kernel/unwind_frame.c +++ b/arch/x86/kernel/unwind_frame.c @@ -130,8 +130,17 @@ bool unwind_next_frame(struct unwind_state *state) } /* make sure the next frame's data is accessible */ - if (!update_stack_state(state, next_frame, next_len)) - return false; + if (!update_stack_state(state, next_frame, next_len)) { + /* + * Don't warn on bad regs->bp. An interrupt in entry code + * might cause a false positive warning. + */ + if (state->regs) + goto the_end; + + goto bad_address; + } + /* move to the next frame */ if (regs) { state->regs = regs; @@ -143,6 +152,17 @@ bool unwind_next_frame(struct unwind_state *state) return true; +bad_address: + if (state->regs) + printk_deferred_once(KERN_WARNING + "WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n", + state->regs, state->task->comm, + state->task->pid, next_bp); + else + printk_deferred_once(KERN_WARNING + "WARNING: kernel stack frame pointer at %p in %s:%d has bad value %p\n", + state->bp, state->task->comm, + state->task->pid, next_bp); the_end: state->stack_info.type = STACK_TYPE_UNKNOWN; return false; -- 2.7.4