• Josh Poimboeuf's avatar
    x86/unwind: Add end-of-stack check for ftrace handlers · 519fb5c3
    Josh Poimboeuf authored
    Dave Jones and Steven Rostedt reported unwinder warnings like the
    following:
    
      WARNING: kernel stack frame pointer at ffff8800bda0ff30 in sshd:1090 has bad value 000055b32abf1fa8
    
    In both cases, the unwinder was attempting to unwind from an ftrace
    handler into entry code.  The callchain was something like:
    
      syscall entry code
        C function
          ftrace handler
            save_stack_trace()
    
    The problem is that the unwinder's end-of-stack logic gets confused by
    the way ftrace lays out the stack frame (with fentry enabled).
    
    I was able to recreate this warning with:
    
      echo call_usermodehelper_exec_async:stacktrace > /sys/kernel/debug/tracing/set_ftrace_filter
      (exit login session)
    
    I considered fixing this by changing the ftrace code to rewrite the
    stack to make the unwinder happy.  But that seemed too intrusive after I
    implemented it.  Instead, just add another check to the unwinder's
    end-of-stack logic to detect this special case.
    
    Side note: We could probably get rid of these end-of-stack checks by
    encoding the frame pointer for syscall entry just like we do for
    interrupt entry.  That would be simpler, but it would also be a lot more
    intrusive since it would slightly affect the performance of every
    syscall.
    Reported-by: default avatarDave Jones <davej@codemonkey.org.uk>
    Reported-by: default avatarSteven Rostedt <rostedt@goodmis.org>
    Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
    Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: live-patching@vger.kernel.org
    Fixes: c32c47c6 ("x86/unwind: Warn on bad frame pointer")
    Link: http://lkml.kernel.org/r/671ba22fbc0156b8f7e0cfa5ab2a795e08bc37e1.1495553739.git.jpoimboe@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    519fb5c3
unwind_frame.c 10.1 KB