1. 06 6月, 2018 1 次提交
    • J
      objtool: Fix GCC 8 cold subfunction detection for aliased functions · cd77849a
      Josh Poimboeuf 提交于
      The kbuild test robot reported the following issue:
      
        kernel/time/posix-stubs.o: warning: objtool: sys_ni_posix_timers.cold.1()+0x0: unreachable instruction
      
      This file creates symbol aliases for the sys_ni_posix_timers() function.
      So there are multiple ELF function symbols for the same function:
      
        23: 0000000000000150     26 FUNC    GLOBAL DEFAULT        1 __x64_sys_timer_create
        24: 0000000000000150     26 FUNC    GLOBAL DEFAULT        1 sys_ni_posix_timers
        25: 0000000000000150     26 FUNC    GLOBAL DEFAULT        1 __ia32_sys_timer_create
        26: 0000000000000150     26 FUNC    GLOBAL DEFAULT        1 __x64_sys_timer_gettime
      
      Here's the corresponding cold subfunction:
      
        11: 0000000000000000     45 FUNC    LOCAL  DEFAULT        6 sys_ni_posix_timers.cold.1
      
      When analyzing overlapping functions, objtool only looks at the first
      one in the symbol list.  The rest of the functions are basically ignored
      because they point to instructions which have already been analyzed.
      
      So in this case it analyzes the __x64_sys_timer_create() function, but
      then it fails to recognize that its cold subfunction is
      sys_ni_posix_timers.cold.1(), because the names are different.
      
      Make the subfunction detection a little smarter by associating each
      subfunction with the first function which jumps to it, since that's the
      one which will be analyzed.
      
      Unfortunately we still have to leave the original subfunction detection
      code in place, thanks to GCC switch tables.  (See the comment for more
      details.)
      
      Fixes: 13810435 ("objtool: Support GCC 8's cold subfunctions")
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/d3ba52662cbc8e3a64a3b64d44b4efc5674fd9ab.1527855808.git.jpoimboe@redhat.com
      cd77849a
  2. 19 5月, 2018 1 次提交
    • J
      objtool: Detect RIP-relative switch table references, part 2 · 7dec80cc
      Josh Poimboeuf 提交于
      With the following commit:
      
        fd35c88b ("objtool: Support GCC 8 switch tables")
      
      I added a "can't find switch jump table" warning, to stop covering up
      silent failures if add_switch_table() can't find anything.
      
      That warning found yet another bug in the objtool switch table detection
      logic.  For cases 1 and 2 (as described in the comments of
      find_switch_table()), the find_symbol_containing() check doesn't adjust
      the offset for RIP-relative switch jumps.
      
      Incidentally, this bug was already fixed for case 3 with:
      
        6f5ec299 ("objtool: Detect RIP-relative switch table references")
      
      However, that commit missed the fix for cases 1 and 2.
      
      The different cases are now starting to look more and more alike.  So
      fix the bug by consolidating them into a single case, by checking the
      original dynamic jump instruction in the case 3 loop.
      
      This also simplifies the code and makes it more robust against future
      switch table detection issues -- of which I'm sure there will be many...
      
      Switch table detection has been the most fragile area of objtool, by
      far.  I long for the day when we'll have a GCC plugin for annotating
      switch tables.  Linus asked me to delay such a plugin due to the
      flakiness of the plugin infrastructure in older versions of GCC, so this
      rickety code is what we're stuck with for now.  At least the code is now
      a little simpler than it was.
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/f400541613d45689086329432f3095119ffbc328.1526674218.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      7dec80cc
  3. 15 5月, 2018 1 次提交
    • J
      objtool: Detect RIP-relative switch table references · 6f5ec299
      Josh Poimboeuf 提交于
      Typically a switch table can be found by detecting a .rodata access
      followed an indirect jump:
      
          1969:	4a 8b 0c e5 00 00 00 	mov    0x0(,%r12,8),%rcx
          1970:	00
      			196d: R_X86_64_32S	.rodata+0x438
          1971:	e9 00 00 00 00       	jmpq   1976 <dispc_runtime_suspend+0xb6a>
      			1972: R_X86_64_PC32	__x86_indirect_thunk_rcx-0x4
      
      Randy Dunlap reported a case (seen with GCC 4.8) where the .rodata
      access uses RIP-relative addressing:
      
          19bd:	48 8b 3d 00 00 00 00 	mov    0x0(%rip),%rdi        # 19c4 <dispc_runtime_suspend+0xbb8>
      			19c0: R_X86_64_PC32	.rodata+0x45c
          19c4:	e9 00 00 00 00       	jmpq   19c9 <dispc_runtime_suspend+0xbbd>
      			19c5: R_X86_64_PC32	__x86_indirect_thunk_rdi-0x4
      
      In this case the relocation addend needs to be adjusted accordingly in
      order to find the location of the switch table.
      
      The fix is for case 3 (as described in the comments), but also make the
      existing case 1 & 2 checks more precise by only adjusting the addend for
      R_X86_64_PC32 relocations.
      
      This fixes the following warnings:
      
        drivers/video/fbdev/omap2/omapfb/dss/dispc.o: warning: objtool: dispc_runtime_suspend()+0xbb8: sibling call from callable instruction with modified stack frame
        drivers/video/fbdev/omap2/omapfb/dss/dispc.o: warning: objtool: dispc_runtime_resume()+0xcc5: sibling call from callable instruction with modified stack frame
      Reported-by: NRandy Dunlap <rdunlap@infradead.org>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/b6098294fd67afb69af8c47c9883d7a68bf0f8ea.1526305958.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      6f5ec299
  4. 14 5月, 2018 3 次提交
    • J
      objtool: Support GCC 8 switch tables · fd35c88b
      Josh Poimboeuf 提交于
      With GCC 8, some issues were found with the objtool switch table
      detection.
      
      1) In the .rodata section, immediately after the switch table, there can
         be another object which contains a pointer to the function which had
         the switch statement.  In this case objtool wrongly considers the
         function pointer to be part of the switch table.  Fix it by:
      
         a) making sure there are no pointers to the beginning of the
            function; and
      
         b) making sure there are no gaps in the switch table.
      
         Only the former was needed, the latter adds additional protection for
         future optimizations.
      
      2) In find_switch_table(), case 1 and case 2 are missing the check to
         ensure that the .rodata switch table data is anonymous, i.e. that it
         isn't already associated with an ELF symbol.  Fix it by adding the
         same find_symbol_containing() check which is used for case 3.
      
      This fixes the following warnings with GCC 8:
      
        drivers/block/virtio_blk.o: warning: objtool: virtio_queue_rq()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+72
        net/ipv6/icmp.o: warning: objtool: icmpv6_rcv()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+64
        drivers/usb/core/quirks.o: warning: objtool: quirks_param_set()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+48
        drivers/mtd/nand/raw/nand_hynix.o: warning: objtool: hynix_nand_decode_id()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+24
        drivers/mtd/nand/raw/nand_samsung.o: warning: objtool: samsung_nand_decode_id()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+32
        drivers/gpu/drm/nouveau/nvkm/subdev/top/gk104.o: warning: objtool: gk104_top_oneinit()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+64
      Reported-by: NArnd Bergmann <arnd@arndb.de>
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: David Laight <David.Laight@ACULAB.COM>
      Cc: Greg KH <gregkh@linuxfoundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: damian <damian.tometzki@icloud.com>
      Link: http://lkml.kernel.org/r/20180510224849.xwi34d6tzheb5wgw@trebleSigned-off-by: NIngo Molnar <mingo@kernel.org>
      fd35c88b
    • J
      objtool: Support GCC 8's cold subfunctions · 13810435
      Josh Poimboeuf 提交于
      GCC 8 moves a lot of unlikely code out of line to "cold" subfunctions in
      .text.unlikely.  Properly detect the new subfunctions and treat them as
      extensions of the original functions.
      
      This fixes a bunch of warnings like:
      
        kernel/cgroup/cgroup.o: warning: objtool: parse_cgroup_root_flags()+0x33: sibling call from callable instruction with modified stack frame
        kernel/cgroup/cgroup.o: warning: objtool: cgroup_addrm_files()+0x290: sibling call from callable instruction with modified stack frame
        kernel/cgroup/cgroup.o: warning: objtool: cgroup_apply_control_enable()+0x25b: sibling call from callable instruction with modified stack frame
        kernel/cgroup/cgroup.o: warning: objtool: rebind_subsystems()+0x325: sibling call from callable instruction with modified stack frame
      Reported-and-tested-by: Ndamian <damian.tometzki@icloud.com>
      Reported-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: David Laight <David.Laight@ACULAB.COM>
      Cc: Greg KH <gregkh@linuxfoundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/0965e7fcfc5f31a276f0c7f298ff770c19b68706.1525923412.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      13810435
    • J
      objtool: Fix "noreturn" detection for recursive sibling calls · 0afd0d9e
      Josh Poimboeuf 提交于
      Objtool has some crude logic for detecting static "noreturn" functions
      (aka "dead ends").  This is necessary for being able to correctly follow
      GCC code flow when such functions are called.
      
      It's remotely possible for two functions to call each other via sibling
      calls.  If they don't have RET instructions, objtool's noreturn
      detection logic goes into a recursive loop:
      
        drivers/char/ipmi/ipmi_ssif.o: warning: objtool: return_hosed_msg()+0x0: infinite recursion (objtool bug!)
        drivers/char/ipmi/ipmi_ssif.o: warning: objtool: deliver_recv_msg()+0x0: infinite recursion (objtool bug!)
      
      Instead of reporting an error in this case, consider the functions to be
      non-dead-ends.
      Reported-and-tested-by: NRandy Dunlap <rdunlap@infradead.org>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: David Laight <David.Laight@ACULAB.COM>
      Cc: Greg KH <gregkh@linuxfoundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: damian <damian.tometzki@icloud.com>
      Link: http://lkml.kernel.org/r/7cc156408c5781a1f62085d352ced1fe39fe2f91.1525923412.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      0afd0d9e
  5. 27 3月, 2018 1 次提交
    • J
      objtool: Add Clang support · 3c1f0583
      Josh Poimboeuf 提交于
      Since the ORC unwinder was made the default on x86_64, Clang-built
      defconfig kernels have triggered some new objtool warnings:
      
        drivers/gpu/drm/i915/i915_gpu_error.o: warning: objtool: i915_error_printf()+0x6c: return with modified stack frame
        drivers/gpu/drm/i915/intel_display.o: warning: objtool: pipe_config_err()+0xa6: return with modified stack frame
      
      The problem is that objtool has never seen clang-built binaries before.
      
      Shockingly enough, objtool is apparently able to follow the code flow
      mostly fine, except for one instruction sequence.  Instead of a LEAVE
      instruction, clang restores RSP and RBP the long way:
      
         67c:   48 89 ec                mov    %rbp,%rsp
         67f:   5d                      pop    %rbp
      
      Teach objtool about this new code sequence.
      Reported-and-test-by: NMatthias Kaehlcke <mka@chromium.org>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/fce88ce81c356eedcae7f00ed349cfaddb3363cc.1521741586.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      3c1f0583
  6. 07 3月, 2018 1 次提交
  7. 28 2月, 2018 1 次提交
  8. 21 2月, 2018 3 次提交
  9. 15 2月, 2018 1 次提交
  10. 09 2月, 2018 1 次提交
  11. 30 1月, 2018 2 次提交
    • J
      objtool: Add support for alternatives at the end of a section · 17bc3391
      Josh Poimboeuf 提交于
      Now that the previous patch gave objtool the ability to read retpoline
      alternatives, it shows a new warning:
      
        arch/x86/entry/entry_64.o: warning: objtool: .entry_trampoline: don't know how to handle alternatives at end of section
      
      This is due to the JMP_NOSPEC in entry_SYSCALL_64_trampoline().
      
      Previously, objtool ignored this situation because it wasn't needed, and
      it would have required a bit of extra code.  Now that this case exists,
      add proper support for it.
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/2a30a3c2158af47d891a76e69bb1ef347e0443fd.1517284349.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      17bc3391
    • J
      objtool: Improve retpoline alternative handling · a845c7cf
      Josh Poimboeuf 提交于
      Currently objtool requires all retpolines to be:
      
        a) patched in with alternatives; and
      
        b) annotated with ANNOTATE_NOSPEC_ALTERNATIVE.
      
      If you forget to do both of the above, objtool segfaults trying to
      dereference a NULL 'insn->call_dest' pointer.
      
      Avoid that situation and print a more helpful error message:
      
        quirks.o: warning: objtool: efi_delete_dummy_variable()+0x99: unsupported intra-function call
        quirks.o: warning: objtool: If this is a retpoline, please patch it in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE.
      
      Future improvements can be made to make objtool smarter with respect to
      retpolines, but this is a good incremental improvement for now.
      Reported-and-tested-by: NGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/819e50b6d9c2e1a22e34c1a636c0b2057cc8c6e5.1517284349.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      a845c7cf
  12. 16 1月, 2018 1 次提交
    • K
      usercopy: Enhance and rename report_usercopy() · b394d468
      Kees Cook 提交于
      In preparation for refactoring the usercopy checks to pass offset to
      the hardened usercopy report, this renames report_usercopy() to the
      more accurate usercopy_abort(), marks it as noreturn because it is,
      adds a hopefully helpful comment for anyone investigating such reports,
      makes the function available to the slab allocators, and adds new "detail"
      and "offset" arguments.
      Signed-off-by: NKees Cook <keescook@chromium.org>
      b394d468
  13. 12 1月, 2018 2 次提交
    • J
      objtool: Allow alternatives to be ignored · 258c7605
      Josh Poimboeuf 提交于
      Getting objtool to understand retpolines is going to be a bit of a
      challenge.  For now, take advantage of the fact that retpolines are
      patched in with alternatives.  Just read the original (sane)
      non-alternative instruction, and ignore the patched-in retpoline.
      
      This allows objtool to understand the control flow *around* the
      retpoline, even if it can't yet follow what's inside.  This means the
      ORC unwinder will fail to unwind from inside a retpoline, but will work
      fine otherwise.
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: NDavid Woodhouse <dwmw@amazon.co.uk>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: gnomes@lxorguk.ukuu.org.uk
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: thomas.lendacky@amd.com
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Jiri Kosina <jikos@kernel.org>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Kees Cook <keescook@google.com>
      Cc: Tim Chen <tim.c.chen@linux.intel.com>
      Cc: Greg Kroah-Hartman <gregkh@linux-foundation.org>
      Cc: Paul Turner <pjt@google.com>
      Link: https://lkml.kernel.org/r/1515707194-20531-3-git-send-email-dwmw@amazon.co.uk
      258c7605
    • J
      objtool: Detect jumps to retpoline thunks · 39b73533
      Josh Poimboeuf 提交于
      A direct jump to a retpoline thunk is really an indirect jump in
      disguise.  Change the objtool instruction type accordingly.
      
      Objtool needs to know where indirect branches are so it can detect
      switch statement jump tables.
      
      This fixes a bunch of warnings with CONFIG_RETPOLINE like:
      
        arch/x86/events/intel/uncore_nhmex.o: warning: objtool: nhmex_rbox_msr_enable_event()+0x44: sibling call from callable instruction with modified stack frame
        kernel/signal.o: warning: objtool: copy_siginfo_to_user()+0x91: sibling call from callable instruction with modified stack frame
        ...
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: NDavid Woodhouse <dwmw@amazon.co.uk>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: gnomes@lxorguk.ukuu.org.uk
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: thomas.lendacky@amd.com
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Jiri Kosina <jikos@kernel.org>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Kees Cook <keescook@google.com>
      Cc: Tim Chen <tim.c.chen@linux.intel.com>
      Cc: Greg Kroah-Hartman <gregkh@linux-foundation.org>
      Cc: Paul Turner <pjt@google.com>
      Link: https://lkml.kernel.org/r/1515707194-20531-2-git-send-email-dwmw@amazon.co.uk
      39b73533
  14. 20 10月, 2017 1 次提交
  15. 28 9月, 2017 1 次提交
  16. 23 9月, 2017 1 次提交
    • J
      objtool: Handle another GCC stack pointer adjustment bug · 0d0970ee
      Josh Poimboeuf 提交于
      The kbuild bot reported the following warning with GCC 4.4 and a
      randconfig:
      
        net/socket.o: warning: objtool: compat_sock_ioctl()+0x1083: stack state mismatch: cfa1=7+160 cfa2=-1+0
      
      This is caused by another GCC non-optimization, where it backs up and
      restores the stack pointer for no apparent reason:
      
          2f91:       48 89 e0                mov    %rsp,%rax
          2f94:       4c 89 e7                mov    %r12,%rdi
          2f97:       4c 89 f6                mov    %r14,%rsi
          2f9a:       ba 20 00 00 00          mov    $0x20,%edx
          2f9f:       48 89 c4                mov    %rax,%rsp
      
      This issue would have been happily ignored before the following commit:
      
        dd88a0a0 ("objtool: Handle GCC stack pointer adjustment bug")
      
      But now that objtool is paying attention to such stack pointer writes
      to/from a register, it needs to understand them properly.  In this case
      that means recognizing that the "mov %rsp, %rax" instruction is
      potentially a backup of the stack pointer.
      Reported-by: Nkbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Dmitriy Vyukov <dvyukov@google.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Fixes: dd88a0a0 ("objtool: Handle GCC stack pointer adjustment bug")
      Link: http://lkml.kernel.org/r/8c7aa8e9a36fbbb6655d9d8e7cea58958c912da8.1505942196.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      0d0970ee
  17. 30 8月, 2017 1 次提交
    • J
      objtool: Handle GCC stack pointer adjustment bug · dd88a0a0
      Josh Poimboeuf 提交于
      Arnd Bergmann reported the following warning with GCC 7.1.1:
      
        fs/fs_pin.o: warning: objtool: pin_kill()+0x139: stack state mismatch: cfa1=7+88 cfa2=7+96
      
      And the kbuild robot reported the following warnings with GCC 5.4.1:
      
        fs/fs_pin.o: warning: objtool: pin_kill()+0x182: return with modified stack frame
        fs/quota/dquot.o: warning: objtool: dquot_alloc_inode()+0x140: stack state mismatch: cfa1=7+120 cfa2=7+128
        fs/quota/dquot.o: warning: objtool: dquot_free_inode()+0x11a: stack state mismatch: cfa1=7+112 cfa2=7+120
      
      Those warnings are caused by an unusual GCC non-optimization where it
      uses an intermediate register to adjust the stack pointer.  It does:
      
        lea    0x8(%rsp), %rcx
        ...
        mov    %rcx, %rsp
      
      Instead of the obvious:
      
        add    $0x8, %rsp
      
      It makes no sense to use an intermediate register, so I opened a GCC bug
      to track it:
      
        https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81813
      
      But it's not exactly a high-priority bug and it looks like we'll be
      stuck with this issue for a while.  So for now we have to track register
      values when they're loaded with stack pointer offsets.
      
      This is kind of a big workaround for a tiny problem, but c'est la vie.
      I hope to eventually create a GCC plugin to implement a big chunk of
      objtool's functionality.  Hopefully at that point we'll be able to
      remove of a lot of these GCC-isms from the objtool code.
      Reported-by: NArnd Bergmann <arnd@arndb.de>
      Reported-by: Nkbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/6a41a96884c725e7f05413bb7df40cfe824b2444.1504028945.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      dd88a0a0
  18. 21 8月, 2017 1 次提交
    • J
      objtool: Fix objtool fallthrough detection with function padding · ee97638b
      Josh Poimboeuf 提交于
      When GCC adds NOP padding between functions, those NOPs aren't
      associated with a function symbol, which breaks objtool's detection of a
      function falling through to another function.  Instead it shows
      confusing errors like:
      
        drivers/mtd/chips/cfi_util.o: warning: objtool: cfi_qry_mode_on()+0x8b: return with modified stack frame
        drivers/mtd/chips/cfi_util.o: warning: objtool: cfi_qry_mode_on()+0x0: stack state mismatch: cfa1=-4-32 cfa2=7+8
        drivers/mtd/chips/cfi_cmdset_0002.o: warning: objtool: fixup_use_fwh_lock()+0x8: unknown stack-related register move
        drivers/mtd/chips/cfi_cmdset_0002.o: warning: objtool: fixup_use_fwh_lock()+0x0: stack state mismatch: cfa1=6+16 cfa2=7+8
        drivers/mtd/chips/cfi_cmdset_0002.o: warning: objtool: do_otp_write()+0xa: unsupported stack pointer realignment
        drivers/mtd/chips/cfi_cmdset_0002.o: warning: objtool: do_otp_write()+0x0: stack state mismatch: cfa1=-4-40 cfa2=7+8
      Reported-by: Nkbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/43e7aae9a7a7710cd6df597fa9dc501da4ba0602.1502472193.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      ee97638b
  19. 11 8月, 2017 2 次提交
  20. 28 7月, 2017 2 次提交
    • J
      objtool: Skip unreachable warnings for 'alt' instructions · 0e2bb2bc
      Josh Poimboeuf 提交于
      When a whitelisted function uses one of the ALTERNATIVE macros, it
      produces false positive warnings like:
      
        arch/x86/kvm/vmx.o: warning: objtool: .altinstr_replacement+0x0: unreachable instruction
        arch/x86/kvm/svm.o: warning: objtool: .altinstr_replacement+0x6e: unreachable instruction
      
      There's no easy way to whitelist alternative instructions, so instead
      just skip any 'unreachable' warnings associated with them.
      Reported-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/a5d0a8c60155f03b36a31fac871e12cf75f35fd0.1501188854.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      0e2bb2bc
    • J
      objtool: Assume unannotated UD2 instructions are dead ends · 649ea4d5
      Josh Poimboeuf 提交于
      Arnd reported some false positive warnings with GCC 7:
      
        drivers/hid/wacom_wac.o: warning: objtool: wacom_bpt3_touch()+0x2a5: stack state mismatch: cfa1=7+8 cfa2=6+16
        drivers/iio/adc/vf610_adc.o: warning: objtool: vf610_adc_calculate_rates() falls through to next function vf610_adc_sample_set()
        drivers/pwm/pwm-hibvt.o: warning: objtool: hibvt_pwm_get_state() falls through to next function hibvt_pwm_remove()
        drivers/pwm/pwm-mediatek.o: warning: objtool: mtk_pwm_config() falls through to next function mtk_pwm_enable()
        drivers/spi/spi-bcm2835.o: warning: objtool: .text: unexpected end of section
        drivers/spi/spi-bcm2835aux.o: warning: objtool: .text: unexpected end of section
        drivers/watchdog/digicolor_wdt.o: warning: objtool: dc_wdt_get_timeleft() falls through to next function dc_wdt_restart()
      
      When GCC 7 detects a potential divide-by-zero condition, it sometimes
      inserts a UD2 instruction for the case where the divisor is zero,
      instead of letting the hardware trap on the divide instruction.
      
      Objtool doesn't consider UD2 to be fatal unless it's annotated with
      unreachable().  So it considers the GCC-generated UD2 to be non-fatal,
      and it tries to follow the control flow past the UD2 and gets
      confused.
      
      Previously, objtool *did* assume UD2 was always a dead end.  That
      changed with the following commit:
      
        d1091c7f ("objtool: Improve detection of BUG() and other dead ends")
      
      The motivation behind that change was that Peter was planning on using
      UD2 for __WARN(), which is *not* a dead end.  However, it turns out
      that some emulators rely on UD2 being fatal, so he ended up using
      'ud0' instead:
      
        9a93848f ("x86/debug: Implement __WARN() using UD0")
      
      For GCC 4.5+, it should be safe to go back to the previous assumption
      that UD2 is fatal, even when it's not annotated with unreachable().
      
      But for pre-4.5 versions of GCC, the unreachable() macro isn't
      supported, so such cases of UD2 need to be explicitly annotated as
      reachable.
      Reported-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Fixes: d1091c7f ("objtool: Improve detection of BUG() and other dead ends")
      Link: http://lkml.kernel.org/r/e57fa9dfede25f79487da8126ee9cdf7b856db65.1501188854.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      649ea4d5
  21. 25 7月, 2017 1 次提交
  22. 18 7月, 2017 2 次提交
    • J
      objtool, x86: Add facility for asm code to provide unwind hints · 39358a03
      Josh Poimboeuf 提交于
      Some asm (and inline asm) code does special things to the stack which
      objtool can't understand.  (Nor can GCC or GNU assembler, for that
      matter.)  In such cases we need a facility for the code to provide
      annotations, so the unwinder can unwind through it.
      
      This provides such a facility, in the form of unwind hints.  They're
      similar to the GNU assembler .cfi* directives, but they give more
      information, and are needed in far fewer places, because objtool can
      fill in the blanks by following branches and adjusting the stack pointer
      for pushes and pops.
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Jiri Slaby <jslaby@suse.cz>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mike Galbraith <efault@gmx.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: live-patching@vger.kernel.org
      Link: http://lkml.kernel.org/r/0f5f3c9104fca559ff4088bece1d14ae3bca52d5.1499786555.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      39358a03
    • J
      objtool: Add ORC unwind table generation · 627fce14
      Josh Poimboeuf 提交于
      Now that objtool knows the states of all registers on the stack for each
      instruction, it's straightforward to generate debuginfo for an unwinder
      to use.
      
      Instead of generating DWARF, generate a new format called ORC, which is
      more suitable for an in-kernel unwinder.  See
      Documentation/x86/orc-unwinder.txt for a more detailed description of
      this new debuginfo format and why it's preferable to DWARF.
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Jiri Slaby <jslaby@suse.cz>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mike Galbraith <efault@gmx.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: live-patching@vger.kernel.org
      Link: http://lkml.kernel.org/r/c9b9f01ba6c5ed2bdc9bb0957b78167fdbf9632e.1499786555.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      627fce14
  23. 08 7月, 2017 1 次提交
    • J
      objtool: Fix sibling call detection logic · 4855022a
      Josh Poimboeuf 提交于
      With some configs, objtool reports the following warning:
      
        arch/x86/kernel/ftrace.o: warning: objtool: ftrace_modify_code_direct()+0x2d: sibling call from callable instruction with modified stack frame
      
      The instruction it's complaining about isn't actually a sibling call.
      It's just a normal jump to an address inside the function.  Objtool
      thought it was a sibling call because the instruction's jump_dest wasn't
      initialized because the function was supposed to be ignored due to its
      use of sync_core().
      
      Objtool ended up validating the function instead of ignoring it because
      it didn't properly recognize a sibling call to the function.  So fix the
      sibling call logic.  Also add a warning to catch ignored functions being
      validated so we'll get a more useful error message next time.
      Reported-by: NMike Galbraith <efault@gmx.de>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/96cc8ecbcdd8cb29ddd783817b4af918a6a171b0.1499437107.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      4855022a
  24. 01 7月, 2017 1 次提交
    • J
      objtool: Silence warnings for functions which use IRET · 2513cbf9
      Josh Poimboeuf 提交于
      Previously, objtool ignored functions which have the IRET instruction
      in them.  That's because it assumed that such functions know what
      they're doing with respect to frame pointers.
      
      With the new "objtool 2.0" changes, it stopped ignoring such functions,
      and started complaining about them:
      
        arch/x86/kernel/alternative.o: warning: objtool: do_sync_core()+0x1b: unsupported instruction in callable function
        arch/x86/kernel/alternative.o: warning: objtool: text_poke()+0x1a8: unsupported instruction in callable function
        arch/x86/kernel/ftrace.o: warning: objtool: do_sync_core()+0x16: unsupported instruction in callable function
        arch/x86/kernel/cpu/mcheck/mce.o: warning: objtool: machine_check_poll()+0x166: unsupported instruction in callable function
        arch/x86/kernel/cpu/mcheck/mce.o: warning: objtool: do_machine_check()+0x147: unsupported instruction in callable function
      
      Silence those warnings for now.  They can be re-enabled later, once we
      have unwind hints which will allow the code to annotate the IRET usages.
      Reported-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Jiri Slaby <jslaby@suse.cz>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: live-patching@vger.kernel.org
      Fixes: baa41469 ("objtool: Implement stack validation 2.0")
      Link: http://lkml.kernel.org/r/20170630140934.mmwtpockvpupahro@trebleSigned-off-by: NIngo Molnar <mingo@kernel.org>
      2513cbf9
  25. 30 6月, 2017 2 次提交
  26. 16 6月, 2017 1 次提交
  27. 20 4月, 2017 1 次提交
  28. 07 3月, 2017 1 次提交
    • J
      objtool: Fix another GCC jump table detection issue · 5c51f4ae
      Josh Poimboeuf 提交于
      Arnd Bergmann reported a (false positive) objtool warning:
      
        drivers/infiniband/sw/rxe/rxe_resp.o: warning: objtool: rxe_responder()+0xfe: sibling call from callable instruction with changed frame pointer
      
      The issue is in find_switch_table().  It tries to find a switch
      statement's jump table by walking backwards from an indirect jump
      instruction, looking for a relocation to the .rodata section.  In this
      case it stopped walking prematurely: the first .rodata relocation it
      encountered was for a variable (resp_state_name) instead of a jump
      table, so it just assumed there wasn't a jump table.
      
      The fix is to ignore any .rodata relocation which refers to an ELF
      object symbol.  This works because the jump tables are anonymous and
      have no symbols associated with them.
      Reported-by: NArnd Bergmann <arnd@arndb.de>
      Tested-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Fixes: 3732710f ("objtool: Improve rare switch jump table pattern detection")
      Link: http://lkml.kernel.org/r/20170302225723.3ndbsnl4hkqbne7a@trebleSigned-off-by: NIngo Molnar <mingo@kernel.org>
      5c51f4ae
  29. 02 3月, 2017 1 次提交
  30. 24 2月, 2017 1 次提交
    • J
      objtool: Improve detection of BUG() and other dead ends · d1091c7f
      Josh Poimboeuf 提交于
      The BUG() macro's use of __builtin_unreachable() via the unreachable()
      macro tells gcc that the instruction is a dead end, and that it's safe
      to assume the current code path will not execute past the previous
      instruction.
      
      On x86, the BUG() macro is implemented with the 'ud2' instruction.  When
      objtool's branch analysis sees that instruction, it knows the current
      code path has come to a dead end.
      
      Peter Zijlstra has been working on a patch to change the WARN macros to
      use 'ud2'.  That patch will break objtool's assumption that 'ud2' is
      always a dead end.
      
      Generally it's best for objtool to avoid making those kinds of
      assumptions anyway.  The more ignorant it is of kernel code internals,
      the better.
      
      So create a more generic way for objtool to detect dead ends by adding
      an annotation to the unreachable() macro.  The annotation stores a
      pointer to the end of the unreachable code path in an '__unreachable'
      section.  Objtool can read that section to find the dead ends.
      Tested-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/41a6d33971462ebd944a1c60ad4bf5be86c17b77.1487712920.git.jpoimboe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      d1091c7f