Skip to content
Snippets Groups Projects
  1. Sep 12, 2022
    • Borislav Petkov's avatar
      scripts/decodecode: improve faulting line determination · 765f2bf0
      Borislav Petkov authored
      There are cases where the IP pointer in a Code: line in an oops doesn't
      point at the beginning of an instruction:
      
      Code: 0f bd c2 e9 a0 cd b5 e4 48 0f bd c2 e9 97 cd b5 e4 0f 1f 80 00 00 00 00 \
      	  e9 8b cd b5 e4 0f 1f 00 66 0f a3 d0 e9 7f cd b5 e4 0f 1f <80> 00 00 00 \
      	  00 0f a3 d0 e9 70 cd b5 e4 48 0f a3 d0 e9 67 cd b5
      
        e9 7f cd b5 e4          jmp    0xffffffffe4b5cda8
        0f 1f 80 00 00 00 00    nopl   0x0(%rax)
      	^^
      
      and the current way of determining the faulting instruction line doesn't
      work because disassembled instructions are counted from the IP byte to
      the end and when that thing points in the middle, the trailing bytes can
      be interpreted as different insns:
      
        Code starting with the faulting instruction
        ===========================================
           0:   80 00 00                addb   $0x0,(%rax)
           3:   00 00                   add    %al,(%rax)
      
      whereas, this is part of
      
      0f 1f 80 00 00 00 00    nopl   0x0(%rax)
      
           5:   0f a3 d0                bt     %edx,%eax
           ...
      
      leading to:
      
        1d:   0f 1f 00                nopl   (%rax)
        20:   66 0f a3 d0             bt     %dx,%ax
        24:*  e9 7f cd b5 e4          jmp    0xffffffffe4b5cda8               <-- trapping instruction
        29:   0f 1f 80 00 00 00 00    nopl   0x0(%rax)
        30:   0f a3 d0                bt     %edx,%eax
      
      which is the wrong faulting instruction.
      
      Change the way the faulting line number is determined by matching the
      opcode bytes from the beginning, leading to correct output:
      
        1d:   0f 1f 00                nopl   (%rax)
        20:   66 0f a3 d0             bt     %dx,%ax
        24:   e9 7f cd b5 e4          jmp    0xffffffffe4b5cda8
        29:*  0f 1f 80 00 00 00 00    nopl   0x0(%rax)                <-- trapping instruction
        30:   0f a3 d0                bt     %edx,%eax
      
      While at it, make decodecode use bash as the interpreter - that thing
      should be present on everything by now. It simplifies the code a lot
      too.
      
      Link: https://lkml.kernel.org/r/20220808085928.29840-1-bp@alien8.de
      
      
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      765f2bf0
  2. Nov 06, 2021
    • weidonghui's avatar
      scripts/decodecode: fix faulting instruction no print when opps.file is DOS format · 75e2f715
      weidonghui authored
      If opps.file is in DOS format, faulting instruction cannot be printed:
      
        / # ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
        / # ./scripts/decodecode < oops.file
        [ 0.734345] Code: d0002881 912f9c21 94067e68 d2800001 (b900003f)
        aarch64-linux-gnu-strip: '/tmp/tmp.5Y9eybnnSi.o': No such file
        aarch64-linux-gnu-objdump: '/tmp/tmp.5Y9eybnnSi.o': No such file
        All code
        ========
           0:   d0002881        adrp    x1, 0x512000
           4:   912f9c21        add     x1, x1, #0xbe7
           8:   94067e68        bl      0x19f9a8
           c:   d2800001        mov     x1, #0x0                        // #0
          10:   b900003f        str     wzr, [x1]
      
        Code starting with the faulting instruction
        ===========================================
      
      Background: The compilation environment is Ubuntu, and the test
      environment is Windows.  Most logs are generated in the Windows
      environment.  In this way, CR (carriage return) will inevitably appear,
      which will affect the use of decodecode in the Ubuntu environment.
      
      The repaired effect is as follows:
      
        / # ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
        / # ./scripts/decodecode < oops.file
        [ 0.734345] Code: d0002881 912f9c21 94067e68 d2800001 (b900003f)
        All code
        ========
           0:   d0002881        adrp    x1, 0x512000
           4:   912f9c21        add     x1, x1, #0xbe7
           8:   94067e68        bl      0x19f9a8
           c:   d2800001        mov     x1, #0x0                        // #0
          10:*  b900003f        str     wzr, [x1]               <-- trapping instruction
      
        Code starting with the faulting instruction
        ===========================================
           0:   b900003f        str     wzr, [x1]
      
      Link: https://lkml.kernel.org/r/20211008064712.926-1-weidonghui@allwinnertech.com
      
      
      Signed-off-by: default avatarweidonghui <weidonghui@allwinnertech.com>
      Acked-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: Marc Zyngier <maz@misterjones.org>
      Cc: Will Deacon <will@kernel.org>
      Cc: Rabin Vincent <rabin@rab.in>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      75e2f715
  3. Oct 14, 2020
    • Borislav Petkov's avatar
      scripts/decodecode: add the capability to supply the program counter · d72e720a
      Borislav Petkov authored
      
      So that comparing with objdump output from vmlinux can ease pinpointing
      where the trapping instruction actually is.  An example is better than a
      thousand words:
      
        $ PC=0xffffffff8329a927 ./scripts/decodecode < ~/tmp/syz/gfs2.splat
        [ 477.379104][T23917] Code: 48 83 ec 28 48 89 3c 24 48 89 54 24 08 e8 c1 b4 4a fe 48 8d bb 00 01 00 00 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 97 05 00 00 48 8b 9b 00 01 00 00 48 85 db 0f 84
        All code
        ========
        ffffffff8329a8fd:       48 83 ec 28             sub    $0x28,%rsp
        ffffffff8329a901:       48 89 3c 24             mov    %rdi,(%rsp)
        ffffffff8329a905:       48 89 54 24 08          mov    %rdx,0x8(%rsp)
        ffffffff8329a90a:       e8 c1 b4 4a fe          callq  0xffffffff81745dd0
        ffffffff8329a90f:       48 8d bb 00 01 00 00    lea    0x100(%rbx),%rdi
        ffffffff8329a916:       48 b8 00 00 00 00 00    movabs $0xdffffc0000000000,%rax
        ffffffff8329a91d:       fc ff df
        ffffffff8329a920:       48 89 fa                mov    %rdi,%rdx
        ffffffff8329a923:       48 c1 ea 03             shr    $0x3,%rdx
        ffffffff8329a927:*      80 3c 02 00             cmpb   $0x0,(%rdx,%rax,1)               <-- trapping instruction
        ffffffff8329a92b:       0f 85 97 05 00 00       jne    0xffffffff8329aec8
        ffffffff8329a931:       48 8b 9b 00 01 00 00    mov    0x100(%rbx),%rbx
        ffffffff8329a938:       48 85 db                test   %rbx,%rbx
        ffffffff8329a93b:       0f                      .byte 0xf
        ffffffff8329a93c:       84                      .byte 0x84
      
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Cc: Marc Zyngier <maz@misterjones.org>
      Cc: Will Deacon <will@kernel.org>
      Cc: Rabin Vincent <rabin@rab.in>
      Link: https://lkml.kernel.org/r/20200930111416.GF6810@zn.tnic
      Link: https://lkml.kernel.org/r/20200929113238.GC21110@zn.tnic
      
      
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      d72e720a
  4. May 08, 2020
  5. Dec 28, 2018
  6. Feb 01, 2018
  7. Jan 19, 2018
  8. Nov 02, 2017
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      
      Reviewed-by: default avatarKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: default avatarPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  9. Apr 29, 2013
    • Borislav Petkov's avatar
      scripts/decodecode: make faulting insn ptr more robust · 18ff44b1
      Borislav Petkov authored
      
      It can accidentally happen that the faulting insn (the exact instruction
      bytes) is repeated a little further on in the trace.  This causes that
      same instruction to be tagged twice, see example below.
      
      What we want to do, however, is to track back from the end of the whole
      disassembly so many lines as the slice which starts with the faulting
      instruction is long.  This leads us to the actual faulting instruction
      and *then* we tag it.
      
      While we're at it, we can drop the sed "g" flag because we address only
      this one line.
      
      Also, if we point to an instruction which changes decoding depending on
      the slice being objdumped, like a Jcc insn, for example, we do not even
      tag it as a faulting instruction because the instruction decode changes
      in the second slice but we use that second format as a regex on the
      fsrst disassembled buffer and more often than not that instruction
      doesn't match.
      
      Again, simply tag the line which is deduced from the original "<>"
      marking we've received from the kernel.
      
      This also solves the pathologic issue of multiple tagging like this:
      
        29:*  0f 0b                   ud2         <-- trapping instruction
        2b:*  0f 0b                   ud2         <-- trapping instruction
        2d:*  0f 0b                   ud2         <-- trapping instruction
      
      Double tagging example:
      
      Code: 34 dd 40 30 ad 81 48 c7 c0 80 f6 00 00 48 8b 3c 30 48 01 c6 b8 ff ff ff ff 48 8d 57 f0 48 39 f7 74 2f 49 8b 4c 24 08 48 8b 47 f0 <48> 39 48 08 75 0e eb 2a 66 90 48 8b 40 f0 48 39 48 08 74 1e 48
      All code
      ========
         0:   34 dd                   xor    $0xdd,%al
         2:   40 30 ad 81 48 c7 c0    xor    %bpl,-0x3f38b77f(%rbp)
         9:   80 f6 00                xor    $0x0,%dh
         c:   00 48 8b                add    %cl,-0x75(%rax)
         f:   3c 30                   cmp    $0x30,%al
        11:   48 01 c6                add    %rax,%rsi
        14:   b8 ff ff ff ff          mov    $0xffffffff,%eax
        19:   48 8d 57 f0             lea    -0x10(%rdi),%rdx
        1d:   48 39 f7                cmp    %rsi,%rdi
        20:   74 2f                   je     0x51
        22:   49 8b 4c 24 08          mov    0x8(%r12),%rcx
        27:   48 8b 47 f0             mov    -0x10(%rdi),%rax
        2b:*  48 39 48 08             cmp    %rcx,0x8(%rax)     <-- trapping instruction
        2f:   75 0e                   jne    0x3f
        31:   eb 2a                   jmp    0x5d
        33:   66 90                   xchg   %ax,%ax
        35:   48 8b 40 f0             mov    -0x10(%rax),%rax
        39:*  48 39 48 08             cmp    %rcx,0x8(%rax)     <-- trapping instruction
        3d:   74 1e                   je     0x5d
        3f:   48                      rex.W
      
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      18ff44b1
  10. Aug 16, 2012
    • Borislav Petkov's avatar
      scripts/decodecode: Fixup trapping instruction marker · 2a95e37c
      Borislav Petkov authored
      
      When dumping "Code: " sections from an oops, the trapping instruction
      %rip points to can be a string copy
      
        2b:*  f3 a5                   rep movsl %ds:(%rsi),%es:(%rdi)
      
      and the line contain a bunch of ":".  Current "cut" selects only the and
      the second field output looks funnily overlaid this:
      
        2b:*  f3 a5                   rep movsl %ds     <-- trapping instruction:(%rsi),%es:(%rdi
      
      Fix this by selecting the remaining fields too.
      
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: linux-kbuild@vger.kernel.org
      Signed-off-by: default avatarBorislav Petkov <borislav.petkov@amd.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2a95e37c
  11. Jun 04, 2010
  12. Feb 02, 2010
    • Rabin Vincent's avatar
      scripts: add ARM support to decodecode · 5358db0b
      Rabin Vincent authored
      
      This patch adds support for decoding ARM oopses to scripts/decodecode.
      The following things are handled:
      
       - ARCH and CROSS_COMPILE environment variables are respected.
      
       - The Code: in x86 oopses is in bytes, while it is in either words (4
         bytes) or halfwords for ARM.
      
       - Some versions of ARM objdump refuse to disassemble instructions
         generated by literal constants (".word 0x...").  The workaround is to
         strip the object file first.
      
       - The faulting instruction is marked (liked so) in ARM, but <like so>
         in x86.
      
       - ARM mnemonics may include characters such as [] which need to be
         escaped before being passed to sed for the "<- trapping instruction"
         substitution.
      
      Signed-off-by: default avatarRabin Vincent <rabin@rab.in>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
      5358db0b
  13. Dec 03, 2008
  14. May 30, 2008
  15. Jan 28, 2008
  16. Jul 16, 2007
Loading