History

scripts/decodecode: add the capability to supply the program counter

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

Borislav Petkov committed 6 years ago

Commit d72e7201 parent 33c5bb31 file · +22 −7Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/decodecode+22−7
@@ -6,6 +6,7 @@ · 5 unmodified lines
6# options: set env. variable AFLAGS=options to pass options to "as";6# options: set env. variable AFLAGS=options to pass options to "as";
7# e.g., to decode an i386 oops on an x86_64 system, use:7# e.g., to decode an i386 oops on an x86_64 system, use:
8# AFLAGS=--32 decodecode < 386.oops8# AFLAGS=--32 decodecode < 386.oops
9# PC=hex - the PC (program counter) the oops points to
9 10
10cleanup() {11cleanup() {
11 rm -f $T $T.s $T.o $T.oo $T.aa $T.dis12 rm -f $T $T.s $T.o $T.oo $T.aa $T.dis
@@ -67,15 +68,19 @@ if [ -z "$ARCH" ]; then · 55 unmodified lines
67 esac68 esac
68fi69fi
69 70
71# Params: (tmp_file, pc_sub)
70disas() {72disas() {
71 ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s > /dev/null 2>&173 t=$1
74 pc_sub=$2
75
76 ${CROSS_COMPILE}as $AFLAGS -o $t.o $t.s > /dev/null 2>&1
72 77
73 if [ "$ARCH" = "arm" ]; then78 if [ "$ARCH" = "arm" ]; then
74 if [ $width -eq 2 ]; then79 if [ $width -eq 2 ]; then
75 OBJDUMPFLAGS="-M force-thumb"80 OBJDUMPFLAGS="-M force-thumb"
76 fi81 fi
77 82
78 ${CROSS_COMPILE}strip $1.o83 ${CROSS_COMPILE}strip $t.o
79 fi84 fi
80 85
81 if [ "$ARCH" = "arm64" ]; then86 if [ "$ARCH" = "arm64" ]; then
@@ -83,11 +88,18 @@ disas() { · 1 unmodified line
83 type=inst88 type=inst
84 fi89 fi
85 90
86 ${CROSS_COMPILE}strip $1.o91 ${CROSS_COMPILE}strip $t.o
87 fi92 fi
88 93
89 ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \94 if [ $pc_sub -ne 0 ]; then
90 grep -v "/tmp\|Disassembly\|\.text\|^$" > $1.dis 2>&195 if [ $PC ]; then
96 adj_vma=$(( $PC - $pc_sub ))
97 OBJDUMPFLAGS="$OBJDUMPFLAGS --adjust-vma=$adj_vma"
98 fi
99 fi
100
101 ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $t.o | \
102 grep -v "/tmp\|Disassembly\|\.text\|^$" > $t.dis 2>&1
91}103}
92 104
93marker=`expr index "$code" "\<"`105marker=`expr index "$code" "\<"`
@@ -95,14 +107,17 @@ if [ $marker -eq 0 ]; then · 1 unmodified line
95 marker=`expr index "$code" "\("`107 marker=`expr index "$code" "\("`
96fi108fi
97 109
110
98touch $T.oo111touch $T.oo
99if [ $marker -ne 0 ]; then112if [ $marker -ne 0 ]; then
113 # 2 opcode bytes and a single space
114 pc_sub=$(( $marker / 3 ))
100 echo All code >> $T.oo115 echo All code >> $T.oo
101 echo ======== >> $T.oo116 echo ======== >> $T.oo
102 beforemark=`echo "$code"`117 beforemark=`echo "$code"`
103 echo -n " .$type 0x" > $T.s118 echo -n " .$type 0x" > $T.s
104 echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s119 echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s
105 disas $T120 disas $T $pc_sub
106 cat $T.dis >> $T.oo121 cat $T.dis >> $T.oo
107 rm -f $T.o $T.s $T.dis122 rm -f $T.o $T.s $T.dis
108 123
@@ -114,7 +129,7 @@ echo =========================================== >> $T.aa · 5 unmodified lines
114code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'`129code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'`
115echo -n " .$type 0x" > $T.s130echo -n " .$type 0x" > $T.s
116echo $code >> $T.s131echo $code >> $T.s
117disas $T132disas $T 0
118cat $T.dis >> $T.aa133cat $T.dis >> $T.aa
119 134
120# (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3,135# (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t