• 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.deSigned-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
decodecode 4.54 KB