scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
#!/bin/bash
|
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
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: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2007-07-16 14:41:15 +08:00
|
|
|
# Disassemble the Code: line in Linux oopses
|
|
|
|
# usage: decodecode < oops.file
|
|
|
|
#
|
|
|
|
# options: set env. variable AFLAGS=options to pass options to "as";
|
|
|
|
# e.g., to decode an i386 oops on an x86_64 system, use:
|
|
|
|
# AFLAGS=--32 decodecode < 386.oops
|
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
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew 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: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-14 07:48:14 +08:00
|
|
|
# PC=hex - the PC (program counter) the oops points to
|
2007-07-16 14:41:15 +08:00
|
|
|
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
faultlinenum=1
|
|
|
|
|
2008-01-15 07:18:31 +08:00
|
|
|
cleanup() {
|
2010-01-05 22:57:58 +08:00
|
|
|
rm -f $T $T.s $T.o $T.oo $T.aa $T.dis
|
2008-01-15 07:18:31 +08:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
T=`mktemp` || die "cannot create temp file"
|
2007-07-16 14:41:15 +08:00
|
|
|
code=
|
scripts/decodecode: make it take multiline Code line
In case of running scripts/decodecode without any parameters in order to
give a copy'n'pasted Code line from, for example, email it would parse
only first line of it, while in emails it's split to few.
ie, when you have a file out of oops the Code line looks like
Code: hh hh ... <hh> ... hh\n
When copy'n'paste from, for example, email where sender or some middle
MTA split it, the line looks like:
Code: hh hh ... hh\n
hh ... <hh> ... hh\n
hh hh ... hh\n
The Code line followed by another oops line usually contains characters
out of hex digit + space + < + > set.
So add logic to join this split back if and only if the following lines
have hex digits, or spaces, or '<', or '>' characters. It will be quite
unlikely to have a broken input in well formed Oops or dmesg, thus a
simple regex is being used.
Link: http://lkml.kernel.org/r/20171212100323.33201-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Dave Martin <Dave.Martin@arm.com>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-02-01 08:14:10 +08:00
|
|
|
cont=
|
2007-07-16 14:41:15 +08:00
|
|
|
|
|
|
|
while read i ; do
|
|
|
|
|
|
|
|
case "$i" in
|
|
|
|
*Code:*)
|
|
|
|
code=$i
|
scripts/decodecode: make it take multiline Code line
In case of running scripts/decodecode without any parameters in order to
give a copy'n'pasted Code line from, for example, email it would parse
only first line of it, while in emails it's split to few.
ie, when you have a file out of oops the Code line looks like
Code: hh hh ... <hh> ... hh\n
When copy'n'paste from, for example, email where sender or some middle
MTA split it, the line looks like:
Code: hh hh ... hh\n
hh ... <hh> ... hh\n
hh hh ... hh\n
The Code line followed by another oops line usually contains characters
out of hex digit + space + < + > set.
So add logic to join this split back if and only if the following lines
have hex digits, or spaces, or '<', or '>' characters. It will be quite
unlikely to have a broken input in well formed Oops or dmesg, thus a
simple regex is being used.
Link: http://lkml.kernel.org/r/20171212100323.33201-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Dave Martin <Dave.Martin@arm.com>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-02-01 08:14:10 +08:00
|
|
|
cont=yes
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
[ -n "$cont" ] && {
|
|
|
|
xdump="$(echo $i | grep '^[[:xdigit:]<>[:space:]]\+$')"
|
|
|
|
if [ -n "$xdump" ]; then
|
|
|
|
code="$code $xdump"
|
|
|
|
else
|
|
|
|
cont=
|
|
|
|
fi
|
|
|
|
}
|
2007-07-16 14:41:15 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$code" ]; then
|
2008-01-15 07:18:31 +08:00
|
|
|
rm $T
|
2007-07-16 14:41:15 +08:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $code
|
|
|
|
code=`echo $code | sed -e 's/.*Code: //'`
|
|
|
|
|
2010-01-05 22:57:58 +08:00
|
|
|
width=`expr index "$code" ' '`
|
2010-06-04 01:18:12 +08:00
|
|
|
width=$((($width-1)/2))
|
2010-01-05 22:57:58 +08:00
|
|
|
case $width in
|
|
|
|
1) type=byte ;;
|
|
|
|
2) type=2byte ;;
|
|
|
|
4) type=4byte ;;
|
|
|
|
esac
|
|
|
|
|
2018-12-28 16:31:21 +08:00
|
|
|
if [ -z "$ARCH" ]; then
|
|
|
|
case `uname -m` in
|
|
|
|
aarch64*) ARCH=arm64 ;;
|
|
|
|
arm*) ARCH=arm ;;
|
scripts/decodecode: add support for LoongArch
An example how to invoke decodecode for loongarch64:
$ echo 'Code: 380839f6 380831f9 28412bae <24000ca6>
004081ad 0014cb50 004083e8 02bff34c 58008e91' | \
ARCH=loongarch CROSS_COMPILE=loongarch64-linux-gnu- \
./scripts/decodecode
Code: 380839f6 380831f9 28412bae <24000ca6> 004081ad 0014cb50 004083e8 02bff34c 58008e91
All code
========
0: 380839f6 ldx.w $fp, $t3, $t2
4: 380831f9 ldx.w $s2, $t3, $t0
8: 28412bae ld.h $t2, $s6, 74(0x4a)
c:* 24000ca6 ldptr.w $a2, $a1, 12(0xc) <-- trapping instruction
10: 004081ad slli.w $t1, $t1, 0x0
14: 0014cb50 and $t4, $s3, $t6
18: 004083e8 slli.w $a4, $s8, 0x0
1c: 02bff34c addi.w $t0, $s3, -4(0xffc)
20: 58008e91 beq $t8, $t5, 140(0x8c) # 0xac
Code starting with the faulting instruction
===========================================
0: 24000ca6 ldptr.w $a2, $a1, 12(0xc)
4: 004081ad slli.w $t1, $t1, 0x0
8: 0014cb50 and $t4, $s3, $t6
c: 004083e8 slli.w $a4, $s8, 0x0
10: 02bff34c addi.w $t0, $s3, -4(0xffc)
14: 58008e91 beq $t8, $t5, 140(0x8c) # 0xa0
Link: https://lkml.kernel.org/r/MW4PR84MB3145B99B9677BB7887BB26CD8192A@MW4PR84MB3145.NAMPRD84.PROD.OUTLOOK.COM
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-12-16 14:51:28 +08:00
|
|
|
loongarch*) ARCH=loongarch ;;
|
2018-12-28 16:31:21 +08:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
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
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew 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: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-14 07:48:14 +08:00
|
|
|
# Params: (tmp_file, pc_sub)
|
2010-01-05 22:57:58 +08:00
|
|
|
disas() {
|
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
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew 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: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-14 07:48:14 +08:00
|
|
|
t=$1
|
|
|
|
pc_sub=$2
|
|
|
|
|
|
|
|
${CROSS_COMPILE}as $AFLAGS -o $t.o $t.s > /dev/null 2>&1
|
2010-01-05 22:57:58 +08:00
|
|
|
|
2010-06-04 01:18:12 +08:00
|
|
|
if [ "$ARCH" = "arm" ]; then
|
|
|
|
if [ $width -eq 2 ]; then
|
2010-01-05 22:57:58 +08:00
|
|
|
OBJDUMPFLAGS="-M force-thumb"
|
|
|
|
fi
|
|
|
|
|
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
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew 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: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-14 07:48:14 +08:00
|
|
|
${CROSS_COMPILE}strip $t.o
|
2010-01-05 22:57:58 +08:00
|
|
|
fi
|
|
|
|
|
2018-01-19 08:33:57 +08:00
|
|
|
if [ "$ARCH" = "arm64" ]; then
|
|
|
|
if [ $width -eq 4 ]; then
|
|
|
|
type=inst
|
|
|
|
fi
|
|
|
|
|
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
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew 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: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-14 07:48:14 +08:00
|
|
|
${CROSS_COMPILE}strip $t.o
|
2018-01-19 08:33:57 +08:00
|
|
|
fi
|
|
|
|
|
scripts/decodecode: Add support for RISC-V
RISC-V has some GNU disassembly quirks, e.g. it requires '-D' to
properly disassemble .2byte directives similar to Arm [1]. Further,
GNU objdump groups RISC-V instruction by 2 or 4 byte chunks, instead
doing byte-for-byte.
Add the required switches, and translate from short/word to bytes when
ARCH is "riscv".
An example how to invoke decodecode for RISC-V:
$ echo 'Code: bf45 f793 1007 f7d9 50ef 37af d541 b7d9 7097 00c8 (80e7)
6140' | AFLAGS="-march=rv64imac_zicbom_zihintpause" \
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./scripts/decodecode
Code: bf45 f793 1007 f7d9 50ef 37af d541 b7d9 7097 00c8 (80e7) 6140
All code
========
0: bf45 c.j 0xffffffffffffffb0
2: 1007f793 andi a5,a5,256
6: f7d9 c.bnez a5,0xffffffffffffff94
8: 37af50ef jal ra,0xf5382
c: d541 c.beqz a0,0xffffffffffffff94
e: b7d9 c.j 0xffffffffffffffd4
10: 00c87097 auipc ra,0xc87
14:* 614080e7 jalr ra,1556(ra) # 0xc87624 <-- trapping instruction
Code starting with the faulting instruction
===========================================
0: 614080e7 jalr ra,1556(ra)
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=10263
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20230119074738.708301-3-bjorn@kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-01-19 15:47:38 +08:00
|
|
|
if [ "$ARCH" = "riscv" ]; then
|
|
|
|
OBJDUMPFLAGS="-M no-aliases --section=.text -D"
|
|
|
|
${CROSS_COMPILE}strip $t.o
|
|
|
|
fi
|
|
|
|
|
scripts/decodecode: add support for LoongArch
An example how to invoke decodecode for loongarch64:
$ echo 'Code: 380839f6 380831f9 28412bae <24000ca6>
004081ad 0014cb50 004083e8 02bff34c 58008e91' | \
ARCH=loongarch CROSS_COMPILE=loongarch64-linux-gnu- \
./scripts/decodecode
Code: 380839f6 380831f9 28412bae <24000ca6> 004081ad 0014cb50 004083e8 02bff34c 58008e91
All code
========
0: 380839f6 ldx.w $fp, $t3, $t2
4: 380831f9 ldx.w $s2, $t3, $t0
8: 28412bae ld.h $t2, $s6, 74(0x4a)
c:* 24000ca6 ldptr.w $a2, $a1, 12(0xc) <-- trapping instruction
10: 004081ad slli.w $t1, $t1, 0x0
14: 0014cb50 and $t4, $s3, $t6
18: 004083e8 slli.w $a4, $s8, 0x0
1c: 02bff34c addi.w $t0, $s3, -4(0xffc)
20: 58008e91 beq $t8, $t5, 140(0x8c) # 0xac
Code starting with the faulting instruction
===========================================
0: 24000ca6 ldptr.w $a2, $a1, 12(0xc)
4: 004081ad slli.w $t1, $t1, 0x0
8: 0014cb50 and $t4, $s3, $t6
c: 004083e8 slli.w $a4, $s8, 0x0
10: 02bff34c addi.w $t0, $s3, -4(0xffc)
14: 58008e91 beq $t8, $t5, 140(0x8c) # 0xa0
Link: https://lkml.kernel.org/r/MW4PR84MB3145B99B9677BB7887BB26CD8192A@MW4PR84MB3145.NAMPRD84.PROD.OUTLOOK.COM
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-12-16 14:51:28 +08:00
|
|
|
if [ "$ARCH" = "loongarch" ]; then
|
|
|
|
${CROSS_COMPILE}strip $t.o
|
|
|
|
fi
|
|
|
|
|
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
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew 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: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-14 07:48:14 +08:00
|
|
|
if [ $pc_sub -ne 0 ]; then
|
|
|
|
if [ $PC ]; then
|
|
|
|
adj_vma=$(( $PC - $pc_sub ))
|
|
|
|
OBJDUMPFLAGS="$OBJDUMPFLAGS --adjust-vma=$adj_vma"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $t.o | \
|
|
|
|
grep -v "/tmp\|Disassembly\|\.text\|^$" > $t.dis 2>&1
|
2010-01-05 22:57:58 +08:00
|
|
|
}
|
|
|
|
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
# Match the maximum number of opcode bytes from @op_bytes contained within
|
|
|
|
# @opline
|
|
|
|
#
|
|
|
|
# Params:
|
|
|
|
# @op_bytes: The string of bytes from the Code: line
|
|
|
|
# @opline: The disassembled line coming from objdump
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# The max number of opcode bytes from the beginning of @op_bytes which match
|
|
|
|
# the opcode bytes in the objdump line.
|
|
|
|
get_substr_opcode_bytes_num()
|
|
|
|
{
|
|
|
|
local op_bytes=$1
|
|
|
|
local opline=$2
|
|
|
|
|
|
|
|
local retval=0
|
|
|
|
substr=""
|
|
|
|
|
|
|
|
for opc in $op_bytes;
|
|
|
|
do
|
|
|
|
substr+="$opc"
|
|
|
|
|
scripts/decodecode: Add support for RISC-V
RISC-V has some GNU disassembly quirks, e.g. it requires '-D' to
properly disassemble .2byte directives similar to Arm [1]. Further,
GNU objdump groups RISC-V instruction by 2 or 4 byte chunks, instead
doing byte-for-byte.
Add the required switches, and translate from short/word to bytes when
ARCH is "riscv".
An example how to invoke decodecode for RISC-V:
$ echo 'Code: bf45 f793 1007 f7d9 50ef 37af d541 b7d9 7097 00c8 (80e7)
6140' | AFLAGS="-march=rv64imac_zicbom_zihintpause" \
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./scripts/decodecode
Code: bf45 f793 1007 f7d9 50ef 37af d541 b7d9 7097 00c8 (80e7) 6140
All code
========
0: bf45 c.j 0xffffffffffffffb0
2: 1007f793 andi a5,a5,256
6: f7d9 c.bnez a5,0xffffffffffffff94
8: 37af50ef jal ra,0xf5382
c: d541 c.beqz a0,0xffffffffffffff94
e: b7d9 c.j 0xffffffffffffffd4
10: 00c87097 auipc ra,0xc87
14:* 614080e7 jalr ra,1556(ra) # 0xc87624 <-- trapping instruction
Code starting with the faulting instruction
===========================================
0: 614080e7 jalr ra,1556(ra)
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=10263
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20230119074738.708301-3-bjorn@kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-01-19 15:47:38 +08:00
|
|
|
opcode="$substr"
|
|
|
|
if [ "$ARCH" = "riscv" ]; then
|
|
|
|
opcode=$(echo $opcode | tr ' ' '\n' | tac | tr -d '\n')
|
|
|
|
fi
|
|
|
|
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
# return if opcode bytes do not match @opline anymore
|
scripts/decodecode: Add support for RISC-V
RISC-V has some GNU disassembly quirks, e.g. it requires '-D' to
properly disassemble .2byte directives similar to Arm [1]. Further,
GNU objdump groups RISC-V instruction by 2 or 4 byte chunks, instead
doing byte-for-byte.
Add the required switches, and translate from short/word to bytes when
ARCH is "riscv".
An example how to invoke decodecode for RISC-V:
$ echo 'Code: bf45 f793 1007 f7d9 50ef 37af d541 b7d9 7097 00c8 (80e7)
6140' | AFLAGS="-march=rv64imac_zicbom_zihintpause" \
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./scripts/decodecode
Code: bf45 f793 1007 f7d9 50ef 37af d541 b7d9 7097 00c8 (80e7) 6140
All code
========
0: bf45 c.j 0xffffffffffffffb0
2: 1007f793 andi a5,a5,256
6: f7d9 c.bnez a5,0xffffffffffffff94
8: 37af50ef jal ra,0xf5382
c: d541 c.beqz a0,0xffffffffffffff94
e: b7d9 c.j 0xffffffffffffffd4
10: 00c87097 auipc ra,0xc87
14:* 614080e7 jalr ra,1556(ra) # 0xc87624 <-- trapping instruction
Code starting with the faulting instruction
===========================================
0: 614080e7 jalr ra,1556(ra)
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=10263
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20230119074738.708301-3-bjorn@kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-01-19 15:47:38 +08:00
|
|
|
if ! echo $opline | grep -q "$opcode";
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
# add trailing space
|
|
|
|
substr+=" "
|
|
|
|
retval=$((retval+1))
|
|
|
|
done
|
|
|
|
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return the line number in objdump output to where the IP marker in the Code:
|
|
|
|
# line points to
|
|
|
|
#
|
|
|
|
# Params:
|
|
|
|
# @all_code: code in bytes without the marker
|
|
|
|
# @dis_file: disassembled file
|
|
|
|
# @ip_byte: The byte to which the IP points to
|
|
|
|
get_faultlinenum()
|
|
|
|
{
|
|
|
|
local all_code="$1"
|
|
|
|
local dis_file="$2"
|
|
|
|
|
|
|
|
# num bytes including IP byte
|
|
|
|
local num_bytes_ip=$(( $3 + 1 * $width ))
|
|
|
|
|
|
|
|
# Add the two header lines (we're counting from 1).
|
|
|
|
local retval=3
|
|
|
|
|
|
|
|
# remove marker
|
|
|
|
all_code=$(echo $all_code | sed -e 's/[<>()]//g')
|
|
|
|
|
|
|
|
while read line
|
|
|
|
do
|
|
|
|
get_substr_opcode_bytes_num "$all_code" "$line"
|
|
|
|
ate_opcodes=$?
|
|
|
|
|
|
|
|
if ! (( $ate_opcodes )); then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
num_bytes_ip=$((num_bytes_ip - ($ate_opcodes * $width) ))
|
|
|
|
if (( $num_bytes_ip <= 0 )); then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete matched opcode bytes from all_code. For that, compute
|
|
|
|
# how many chars those opcodes are represented by and include
|
|
|
|
# trailing space.
|
|
|
|
#
|
|
|
|
# a byte is 2 chars, ate_opcodes is also the number of trailing
|
|
|
|
# spaces
|
|
|
|
del_chars=$(( ($ate_opcodes * $width * 2) + $ate_opcodes ))
|
|
|
|
|
|
|
|
all_code=$(echo $all_code | sed -e "s!^.\{$del_chars\}!!")
|
|
|
|
|
|
|
|
let "retval+=1"
|
|
|
|
|
|
|
|
done < $dis_file
|
|
|
|
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
|
2007-07-16 14:41:15 +08:00
|
|
|
marker=`expr index "$code" "\<"`
|
|
|
|
if [ $marker -eq 0 ]; then
|
|
|
|
marker=`expr index "$code" "\("`
|
|
|
|
fi
|
|
|
|
|
2008-12-02 06:21:06 +08:00
|
|
|
touch $T.oo
|
2007-07-16 14:41:15 +08:00
|
|
|
if [ $marker -ne 0 ]; then
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
# How many bytes to subtract from the program counter
|
|
|
|
# in order to get to the beginning virtual address of the
|
|
|
|
# Code:
|
|
|
|
pc_sub=$(( (($marker - 1) / (2 * $width + 1)) * $width ))
|
2008-12-02 06:21:06 +08:00
|
|
|
echo All code >> $T.oo
|
|
|
|
echo ======== >> $T.oo
|
|
|
|
beforemark=`echo "$code"`
|
2010-01-05 22:57:58 +08:00
|
|
|
echo -n " .$type 0x" > $T.s
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
|
2010-01-05 22:57:58 +08:00
|
|
|
echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
|
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
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew 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: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-14 07:48:14 +08:00
|
|
|
disas $T $pc_sub
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
|
2010-01-05 22:57:58 +08:00
|
|
|
cat $T.dis >> $T.oo
|
2007-07-16 14:41:15 +08:00
|
|
|
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
get_faultlinenum "$code" "$T.dis" $pc_sub
|
|
|
|
faultlinenum=$?
|
|
|
|
|
|
|
|
# and fix code at-and-after marker
|
2007-07-16 14:41:15 +08:00
|
|
|
code=`echo "$code" | cut -c$((${marker} + 1))-`
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
|
|
|
|
rm -f $T.o $T.s $T.dis
|
2007-07-16 14:41:15 +08:00
|
|
|
fi
|
scripts/decodecode: improve faulting line determination
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: Borislav Petkov <bp@suse.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-08-08 16:59:28 +08:00
|
|
|
|
2008-12-02 06:21:06 +08:00
|
|
|
echo Code starting with the faulting instruction > $T.aa
|
|
|
|
echo =========================================== >> $T.aa
|
scripts/decodecode: fix faulting instruction no print when opps.file is DOS format
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: weidonghui <weidonghui@allwinnertech.com>
Acked-by: Borislav 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-11-06 04:34:42 +08:00
|
|
|
code=`echo $code | sed -e 's/\r//;s/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'`
|
2010-01-05 22:57:58 +08:00
|
|
|
echo -n " .$type 0x" > $T.s
|
2007-07-16 14:41:15 +08:00
|
|
|
echo $code >> $T.s
|
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
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew 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: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-14 07:48:14 +08:00
|
|
|
disas $T 0
|
2010-01-05 22:57:58 +08:00
|
|
|
cat $T.dis >> $T.aa
|
2008-12-02 06:21:06 +08:00
|
|
|
|
2020-05-08 09:35:53 +08:00
|
|
|
cat $T.oo | sed -e "${faultlinenum}s/^\([^:]*:\)\(.*\)/\1\*\2\t\t<-- trapping instruction/"
|
2008-12-02 06:21:06 +08:00
|
|
|
echo
|
|
|
|
cat $T.aa
|
|
|
|
cleanup
|