From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934054AbcHDW0G (ORCPT ); Thu, 4 Aug 2016 18:26:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59680 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933720AbcHDWXw (ORCPT ); Thu, 4 Aug 2016 18:23:52 -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 Subject: [PATCH v2 37/44] x86/unwind: detect syscall entry regs Date: Thu, 4 Aug 2016 17:22:33 -0500 Message-Id: <41da7fc41abc1d4e0e59575b30acf87b93666104.1470345772.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.39]); Thu, 04 Aug 2016 22:23:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The entry code doesn't encode pt_regs for syscalls. But they're always at the same location, so we can add a manual check for them. Signed-off-by: Josh Poimboeuf --- arch/x86/kernel/unwind_frame.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c index d24c192..f60a089 100644 --- a/arch/x86/kernel/unwind_frame.c +++ b/arch/x86/kernel/unwind_frame.c @@ -21,6 +21,14 @@ unsigned long unwind_get_return_address(struct unwind_state *state) } EXPORT_SYMBOL_GPL(unwind_get_return_address); +static bool is_last_task_frame(struct unwind_state *state) +{ + unsigned long bp = (unsigned long)state->bp; + unsigned long regs = (unsigned long)task_pt_regs(state->task); + + return bp == regs - FRAME_HEADER_SIZE; +} + #ifdef CONFIG_X86_64 /* * This determines if the frame pointer actually contains an encoded pointer to @@ -99,6 +107,20 @@ bool unwind_next_frame(struct unwind_state *state) if (unwind_done(state)) return false; + /* + * The entry code doesn't encode pt_regs on syscalls, so check for them + * here. The last frame pointer and associated syscall pt_regs (for + * user tasks) are always at a standard location at the end of the task + * stack. If we've reached the end, go ahead and exit early to avoid + * trying to decode an invalid frame pointer. + */ + if (is_last_task_frame(state)) { + if (!(state->task->flags & PF_KTHREAD)) + state->regs = task_pt_regs(state->task); + state->stack_info.type = STACK_TYPE_UNKNOWN; + return false; + } + next_bp = (unsigned long *)*state->bp; /* -- 2.7.4